Skip to content

Commit

Permalink
Merge pull request #1 from rickcrawford/master
Browse files Browse the repository at this point in the history
latest code
  • Loading branch information
ltran authored Jan 27, 2017
2 parents e22df00 + 0a32945 commit 0b6cb03
Show file tree
Hide file tree
Showing 11 changed files with 924 additions and 445 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.tags*
.DS_Store
87 changes: 87 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

var CENTRES = {
"annapolis": "annapolis",
"brandon": "brandon",
"broward": "broward",
"century city": "centurycity",
"citrus park": "citruspark",
"countryside": "countryside",
"culver city": "culvercity",
"fashion square": "fashionsquare",
"galleria at roseville": "galleriaatroseville",
"galleria roseville": "galleriaatroseville",
"galleria": "galleriaatroseville",
"roseville": "galleriaatroseville",
"roseville galleria": "galleriaatroseville",
"garden state plaza": "gardenstateplaza",
"garden state": "gardenstateplaza",
"horton plaza": "hortonplaza",
"horton": "hortonplaza",
"meriden": "meriden",
"mission valley": "missionvalley",
"montgomery": "montgomery",
"north county": "northcounty",
"oakridge": "oakridge",
"old orchard": "oldorchard",
"palm desert": "palmdesert",
"plaza bonita": "plazabonita",
"san francisco": "sanfrancisco",
"san francisco centre": "sanfrancisco",
"santa anita": "santaanita",
"sarasota square": "sarasota",
"southcenter": "southcenter",
"southgate": "southgate",
"south shore": "southshore",
"sunrise": "sunrise",
"topanga and the village": "topanga",
"topanga": "topanga",
"trumbull": "trumbull",
"utc": "utc",
"valencia town center": "valencia",
"valley fair": "valleyfair",
"wheaton": "wheaton",
"world trade center": "westfieldworldtradecenter",
"world trade": "westfieldworldtradecenter"
};

var CENTRE_NAMES = [
"annapolis",
"brandon",
"broward",
"century city",
"citrus park",
"countryside",
"culver city",
"fashion square",
"galleria at roseville",
"garden state plaza",
"horton plaza",
"horton",
"meriden",
"mission valley",
"montgomery",
"north county",
"oakridge",
"old orchard",
"palm desert",
"plaza bonita",
"san francisco centre",
"santa anita",
"sarasota square",
"southcenter",
"southgate",
"south shore",
"sunrise",
"topanga and the village",
"trumbull",
"utc",
"valencia town center",
"valley fair",
"wheaton",
"world trade center"
];

module.exports = {
CENTRE_NAMES: CENTRE_NAMES,
CENTRES: CENTRES
}
17 changes: 14 additions & 3 deletions dealer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
var http = require('https');

var getDealsByCentre = function (centreId, callback) {
requestDeals(process.env["WF_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId, function(err, data) {
requestDeals(process.env["WF_DEALS_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&fields=title%2Csubtitle%2Cdescription%2Cstores%2C_links&per_page=3&state=live", function(err, data) {
if (err) {
return callback(err)
}

return callback(err, data)
})
}

var getRetailerDealsByCentre = function (centreId, callback) {
requestDeals(process.env["WF_DEALS_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&fields=_links&per_page=10&state=live", function(err, data) {
if (err) {
return callback(err)
}
Expand All @@ -11,7 +21,7 @@ var getDealsByCentre = function (centreId, callback) {
}

var getDealsByCentreByStore = function (centreId, storeId, callback) {
requestDeals(process.env["WF_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&store_id=" + storeId, function(err, data) {
requestDeals(process.env["WF_DEALS_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&store_id=" + storeId + "&fields=title%2Csubtitle%2Cdescription%2Cstores%2C_links&per_page=3&state=live", function(err, data) {
if (err) {
return callback(err)
}
Expand All @@ -22,7 +32,7 @@ var getDealsByCentreByStore = function (centreId, storeId, callback) {
}

var getDealsByCentreByRetailer = function (centreId, retailerID, callback) {
requestDeals(process.env["WF_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&retailer_id=" + retailerId, function(err, data) {
requestDeals(process.env["WF_DEALS_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&retailer_id=" + retailerId + "&fields=title%2Csubtitle%2Cdescription%2Cstores%2C_links&per_page=3&state=live", function(err, data) {
if (err) {
return callback(err)
}
Expand Down Expand Up @@ -64,4 +74,5 @@ module.exports = {
getDealsByCentre : getDealsByCentre,
getDealsByCentreByStore : getDealsByCentreByStore,
getDealsByCentreByRetailer : getDealsByCentreByRetailer,
getRetailerDealsByCentre: getRetailerDealsByCentre,
}
44 changes: 44 additions & 0 deletions events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var http = require('https');

var getEventsByCenter = function (centreId, callback) {
requestEvents(process.env["WF_EVENTS_API_ENDPOINT"] + "?api_key=" + process.env["WF_API_KEY"], "&centre_id=" + centreId + "&fields=name%2Cdescription%2Clocations&per_page=3&status=active", function(err, data) {
if (err) {
return callback(err)
}

return callback(err, data)
})
}

var requestEvents = function (endpoint, queryString, callback) {
http.get(endpoint + queryString, function (res) {
var responseString = '';
console.log('Status Code: ' + res.statusCode);

if (res.statusCode != 200) {
callback(new Error("Non 200 Response"));
}

res.on('data', function (data) {
responseString += data;
});

res.on('end', function () {
var responseObject = JSON.parse(responseString);

if (responseObject.error) {
console.log("NOAA error: " + responseObject.error.message);
callback(new Error(responseObject.error.message));
} else {
callback(null, responseObject);
}
});
}).on('error', function (e) {
console.log("Communications error: " + e.message);
callback(new Error(e.message));
});
}

module.exports = {
getEventsByCenter : getEventsByCenter
}
Loading

0 comments on commit 0b6cb03

Please sign in to comment.