Created
July 6, 2017 17:44
-
-
Save rafa-acioly/88262b3c509d1a700031067453a0427d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import WoocommerceAPI from 'npm:woocommerce-api'; | |
import sweetAlert from 'npm:sweetalert2'; | |
export default Ember.Route.extend({ | |
model () { | |
return this.store.createRecord('api-auth'); | |
}, | |
actions: { | |
validateData (keys) { | |
const woocommerce = new WoocommerceAPI({ | |
url: 'http://wc-project.dev/', // keys.get('url'), | |
consumerKey: 'ck_e2f13f8e29df209a0d888213b6708f927784c7ac', // keys.get('consumerKey'), | |
consumerSecret: 'cs_3bef0170082a94a412ae0316c03969564a96ed10', // keys.get('consumerSecret'), | |
wpAPI: true, | |
version: 'wc/v2' | |
}); | |
this.controller.set('isLoading', true); | |
woocommerce.get(`products`, (err, data, res) => { | |
let response = JSON.parse(res); | |
console.log(response); | |
if (response.hasOwnProperty('data') && response.data.status !== 200) { | |
sweetAlert({ | |
title: 'Ops!', | |
text: response.message, | |
type: 'error', | |
confirmButtonText: 'Entendi' | |
}); | |
} else { | |
this.controller.set('isValidApiData', true); | |
this.controller.set('alertMessage', 'Dados válidados com sucesso!'); | |
this.controller.set('alertType', 'is-info'); | |
this.controller.set('showAlert', true); | |
} | |
this.controller.set('isLoading', false); | |
}) | |
}, | |
saveData (keys) { | |
this.controller.set('showAlert', false); | |
keys.userId = this.get('session.currentUser.uid'); | |
keys.save().then(() => { | |
sweetAlert({ | |
title: 'Pronto!', | |
text: 'Dados salvos com sucesso!', | |
type: 'success' | |
}); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment