with
with
with
Seasoned start-up software developer.
Co-founder & Lead (read: only) developer @ FoKo.
Traditionally are web apps.
Offline/Service worker with node.js
Registered shopify app makes HTTP requests.
Read the documentation.
Read it again.
And read it again.
Are you the App you say you are?
Each Shopify customer must give you permission.
Shopify Apps use OAuth 2.0.
You get a token. Keep that token.
DRY approach - to an extent.
Get shop info.
var requestData = {
hostname: shopDomain,
path: '/admin/shop.json',
method: 'GET',
headers: {
'X-Shopify-Access-Token': token,
'Expect:': ''
}
};
var https = require('https');
var req = https.request(requestData, function(res) {
res.on('data', function(){
// collect data
});
res.on('end', function(){
// check for http statusCodes, etc
});
});
req.on('error', function(e) {
// handle error in making request
});
req.end();
var ShopifyAPI = require('shopify-node-promise');
var api = new ShopifyAPI(shopDomain, token);
api.get("/admin/shop.json").then(function(result){
console.log(result);
});
Purists may not like the URL Path being repeated.
All comes back to following the API docs.
I use promises
api.get("/admin/shop.json").then(function(result){
console.log(result);
}, function(e){
console.error(e);
});
api.get("/admin/shop.json").then(function(result){
shop = result;
return api.get("/admin/customers.json");
}).then(function(result){
customers = result;
// save to local datastore
return data.save(shop, customers);
}).then(function(saveResults){
console.log('All Passed!');
}, function(e){
console.error(e);
};
Group a set of API calls together.
Retry on certain errors.
Only continue when they pass.
Organizes business logic by procedures where each procedure handles a single request...
Finding the right balance of code-coverage.
Integration is high-level, unit is low-level.
Integration typically do not use mock objects.
mocha
&
require("chai")
describe('ShopifyAPI.get', function() {
it('should return shop object', function(done) {
shopifyAPI.get("/admin/shop.json").then(function(result) {
assert.equal(result.data.shop.name, config.shopName);
done();
}, function(error) { done(error); });
});