Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

wire repositories up to remote server instance

  • Loading branch information...
commit 3e11e1c4f97f6c32fb0cfac5a33147e1a7b27b24 1 parent 628464e
Seth Carney authored
Showing with 33 additions and 17 deletions.
  1. +19 −2 repositories/orders.js
  2. +14 −15 repositories/products.js
View
21 repositories/orders.js
@@ -1,8 +1,25 @@
-module.exports = function(){
+var request = require('request');
+
+var makeRequest = function(options, cb) {
+ request(options, function(err, res, body) {
+ if (err !== null) {
+ cb(err);
+ } else if (res.statusCode !== 200 && res.statusCode !== 201) {
+ cb(res.statusCode + ": " + body);
+ } else {
+ cb(null, body);
+ }
+ });
+};
+
+module.exports = function(config) {
var self = this;
+ var baseUrl = config.serverUrl;
self.find = function(cb){
- cb([]);
+ var url = baseUrl + '/orders';
+ var options = { json: true, method: 'get', url: url };
+ makeRequest(options, cb);
};
self.add = function(order, cb){
View
29 repositories/products.js
@@ -1,32 +1,31 @@
var request = require('request');
-var respond = function(cb) {
- if (err !== null) return
+var makeRequest = function(url, cb) {
+ var options = { json: true, method: 'get', url: url };
+ request(options, function(err, res, body) {
+ if (err !== null) {
+ cb(err);
+ } else if (res.statusCode !== 200 && res.statusCode !== 201) {
+ cb(res.statusCode + ": " + body);
+ } else {
+ cb(null, body);
+ }
+ });
};
module.exports = function(config) {
var self = this;
var baseUrl = config.serverUrl;
+ var baseOptions = { json: true, method: 'get' };
self.find = function(page, pageSize, cb){
var url = baseUrl + '/products';
- var options = {url: url, json: true, method: 'get'};
- request(options, function(err, res, body){
- if (err !== null) return cb(err);
- cb(null, body);
- });
+ makeRequest(url, cb);
};
self.get = function(id, cb){
var url = baseUrl + '/product/' + id;
- var options = {url: url, json: true, method: 'get'};
- request(options, function(err, res, body){
- if (err !== null) {
- cb(err);
- } else {
- cb(null, body);
- }
- });
+ makeRequest(url, cb);
};
return this;
Please sign in to comment.
Something went wrong with that request. Please try again.