From ccbeb4d54a8e1a3af95004969f4b06a579b78bff Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 28 Jul 2016 15:50:44 -0700 Subject: [PATCH 01/46] simplified npm scripts via cross-env --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 074d449..8a90823 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,9 @@ "description": "SDK for the Ticketmaster Open Platform", "main": "index.js", "scripts": { - "build": "webpack && NODE_ENV=prod webpack", + "build": "webpack && npm run prod", "dev": "webpack", - "prod": "NODE_ENV=prod webpack", - "win-prod": "set NODE_ENV=prod && webpack", + "prod": "cross-env NODE_ENV=prod webpack", "test": "mocha --recursive", "postversion": "./scripts/post-release.sh" }, @@ -25,12 +24,13 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { - "webpack": "^1.13.1", - "json-loader": "^0.5.4", "chai": "3.0.0", + "cross-env": "^2.0.0", "inherits": "^2.0.1", + "json-loader": "^0.5.4", "mocha": "2.2.5", - "nock": "2.6.0" + "nock": "2.6.0", + "webpack": "^1.13.1" }, "dependencies": { "bluebird": "2.9.30", From d67a5d51556ec85f4bc93d7a7efc5d0d5e194d9d Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 28 Jul 2016 16:36:46 -0700 Subject: [PATCH 02/46] Updated dependencies and amended tests in response --- lib/discovery/v1/attraction/find.js | 6 +++--- lib/discovery/v1/category/find.js | 6 +++--- lib/discovery/v1/event/all.js | 6 +++--- lib/discovery/v1/event/find.js | 6 +++--- lib/discovery/v1/venue/find.js | 6 +++--- lib/helpers/result_helper.js | 8 ++++---- package.json | 10 +++++----- test/commerce/v2/offer/find.js | 17 +++++++++-------- 8 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lib/discovery/v1/attraction/find.js b/lib/discovery/v1/attraction/find.js index f37376f..e24ad84 100644 --- a/lib/discovery/v1/attraction/find.js +++ b/lib/discovery/v1/attraction/find.js @@ -8,11 +8,11 @@ module.exports = function(apiKey, accessToken) { url: config.baseURL + '/discovery/v1/attractions/' + attractionId + '?apikey=' + apiKey, method: 'GET' }) - .spread(function (response, body) { + .then(function (response) { if(response.statusCode === 200) { - return JSON.parse(body); + return JSON.parse(response.body); } else { - parsedBody = JSON.parse(body); + parsedBody = JSON.parse(response.body); return Promise.reject(parsedBody); } }); diff --git a/lib/discovery/v1/category/find.js b/lib/discovery/v1/category/find.js index 47bf551..e310f05 100644 --- a/lib/discovery/v1/category/find.js +++ b/lib/discovery/v1/category/find.js @@ -8,11 +8,11 @@ module.exports = function(apiKey, accessToken) { url: config.baseURL + '/discovery/v1/categories/' + categoryId + '?apikey=' + apiKey, method: 'GET' }) - .spread(function (response, body) { + .then(function (response) { if(response.statusCode === 200) { - return JSON.parse(body); + return JSON.parse(response.body); } else { - parsedBody = JSON.parse(body); + parsedBody = JSON.parse(response.body); return Promise.reject(parsedBody); } }); diff --git a/lib/discovery/v1/event/all.js b/lib/discovery/v1/event/all.js index 3a91476..25ae213 100644 --- a/lib/discovery/v1/event/all.js +++ b/lib/discovery/v1/event/all.js @@ -12,12 +12,12 @@ module.exports = function(apiKey, accessToken) { method: 'GET', qs: options }) - .spread(function (response, body) { + .then(function (response) { if(response.statusCode === 200) { - var result = JSON.parse(body); + var result = JSON.parse(response.body); return result._embedded.events; } else { - parsedBody = JSON.parse(body); + parsedBody = JSON.parse(response.body); return Promise.reject(parsedBody); } }); diff --git a/lib/discovery/v1/event/find.js b/lib/discovery/v1/event/find.js index 1682448..fb8cd19 100644 --- a/lib/discovery/v1/event/find.js +++ b/lib/discovery/v1/event/find.js @@ -8,11 +8,11 @@ module.exports = function(apiKey, accessToken) { url: config.baseURL + '/discovery/v1/events/' + eventId + '?apikey=' + apiKey, method: 'GET' }) - .spread(function (response, body) { + .then(function (response) { if(response.statusCode === 200) { - return JSON.parse(body); + return JSON.parse(response.body); } else { - parsedBody = JSON.parse(body); + parsedBody = JSON.parse(response.body); return Promise.reject(parsedBody); } }); diff --git a/lib/discovery/v1/venue/find.js b/lib/discovery/v1/venue/find.js index 3ded796..29f795f 100644 --- a/lib/discovery/v1/venue/find.js +++ b/lib/discovery/v1/venue/find.js @@ -8,11 +8,11 @@ module.exports = function(apiKey, accessToken) { url: config.baseURL + '/discovery/v1/venues/' + venueId + '?apikey=' + apiKey, method: 'GET' }) - .spread(function (response, body) { + .then(function (response) { if(response.statusCode === 200) { - return JSON.parse(body); + return JSON.parse(response.body); } else { - parsedBody = JSON.parse(body); + parsedBody = JSON.parse(response.body); return Promise.reject(parsedBody); } }); diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index 554aad9..f6d7043 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -29,9 +29,9 @@ var getData = function(obj) { method: obj.method || 'GET', qs: obj.qs }) - .spread(function (response, body) { + .then(function (response, body) { if(response.statusCode === 200) { - var result = JSON.parse(body); + var result = JSON.parse(response.body); if (obj.url[2]) { return result; } else { @@ -42,7 +42,7 @@ var getData = function(obj) { }); } } else { - return Promise.reject(JSON.parse(body)); + return Promise.reject(JSON.parse(response.body)); } }); }; @@ -123,4 +123,4 @@ Result.prototype.isLastPage = function () { * Module interface * @type {getData} */ -module.exports = getData; \ No newline at end of file +module.exports = getData; diff --git a/package.json b/package.json index 8a90823..4397b07 100644 --- a/package.json +++ b/package.json @@ -24,17 +24,17 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { - "chai": "3.0.0", + "chai": "3.5.0", "cross-env": "^2.0.0", "inherits": "^2.0.1", "json-loader": "^0.5.4", - "mocha": "2.2.5", - "nock": "2.6.0", + "mocha": "2.5.3", + "nock": "8.0.0", "webpack": "^1.13.1" }, "dependencies": { - "bluebird": "2.9.30", - "request": "2.58.0" + "bluebird": "3.4.1", + "request": "2.74.0" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" } diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index be05f18..335ccee 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -9,16 +9,17 @@ describe('commerce.v2.offer.find', function() { nockBack.fixtures = './test/fixtures/commerce/v2' }); - describe('success', function() { - it('should find offers', function(done) { - nockBack('offer/find-200.json', {}, function(nockDone) { + describe('success', function () { + it('should find offers', function (done) { + nockBack('offer/find-200.json', {}, function (nockDone) { var find = Find('mock-api-key'); + find('vvG1iZKU5jIxKX') - .then(function(result) { - result.limits.max.should.equal(14); - nockDone(); - done(); - }); + .then(function (result) { + result.limits.max.should.equal(14); + nockDone(); + done(); + }); }); }); }); From 2c2d6fea1958889b271190d12b54e0b9c50fe95d Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 28 Jul 2016 21:20:10 -0700 Subject: [PATCH 03/46] Adds ESLint and tweaked Standard config, adapts source to satisfy rules --- .eslintrc | 7 +++++ lib/commerce/v2/index.js | 2 +- lib/commerce/v2/offer/find.js | 2 +- lib/commerce/v2/offer/index.js | 4 +-- lib/discovery/index.js | 4 +-- lib/discovery/v1/attraction/find.js | 22 ++++++++-------- lib/discovery/v1/attraction/index.js | 2 +- lib/discovery/v1/attraction/parse_response.js | 2 +- lib/discovery/v1/category/find.js | 24 ++++++++--------- lib/discovery/v1/category/index.js | 2 +- lib/discovery/v1/category/parse_response.js | 2 +- lib/discovery/v1/event/all.js | 23 ++++++++-------- lib/discovery/v1/event/find.js | 24 ++++++++--------- lib/discovery/v1/event/index.js | 8 +++--- lib/discovery/v1/event/parse_response.js | 2 +- lib/discovery/v1/index.js | 8 +++--- lib/discovery/v1/venue/find.js | 24 ++++++++--------- lib/discovery/v1/venue/index.js | 2 +- lib/discovery/v1/venue/parse_response.js | 2 +- lib/discovery/v2/attraction/all.js | 4 +-- lib/discovery/v2/attraction/find.js | 4 +-- lib/discovery/v2/attraction/index.js | 6 ++--- lib/discovery/v2/attraction/parse_response.js | 2 +- lib/discovery/v2/classification/all.js | 4 +-- lib/discovery/v2/classification/find.js | 4 +-- lib/discovery/v2/classification/index.js | 6 ++--- .../v2/classification/parse_response.js | 2 +- lib/discovery/v2/event/all.js | 8 +++--- lib/discovery/v2/event/find.js | 4 +-- lib/discovery/v2/event/index.js | 8 +++--- lib/discovery/v2/event/parse_response.js | 2 +- lib/discovery/v2/genre/parse_response.js | 2 +- lib/discovery/v2/index.js | 6 ++--- lib/discovery/v2/segment/parse_response.js | 2 +- lib/discovery/v2/subgenre/parse_response.js | 2 +- lib/discovery/v2/venue/find.js | 4 +-- lib/discovery/v2/venue/index.js | 2 +- lib/discovery/v2/venue/parse_response.js | 2 +- lib/helpers/result_helper.js | 26 +++++++++---------- package.json | 7 ++++- 40 files changed, 142 insertions(+), 131 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..30d2f1d --- /dev/null +++ b/.eslintrc @@ -0,0 +1,7 @@ +{ + "extends": "standard", + "rules": { + "semi": [2, "always"], + "space-before-function-paren": [2, "never"] + } +} diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js index 16ffea7..b2d3f45 100644 --- a/lib/commerce/v2/index.js +++ b/lib/commerce/v2/index.js @@ -4,4 +4,4 @@ module.exports = function(apiKey, accessToken) { return { offer: offer(apiKey, accessToken) }; }; -module.exports.offer = offer; \ No newline at end of file +module.exports.offer = offer; diff --git a/lib/commerce/v2/offer/find.js b/lib/commerce/v2/offer/find.js index 97307f2..35978cb 100644 --- a/lib/commerce/v2/offer/find.js +++ b/lib/commerce/v2/offer/find.js @@ -12,5 +12,5 @@ module.exports = function(apiKey, accessToken) { qs: {apikey: apiKey} }; return getData(params); - } + }; }; diff --git a/lib/commerce/v2/offer/index.js b/lib/commerce/v2/offer/index.js index a6a039b..37d25ab 100644 --- a/lib/commerce/v2/offer/index.js +++ b/lib/commerce/v2/offer/index.js @@ -1,7 +1,7 @@ var find = require('./find'); module.exports = function(apiKey, accessToken) { - return { find: find(apiKey, accessToken) } + return { find: find(apiKey, accessToken) }; }; -module.exports.find = find; \ No newline at end of file +module.exports.find = find; diff --git a/lib/discovery/index.js b/lib/discovery/index.js index 7043c53..b536b75 100644 --- a/lib/discovery/index.js +++ b/lib/discovery/index.js @@ -1,5 +1,5 @@ -var v1 = require('./v1'), - v2 = require('./v2'); +var v1 = require('./v1'); +var v2 = require('./v2'); module.exports = function(apiKey, accessToken) { return { diff --git a/lib/discovery/v1/attraction/find.js b/lib/discovery/v1/attraction/find.js index e24ad84..ef73e3c 100644 --- a/lib/discovery/v1/attraction/find.js +++ b/lib/discovery/v1/attraction/find.js @@ -1,6 +1,6 @@ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); +var config = require('../../../../config'); module.exports = function(apiKey, accessToken) { return function(attractionId) { @@ -8,13 +8,13 @@ module.exports = function(apiKey, accessToken) { url: config.baseURL + '/discovery/v1/attractions/' + attractionId + '?apikey=' + apiKey, method: 'GET' }) - .then(function (response) { - if(response.statusCode === 200) { - return JSON.parse(response.body); - } else { - parsedBody = JSON.parse(response.body); - return Promise.reject(parsedBody); - } - }); - } + .then(function(response) { + var parsedBody = JSON.parse(response.body); + if (response.statusCode === 200) { + return parsedBody; + } else { + return Promise.reject(parsedBody); + } + }); + }; }; diff --git a/lib/discovery/v1/attraction/index.js b/lib/discovery/v1/attraction/index.js index 10ab67f..e697cd2 100644 --- a/lib/discovery/v1/attraction/index.js +++ b/lib/discovery/v1/attraction/index.js @@ -3,7 +3,7 @@ var find = require('./find'); module.exports = function(apiKey, accessToken) { return { find: find(apiKey, accessToken) - } + }; }; module.exports.find = find; diff --git a/lib/discovery/v1/attraction/parse_response.js b/lib/discovery/v1/attraction/parse_response.js index df23cf3..71f4226 100644 --- a/lib/discovery/v1/attraction/parse_response.js +++ b/lib/discovery/v1/attraction/parse_response.js @@ -1,7 +1,7 @@ var Attraction = require('./model'); module.exports = function(response) { - var attraction = new Attraction; + var attraction = new Attraction(); attraction.id = response.id; attraction.name = response.name; diff --git a/lib/discovery/v1/category/find.js b/lib/discovery/v1/category/find.js index e310f05..7806f7a 100644 --- a/lib/discovery/v1/category/find.js +++ b/lib/discovery/v1/category/find.js @@ -1,20 +1,20 @@ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); +var config = require('../../../../config'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(categoryId) { return requestAsync({ url: config.baseURL + '/discovery/v1/categories/' + categoryId + '?apikey=' + apiKey, method: 'GET' }) - .then(function (response) { - if(response.statusCode === 200) { - return JSON.parse(response.body); - } else { - parsedBody = JSON.parse(response.body); - return Promise.reject(parsedBody); - } - }); - } + .then(function(response) { + var parsedBody = JSON.parse(response.body); + if (response.statusCode === 200) { + return parsedBody; + } else { + return Promise.reject(parsedBody); + } + }); + }; }; diff --git a/lib/discovery/v1/category/index.js b/lib/discovery/v1/category/index.js index 10ab67f..e697cd2 100644 --- a/lib/discovery/v1/category/index.js +++ b/lib/discovery/v1/category/index.js @@ -3,7 +3,7 @@ var find = require('./find'); module.exports = function(apiKey, accessToken) { return { find: find(apiKey, accessToken) - } + }; }; module.exports.find = find; diff --git a/lib/discovery/v1/category/parse_response.js b/lib/discovery/v1/category/parse_response.js index b1744db..4470a27 100644 --- a/lib/discovery/v1/category/parse_response.js +++ b/lib/discovery/v1/category/parse_response.js @@ -1,7 +1,7 @@ var Category = require('./model'); module.exports = function(response) { - var category = new Category; + var category = new Category(); category.id = response.id; category.name = response.name; diff --git a/lib/discovery/v1/event/all.js b/lib/discovery/v1/event/all.js index 25ae213..540a7ee 100644 --- a/lib/discovery/v1/event/all.js +++ b/lib/discovery/v1/event/all.js @@ -1,6 +1,6 @@ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); +var config = require('../../../../config'); module.exports = function(apiKey, accessToken) { return function(options) { @@ -12,14 +12,13 @@ module.exports = function(apiKey, accessToken) { method: 'GET', qs: options }) - .then(function (response) { - if(response.statusCode === 200) { - var result = JSON.parse(response.body); - return result._embedded.events; - } else { - parsedBody = JSON.parse(response.body); - return Promise.reject(parsedBody); - } - }); - } + .then(function(response) { + var parsedBody = JSON.parse(response.body); + if (response.statusCode === 200) { + return parsedBody._embedded.events; + } else { + return Promise.reject(parsedBody); + } + }); + }; }; diff --git a/lib/discovery/v1/event/find.js b/lib/discovery/v1/event/find.js index fb8cd19..b31993a 100644 --- a/lib/discovery/v1/event/find.js +++ b/lib/discovery/v1/event/find.js @@ -1,20 +1,20 @@ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); +var config = require('../../../../config'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(eventId) { return requestAsync({ url: config.baseURL + '/discovery/v1/events/' + eventId + '?apikey=' + apiKey, method: 'GET' }) - .then(function (response) { - if(response.statusCode === 200) { - return JSON.parse(response.body); - } else { - parsedBody = JSON.parse(response.body); - return Promise.reject(parsedBody); - } - }); - } + .then(function(response) { + var parsedBody = JSON.parse(response.body); + if (response.statusCode === 200) { + return parsedBody; + } else { + return Promise.reject(parsedBody); + } + }); + }; }; diff --git a/lib/discovery/v1/event/index.js b/lib/discovery/v1/event/index.js index aef3fb6..99c602b 100644 --- a/lib/discovery/v1/event/index.js +++ b/lib/discovery/v1/event/index.js @@ -1,12 +1,12 @@ -var all = require('./all'), - find = require('./find'); +var all = require('./all'); +var find = require('./find'); module.exports = function(apiKey, accessToken) { return { all: all(apiKey, accessToken), find: find(apiKey, accessToken) - } + }; }; -module.exports.all = all; +module.exports.all = all; module.exports.find = find; diff --git a/lib/discovery/v1/event/parse_response.js b/lib/discovery/v1/event/parse_response.js index f71d1e5..a97d50c 100644 --- a/lib/discovery/v1/event/parse_response.js +++ b/lib/discovery/v1/event/parse_response.js @@ -4,7 +4,7 @@ var AttractionParser = require('../attraction/parse_response'); var VenueParser = require('../venue/parse_response'); module.exports = function(response) { - var event = new Event; + var event = new Event(); event.id = response.id; event.name = response.name; diff --git a/lib/discovery/v1/index.js b/lib/discovery/v1/index.js index c984c51..fcaf64a 100644 --- a/lib/discovery/v1/index.js +++ b/lib/discovery/v1/index.js @@ -1,7 +1,7 @@ -var attraction = require('./attraction'), - category = require('./category'), - event = require('./event'), - venue = require('./venue'); +var attraction = require('./attraction'); +var category = require('./category'); +var event = require('./event'); +var venue = require('./venue'); module.exports = function(apiKey, accessToken) { return { diff --git a/lib/discovery/v1/venue/find.js b/lib/discovery/v1/venue/find.js index 29f795f..9462782 100644 --- a/lib/discovery/v1/venue/find.js +++ b/lib/discovery/v1/venue/find.js @@ -1,20 +1,20 @@ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); +var config = require('../../../../config'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(venueId) { return requestAsync({ url: config.baseURL + '/discovery/v1/venues/' + venueId + '?apikey=' + apiKey, method: 'GET' }) - .then(function (response) { - if(response.statusCode === 200) { - return JSON.parse(response.body); - } else { - parsedBody = JSON.parse(response.body); - return Promise.reject(parsedBody); - } - }); - } + .then(function(response) { + var parsedBody = JSON.parse(response.body); + if (response.statusCode === 200) { + return parsedBody; + } else { + return Promise.reject(parsedBody); + } + }); + }; }; diff --git a/lib/discovery/v1/venue/index.js b/lib/discovery/v1/venue/index.js index bdb6540..9ea812b 100644 --- a/lib/discovery/v1/venue/index.js +++ b/lib/discovery/v1/venue/index.js @@ -3,5 +3,5 @@ var find = require('./find'); module.exports = function(apiKey, accessToken) { return { find: find(apiKey, accessToken) - } + }; }; diff --git a/lib/discovery/v1/venue/parse_response.js b/lib/discovery/v1/venue/parse_response.js index 574ffb3..8910a75 100644 --- a/lib/discovery/v1/venue/parse_response.js +++ b/lib/discovery/v1/venue/parse_response.js @@ -1,7 +1,7 @@ var Venue = require('./model'); module.exports = function(response) { - var venue = new Venue; + var venue = new Venue(); venue.id = response.id; venue.name = response.name; diff --git a/lib/discovery/v2/attraction/all.js b/lib/discovery/v2/attraction/all.js index 584fb68..edc4847 100644 --- a/lib/discovery/v2/attraction/all.js +++ b/lib/discovery/v2/attraction/all.js @@ -2,7 +2,7 @@ var getData = require('../../../helpers/result_helper'); module.exports = function(apiKey, accessToken) { return function(options) { - var options = options || {}; + options = options || {}; options.apikey = apiKey; var params = { url: [ @@ -12,5 +12,5 @@ module.exports = function(apiKey, accessToken) { qs: options }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/attraction/find.js b/lib/discovery/v2/attraction/find.js index 0c1436e..fae89e2 100644 --- a/lib/discovery/v2/attraction/find.js +++ b/lib/discovery/v2/attraction/find.js @@ -1,6 +1,6 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(attractionId) { var params = { url: [ @@ -11,5 +11,5 @@ module.exports = function(apiKey, accessToken) { qs: {apikey: apiKey} }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/attraction/index.js b/lib/discovery/v2/attraction/index.js index 9694399..99c602b 100644 --- a/lib/discovery/v2/attraction/index.js +++ b/lib/discovery/v2/attraction/index.js @@ -1,11 +1,11 @@ -var all = require('./all'), - find = require('./find'); +var all = require('./all'); +var find = require('./find'); module.exports = function(apiKey, accessToken) { return { all: all(apiKey, accessToken), find: find(apiKey, accessToken) - } + }; }; module.exports.all = all; diff --git a/lib/discovery/v2/attraction/parse_response.js b/lib/discovery/v2/attraction/parse_response.js index 8c95cc7..2d509c5 100644 --- a/lib/discovery/v2/attraction/parse_response.js +++ b/lib/discovery/v2/attraction/parse_response.js @@ -1,7 +1,7 @@ var Attraction = require('./model'); module.exports = function(response) { - var attraction = new Attraction; + var attraction = new Attraction(); attraction.id = response.id; attraction.name = response.name; diff --git a/lib/discovery/v2/classification/all.js b/lib/discovery/v2/classification/all.js index 9fbc224..e3f71ed 100644 --- a/lib/discovery/v2/classification/all.js +++ b/lib/discovery/v2/classification/all.js @@ -1,6 +1,6 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(options) { options = options || {}; options.apikey = apiKey; @@ -12,5 +12,5 @@ module.exports = function(apiKey, accessToken) { qs: options }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/classification/find.js b/lib/discovery/v2/classification/find.js index 2a1557b..f2e6fdc 100644 --- a/lib/discovery/v2/classification/find.js +++ b/lib/discovery/v2/classification/find.js @@ -1,6 +1,6 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(classificationId) { var params = { url: [ @@ -11,5 +11,5 @@ module.exports = function(apiKey, accessToken) { qs: {apikey: apiKey} }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/classification/index.js b/lib/discovery/v2/classification/index.js index 9694399..99c602b 100644 --- a/lib/discovery/v2/classification/index.js +++ b/lib/discovery/v2/classification/index.js @@ -1,11 +1,11 @@ -var all = require('./all'), - find = require('./find'); +var all = require('./all'); +var find = require('./find'); module.exports = function(apiKey, accessToken) { return { all: all(apiKey, accessToken), find: find(apiKey, accessToken) - } + }; }; module.exports.all = all; diff --git a/lib/discovery/v2/classification/parse_response.js b/lib/discovery/v2/classification/parse_response.js index 55e0eb8..37f4c09 100644 --- a/lib/discovery/v2/classification/parse_response.js +++ b/lib/discovery/v2/classification/parse_response.js @@ -2,7 +2,7 @@ var Classification = require('./model'); var SegmentParser = require('../segment/parse_response'); module.exports = function(response) { - var classification = new Classification; + var classification = new Classification(); classification.segment = SegmentParser(response._embedded.segment); diff --git a/lib/discovery/v2/event/all.js b/lib/discovery/v2/event/all.js index 41bfe65..3fc8bca 100644 --- a/lib/discovery/v2/event/all.js +++ b/lib/discovery/v2/event/all.js @@ -1,8 +1,8 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(options) { - var options = options || {}; + options = options || {}; options.apikey = apiKey; var params = { url: [ @@ -12,5 +12,5 @@ module.exports = function(apiKey, accessToken) { qs: options }; return getData(params); - } -}; \ No newline at end of file + }; +}; diff --git a/lib/discovery/v2/event/find.js b/lib/discovery/v2/event/find.js index f88ca8c..06c59bd 100644 --- a/lib/discovery/v2/event/find.js +++ b/lib/discovery/v2/event/find.js @@ -1,6 +1,6 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(eventId) { var params = { url: [ @@ -11,5 +11,5 @@ module.exports = function(apiKey, accessToken) { qs: {apikey: apiKey} }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/event/index.js b/lib/discovery/v2/event/index.js index aef3fb6..99c602b 100644 --- a/lib/discovery/v2/event/index.js +++ b/lib/discovery/v2/event/index.js @@ -1,12 +1,12 @@ -var all = require('./all'), - find = require('./find'); +var all = require('./all'); +var find = require('./find'); module.exports = function(apiKey, accessToken) { return { all: all(apiKey, accessToken), find: find(apiKey, accessToken) - } + }; }; -module.exports.all = all; +module.exports.all = all; module.exports.find = find; diff --git a/lib/discovery/v2/event/parse_response.js b/lib/discovery/v2/event/parse_response.js index 12983ee..4be8bc3 100644 --- a/lib/discovery/v2/event/parse_response.js +++ b/lib/discovery/v2/event/parse_response.js @@ -3,7 +3,7 @@ var AttractionParser = require('../attraction/parse_response'); var VenueParser = require('../venue/parse_response'); module.exports = function(response) { - var event = new Event; + var event = new Event(); event.id = response.id; event.name = response.name; diff --git a/lib/discovery/v2/genre/parse_response.js b/lib/discovery/v2/genre/parse_response.js index c35d287..07d493b 100644 --- a/lib/discovery/v2/genre/parse_response.js +++ b/lib/discovery/v2/genre/parse_response.js @@ -2,7 +2,7 @@ var Genre = require('./model'); var SubgenreParser = require('../subgenre/parse_response'); module.exports = function(response) { - var genre = new Genre; + var genre = new Genre(); genre.id = response.id; genre.name = response.name; diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2/index.js index b6a7530..7043cd2 100644 --- a/lib/discovery/v2/index.js +++ b/lib/discovery/v2/index.js @@ -1,6 +1,6 @@ -var attraction = require('./attraction'), - event = require('./event'), - venue = require('./venue'); +var attraction = require('./attraction'); +var event = require('./event'); +var venue = require('./venue'); module.exports = function(apiKey, accessToken) { return { diff --git a/lib/discovery/v2/segment/parse_response.js b/lib/discovery/v2/segment/parse_response.js index b23e8b8..e9a363e 100644 --- a/lib/discovery/v2/segment/parse_response.js +++ b/lib/discovery/v2/segment/parse_response.js @@ -2,7 +2,7 @@ var Segment = require('./model'); var GenreParser = require('../genre/parse_response'); module.exports = function(response) { - var segment = new Segment; + var segment = new Segment(); segment.id = response.id; segment.name = response.name; diff --git a/lib/discovery/v2/subgenre/parse_response.js b/lib/discovery/v2/subgenre/parse_response.js index 27c8364..2ef8e35 100644 --- a/lib/discovery/v2/subgenre/parse_response.js +++ b/lib/discovery/v2/subgenre/parse_response.js @@ -1,7 +1,7 @@ var Subgenre = require('./model'); module.exports = function(response) { - var subgenre = new Subgenre; + var subgenre = new Subgenre(); subgenre.id = response.id; subgenre.name = response.name; diff --git a/lib/discovery/v2/venue/find.js b/lib/discovery/v2/venue/find.js index 1c0841b..d394ffe 100644 --- a/lib/discovery/v2/venue/find.js +++ b/lib/discovery/v2/venue/find.js @@ -1,6 +1,6 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return function(venueId) { var params = { url: [ @@ -11,5 +11,5 @@ module.exports = function(apiKey, accessToken) { qs: {apikey: apiKey} }; return getData(params); - } + }; }; diff --git a/lib/discovery/v2/venue/index.js b/lib/discovery/v2/venue/index.js index bdb6540..9ea812b 100644 --- a/lib/discovery/v2/venue/index.js +++ b/lib/discovery/v2/venue/index.js @@ -3,5 +3,5 @@ var find = require('./find'); module.exports = function(apiKey, accessToken) { return { find: find(apiKey, accessToken) - } + }; }; diff --git a/lib/discovery/v2/venue/parse_response.js b/lib/discovery/v2/venue/parse_response.js index 07bb107..855295f 100644 --- a/lib/discovery/v2/venue/parse_response.js +++ b/lib/discovery/v2/venue/parse_response.js @@ -1,7 +1,7 @@ var Venue = require('./model'); module.exports = function(response) { - var venue = new Venue; + var venue = new Venue(); venue.id = response.id; venue.name = response.name; diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index f6d7043..dce44d5 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -1,9 +1,9 @@ /** * Module dependencies and locals */ -var Promise = require('bluebird'); +var Promise = require('bluebird'); var requestAsync = require('./request_helper'); -var config = require('../../config'); +var config = require('../../config'); var params; /** @@ -11,7 +11,7 @@ var params; * @param options * @constructor */ -var Result = function (options) { +var Result = function(options) { var opt = options || {}; this.items = opt.items || null; this.page = opt.page || null; @@ -29,8 +29,8 @@ var getData = function(obj) { method: obj.method || 'GET', qs: obj.qs }) - .then(function (response, body) { - if(response.statusCode === 200) { + .then(function(response) { + if (response.statusCode === 200) { var result = JSON.parse(response.body); if (obj.url[2]) { return result; @@ -53,7 +53,7 @@ var getData = function(obj) { * @param page {number} * @returns {promise} */ -Result.prototype.getPage = function (page) { +Result.prototype.getPage = function(page) { if (page && this.page && page > 0 && page <= this.page.totalPages) { params.qs.page = page; return getData(params); @@ -68,8 +68,8 @@ Result.prototype.getPage = function (page) { * @param step {number} * @returns {promise} */ -Result.prototype.nextPage = function (step) { - var step = step || 1; +Result.prototype.nextPage = function(step) { + step = step || 1; if (this.page && this.page.number <= this.page.totalPages) { params.qs.page = this.page.number + step; return getData(params); @@ -84,8 +84,8 @@ Result.prototype.nextPage = function (step) { * @param step {number} * @returns {promise} */ -Result.prototype.previousPage = function (step) { - var step = step || 1; +Result.prototype.previousPage = function(step) { + step = step || 1; if (this.page && this.page.number > 0) { params.qs.page = this.page.number - step; return getData(params); @@ -98,7 +98,7 @@ Result.prototype.previousPage = function (step) { * Method of Result object type * @returns {array|null} */ -Result.prototype.records = function () { +Result.prototype.records = function() { return this.items; }; @@ -106,7 +106,7 @@ Result.prototype.records = function () { * Method of Result object type * @returns {number} quantity of all items of the same type */ -Result.prototype.count = function () { +Result.prototype.count = function() { return this.page && this.page.totalElements || 0; }; @@ -115,7 +115,7 @@ Result.prototype.count = function () { * Checker if current result page is the last one * @returns {boolean} */ -Result.prototype.isLastPage = function () { +Result.prototype.isLastPage = function() { return this.page.number === this.page.totalPages; }; diff --git a/package.json b/package.json index 4397b07..f1322a7 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "webpack", "prod": "cross-env NODE_ENV=prod webpack", "test": "mocha --recursive", - "postversion": "./scripts/post-release.sh" + "postversion": "./scripts/post-release.sh", + "lint": "eslint ./lib" }, "keywords": [ "ticketmaster", @@ -26,6 +27,10 @@ "devDependencies": { "chai": "3.5.0", "cross-env": "^2.0.0", + "eslint": "^3.1.1", + "eslint-config-standard": "^5.3.5", + "eslint-plugin-promise": "^2.0.0", + "eslint-plugin-standard": "^2.0.0", "inherits": "^2.0.1", "json-loader": "^0.5.4", "mocha": "2.5.3", From f89dba30951ffb556a3c5779a371db13babfb0ca Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 30 Jul 2016 09:18:58 -0700 Subject: [PATCH 04/46] Transitions to es2015 --- .babelrc | 4 + lib/discovery/index.js | 9 +- lib/discovery/v2/attraction.js | 7 + lib/discovery/v2/attraction/all.js | 16 -- lib/discovery/v2/attraction/find.js | 15 -- lib/discovery/v2/attraction/index.js | 12 -- lib/discovery/v2/attraction/model.js | 11 - lib/discovery/v2/attraction/parse_response.js | 15 -- lib/discovery/v2/classification.js | 7 + lib/discovery/v2/classification/all.js | 16 -- lib/discovery/v2/classification/find.js | 15 -- lib/discovery/v2/classification/index.js | 12 -- lib/discovery/v2/classification/model.js | 5 - .../v2/classification/parse_response.js | 10 - lib/discovery/v2/event.js | 7 + lib/discovery/v2/event/find.js | 15 -- lib/discovery/v2/event/index.js | 12 -- lib/discovery/v2/event/model.js | 20 -- lib/discovery/v2/event/parse_response.js | 31 --- lib/discovery/v2/genre/model.js | 7 - lib/discovery/v2/genre/parse_response.js | 15 -- lib/discovery/v2/index.js | 24 +-- lib/discovery/v2/{event => utils}/all.js | 11 +- lib/discovery/v2/{venue => utils}/find.js | 11 +- lib/discovery/v2/venue.js | 5 + lib/discovery/v2/venue/index.js | 7 - lib/discovery/v2/venue/model.js | 17 -- lib/discovery/v2/venue/parse_response.js | 21 -- lib/helpers/result_helper.js | 191 +++++++++--------- package.json | 4 +- test/discovery/v2/attraction/all.js | 34 ++-- test/discovery/v2/attraction/find.js | 34 ++-- test/discovery/v2/attraction/index.js | 17 +- test/discovery/v2/classification/all.js | 23 +-- test/discovery/v2/classification/find.js | 19 +- test/discovery/v2/event/all.js | 15 +- test/discovery/v2/event/find.js | 28 ++- test/discovery/v2/venue/find.js | 11 +- 38 files changed, 235 insertions(+), 498 deletions(-) create mode 100644 .babelrc create mode 100644 lib/discovery/v2/attraction.js delete mode 100644 lib/discovery/v2/attraction/all.js delete mode 100644 lib/discovery/v2/attraction/find.js delete mode 100644 lib/discovery/v2/attraction/index.js delete mode 100644 lib/discovery/v2/attraction/model.js delete mode 100644 lib/discovery/v2/attraction/parse_response.js create mode 100644 lib/discovery/v2/classification.js delete mode 100644 lib/discovery/v2/classification/all.js delete mode 100644 lib/discovery/v2/classification/find.js delete mode 100644 lib/discovery/v2/classification/index.js delete mode 100644 lib/discovery/v2/classification/model.js delete mode 100644 lib/discovery/v2/classification/parse_response.js create mode 100644 lib/discovery/v2/event.js delete mode 100644 lib/discovery/v2/event/find.js delete mode 100644 lib/discovery/v2/event/index.js delete mode 100644 lib/discovery/v2/event/model.js delete mode 100644 lib/discovery/v2/event/parse_response.js delete mode 100644 lib/discovery/v2/genre/model.js delete mode 100644 lib/discovery/v2/genre/parse_response.js rename lib/discovery/v2/{event => utils}/all.js (51%) rename lib/discovery/v2/{venue => utils}/find.js (50%) create mode 100644 lib/discovery/v2/venue.js delete mode 100644 lib/discovery/v2/venue/index.js delete mode 100644 lib/discovery/v2/venue/model.js delete mode 100644 lib/discovery/v2/venue/parse_response.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..8eb1003 --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "compact": "true", + "presets": ["es2015"] +} diff --git a/lib/discovery/index.js b/lib/discovery/index.js index b536b75..b2bdca5 100644 --- a/lib/discovery/index.js +++ b/lib/discovery/index.js @@ -1,12 +1,9 @@ var v1 = require('./v1'); var v2 = require('./v2'); -module.exports = function(apiKey, accessToken) { +module.exports = function(apiKey) { return { - v1: v1(apiKey, accessToken), - v2: v2(apiKey, accessToken) + v1: v1(apiKey), + v2: v2(apiKey) }; }; - -module.exports.v1 = v1; -module.exports.v2 = v2; diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js new file mode 100644 index 0000000..c4c0ce8 --- /dev/null +++ b/lib/discovery/v2/attraction.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'attractions'), + find: find(apiKey, 'attractions') +}); diff --git a/lib/discovery/v2/attraction/all.js b/lib/discovery/v2/attraction/all.js deleted file mode 100644 index edc4847..0000000 --- a/lib/discovery/v2/attraction/all.js +++ /dev/null @@ -1,16 +0,0 @@ -var getData = require('../../../helpers/result_helper'); - -module.exports = function(apiKey, accessToken) { - return function(options) { - options = options || {}; - options.apikey = apiKey; - var params = { - url: [ - 'discovery/v2', - 'attractions' - ], - qs: options - }; - return getData(params); - }; -}; diff --git a/lib/discovery/v2/attraction/find.js b/lib/discovery/v2/attraction/find.js deleted file mode 100644 index fae89e2..0000000 --- a/lib/discovery/v2/attraction/find.js +++ /dev/null @@ -1,15 +0,0 @@ -var getData = require('../../../helpers/result_helper'); - -module.exports = function(apiKey) { - return function(attractionId) { - var params = { - url: [ - 'discovery/v2', - 'attractions', - attractionId - ], - qs: {apikey: apiKey} - }; - return getData(params); - }; -}; diff --git a/lib/discovery/v2/attraction/index.js b/lib/discovery/v2/attraction/index.js deleted file mode 100644 index 99c602b..0000000 --- a/lib/discovery/v2/attraction/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var all = require('./all'); -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - all: all(apiKey, accessToken), - find: find(apiKey, accessToken) - }; -}; - -module.exports.all = all; -module.exports.find = find; diff --git a/lib/discovery/v2/attraction/model.js b/lib/discovery/v2/attraction/model.js deleted file mode 100644 index ab834d2..0000000 --- a/lib/discovery/v2/attraction/model.js +++ /dev/null @@ -1,11 +0,0 @@ -var Attraction = function() { - this.id = undefined; - this.name = undefined; - this.test = undefined; - this.url = undefined; - this.locale = undefined; - this.images = undefined; - this.classifications = undefined; -}; - -module.exports = Attraction; diff --git a/lib/discovery/v2/attraction/parse_response.js b/lib/discovery/v2/attraction/parse_response.js deleted file mode 100644 index 2d509c5..0000000 --- a/lib/discovery/v2/attraction/parse_response.js +++ /dev/null @@ -1,15 +0,0 @@ -var Attraction = require('./model'); - -module.exports = function(response) { - var attraction = new Attraction(); - - attraction.id = response.id; - attraction.name = response.name; - attraction.test = response.test; - attraction.url = response.url; - attraction.locale = response.locale; - attraction.images = response.images; - attraction.classifications = response.classifications; - - return attraction; -}; diff --git a/lib/discovery/v2/classification.js b/lib/discovery/v2/classification.js new file mode 100644 index 0000000..f1e4390 --- /dev/null +++ b/lib/discovery/v2/classification.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'classifications'), + find: find(apiKey, 'classifications') +}); diff --git a/lib/discovery/v2/classification/all.js b/lib/discovery/v2/classification/all.js deleted file mode 100644 index e3f71ed..0000000 --- a/lib/discovery/v2/classification/all.js +++ /dev/null @@ -1,16 +0,0 @@ -var getData = require('../../../helpers/result_helper'); - -module.exports = function(apiKey) { - return function(options) { - options = options || {}; - options.apikey = apiKey; - var params = { - url: [ - 'discovery/v2', - 'classifications' - ], - qs: options - }; - return getData(params); - }; -}; diff --git a/lib/discovery/v2/classification/find.js b/lib/discovery/v2/classification/find.js deleted file mode 100644 index f2e6fdc..0000000 --- a/lib/discovery/v2/classification/find.js +++ /dev/null @@ -1,15 +0,0 @@ -var getData = require('../../../helpers/result_helper'); - -module.exports = function(apiKey) { - return function(classificationId) { - var params = { - url: [ - 'discovery/v2', - 'classifications', - classificationId - ], - qs: {apikey: apiKey} - }; - return getData(params); - }; -}; diff --git a/lib/discovery/v2/classification/index.js b/lib/discovery/v2/classification/index.js deleted file mode 100644 index 99c602b..0000000 --- a/lib/discovery/v2/classification/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var all = require('./all'); -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - all: all(apiKey, accessToken), - find: find(apiKey, accessToken) - }; -}; - -module.exports.all = all; -module.exports.find = find; diff --git a/lib/discovery/v2/classification/model.js b/lib/discovery/v2/classification/model.js deleted file mode 100644 index d139863..0000000 --- a/lib/discovery/v2/classification/model.js +++ /dev/null @@ -1,5 +0,0 @@ -var Classification = function() { - this.segment = undefined; -}; - -module.exports = Classification; diff --git a/lib/discovery/v2/classification/parse_response.js b/lib/discovery/v2/classification/parse_response.js deleted file mode 100644 index 37f4c09..0000000 --- a/lib/discovery/v2/classification/parse_response.js +++ /dev/null @@ -1,10 +0,0 @@ -var Classification = require('./model'); -var SegmentParser = require('../segment/parse_response'); - -module.exports = function(response) { - var classification = new Classification(); - - classification.segment = SegmentParser(response._embedded.segment); - - return classification; -}; diff --git a/lib/discovery/v2/event.js b/lib/discovery/v2/event.js new file mode 100644 index 0000000..89c7276 --- /dev/null +++ b/lib/discovery/v2/event.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'events'), + find: find(apiKey, 'events') +}); diff --git a/lib/discovery/v2/event/find.js b/lib/discovery/v2/event/find.js deleted file mode 100644 index 06c59bd..0000000 --- a/lib/discovery/v2/event/find.js +++ /dev/null @@ -1,15 +0,0 @@ -var getData = require('../../../helpers/result_helper'); - -module.exports = function(apiKey) { - return function(eventId) { - var params = { - url: [ - 'discovery/v2', - 'events', - eventId - ], - qs: {apikey: apiKey} - }; - return getData(params); - }; -}; diff --git a/lib/discovery/v2/event/index.js b/lib/discovery/v2/event/index.js deleted file mode 100644 index 99c602b..0000000 --- a/lib/discovery/v2/event/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var all = require('./all'); -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - all: all(apiKey, accessToken), - find: find(apiKey, accessToken) - }; -}; - -module.exports.all = all; -module.exports.find = find; diff --git a/lib/discovery/v2/event/model.js b/lib/discovery/v2/event/model.js deleted file mode 100644 index 5b3d515..0000000 --- a/lib/discovery/v2/event/model.js +++ /dev/null @@ -1,20 +0,0 @@ -var Event = function() { - this.id = undefined; - this.name = undefined; - this.locale = undefined; - this.test = undefined; - this.url = undefined; - this.locale = undefined; - this.images = []; - this.sale = []; - this.date = []; - this.classification = []; - this.promoter = undefined; - this.info = undefined; - this.priceRange = []; - - this.attractions = []; - this.venue = undefined; -}; - -module.exports = Event; diff --git a/lib/discovery/v2/event/parse_response.js b/lib/discovery/v2/event/parse_response.js deleted file mode 100644 index 4be8bc3..0000000 --- a/lib/discovery/v2/event/parse_response.js +++ /dev/null @@ -1,31 +0,0 @@ -var Event = require('./model'); -var AttractionParser = require('../attraction/parse_response'); -var VenueParser = require('../venue/parse_response'); - -module.exports = function(response) { - var event = new Event(); - - event.id = response.id; - event.name = response.name; - event.locale = response.locale; - event.test = response.test; - event.url = response.url; - event.locale = response.locale; - event.images = response.images; - event.sale = response.sale; - event.date = response.date; - event.classification = response.classification; - event.promoter = response.promoter; - event.info = response.info; - event.priceRange = response.priceRange; - - response._embedded.attractions.forEach(function(response) { - event.attractions.push(AttractionParser(response)); - }); - - response._embedded.venues.forEach(function(response) { - event.venues.push(VenueParser(response)); - }); - - return event; -}; diff --git a/lib/discovery/v2/genre/model.js b/lib/discovery/v2/genre/model.js deleted file mode 100644 index 5eaab95..0000000 --- a/lib/discovery/v2/genre/model.js +++ /dev/null @@ -1,7 +0,0 @@ -var Genre = function() { - this.id = undefined; - this.name = undefined; - this.subgenres = []; -}; - -module.exports = Genre; diff --git a/lib/discovery/v2/genre/parse_response.js b/lib/discovery/v2/genre/parse_response.js deleted file mode 100644 index 07d493b..0000000 --- a/lib/discovery/v2/genre/parse_response.js +++ /dev/null @@ -1,15 +0,0 @@ -var Genre = require('./model'); -var SubgenreParser = require('../subgenre/parse_response'); - -module.exports = function(response) { - var genre = new Genre(); - - genre.id = response.id; - genre.name = response.name; - - response._embedded.genres.forEach(function(response) { - genre.subgenres.push(SubgenreParser(response)); - }); - - return genre; -}; diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2/index.js index 7043cd2..9e59a10 100644 --- a/lib/discovery/v2/index.js +++ b/lib/discovery/v2/index.js @@ -1,15 +1,11 @@ -var attraction = require('./attraction'); -var event = require('./event'); -var venue = require('./venue'); +import attraction from './attraction'; +import classification from './classification'; +import event from './event'; +import venue from './venue'; -module.exports = function(apiKey, accessToken) { - return { - attraction: attraction(apiKey, accessToken), - event: event(apiKey, accessToken), - venue: venue(apiKey, accessToken) - }; -}; - -module.exports.attraction = attraction; -module.exports.event = event; -module.exports.venue = venue; +export default (apiKey) => ({ + attraction: attraction(apiKey), + classification: classification(apiKey), + event: event(apiKey), + venue: venue(apiKey) +}); diff --git a/lib/discovery/v2/event/all.js b/lib/discovery/v2/utils/all.js similarity index 51% rename from lib/discovery/v2/event/all.js rename to lib/discovery/v2/utils/all.js index 3fc8bca..908a9cb 100644 --- a/lib/discovery/v2/event/all.js +++ b/lib/discovery/v2/utils/all.js @@ -1,16 +1,13 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey) { - return function(options) { - options = options || {}; +module.exports = function(apiKey, type) { + return function(options = {}) { options.apikey = apiKey; var params = { - url: [ - 'discovery/v2', - 'events' - ], + url: ['discovery/v2', type], qs: options }; + return getData(params); }; }; diff --git a/lib/discovery/v2/venue/find.js b/lib/discovery/v2/utils/find.js similarity index 50% rename from lib/discovery/v2/venue/find.js rename to lib/discovery/v2/utils/find.js index d394ffe..2a0b90e 100644 --- a/lib/discovery/v2/venue/find.js +++ b/lib/discovery/v2/utils/find.js @@ -1,15 +1,12 @@ var getData = require('../../../helpers/result_helper'); -module.exports = function(apiKey) { - return function(venueId) { +module.exports = function(apiKey, type) { + return function(id) { var params = { - url: [ - 'discovery/v2', - 'venues', - venueId - ], + url: ['discovery/v2', type, id], qs: {apikey: apiKey} }; + return getData(params); }; }; diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js new file mode 100644 index 0000000..835967f --- /dev/null +++ b/lib/discovery/v2/venue.js @@ -0,0 +1,5 @@ +import find from './utils/find'; + +export default (apiKey) => ({ + find: find(apiKey, 'venues') +}); diff --git a/lib/discovery/v2/venue/index.js b/lib/discovery/v2/venue/index.js deleted file mode 100644 index 9ea812b..0000000 --- a/lib/discovery/v2/venue/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - find: find(apiKey, accessToken) - }; -}; diff --git a/lib/discovery/v2/venue/model.js b/lib/discovery/v2/venue/model.js deleted file mode 100644 index cf2798d..0000000 --- a/lib/discovery/v2/venue/model.js +++ /dev/null @@ -1,17 +0,0 @@ -var Venue = function() { - this.id = undefined; - this.name = undefined; - this.test = undefined; - this.url = undefined; - this.locale = undefined; - this.postalCode = undefined; - this.timezone = undefined; - this.city = undefined; - this.country = undefined; - this.address = undefined; - this.location = undefined; - this.markets = []; - this.dmas = []; -}; - -module.exports = Venue; diff --git a/lib/discovery/v2/venue/parse_response.js b/lib/discovery/v2/venue/parse_response.js deleted file mode 100644 index 855295f..0000000 --- a/lib/discovery/v2/venue/parse_response.js +++ /dev/null @@ -1,21 +0,0 @@ -var Venue = require('./model'); - -module.exports = function(response) { - var venue = new Venue(); - - venue.id = response.id; - venue.name = response.name; - venue.test = response.test; - venue.url = response.url; - venue.locale = response.locale; - venue.postal_code = response.postalCode; - venue.timezone = response.timezone; - venue.city = response.city; - venue.country = response.country; - venue.address = response.address; - venue.location = response.location; - venue.markets = response.markets; - venue.dmas = response.dmas; - - return venue; -}; diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index dce44d5..adc470b 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -11,113 +11,114 @@ var params; * @param options * @constructor */ -var Result = function(options) { - var opt = options || {}; - this.items = opt.items || null; - this.page = opt.page || null; - params = opt.params; -}; +// TODO fix params +class Result { + constructor({items, page, params}) { + this.items = items; + this.page = page; + } -/** - * Main GET Data configuration function for API - * @param obj {object} Configuration object - * @returns {promise} - */ -var getData = function(obj) { - return requestAsync({ - url: [config.baseURL].concat(obj.url).join('/'), - method: obj.method || 'GET', - qs: obj.qs - }) - .then(function(response) { - if (response.statusCode === 200) { - var result = JSON.parse(response.body); - if (obj.url[2]) { - return result; - } else { - return new Result({ - items: result._embedded && result._embedded[obj.url[1]], - page: result.page, - params: obj - }); - } - } else { - return Promise.reject(JSON.parse(response.body)); + /** + * Method of Result object type + * Gets some page of results by it's number passed as param. + * @param page {number} + * @returns {promise} + */ + getPage(page) { + if (page && this.page && page > 0 && page <= this.page.totalPages) { + params.qs.page = page; + return getData(params); } - }); -}; -/** - * Method of Result object type - * Gets some page of results by it's number passed as param. - * @param page {number} - * @returns {promise} - */ -Result.prototype.getPage = function(page) { - if (page && this.page && page > 0 && page <= this.page.totalPages) { - params.qs.page = page; - return getData(params); - } else { return Promise.reject({message: 'You should pass correct page number.', page: page}); - } -}; + }; -/** - * Method of Result object type - * (Iterator method) Gets next page of same type results - * @param step {number} - * @returns {promise} - */ -Result.prototype.nextPage = function(step) { - step = step || 1; - if (this.page && this.page.number <= this.page.totalPages) { - params.qs.page = this.page.number + step; - return getData(params); - } else { - return Promise.reject({message: 'No next page! You are on the last.', params: params}); - } -}; + /** + * Method of Result object type + * (Iterator method) Gets next page of same type results + * @param step {number} + * @returns {promise} + */ + nextPage(step) { + step = step || 1; + if (this.page && this.page.number <= this.page.totalPages) { + params.qs.page = this.page.number + step; + return getData(params); + } else { + return Promise.reject({message: 'No next page! You are on the last.', params: params}); + } + }; + + /** + * Method of Result object type + * (Iterator method) Gets previous page of same type results + * @param step {number} + * @returns {promise} + */ + previousPage(step) { + step = step || 1; + if (this.page && this.page.number > 0) { + params.qs.page = this.page.number - step; + return getData(params); + } else { + return Promise.reject({message: 'No previous page! You are on the first one.', params: params}); + } + }; + + /** + * Method of Result object type + * @returns {array|null} + */ + records() { + return this.items; + }; + + /** + * Method of Result object type + * @returns {number} quantity of all items of the same type + */ + count() { + return this.page && this.page.totalElements || 0; + }; + + /** + * Method of Result object type + * Checker if current result page is the last one + * @returns {boolean} + */ + isLastPage() { + return this.page.number === this.page.totalPages; + }; +} +; /** - * Method of Result object type - * (Iterator method) Gets previous page of same type results - * @param step {number} + * Main GET Data configuration function for API + * + * @param url {string} + * @param qs {string} + * @param method {string} + * * @returns {promise} */ -Result.prototype.previousPage = function(step) { - step = step || 1; - if (this.page && this.page.number > 0) { - params.qs.page = this.page.number - step; - return getData(params); - } else { - return Promise.reject({message: 'No previous page! You are on the first one.', params: params}); - } -}; +const getData = ({url, qs, method = 'GET'}) => + requestAsync({url: [config.baseURL].concat(url).join('/'), method, qs}) + .then((response) => { + if (response.statusCode === 200) { + var result = JSON.parse(response.body); -/** - * Method of Result object type - * @returns {array|null} - */ -Result.prototype.records = function() { - return this.items; -}; + if (url[2]) { + return result; + } -/** - * Method of Result object type - * @returns {number} quantity of all items of the same type - */ -Result.prototype.count = function() { - return this.page && this.page.totalElements || 0; -}; + return new Result({ + items: result._embedded && result._embedded[url[1]], + page: result.page + }); + } -/** - * Method of Result object type - * Checker if current result page is the last one - * @returns {boolean} - */ -Result.prototype.isLastPage = function() { - return this.page.number === this.page.totalPages; -}; + return Promise.reject(JSON.parse(response.body)); + }); /** * Module interface diff --git a/package.json b/package.json index f1322a7..1ca1ae5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "webpack && npm run prod", "dev": "webpack", "prod": "cross-env NODE_ENV=prod webpack", - "test": "mocha --recursive", + "test": "mocha --compilers js:babel-core/register --recursive", "postversion": "./scripts/post-release.sh", "lint": "eslint ./lib" }, @@ -25,6 +25,8 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { + "babel-core": "^6.11.4", + "babel-preset-es2015": "^6.9.0", "chai": "3.5.0", "cross-env": "^2.0.0", "eslint": "^3.1.1", diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index 599fb42..a6f2e2f 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,24 +1,24 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var All = require('../../../../lib/discovery/v2/attraction/all'); +import chai from "chai"; +const should = chai.should(); +import nock from 'nock'; +const nockBack = nock.back; -describe('discovery.v2.attraction.all', function() { - before(function() { +import Attraction from '../../../../lib/discovery/v2/attraction'; + +describe('discovery.v2.attraction.all', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v2' }); - describe('success', function() { - it('should find an attraction', function(done) { - nockBack('attraction/all-200.json', {}, function(nockDone) { - var all = All('mock-api-key'); - all() - .then(function(attractions) { - attractions.items[0].name.should.equal("!!!"); - nockDone(); - done(); - }) + describe('success', () => { + it('should find an attraction', (done) => { + nockBack('attraction/all-200.json', {}, nockDone => { + Attraction('mock-api-key').all() + .then((attractions) => { + attractions.items[0].name.should.equal("!!!"); + nockDone(); + done(); + }) }); }); }); diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 563113c..2e5fd06 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,26 +1,24 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v2/attraction/find'); +import chai from "chai"; +const should = chai.should(); +import nock from 'nock'; +const nockBack = nock.back; -describe('discovery.v2.attraction.find', function() { - before(function() { +import Attraction from '../../../../lib/discovery/v2/attraction'; + +describe('discovery.v2.attraction.find', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v2' }); - describe('success', function() { - it('should find a attraction', function(done) { + describe('success', () => { + it('should find a attraction', done => { nockBack('attraction/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('K8vZ917Kew0') - .then((function(_this) { - return function(result) { - result.name.should.equal("Susquehanna Breakdown Music Festival"); - nockDone(); - done(); - }; - })(this)) + Attraction('mock-api-key').find('K8vZ917Kew0') + .then(((_this => result => { + result.name.should.equal("Susquehanna Breakdown Music Festival"); + nockDone(); + done(); + }))(this)) }); }); }); diff --git a/test/discovery/v2/attraction/index.js b/test/discovery/v2/attraction/index.js index 7a0887e..69f76a1 100644 --- a/test/discovery/v2/attraction/index.js +++ b/test/discovery/v2/attraction/index.js @@ -1,15 +1,16 @@ -var chai = require("chai"); -var should = chai.should(); -var attraction = require('../../../../lib/discovery/v2/attraction'); +import chai from "chai"; +const should = chai.should(); -describe('discovery.v2.attraction', function() { - it('should provide all', function(done) { - attraction().should.have.property('all'); +import Attraction from '../../../../lib/discovery/v2/attraction'; + +describe('discovery.v2.attraction', () => { + it('should provide all', (done) => { + Attraction().should.have.property('all'); done(); }); - it('should provide find', function(done) { - attraction().should.have.property('find'); + it('should provide find', (done) => { + Attraction().should.have.property('find'); done(); }); }); diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index dd9d0ec..8a4898c 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,8 +1,8 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var All = require('../../../../lib/discovery/v2/classification/all'); +var chai = require("chai"); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Classification = require('../../../../lib/discovery/v2/classification'); describe('discovery.v2.classification.all', function() { before(function() { @@ -12,13 +12,12 @@ describe('discovery.v2.classification.all', function() { describe('success', function() { it('should find an classification', function(done) { nockBack('classification/all-200.json', {}, function(nockDone) { - var all = All('mock-api-key'); - all() - .then(function(classifications) { - classifications.items[0].should.not.be.an('undefined'); - nockDone(); - done(); - }) + Classification('mock-api-key').all() + .then(function(classifications) { + classifications.items[0].should.not.be.an('undefined'); + nockDone(); + done(); + }) }); }); }); diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index 8f4ea37..95a8845 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,8 +1,8 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v2/classification/find'); +var chai = require("chai"); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Classification = require('../../../../lib/discovery/v2/classification'); describe('discovery.v2.classification.find', function() { before(function() { @@ -12,15 +12,12 @@ describe('discovery.v2.classification.find', function() { describe('success', function() { it('should find a classification', function(done) { nockBack('classification/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('KZFzniwnSyZfZ7v7na') - .then((function(_this) { - return function(result) { + Classification('mock-api-key').find('KZFzniwnSyZfZ7v7na') + .then(function(result) { result.segment.name.should.equal("Arts & Theatre"); nockDone(); done(); - }; - })(this)) + }) }); }); }); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 16f984b..28d4329 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -2,7 +2,7 @@ var chai = require("chai"); var should = chai.should(); var nock = require('nock'); var nockBack = nock.back; -var All = require('../../../../lib/discovery/v2/event/all'); +var Event = require('../../../../lib/discovery/v2/event'); describe('discovery.v2.event.all', function() { before(function() { @@ -12,13 +12,12 @@ describe('discovery.v2.event.all', function() { describe('success', function() { it('should find an event', function(done) { nockBack('event/all-200.json', {}, function(nockDone) { - var all = All('mock-api-key'); - all() - .then(function(events) { - events.items[0].name.should.equal("OSEA Membership Registration"); - nockDone(); - done(); - }) + Event('mock-api-key').all() + .then(function(events) { + events.items[0].name.should.equal("OSEA Membership Registration"); + nockDone(); + done(); + }) }); }); }); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index eab0c9e..ebad96f 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -2,7 +2,7 @@ var chai = require("chai"); var should = chai.should(); var nock = require('nock'); var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v2/event/find'); +var Event = require('../../../../lib/discovery/v2/event'); describe('discovery.v2.event.find', function() { before(function() { @@ -12,13 +12,12 @@ describe('discovery.v2.event.find', function() { describe('success', function() { it('should find an event', function(done) { nockBack('event/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('vv17FZfdGkSrrMju') - .then(function(result) { - result.name.should.equal("Susquehanna Breakdown RV Pass"); - nockDone(); - done(); - }); + Event('mock-api-key').find('vv17FZfdGkSrrMju') + .then(function(result) { + result.name.should.equal("Susquehanna Breakdown RV Pass"); + nockDone(); + done(); + }); }); }); }); @@ -26,13 +25,12 @@ describe('discovery.v2.event.find', function() { describe('not found', function() { it('should handle 404', function(done) { nockBack('event/find-404.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('unknown-id') - .catch(function(response) { - response.errors[0].code.should.equal('DIS1004'); - nockDone(); - done(); - }); + Event('mock-api-key').find('unknown-id') + .catch(function(response) { + response.errors[0].code.should.equal('DIS1004'); + nockDone(); + done(); + }); }); }); }); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index df03677..5b224a0 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -2,7 +2,7 @@ var chai = require("chai"); var should = chai.should(); var nock = require('nock'); var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v2/venue/find'); +var Venue = require('../../../../lib/discovery/v2/venue'); describe('discovery.v2.venue.find', function() { before(function() { @@ -12,15 +12,12 @@ describe('discovery.v2.venue.find', function() { describe('success', function() { it('should find a venue', function(done) { nockBack('venue/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('KovZpZAEA76A') - .then((function(_this) { - return function(result) { + Venue('mock-api-key').find('KovZpZAEA76A') + .then(function(result) { result.name.should.equal("The Pavilion at Montage Mountain"); nockDone(); done(); - }; - })(this)) + }) }); }); }); From 7c1980e6de643067c5a4775167fd2c442647c5d9 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 30 Jul 2016 10:43:44 -0700 Subject: [PATCH 05/46] Added method and test for finding event images --- .eslintrc | 6 + lib/commerce/index.js | 10 +- lib/commerce/v2/index.js | 10 +- lib/commerce/v2/offer/find.js | 25 ++-- lib/commerce/v2/offer/index.js | 10 +- lib/discovery/index.js | 14 +-- lib/discovery/v2/segment/model.js | 7 -- lib/discovery/v2/segment/parse_response.js | 15 --- lib/discovery/v2/subgenre/model.js | 6 - lib/discovery/v2/subgenre/parse_response.js | 10 -- lib/discovery/v2/utils/all.js | 18 ++- lib/discovery/v2/utils/find.js | 16 ++- lib/helpers/result_helper.js | 44 +++---- package.json | 2 +- test/commerce/index.js | 8 +- test/commerce/v2/index.js | 8 +- test/commerce/v2/offer/find.js | 34 +++--- test/commerce/v2/offer/index.js | 8 +- test/discovery/index.js | 12 +- test/discovery/v1/attraction/find.js | 16 +-- test/discovery/v1/attraction/index.js | 2 +- .../discovery/v1/attraction/parse_response.js | 4 +- test/discovery/v1/category/find.js | 16 +-- test/discovery/v1/category/index.js | 2 +- test/discovery/v1/category/parse_response.js | 4 +- test/discovery/v1/event/all.js | 16 +-- test/discovery/v1/event/find.js | 18 +-- test/discovery/v1/event/index.js | 2 +- test/discovery/v1/event/parse_response.js | 4 +- test/discovery/v1/index.js | 4 +- test/discovery/v1/venue/find.js | 16 +-- test/discovery/v1/venue/index.js | 2 +- test/discovery/v1/venue/parse_response.js | 4 +- test/discovery/v2/attraction/all.js | 11 +- test/discovery/v2/attraction/find.js | 15 +-- test/discovery/v2/attraction/index.js | 3 - test/discovery/v2/classification/all.js | 24 ++-- test/discovery/v2/classification/find.js | 26 ++-- test/discovery/v2/event/all.js | 26 ++-- test/discovery/v2/event/find.js | 49 +++++--- test/discovery/v2/event/index.js | 10 +- test/discovery/v2/index.js | 12 +- test/discovery/v2/venue/find.js | 26 ++-- test/discovery/v2/venue/index.js | 8 +- .../discovery/v2/event/findImages-200.json | 113 ++++++++++++++++++ 45 files changed, 370 insertions(+), 326 deletions(-) delete mode 100644 lib/discovery/v2/segment/model.js delete mode 100644 lib/discovery/v2/segment/parse_response.js delete mode 100644 lib/discovery/v2/subgenre/model.js delete mode 100644 lib/discovery/v2/subgenre/parse_response.js create mode 100644 test/fixtures/discovery/v2/event/findImages-200.json diff --git a/.eslintrc b/.eslintrc index 30d2f1d..edca18e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,5 +3,11 @@ "rules": { "semi": [2, "always"], "space-before-function-paren": [2, "never"] + }, + "globals": { + "it": true, + "should": true, + "describe": true, + "before": true, } } diff --git a/lib/commerce/index.js b/lib/commerce/index.js index cee8967..af009fc 100644 --- a/lib/commerce/index.js +++ b/lib/commerce/index.js @@ -1,7 +1,5 @@ -var v2 = require('./v2'); +import v2 from './v2'; -module.exports = function(apiKey, accessToken) { - return { v2: v2(apiKey, accessToken) }; -}; - -module.exports.v2 = v2; +export default (apiKey, accessToken) => ({ + v2: v2(apiKey, accessToken) +}); diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js index b2d3f45..32c46da 100644 --- a/lib/commerce/v2/index.js +++ b/lib/commerce/v2/index.js @@ -1,7 +1,5 @@ -var offer = require('./offer'); +import offer from './offer'; -module.exports = function(apiKey, accessToken) { - return { offer: offer(apiKey, accessToken) }; -}; - -module.exports.offer = offer; +export default (apiKey, accessToken) => ({ + offer: offer(apiKey, accessToken) +}); diff --git a/lib/commerce/v2/offer/find.js b/lib/commerce/v2/offer/find.js index 35978cb..a947207 100644 --- a/lib/commerce/v2/offer/find.js +++ b/lib/commerce/v2/offer/find.js @@ -1,16 +1,15 @@ -var getData = require('../../../helpers/result_helper'); +import getData from '../../../helpers/result_helper'; -module.exports = function(apiKey, accessToken) { - return function(eventId) { - var params = { - url: [ - 'commerce/v2', - 'events', - eventId, - 'offers' - ], - qs: {apikey: apiKey} - }; - return getData(params); +export default (apiKey) => (eventId) => { + const params = { + url: [ + 'commerce/v2', + 'events', + eventId, + 'offers' + ], + qs: {apikey: apiKey} }; + + return getData(params); }; diff --git a/lib/commerce/v2/offer/index.js b/lib/commerce/v2/offer/index.js index 37d25ab..8a26598 100644 --- a/lib/commerce/v2/offer/index.js +++ b/lib/commerce/v2/offer/index.js @@ -1,7 +1,5 @@ -var find = require('./find'); +import find from './find'; -module.exports = function(apiKey, accessToken) { - return { find: find(apiKey, accessToken) }; -}; - -module.exports.find = find; +export default (apiKey, accessToken) => ({ + find: find(apiKey, accessToken) +}); diff --git a/lib/discovery/index.js b/lib/discovery/index.js index b2bdca5..2c69d81 100644 --- a/lib/discovery/index.js +++ b/lib/discovery/index.js @@ -1,9 +1,7 @@ -var v1 = require('./v1'); -var v2 = require('./v2'); +import v1 from './v1'; +import v2 from './v2'; -module.exports = function(apiKey) { - return { - v1: v1(apiKey), - v2: v2(apiKey) - }; -}; +export default (apiKey) => ({ + v1: v1(apiKey), + v2: v2(apiKey) +}); diff --git a/lib/discovery/v2/segment/model.js b/lib/discovery/v2/segment/model.js deleted file mode 100644 index 3654f09..0000000 --- a/lib/discovery/v2/segment/model.js +++ /dev/null @@ -1,7 +0,0 @@ -var Segment = function() { - this.id = undefined; - this.name = undefined; - this.genres = []; -}; - -module.exports = Segment; diff --git a/lib/discovery/v2/segment/parse_response.js b/lib/discovery/v2/segment/parse_response.js deleted file mode 100644 index e9a363e..0000000 --- a/lib/discovery/v2/segment/parse_response.js +++ /dev/null @@ -1,15 +0,0 @@ -var Segment = require('./model'); -var GenreParser = require('../genre/parse_response'); - -module.exports = function(response) { - var segment = new Segment(); - - segment.id = response.id; - segment.name = response.name; - - response._embedded.genres.forEach(function(response) { - segment.genres.push(GenreParser(response)); - }); - - return segment; -}; diff --git a/lib/discovery/v2/subgenre/model.js b/lib/discovery/v2/subgenre/model.js deleted file mode 100644 index 8ff9bbd..0000000 --- a/lib/discovery/v2/subgenre/model.js +++ /dev/null @@ -1,6 +0,0 @@ -var Subgenre = function() { - this.id = undefined; - this.name = undefined; -}; - -module.exports = Subgenre; diff --git a/lib/discovery/v2/subgenre/parse_response.js b/lib/discovery/v2/subgenre/parse_response.js deleted file mode 100644 index 2ef8e35..0000000 --- a/lib/discovery/v2/subgenre/parse_response.js +++ /dev/null @@ -1,10 +0,0 @@ -var Subgenre = require('./model'); - -module.exports = function(response) { - var subgenre = new Subgenre(); - - subgenre.id = response.id; - subgenre.name = response.name; - - return subgenre; -}; diff --git a/lib/discovery/v2/utils/all.js b/lib/discovery/v2/utils/all.js index 908a9cb..666b0ea 100644 --- a/lib/discovery/v2/utils/all.js +++ b/lib/discovery/v2/utils/all.js @@ -1,13 +1,11 @@ -var getData = require('../../../helpers/result_helper'); +import getData from '../../../helpers/result_helper'; -module.exports = function(apiKey, type) { - return function(options = {}) { - options.apikey = apiKey; - var params = { - url: ['discovery/v2', type], - qs: options - }; - - return getData(params); +export default (apiKey, type) => (options = {}) => { + options.apikey = apiKey; + const params = { + url: ['discovery/v2', type], + qs: options }; + + return getData(params); }; diff --git a/lib/discovery/v2/utils/find.js b/lib/discovery/v2/utils/find.js index 2a0b90e..1b531d6 100644 --- a/lib/discovery/v2/utils/find.js +++ b/lib/discovery/v2/utils/find.js @@ -1,12 +1,10 @@ -var getData = require('../../../helpers/result_helper'); +import getData from '../../../helpers/result_helper'; -module.exports = function(apiKey, type) { - return function(id) { - var params = { - url: ['discovery/v2', type, id], - qs: {apikey: apiKey} - }; - - return getData(params); +export default (apiKey, type) => (...path) => { + const params = { + url: ['discovery/v2', type, ...path], + qs: {apikey: apiKey} }; + + return getData(params); }; diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index adc470b..5b00ace 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -1,10 +1,8 @@ -/** - * Module dependencies and locals - */ -var Promise = require('bluebird'); -var requestAsync = require('./request_helper'); -var config = require('../../config'); -var params; +import Promise from 'bluebird'; +import requestAsync from './request_helper'; +import config from '../../config'; + +let params; /** * Result object constructor @@ -27,10 +25,11 @@ class Result { getPage(page) { if (page && this.page && page > 0 && page <= this.page.totalPages) { params.qs.page = page; + return getData(params); } - return Promise.reject({message: 'You should pass correct page number.', page: page}); + return Promise.reject({message: 'You should pass correct page number.', page}); }; /** @@ -39,14 +38,14 @@ class Result { * @param step {number} * @returns {promise} */ - nextPage(step) { - step = step || 1; + nextPage(step=1) { if (this.page && this.page.number <= this.page.totalPages) { params.qs.page = this.page.number + step; + return getData(params); - } else { - return Promise.reject({message: 'No next page! You are on the last.', params: params}); } + + return Promise.reject({message: 'No next page! You are on the last.', params}); }; /** @@ -55,14 +54,14 @@ class Result { * @param step {number} * @returns {promise} */ - previousPage(step) { - step = step || 1; + previousPage(step=1) { if (this.page && this.page.number > 0) { params.qs.page = this.page.number - step; + return getData(params); - } else { - return Promise.reject({message: 'No previous page! You are on the first one.', params: params}); } + + return Promise.reject({message: 'No previous page! You are on the first one.', params}); }; /** @@ -90,7 +89,6 @@ class Result { return this.page.number === this.page.totalPages; }; } -; /** * Main GET Data configuration function for API @@ -104,9 +102,9 @@ class Result { const getData = ({url, qs, method = 'GET'}) => requestAsync({url: [config.baseURL].concat(url).join('/'), method, qs}) .then((response) => { - if (response.statusCode === 200) { - var result = JSON.parse(response.body); + const result = JSON.parse(response.body); + if (response.statusCode === 200) { if (url[2]) { return result; } @@ -117,11 +115,7 @@ const getData = ({url, qs, method = 'GET'}) => }); } - return Promise.reject(JSON.parse(response.body)); + return Promise.reject(result); }); -/** - * Module interface - * @type {getData} - */ -module.exports = getData; +export default getData; diff --git a/package.json b/package.json index 1ca1ae5..1bb2da0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "prod": "cross-env NODE_ENV=prod webpack", "test": "mocha --compilers js:babel-core/register --recursive", "postversion": "./scripts/post-release.sh", - "lint": "eslint ./lib" + "lint": "eslint ./lib ./test" }, "keywords": [ "ticketmaster", diff --git a/test/commerce/index.js b/test/commerce/index.js index d43c5fb..054a96b 100644 --- a/test/commerce/index.js +++ b/test/commerce/index.js @@ -1,9 +1,7 @@ -var chai = require("chai"); -var should = chai.should(); -var commerce = require('../../lib/commerce'); +import commerce from '../../lib/commerce'; -describe('commerce', function() { - it('should provide v2', function(done) { +describe('commerce', () => { + it('should provide v2', done => { commerce().should.have.property('v2'); done(); }); diff --git a/test/commerce/v2/index.js b/test/commerce/v2/index.js index f460cd3..a1a7a87 100644 --- a/test/commerce/v2/index.js +++ b/test/commerce/v2/index.js @@ -1,9 +1,7 @@ -var chai = require("chai"); -var should = chai.should(); -var v2 = require('../../../lib/commerce/v2'); +import v2 from '../../../lib/commerce/v2'; -describe('commerce.v2', function() { - it('should provide offer', function(done) { +describe('commerce.v2', () => { + it('should provide offer', done => { v2().should.have.property('offer'); done(); }); diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index 335ccee..a44f470 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -1,21 +1,19 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/commerce/v2/offer/find'); +import {back as nockBack} from 'nock'; -describe('commerce.v2.offer.find', function() { - before(function() { - nockBack.fixtures = './test/fixtures/commerce/v2' +import Find from '../../../../lib/commerce/v2/offer/find'; + +describe('commerce.v2.offer.find', () => { + before(() => { + nockBack.fixtures = './test/fixtures/commerce/v2'; }); - describe('success', function () { - it('should find offers', function (done) { - nockBack('offer/find-200.json', {}, function (nockDone) { - var find = Find('mock-api-key'); + describe('success', () => { + it('should find offers', done => { + nockBack('offer/find-200.json', {}, nockDone => { + const find = Find('mock-api-key'); find('vvG1iZKU5jIxKX') - .then(function (result) { + .then(result => { result.limits.max.should.equal(14); nockDone(); done(); @@ -24,12 +22,12 @@ describe('commerce.v2.offer.find', function() { }); }); - describe('not found', function() { - it('should handle 500', function(done) { - nockBack('offer/find-500.json', {}, function(nockDone) { - var find = Find('mock-api-key'); + describe('not found', () => { + it('should handle 500', done => { + nockBack('offer/find-500.json', {}, nockDone => { + const find = Find('mock-api-key'); find('unknown-id') - .catch(function(response) { + .catch(response => { response.errors[0].code.should.equal('40001'); nockDone(); done(); diff --git a/test/commerce/v2/offer/index.js b/test/commerce/v2/offer/index.js index 6c0e325..519822c 100644 --- a/test/commerce/v2/offer/index.js +++ b/test/commerce/v2/offer/index.js @@ -1,9 +1,7 @@ -var chai = require("chai"); -var should = chai.should(); -var event = require('../../../../lib/commerce/v2/offer'); +import event from '../../../../lib/commerce/v2/offer'; -describe('commerce.v2.offer', function() { - it('should provide find', function(done) { +describe('commerce.v2.offer', () => { + it('should provide find', (done) => { event().should.have.property('find'); done(); }); diff --git a/test/discovery/index.js b/test/discovery/index.js index a0a0d54..e05d3f1 100644 --- a/test/discovery/index.js +++ b/test/discovery/index.js @@ -1,16 +1,14 @@ -var chai = require("chai"); -var should = chai.should(); -var discovery = require('../../lib/discovery'); +import discovery from '../../lib/discovery'; -describe('discovery', function() { - it('should provide v1', function(done) { +describe('discovery', () => { + it('should provide v1', done => { discovery().should.have.property('v1'); done(); }); }); -describe('discovery', function() { - it('should provide v2', function(done) { +describe('discovery', () => { + it('should provide v2', done => { discovery().should.have.property('v2'); done(); }); diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index 33872d8..3fe70c0 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,12 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/attraction/find'); +var chai = require('chai'); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Find = require('../../../../lib/discovery/v1/attraction/find'); describe('discovery.v1.attraction.find', function() { before(function() { - nockBack.fixtures = './test/fixtures/discovery/v1' + nockBack.fixtures = './test/fixtures/discovery/v1'; }); describe('success', function() { @@ -16,11 +16,11 @@ describe('discovery.v1.attraction.find', function() { find('1542376') .then((function(_this) { return function(result) { - result.name.should.equal("Monster Jam"); + result.name.should.equal('Monster Jam'); nockDone(); done(); }; - })(this)) + })(this)); }); }); }); diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js index 85c905a..9bee98e 100644 --- a/test/discovery/v1/attraction/index.js +++ b/test/discovery/v1/attraction/index.js @@ -1,4 +1,4 @@ -var chai = require("chai"); +var chai = require('chai'); var should = chai.should(); var attraction = require('../../../../lib/discovery/v1/attraction'); diff --git a/test/discovery/v1/attraction/parse_response.js b/test/discovery/v1/attraction/parse_response.js index 7454a99..303b6f6 100644 --- a/test/discovery/v1/attraction/parse_response.js +++ b/test/discovery/v1/attraction/parse_response.js @@ -1,5 +1,5 @@ -var chai = require("chai"); -var should = chai.should(); +var chai = require('chai'); +var should = chai.should(); var getAttractionJson = require('../../../fixtures/discovery/v1/attraction/find-200')[0].response; var ParseResponse = require('../../../../lib/discovery/v1/attraction/parse_response'); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index 81a13b3..8d3d22b 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,12 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/category/find'); +var chai = require('chai'); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Find = require('../../../../lib/discovery/v1/category/find'); describe('discovery.v1.category.find', function() { before(function() { - nockBack.fixtures = './test/fixtures/discovery/v1' + nockBack.fixtures = './test/fixtures/discovery/v1'; }); describe('success', function() { @@ -16,11 +16,11 @@ describe('discovery.v1.category.find', function() { find('10004') .then((function(_this) { return function(result) { - result.name.should.equal("Sports"); + result.name.should.equal('Sports'); nockDone(); done(); }; - })(this)) + })(this)); }); }); }); diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js index 2e325cf..44710b8 100644 --- a/test/discovery/v1/category/index.js +++ b/test/discovery/v1/category/index.js @@ -1,4 +1,4 @@ -var chai = require("chai"); +var chai = require('chai'); var should = chai.should(); var category = require('../../../../lib/discovery/v1/category'); diff --git a/test/discovery/v1/category/parse_response.js b/test/discovery/v1/category/parse_response.js index 963fa22..6538ae3 100644 --- a/test/discovery/v1/category/parse_response.js +++ b/test/discovery/v1/category/parse_response.js @@ -1,5 +1,5 @@ -var chai = require("chai"); -var should = chai.should(); +var chai = require('chai'); +var should = chai.should(); var getCategoryJson = require('../../../fixtures/discovery/v1/category/find-200')[0].response; var ParseResponse = require('../../../../lib/discovery/v1/category/parse_response'); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 48a4953..8e3e79b 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,12 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var All = require('../../../../lib/discovery/v1/event/all'); +var chai = require('chai'); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var All = require('../../../../lib/discovery/v1/event/all'); describe('discovery.v1.event.all', function() { before(function() { - nockBack.fixtures = './test/fixtures/discovery/v1' + nockBack.fixtures = './test/fixtures/discovery/v1'; }); describe('success', function() { @@ -15,10 +15,10 @@ describe('discovery.v1.event.all', function() { var all = All('mock-api-key'); all() .then(function(events) { - events[0].name.should.equal("OSEA Membership Registration"); + events[0].name.should.equal('OSEA Membership Registration'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index 10992be..7a0043f 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,12 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/event/find'); +var chai = require('chai'); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Find = require('../../../../lib/discovery/v1/event/find'); describe('discovery.v1.event.find', function() { before(function() { - nockBack.fixtures = './test/fixtures/discovery/v1' + nockBack.fixtures = './test/fixtures/discovery/v1'; }); describe('success', function() { @@ -16,11 +16,11 @@ describe('discovery.v1.event.find', function() { find('3A004F38C8275108') .then((function(_this) { return function(result) { - result.name.should.equal("Monster Jam"); + result.name.should.equal('Monster Jam'); nockDone(); done(); }; - })(this)) + })(this)); }); }); }); @@ -36,7 +36,7 @@ describe('discovery.v1.event.find', function() { nockDone(); done(); }; - })(this)) + })(this)); }); }); }); diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js index 698a554..d5f6f9e 100644 --- a/test/discovery/v1/event/index.js +++ b/test/discovery/v1/event/index.js @@ -1,4 +1,4 @@ -var chai = require("chai"); +var chai = require('chai'); var should = chai.should(); var event = require('../../../../lib/discovery/v1/event'); diff --git a/test/discovery/v1/event/parse_response.js b/test/discovery/v1/event/parse_response.js index a8a559c..b04749f 100644 --- a/test/discovery/v1/event/parse_response.js +++ b/test/discovery/v1/event/parse_response.js @@ -1,5 +1,5 @@ -var chai = require("chai"); -var should = chai.should(); +var chai = require('chai'); +var should = chai.should(); var getEventJson = require('../../../fixtures/discovery/v1/event/find-200')[0].response; var ParseResponse = require('../../../../lib/discovery/v1/event/parse_response'); diff --git a/test/discovery/v1/index.js b/test/discovery/v1/index.js index 6f1cb91..5a2b56a 100644 --- a/test/discovery/v1/index.js +++ b/test/discovery/v1/index.js @@ -1,6 +1,6 @@ -var chai = require("chai"); +var chai = require('chai'); var should = chai.should(); -var v1 = require('../../../lib/discovery/v1'); +var v1 = require('../../../lib/discovery/v1'); describe('discovery.v1', function() { it('should provide attraction', function(done) { diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index f330014..402df2c 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,12 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/venue/find'); +var chai = require('chai'); +var should = chai.should(); +var nock = require('nock'); +var nockBack = nock.back; +var Find = require('../../../../lib/discovery/v1/venue/find'); describe('discovery.v1.venue.find', function() { before(function() { - nockBack.fixtures = './test/fixtures/discovery/v1' + nockBack.fixtures = './test/fixtures/discovery/v1'; }); describe('success', function() { @@ -16,11 +16,11 @@ describe('discovery.v1.venue.find', function() { find('475247') .then((function(_this) { return function(result) { - result.name.should.equal("Alamodome"); + result.name.should.equal('Alamodome'); nockDone(); done(); }; - })(this)) + })(this)); }); }); }); diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js index e090a76..c6bcde7 100644 --- a/test/discovery/v1/venue/index.js +++ b/test/discovery/v1/venue/index.js @@ -1,4 +1,4 @@ -var chai = require("chai"); +var chai = require('chai'); var should = chai.should(); var venue = require('../../../../lib/discovery/v1/venue'); diff --git a/test/discovery/v1/venue/parse_response.js b/test/discovery/v1/venue/parse_response.js index 6f34b5a..ee286c0 100644 --- a/test/discovery/v1/venue/parse_response.js +++ b/test/discovery/v1/venue/parse_response.js @@ -1,5 +1,5 @@ -var chai = require("chai"); -var should = chai.should(); +var chai = require('chai'); +var should = chai.should(); var getVenueJson = require('../../../fixtures/discovery/v1/venue/find-200')[0].response; var ParseResponse = require('../../../../lib/discovery/v1/venue/parse_response'); diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index a6f2e2f..01b6f0b 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,13 +1,10 @@ -import chai from "chai"; -const should = chai.should(); -import nock from 'nock'; -const nockBack = nock.back; +import {back as nockBack} from 'nock'; import Attraction from '../../../../lib/discovery/v2/attraction'; describe('discovery.v2.attraction.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' + nockBack.fixtures = './test/fixtures/discovery/v2'; }); describe('success', () => { @@ -15,10 +12,10 @@ describe('discovery.v2.attraction.all', () => { nockBack('attraction/all-200.json', {}, nockDone => { Attraction('mock-api-key').all() .then((attractions) => { - attractions.items[0].name.should.equal("!!!"); + attractions.items[0].name.should.equal('!!!'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 2e5fd06..3285b1c 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,13 +1,10 @@ -import chai from "chai"; -const should = chai.should(); -import nock from 'nock'; -const nockBack = nock.back; +import {back as nockBack} from 'nock'; import Attraction from '../../../../lib/discovery/v2/attraction'; describe('discovery.v2.attraction.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' + nockBack.fixtures = './test/fixtures/discovery/v2'; }); describe('success', () => { @@ -15,10 +12,10 @@ describe('discovery.v2.attraction.find', () => { nockBack('attraction/find-200.json', {}, function(nockDone) { Attraction('mock-api-key').find('K8vZ917Kew0') .then(((_this => result => { - result.name.should.equal("Susquehanna Breakdown Music Festival"); - nockDone(); - done(); - }))(this)) + result.name.should.equal('Susquehanna Breakdown Music Festival'); + nockDone(); + done(); + }))(this)); }); }); }); diff --git a/test/discovery/v2/attraction/index.js b/test/discovery/v2/attraction/index.js index 69f76a1..29a3aad 100644 --- a/test/discovery/v2/attraction/index.js +++ b/test/discovery/v2/attraction/index.js @@ -1,6 +1,3 @@ -import chai from "chai"; -const should = chai.should(); - import Attraction from '../../../../lib/discovery/v2/attraction'; describe('discovery.v2.attraction', () => { diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index 8a4898c..7af4b45 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,23 +1,21 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Classification = require('../../../../lib/discovery/v2/classification'); +import {back as nockBack} from 'nock'; -describe('discovery.v2.classification.all', function() { - before(function() { - nockBack.fixtures = './test/fixtures/discovery/v2' +import Classification from '../../../../lib/discovery/v2/classification'; + +describe('discovery.v2.classification.all', () => { + before(() => { + nockBack.fixtures = './test/fixtures/discovery/v2'; }); - describe('success', function() { - it('should find an classification', function(done) { - nockBack('classification/all-200.json', {}, function(nockDone) { + describe('success', () => { + it('should find an classification', done => { + nockBack('classification/all-200.json', {}, nockDone => { Classification('mock-api-key').all() - .then(function(classifications) { + .then(classifications => { classifications.items[0].should.not.be.an('undefined'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index 95a8845..b342fe0 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,23 +1,21 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Classification = require('../../../../lib/discovery/v2/classification'); +import {back as nockBack} from 'nock'; -describe('discovery.v2.classification.find', function() { - before(function() { - nockBack.fixtures = './test/fixtures/discovery/v2' +import Classification from '../../../../lib/discovery/v2/classification'; + +describe('discovery.v2.classification.find', () => { + before(() => { + nockBack.fixtures = './test/fixtures/discovery/v2'; }); - describe('success', function() { - it('should find a classification', function(done) { - nockBack('classification/find-200.json', {}, function(nockDone) { + describe('success', () => { + it('should find a classification', done => { + nockBack('classification/find-200.json', {}, nockDone => { Classification('mock-api-key').find('KZFzniwnSyZfZ7v7na') - .then(function(result) { - result.segment.name.should.equal("Arts & Theatre"); + .then(result => { + result.segment.name.should.equal('Arts & Theatre'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 28d4329..278db08 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,23 +1,21 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Event = require('../../../../lib/discovery/v2/event'); +import {back as nockBack} from 'nock'; -describe('discovery.v2.event.all', function() { - before(function() { - nockBack.fixtures = './test/fixtures/discovery/v2' +import Event from '../../../../lib/discovery/v2/event'; + +describe('discovery.v2.event.all', () => { + before(() => { + nockBack.fixtures = './test/fixtures/discovery/v2'; }); - describe('success', function() { - it('should find an event', function(done) { - nockBack('event/all-200.json', {}, function(nockDone) { + describe('success', () => { + it('should find an event', done => { + nockBack('event/all-200.json', {}, nockDone => { Event('mock-api-key').all() - .then(function(events) { - events.items[0].name.should.equal("OSEA Membership Registration"); + .then(events => { + events.items[0].name.should.equal('OSEA Membership Registration'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index ebad96f..cd0def4 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -1,20 +1,35 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Event = require('../../../../lib/discovery/v2/event'); +import {back as nockBack} from 'nock'; -describe('discovery.v2.event.find', function() { - before(function() { - nockBack.fixtures = './test/fixtures/discovery/v2' +import Event from '../../../../lib/discovery/v2/event'; + +describe('discovery.v2.event.find', () => { + before(() => { + nockBack.fixtures = './test/fixtures/discovery/v2'; }); - describe('success', function() { - it('should find an event', function(done) { - nockBack('event/find-200.json', {}, function(nockDone) { + describe('success', () => { + it('should find an event', done => { + nockBack('event/find-200.json', {}, nockDone => { Event('mock-api-key').find('vv17FZfdGkSrrMju') - .then(function(result) { - result.name.should.equal("Susquehanna Breakdown RV Pass"); + .then(result => { + result.name.should.equal('Susquehanna Breakdown RV Pass'); + nockDone(); + done(); + }); + }); + }); + + it('should find images for an event', done => { + nockBack('event/findImages-200.json', {}, nockDone => { + Event('mock-api-key').find('vv17FZfdGkSrrMju', 'images') + .then((result) => { + result.images[0].should.deep.equal({ + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }); nockDone(); done(); }); @@ -22,11 +37,11 @@ describe('discovery.v2.event.find', function() { }); }); - describe('not found', function() { - it('should handle 404', function(done) { - nockBack('event/find-404.json', {}, function(nockDone) { + describe('not found', () => { + it('should handle 404', done => { + nockBack('event/find-404.json', {}, nockDone => { Event('mock-api-key').find('unknown-id') - .catch(function(response) { + .catch(response => { response.errors[0].code.should.equal('DIS1004'); nockDone(); done(); diff --git a/test/discovery/v2/event/index.js b/test/discovery/v2/event/index.js index f17149a..cdbed0b 100644 --- a/test/discovery/v2/event/index.js +++ b/test/discovery/v2/event/index.js @@ -1,14 +1,12 @@ -var chai = require("chai"); -var should = chai.should(); -var event = require('../../../../lib/discovery/v2/event'); +import event from '../../../../lib/discovery/v2/event'; -describe('discovery.v2.event', function() { - it('should provide all', function(done) { +describe('discovery.v2.event', () => { + it('should provide all', done => { event().should.have.property('all'); done(); }); - it('should provide find', function(done) { + it('should provide find', done => { event().should.have.property('find'); done(); }); diff --git a/test/discovery/v2/index.js b/test/discovery/v2/index.js index ca54c81..00376a3 100644 --- a/test/discovery/v2/index.js +++ b/test/discovery/v2/index.js @@ -1,19 +1,17 @@ -var chai = require("chai"); -var should = chai.should(); -var v2 = require('../../../lib/discovery/v2'); +import v2 from '../../../lib/discovery/v2'; -describe('discovery.v2', function() { - it('should provide attraction', function(done) { +describe('discovery.v2', () => { + it('should provide attraction', (done) => { v2().should.have.property('attraction'); done(); }); - it('should provide event', function(done) { + it('should provide event', (done) => { v2().should.have.property('event'); done(); }); - it('should provide venue', function(done) { + it('should provide venue', (done) => { v2().should.have.property('venue'); done(); }); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index 5b224a0..181dba3 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -1,23 +1,21 @@ -var chai = require("chai"); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Venue = require('../../../../lib/discovery/v2/venue'); +import {back as nockBack} from 'nock'; -describe('discovery.v2.venue.find', function() { - before(function() { - nockBack.fixtures = './test/fixtures/discovery/v2' +import Venue from '../../../../lib/discovery/v2/venue'; + +describe('discovery.v2.venue.find', () => { + before(() => { + nockBack.fixtures = './test/fixtures/discovery/v2'; }); - describe('success', function() { - it('should find a venue', function(done) { - nockBack('venue/find-200.json', {}, function(nockDone) { + describe('success', () => { + it('should find a venue', done => { + nockBack('venue/find-200.json', {}, nockDone => { Venue('mock-api-key').find('KovZpZAEA76A') - .then(function(result) { - result.name.should.equal("The Pavilion at Montage Mountain"); + .then(result => { + result.name.should.equal('The Pavilion at Montage Mountain'); nockDone(); done(); - }) + }); }); }); }); diff --git a/test/discovery/v2/venue/index.js b/test/discovery/v2/venue/index.js index 83d645e..1c2ecd5 100644 --- a/test/discovery/v2/venue/index.js +++ b/test/discovery/v2/venue/index.js @@ -1,9 +1,7 @@ -var chai = require("chai"); -var should = chai.should(); -var venue = require('../../../../lib/discovery/v2/venue'); +import venue from '../../../../lib/discovery/v2/venue'; -describe('discovery.v2.venue', function() { - it('should provide find', function(done) { +describe('discovery.v2.venue', () => { + it('should provide find', (done) => { venue().should.have.property('find'); done(); }); diff --git a/test/fixtures/discovery/v2/event/findImages-200.json b/test/fixtures/discovery/v2/event/findImages-200.json new file mode 100644 index 0000000..ebad858 --- /dev/null +++ b/test/fixtures/discovery/v2/event/findImages-200.json @@ -0,0 +1,113 @@ +[ + { + "scope": "https://app.ticketmaster.com", + "method": "GET", + "path": "/discovery/v2/events/vv17FZfdGkSrrMju/images?apikey=mock-api-key", + "status": 200, + "headers": { + "Access-Control-Allow-Headers": "origin, x-requested-with, accept", + "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE", + "Access-Control-Allow-Origin": "*", + "Access-Control-Max-Age": 3628800, + "Content-Type": "application/hal+json;charset=utf-8", + "Date": "Sat, 30 Jul 2016 17:11:07 GMT", + "Rate-Limit": 5000, + "Rate-Limit-Available": 4990, + "Rate-Limit-Over": 0, + "Rate-Limit-Reset": 1469920563443, + "Server": "Apache-Coyote/1.1", + "X-Application-Context": "application:local,default,jphx1:8080", + "X-TM-GTM-Origin": "uapi-us-phx2", + "Content-Length": 1932, + "Connection": "Close" + }, + "response": { + "type": "event", + "id": "Z1lMVSyiJynZ177dJa", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_EVENT_DETAIL_PAGE_16_9.jpg", + "width": 205, + "height": 115, + "fallback": true + }, + { + "ratio": "3_2", + "url": "https://static-label.frontgatetickets.com/common/events/92970.jpg", + "width": 120, + "height": 80, + "fallback": false + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/Z1lMVSyiJynZ177dJa/images?locale=en-us" + } + } + } + } +] From 6e126871912353e7480d01bffacf2050c6c99f8c Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 1 Aug 2016 10:24:59 +0100 Subject: [PATCH 06/46] All files now converted to ES6 --- index.js | 18 ----- lib/commerce/index.js | 4 +- lib/commerce/v2/index.js | 4 +- lib/commerce/v2/offer/find.js | 15 ---- lib/commerce/v2/offer/index.js | 6 +- lib/commerce/v2/utils/all.js | 12 ++++ lib/commerce/v2/utils/find.js | 10 +++ config.js => lib/config.js | 6 +- lib/discovery/v1/attraction.js | 7 ++ lib/discovery/v1/attraction/find.js | 20 ------ lib/discovery/v1/attraction/index.js | 9 --- lib/discovery/v1/attraction/model.js | 8 --- lib/discovery/v1/attraction/parse_response.js | 13 ---- lib/discovery/v1/category.js | 7 ++ lib/discovery/v1/category/find.js | 20 ------ lib/discovery/v1/category/index.js | 9 --- lib/discovery/v1/category/model.js | 7 -- lib/discovery/v1/category/parse_response.js | 11 --- lib/discovery/v1/event.js | 7 ++ lib/discovery/v1/event/all.js | 24 ------- lib/discovery/v1/event/find.js | 20 ------ lib/discovery/v1/event/index.js | 12 ---- lib/discovery/v1/event/model.js | 11 --- lib/discovery/v1/event/parse_response.js | 24 ------- lib/discovery/v1/index.js | 27 +++----- lib/discovery/v1/utils/all.js | 10 +++ lib/discovery/v1/utils/find.js | 10 +++ lib/discovery/v1/venue.js | 7 ++ lib/discovery/v1/venue/find.js | 20 ------ lib/discovery/v1/venue/index.js | 7 -- lib/discovery/v1/venue/model.js | 18 ----- lib/discovery/v1/venue/parse_response.js | 19 ------ lib/discovery/v2/utils/all.js | 5 +- lib/discovery/v2/utils/find.js | 4 +- lib/helpers/request_helper.js | 8 +-- lib/helpers/result_helper.js | 6 +- lib/index.js | 10 +++ package.json | 3 +- test/commerce/v2/offer/find.js | 29 ++++---- test/discovery/v1/attraction/find.js | 25 +++---- test/discovery/v1/attraction/index.js | 8 +-- .../discovery/v1/attraction/parse_response.js | 33 --------- test/discovery/v1/category/find.js | 27 +++----- test/discovery/v1/category/index.js | 8 +-- test/discovery/v1/category/parse_response.js | 28 -------- test/discovery/v1/event/all.js | 31 ++++----- test/discovery/v1/event/find.js | 38 ++++------- test/discovery/v1/event/index.js | 12 ++-- test/discovery/v1/event/parse_response.js | 41 ----------- test/discovery/v1/index.js | 14 ++-- test/discovery/v1/venue/find.js | 25 +++---- test/discovery/v1/venue/index.js | 8 +-- test/discovery/v1/venue/parse_response.js | 68 ------------------- test/discovery/v2/event/all.js | 26 ++++--- test/fixtures/discovery/v1/event/all-200.json | 2 +- 55 files changed, 227 insertions(+), 634 deletions(-) delete mode 100644 index.js delete mode 100644 lib/commerce/v2/offer/find.js create mode 100644 lib/commerce/v2/utils/all.js create mode 100644 lib/commerce/v2/utils/find.js rename config.js => lib/config.js (50%) create mode 100644 lib/discovery/v1/attraction.js delete mode 100644 lib/discovery/v1/attraction/find.js delete mode 100644 lib/discovery/v1/attraction/index.js delete mode 100644 lib/discovery/v1/attraction/model.js delete mode 100644 lib/discovery/v1/attraction/parse_response.js create mode 100644 lib/discovery/v1/category.js delete mode 100644 lib/discovery/v1/category/find.js delete mode 100644 lib/discovery/v1/category/index.js delete mode 100644 lib/discovery/v1/category/model.js delete mode 100644 lib/discovery/v1/category/parse_response.js create mode 100644 lib/discovery/v1/event.js delete mode 100644 lib/discovery/v1/event/all.js delete mode 100644 lib/discovery/v1/event/find.js delete mode 100644 lib/discovery/v1/event/index.js delete mode 100644 lib/discovery/v1/event/model.js delete mode 100644 lib/discovery/v1/event/parse_response.js create mode 100644 lib/discovery/v1/utils/all.js create mode 100644 lib/discovery/v1/utils/find.js create mode 100644 lib/discovery/v1/venue.js delete mode 100644 lib/discovery/v1/venue/find.js delete mode 100644 lib/discovery/v1/venue/index.js delete mode 100644 lib/discovery/v1/venue/model.js delete mode 100644 lib/discovery/v1/venue/parse_response.js create mode 100644 lib/index.js delete mode 100644 test/discovery/v1/attraction/parse_response.js delete mode 100644 test/discovery/v1/category/parse_response.js delete mode 100644 test/discovery/v1/event/parse_response.js delete mode 100644 test/discovery/v1/venue/parse_response.js diff --git a/index.js b/index.js deleted file mode 100644 index 029834d..0000000 --- a/index.js +++ /dev/null @@ -1,18 +0,0 @@ -var discovery = require('./lib/discovery'); -var commerce = require('./lib/commerce'); - -var API = function(apiKey, accessToken) { - return { - apiKey: apiKey, - accessToken: accessToken, - discovery: discovery(apiKey, accessToken), - commerce: commerce(apiKey, accessToken) - } -}; - -module.exports = function(apiKey, accessToken) { - return API(apiKey, accessToken); -}; - -module.exports.discovery = discovery; -module.exports.commerce = commerce; \ No newline at end of file diff --git a/lib/commerce/index.js b/lib/commerce/index.js index af009fc..2d10a12 100644 --- a/lib/commerce/index.js +++ b/lib/commerce/index.js @@ -1,5 +1,5 @@ import v2 from './v2'; -export default (apiKey, accessToken) => ({ - v2: v2(apiKey, accessToken) +export default (apiKey) => ({ + v2: v2(apiKey) }); diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js index 32c46da..54d59e1 100644 --- a/lib/commerce/v2/index.js +++ b/lib/commerce/v2/index.js @@ -1,5 +1,5 @@ import offer from './offer'; -export default (apiKey, accessToken) => ({ - offer: offer(apiKey, accessToken) +export default (apikey) => ({ + offer: offer(apikey) }); diff --git a/lib/commerce/v2/offer/find.js b/lib/commerce/v2/offer/find.js deleted file mode 100644 index a947207..0000000 --- a/lib/commerce/v2/offer/find.js +++ /dev/null @@ -1,15 +0,0 @@ -import getData from '../../../helpers/result_helper'; - -export default (apiKey) => (eventId) => { - const params = { - url: [ - 'commerce/v2', - 'events', - eventId, - 'offers' - ], - qs: {apikey: apiKey} - }; - - return getData(params); -}; diff --git a/lib/commerce/v2/offer/index.js b/lib/commerce/v2/offer/index.js index 8a26598..4bc3519 100644 --- a/lib/commerce/v2/offer/index.js +++ b/lib/commerce/v2/offer/index.js @@ -1,5 +1,5 @@ -import find from './find'; +import find from '../utils/find'; -export default (apiKey, accessToken) => ({ - find: find(apiKey, accessToken) +export default (apikey) => ({ + find: find(apikey, 'events') }); diff --git a/lib/commerce/v2/utils/all.js b/lib/commerce/v2/utils/all.js new file mode 100644 index 0000000..8cc90bb --- /dev/null +++ b/lib/commerce/v2/utils/all.js @@ -0,0 +1,12 @@ +import getData from '../../../helpers/result_helper'; + +export default (apikey, type) => (options = {}) => { + options.apikey = apikey; + + const params = { + url: ['commerce/v2', type], + qs: options + }; + + return getData(params); +}; diff --git a/lib/commerce/v2/utils/find.js b/lib/commerce/v2/utils/find.js new file mode 100644 index 0000000..ab073f4 --- /dev/null +++ b/lib/commerce/v2/utils/find.js @@ -0,0 +1,10 @@ +import getData from '../../../helpers/result_helper'; + +export default (apikey, type) => (...path) => { + const params = { + url: ['commerce/v2', type, ...path], + qs: {apikey} + }; + + return getData(params); +}; diff --git a/config.js b/lib/config.js similarity index 50% rename from config.js rename to lib/config.js index 40a5943..a8b049b 100644 --- a/config.js +++ b/lib/config.js @@ -1,5 +1,5 @@ -var config = { +const config = { baseURL: "https://app.ticketmaster.com" -} +}; -module.exports = config; +export default config; diff --git a/lib/discovery/v1/attraction.js b/lib/discovery/v1/attraction.js new file mode 100644 index 0000000..c4c0ce8 --- /dev/null +++ b/lib/discovery/v1/attraction.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'attractions'), + find: find(apiKey, 'attractions') +}); diff --git a/lib/discovery/v1/attraction/find.js b/lib/discovery/v1/attraction/find.js deleted file mode 100644 index ef73e3c..0000000 --- a/lib/discovery/v1/attraction/find.js +++ /dev/null @@ -1,20 +0,0 @@ -var Promise = require('bluebird'); -var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); - -module.exports = function(apiKey, accessToken) { - return function(attractionId) { - return requestAsync({ - url: config.baseURL + '/discovery/v1/attractions/' + attractionId + '?apikey=' + apiKey, - method: 'GET' - }) - .then(function(response) { - var parsedBody = JSON.parse(response.body); - if (response.statusCode === 200) { - return parsedBody; - } else { - return Promise.reject(parsedBody); - } - }); - }; -}; diff --git a/lib/discovery/v1/attraction/index.js b/lib/discovery/v1/attraction/index.js deleted file mode 100644 index e697cd2..0000000 --- a/lib/discovery/v1/attraction/index.js +++ /dev/null @@ -1,9 +0,0 @@ -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - find: find(apiKey, accessToken) - }; -}; - -module.exports.find = find; diff --git a/lib/discovery/v1/attraction/model.js b/lib/discovery/v1/attraction/model.js deleted file mode 100644 index 72734fe..0000000 --- a/lib/discovery/v1/attraction/model.js +++ /dev/null @@ -1,8 +0,0 @@ -var Attraction = function() { - this.id = undefined; - this.name = undefined; - this.url = undefined; - this.image_url = undefined; -}; - -module.exports = Attraction; diff --git a/lib/discovery/v1/attraction/parse_response.js b/lib/discovery/v1/attraction/parse_response.js deleted file mode 100644 index 71f4226..0000000 --- a/lib/discovery/v1/attraction/parse_response.js +++ /dev/null @@ -1,13 +0,0 @@ -var Attraction = require('./model'); - -module.exports = function(response) { - var attraction = new Attraction(); - - attraction.id = response.id; - attraction.name = response.name; - attraction.url = response.url; - attraction.url = response.url; - attraction.image_url = response.image.url; - - return attraction; -}; diff --git a/lib/discovery/v1/category.js b/lib/discovery/v1/category.js new file mode 100644 index 0000000..5d2dc74 --- /dev/null +++ b/lib/discovery/v1/category.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'categories'), + find: find(apiKey, 'categories') +}); diff --git a/lib/discovery/v1/category/find.js b/lib/discovery/v1/category/find.js deleted file mode 100644 index 7806f7a..0000000 --- a/lib/discovery/v1/category/find.js +++ /dev/null @@ -1,20 +0,0 @@ -var Promise = require('bluebird'); -var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); - -module.exports = function(apiKey) { - return function(categoryId) { - return requestAsync({ - url: config.baseURL + '/discovery/v1/categories/' + categoryId + '?apikey=' + apiKey, - method: 'GET' - }) - .then(function(response) { - var parsedBody = JSON.parse(response.body); - if (response.statusCode === 200) { - return parsedBody; - } else { - return Promise.reject(parsedBody); - } - }); - }; -}; diff --git a/lib/discovery/v1/category/index.js b/lib/discovery/v1/category/index.js deleted file mode 100644 index e697cd2..0000000 --- a/lib/discovery/v1/category/index.js +++ /dev/null @@ -1,9 +0,0 @@ -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - find: find(apiKey, accessToken) - }; -}; - -module.exports.find = find; diff --git a/lib/discovery/v1/category/model.js b/lib/discovery/v1/category/model.js deleted file mode 100644 index 78e9182..0000000 --- a/lib/discovery/v1/category/model.js +++ /dev/null @@ -1,7 +0,0 @@ -var Category = function() { - this.id = undefined; - this.name = undefined; - this.level = undefined; -}; - -module.exports = Category; diff --git a/lib/discovery/v1/category/parse_response.js b/lib/discovery/v1/category/parse_response.js deleted file mode 100644 index 4470a27..0000000 --- a/lib/discovery/v1/category/parse_response.js +++ /dev/null @@ -1,11 +0,0 @@ -var Category = require('./model'); - -module.exports = function(response) { - var category = new Category(); - - category.id = response.id; - category.name = response.name; - category.level = response.level; - - return category; -}; diff --git a/lib/discovery/v1/event.js b/lib/discovery/v1/event.js new file mode 100644 index 0000000..89c7276 --- /dev/null +++ b/lib/discovery/v1/event.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'events'), + find: find(apiKey, 'events') +}); diff --git a/lib/discovery/v1/event/all.js b/lib/discovery/v1/event/all.js deleted file mode 100644 index 540a7ee..0000000 --- a/lib/discovery/v1/event/all.js +++ /dev/null @@ -1,24 +0,0 @@ -var Promise = require('bluebird'); -var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); - -module.exports = function(apiKey, accessToken) { - return function(options) { - options = options || {}; - options.apikey = apiKey; - - return requestAsync({ - url: config.baseURL + '/discovery/v1/events/', - method: 'GET', - qs: options - }) - .then(function(response) { - var parsedBody = JSON.parse(response.body); - if (response.statusCode === 200) { - return parsedBody._embedded.events; - } else { - return Promise.reject(parsedBody); - } - }); - }; -}; diff --git a/lib/discovery/v1/event/find.js b/lib/discovery/v1/event/find.js deleted file mode 100644 index b31993a..0000000 --- a/lib/discovery/v1/event/find.js +++ /dev/null @@ -1,20 +0,0 @@ -var Promise = require('bluebird'); -var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); - -module.exports = function(apiKey) { - return function(eventId) { - return requestAsync({ - url: config.baseURL + '/discovery/v1/events/' + eventId + '?apikey=' + apiKey, - method: 'GET' - }) - .then(function(response) { - var parsedBody = JSON.parse(response.body); - if (response.statusCode === 200) { - return parsedBody; - } else { - return Promise.reject(parsedBody); - } - }); - }; -}; diff --git a/lib/discovery/v1/event/index.js b/lib/discovery/v1/event/index.js deleted file mode 100644 index 99c602b..0000000 --- a/lib/discovery/v1/event/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var all = require('./all'); -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - all: all(apiKey, accessToken), - find: find(apiKey, accessToken) - }; -}; - -module.exports.all = all; -module.exports.find = find; diff --git a/lib/discovery/v1/event/model.js b/lib/discovery/v1/event/model.js deleted file mode 100644 index ea3b687..0000000 --- a/lib/discovery/v1/event/model.js +++ /dev/null @@ -1,11 +0,0 @@ -var Event = function() { - this.id = undefined; - this.name = undefined; - this.locale = undefined; - - this.categories = []; - this.attractions = []; - this.venue = undefined; -}; - -module.exports = Event; diff --git a/lib/discovery/v1/event/parse_response.js b/lib/discovery/v1/event/parse_response.js deleted file mode 100644 index a97d50c..0000000 --- a/lib/discovery/v1/event/parse_response.js +++ /dev/null @@ -1,24 +0,0 @@ -var Event = require('./model'); -var CategoryParser = require('../category/parse_response'); -var AttractionParser = require('../attraction/parse_response'); -var VenueParser = require('../venue/parse_response'); - -module.exports = function(response) { - var event = new Event(); - - event.id = response.id; - event.name = response.name; - event.locale = response.locale; - - response._embedded.categories.forEach(function(response) { - event.categories.push(CategoryParser(response)); - }); - - response._embedded.attractions.forEach(function(response) { - event.attractions.push(AttractionParser(response)); - }); - - event.venue = VenueParser(response._embedded.venue[0]); - - return event; -}; diff --git a/lib/discovery/v1/index.js b/lib/discovery/v1/index.js index fcaf64a..bf84e4d 100644 --- a/lib/discovery/v1/index.js +++ b/lib/discovery/v1/index.js @@ -1,18 +1,11 @@ -var attraction = require('./attraction'); -var category = require('./category'); -var event = require('./event'); -var venue = require('./venue'); +import attraction from './attraction'; +import category from './category'; +import event from './event'; +import venue from './venue'; -module.exports = function(apiKey, accessToken) { - return { - attraction: attraction(apiKey, accessToken), - category: category(apiKey, accessToken), - event: event(apiKey, accessToken), - venue: venue(apiKey, accessToken) - }; -}; - -module.exports.attraction = attraction; -module.exports.category = category; -module.exports.event = event; -module.exports.venue = venue; +export default apiKey => ({ + attraction: attraction(apiKey), + category: category(apiKey), + event: event(apiKey), + venue: venue(apiKey) +}); diff --git a/lib/discovery/v1/utils/all.js b/lib/discovery/v1/utils/all.js new file mode 100644 index 0000000..1e32a28 --- /dev/null +++ b/lib/discovery/v1/utils/all.js @@ -0,0 +1,10 @@ +import getData from '../../../helpers/result_helper'; + +export default (apikey, type) => (options = {}) => { + options.apikey = apikey; + + return getData({ + url: ['discovery/v1', type], + qs: options + }); +}; diff --git a/lib/discovery/v1/utils/find.js b/lib/discovery/v1/utils/find.js new file mode 100644 index 0000000..eab7b54 --- /dev/null +++ b/lib/discovery/v1/utils/find.js @@ -0,0 +1,10 @@ +import getData from '../../../helpers/result_helper'; + +export default (apikey, type) => (...path) => { + const params = { + url: ['discovery/v1', type, ...path], + qs: {apikey} + }; + + return getData(params); +}; diff --git a/lib/discovery/v1/venue.js b/lib/discovery/v1/venue.js new file mode 100644 index 0000000..3e4ba46 --- /dev/null +++ b/lib/discovery/v1/venue.js @@ -0,0 +1,7 @@ +import all from './utils/all'; +import find from './utils/find'; + +export default (apiKey) => ({ + all: all(apiKey, 'venues'), + find: find(apiKey, 'venues') +}); diff --git a/lib/discovery/v1/venue/find.js b/lib/discovery/v1/venue/find.js deleted file mode 100644 index 9462782..0000000 --- a/lib/discovery/v1/venue/find.js +++ /dev/null @@ -1,20 +0,0 @@ -var Promise = require('bluebird'); -var requestAsync = require('../../../helpers/request_helper'); -var config = require('../../../../config'); - -module.exports = function(apiKey) { - return function(venueId) { - return requestAsync({ - url: config.baseURL + '/discovery/v1/venues/' + venueId + '?apikey=' + apiKey, - method: 'GET' - }) - .then(function(response) { - var parsedBody = JSON.parse(response.body); - if (response.statusCode === 200) { - return parsedBody; - } else { - return Promise.reject(parsedBody); - } - }); - }; -}; diff --git a/lib/discovery/v1/venue/index.js b/lib/discovery/v1/venue/index.js deleted file mode 100644 index 9ea812b..0000000 --- a/lib/discovery/v1/venue/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var find = require('./find'); - -module.exports = function(apiKey, accessToken) { - return { - find: find(apiKey, accessToken) - }; -}; diff --git a/lib/discovery/v1/venue/model.js b/lib/discovery/v1/venue/model.js deleted file mode 100644 index 1dc184c..0000000 --- a/lib/discovery/v1/venue/model.js +++ /dev/null @@ -1,18 +0,0 @@ -var Venue = function() { - this.id = undefined; - this.name = undefined; - this.test = undefined; - this.url = undefined; - this.locale = undefined; - this.postalCode = undefined; - this.timezone = undefined; - this.city = undefined; - this.state = undefined; - this.country = undefined; - this.address = undefined; - this.location = undefined; - this.markets = undefined; - this.dmas = undefined; -}; - -module.exports = Venue; diff --git a/lib/discovery/v1/venue/parse_response.js b/lib/discovery/v1/venue/parse_response.js deleted file mode 100644 index 8910a75..0000000 --- a/lib/discovery/v1/venue/parse_response.js +++ /dev/null @@ -1,19 +0,0 @@ -var Venue = require('./model'); - -module.exports = function(response) { - var venue = new Venue(); - - venue.id = response.id; - venue.name = response.name; - venue.country = response.country.countryCode; - venue.state = response.state.stateCode; - venue.city = response.city.name; - venue.postal_code = response.postalCode; - venue.latitude = response.location.latitude; - venue.longitude = response.location.longitude; - venue.address_line_1 = response.address.line1; - venue.address_line_2 = response.address.line2; - venue.time_zone = response.timeZone; - - return venue; -}; diff --git a/lib/discovery/v2/utils/all.js b/lib/discovery/v2/utils/all.js index 666b0ea..bdab8fc 100644 --- a/lib/discovery/v2/utils/all.js +++ b/lib/discovery/v2/utils/all.js @@ -1,7 +1,8 @@ import getData from '../../../helpers/result_helper'; -export default (apiKey, type) => (options = {}) => { - options.apikey = apiKey; +export default (apikey, type) => (options = {}) => { + options.apikey = apikey; + const params = { url: ['discovery/v2', type], qs: options diff --git a/lib/discovery/v2/utils/find.js b/lib/discovery/v2/utils/find.js index 1b531d6..ab438c4 100644 --- a/lib/discovery/v2/utils/find.js +++ b/lib/discovery/v2/utils/find.js @@ -1,9 +1,9 @@ import getData from '../../../helpers/result_helper'; -export default (apiKey, type) => (...path) => { +export default (apikey, type) => (...path) => { const params = { url: ['discovery/v2', type, ...path], - qs: {apikey: apiKey} + qs: {apikey} }; return getData(params); diff --git a/lib/helpers/request_helper.js b/lib/helpers/request_helper.js index ad5d960..88652b4 100644 --- a/lib/helpers/request_helper.js +++ b/lib/helpers/request_helper.js @@ -1,7 +1,7 @@ -var Promise = require('bluebird'); -var request = require('request'); +import Promise from 'bluebird'; +import request from 'request'; -var requestAsync = Promise.promisify(request.defaults({ +const requestAsync = Promise.promisify(request.defaults({ headers: { 'Accept': 'application/json' }, @@ -9,4 +9,4 @@ var requestAsync = Promise.promisify(request.defaults({ timeout: 30000 })); -module.exports = requestAsync; +export default requestAsync; diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index 5b00ace..73e3c1b 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -1,6 +1,6 @@ import Promise from 'bluebird'; import requestAsync from './request_helper'; -import config from '../../config'; +import config from '../config'; let params; @@ -38,7 +38,7 @@ class Result { * @param step {number} * @returns {promise} */ - nextPage(step=1) { + nextPage(step = 1) { if (this.page && this.page.number <= this.page.totalPages) { params.qs.page = this.page.number + step; @@ -54,7 +54,7 @@ class Result { * @param step {number} * @returns {promise} */ - previousPage(step=1) { + previousPage(step = 1) { if (this.page && this.page.number > 0) { params.qs.page = this.page.number - step; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..6490fed --- /dev/null +++ b/lib/index.js @@ -0,0 +1,10 @@ +import discovery from './discovery/index'; +import commerce from './commerce/index'; + +const API = (apikey) => ({ + apikey, + discovery: discovery(apikey), + commerce: commerce(apikey) +}); + +export default API; diff --git a/package.json b/package.json index 1bb2da0..d04cd85 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "ticketmaster", "version": "1.0.0", "description": "SDK for the Ticketmaster Open Platform", - "main": "index.js", + "main": "dist/server/index.js", + "jsnext:main": "lib/index.js", "scripts": { "build": "webpack && npm run prod", "dev": "webpack", diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index a44f470..16e9287 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Find from '../../../../lib/commerce/v2/offer/find'; +import Offer from '../../../../lib/commerce/v2/offer'; describe('commerce.v2.offer.find', () => { before(() => { @@ -8,12 +8,10 @@ describe('commerce.v2.offer.find', () => { }); describe('success', () => { - it('should find offers', done => { - nockBack('offer/find-200.json', {}, nockDone => { - const find = Find('mock-api-key'); - - find('vvG1iZKU5jIxKX') - .then(result => { + it('should find offers', (done) => { + nockBack('offer/find-200.json', {}, (nockDone) => { + Offer('mock-api-key').find('vvG1iZKU5jIxKX', 'offers') + .then((result) => { result.limits.max.should.equal(14); nockDone(); done(); @@ -23,15 +21,14 @@ describe('commerce.v2.offer.find', () => { }); describe('not found', () => { - it('should handle 500', done => { - nockBack('offer/find-500.json', {}, nockDone => { - const find = Find('mock-api-key'); - find('unknown-id') - .catch(response => { - response.errors[0].code.should.equal('40001'); - nockDone(); - done(); - }); + it('should handle 500', (done) => { + nockBack('offer/find-500.json', {}, (nockDone) => { + Offer('mock-api-key').find('unknown-id', 'offers') + .catch((response) => { + response.errors[0].code.should.equal('40001'); + nockDone(); + done(); + }); }); }); }); diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index 3fe70c0..aa660cc 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,26 +1,21 @@ -var chai = require('chai'); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/attraction/find'); +import {back as nockBack} from 'nock'; -describe('discovery.v1.attraction.find', function() { - before(function() { +import Attraction from '../../../../lib/discovery/v1/attraction'; + +describe('discovery.v1.attraction.find', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v1'; }); - describe('success', function() { - it('should find a attraction', function(done) { + describe('success', () => { + it('should find a attraction', done => { nockBack('attraction/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('1542376') - .then((function(_this) { - return function(result) { + Attraction('mock-api-key').find('1542376') + .then((result) => { result.name.should.equal('Monster Jam'); nockDone(); done(); - }; - })(this)); + }); }); }); }); diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js index 9bee98e..cc400f6 100644 --- a/test/discovery/v1/attraction/index.js +++ b/test/discovery/v1/attraction/index.js @@ -1,9 +1,7 @@ -var chai = require('chai'); -var should = chai.should(); -var attraction = require('../../../../lib/discovery/v1/attraction'); +import attraction from '../../../../lib/discovery/v1/attraction'; -describe('discovery.v1.attraction', function() { - it('should provide find', function(done) { +describe('discovery.v1.attraction', () => { + it('should provide find', done => { attraction().should.have.property('find'); done(); }); diff --git a/test/discovery/v1/attraction/parse_response.js b/test/discovery/v1/attraction/parse_response.js deleted file mode 100644 index 303b6f6..0000000 --- a/test/discovery/v1/attraction/parse_response.js +++ /dev/null @@ -1,33 +0,0 @@ -var chai = require('chai'); -var should = chai.should(); -var getAttractionJson = require('../../../fixtures/discovery/v1/attraction/find-200')[0].response; -var ParseResponse = require('../../../../lib/discovery/v1/attraction/parse_response'); - -describe('discovery.v1.attraction.parseResponse', function() { - describe('success', function() { - it('should return a Attraction object', function(done) { - ParseResponse(getAttractionJson).should.be.a('object'); - done(); - }); - - it('should set name', function(done) { - ParseResponse(getAttractionJson).name.should.eq('Monster Jam'); - done(); - }); - - it('should set id', function(done) { - ParseResponse(getAttractionJson).id.should.eq('1542376'); - done(); - }); - - it('should set url', function(done) { - ParseResponse(getAttractionJson).url.should.eq('/Monster-Jam-tickets/artist/1542376'); - done(); - }); - - it('should set image_url', function(done) { - ParseResponse(getAttractionJson).image_url.should.eq('/dam/a/538/8948796f-1145-44d1-b738-c4308059d538_55751_EVENT_DETAIL_PAGE_16_9.jpg'); - done(); - }); - }); -}); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index 8d3d22b..7b24a37 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,26 +1,21 @@ -var chai = require('chai'); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/category/find'); +import {back as nockBack} from 'nock'; -describe('discovery.v1.category.find', function() { - before(function() { +import Category from '../../../../lib/discovery/v1/category'; + +describe('discovery.v1.category.find', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v1'; }); - describe('success', function() { - it('should find a category', function(done) { - nockBack('category/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('10004') - .then((function(_this) { - return function(result) { + describe('success', () => { + it('should find a category', done => { + nockBack('category/find-200.json', {}, nockDone => { + Category('mock-api-key').find('10004') + .then((result) => { result.name.should.equal('Sports'); nockDone(); done(); - }; - })(this)); + }); }); }); }); diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js index 44710b8..008d7e5 100644 --- a/test/discovery/v1/category/index.js +++ b/test/discovery/v1/category/index.js @@ -1,9 +1,7 @@ -var chai = require('chai'); -var should = chai.should(); -var category = require('../../../../lib/discovery/v1/category'); +import category from '../../../../lib/discovery/v1/category'; -describe('discovery.v1.category', function() { - it('should provide find', function(done) { +describe('discovery.v1.category', () => { + it('should provide find', done => { category().should.have.property('find'); done(); }); diff --git a/test/discovery/v1/category/parse_response.js b/test/discovery/v1/category/parse_response.js deleted file mode 100644 index 6538ae3..0000000 --- a/test/discovery/v1/category/parse_response.js +++ /dev/null @@ -1,28 +0,0 @@ -var chai = require('chai'); -var should = chai.should(); -var getCategoryJson = require('../../../fixtures/discovery/v1/category/find-200')[0].response; -var ParseResponse = require('../../../../lib/discovery/v1/category/parse_response'); - -describe('discovery.v1.category.parseResponse', function() { - describe('success', function() { - it('should return a Category object', function(done) { - ParseResponse(getCategoryJson).should.be.a('object'); - done(); - }); - - it('should set name', function(done) { - ParseResponse(getCategoryJson).name.should.eq('Sports'); - done(); - }); - - it('should set id', function(done) { - ParseResponse(getCategoryJson).id.should.eq('10004'); - done(); - }); - - it('should set level', function(done) { - ParseResponse(getCategoryJson).level.should.eq(1); - done(); - }); - }); -}); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 8e3e79b..06b59c6 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,24 +1,21 @@ -var chai = require('chai'); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var All = require('../../../../lib/discovery/v1/event/all'); +import {back as nockBack} from 'nock'; -describe('discovery.v1.event.all', function() { - before(function() { +import Event from '../../../../lib/discovery/v1/event'; + +describe('discovery.v1.event.all', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v1'; }); - describe('success', function() { - it('should find an event', function(done) { - nockBack('event/all-200.json', {}, function(nockDone) { - var all = All('mock-api-key'); - all() - .then(function(events) { - events[0].name.should.equal('OSEA Membership Registration'); - nockDone(); - done(); - }); + describe('success', () => { + it('should find an event', done => { + nockBack('event/all-200.json', {}, nockDone => { + Event('mock-api-key').all() + .then((result) => { + result.items[0].name.should.equal('OSEA Membership Registration'); + nockDone(); + done(); + }); }); }); }); diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index 7a0043f..de81b87 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,42 +1,34 @@ -var chai = require('chai'); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/event/find'); +import {back as nockBack} from 'nock'; -describe('discovery.v1.event.find', function() { - before(function() { +import Event from '../../../../lib/discovery/v1/event'; + +describe('discovery.v1.event.find', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v1'; }); - describe('success', function() { - it('should find an event', function(done) { + describe('success', () => { + it('should find an event', done => { nockBack('event/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('3A004F38C8275108') - .then((function(_this) { - return function(result) { + Event('mock-api-key').find('3A004F38C8275108') + .then((result) => { result.name.should.equal('Monster Jam'); nockDone(); done(); - }; - })(this)); + }); }); }); }); - describe('not found', function() { - it('should handle 404', function(done) { + describe('not found', () => { + it('should handle 404', done => { nockBack('event/find-404.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('unknown-id') - .catch((function(_this) { - return function(response) { + Event('mock-api-key').find('unknown-id') + .catch((response) => { response.errors[0].code.should.equal('DIS1004'); nockDone(); done(); - }; - })(this)); + }); }); }); }); diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js index d5f6f9e..218af01 100644 --- a/test/discovery/v1/event/index.js +++ b/test/discovery/v1/event/index.js @@ -1,14 +1,14 @@ -var chai = require('chai'); -var should = chai.should(); -var event = require('../../../../lib/discovery/v1/event'); +import chai from 'chai'; +const should = chai.should(); +import event from '../../../../lib/discovery/v1/event'; -describe('discovery.v1.event', function() { - it('should provide find', function(done) { +describe('discovery.v1.event', () => { + it('should provide find', done => { event().should.have.property('find'); done(); }); - it('should provide all', function(done) { + it('should provide all', done => { event().should.have.property('all'); done(); }); diff --git a/test/discovery/v1/event/parse_response.js b/test/discovery/v1/event/parse_response.js deleted file mode 100644 index b04749f..0000000 --- a/test/discovery/v1/event/parse_response.js +++ /dev/null @@ -1,41 +0,0 @@ -var chai = require('chai'); -var should = chai.should(); -var getEventJson = require('../../../fixtures/discovery/v1/event/find-200')[0].response; -var ParseResponse = require('../../../../lib/discovery/v1/event/parse_response'); - -describe('discovery.v1.event.parseResponse', function() { - describe('success', function() { - it('should return an Event object', function(done) { - ParseResponse(getEventJson).should.be.a('object'); - done(); - }); - - it('should set name', function(done) { - ParseResponse(getEventJson).name.should.eq('Monster Jam'); - done(); - }); - - it('should set locale', function(done) { - ParseResponse(getEventJson).locale.should.eq('en-us'); - done(); - }); - - it('should set categories', function(done) { - ParseResponse(getEventJson).categories.should.be.a('array'); - ParseResponse(getEventJson).categories[0].should.be.a('object'); - ParseResponse(getEventJson).categories[1].should.be.a('object'); - done(); - }); - - it('should set attractions', function(done) { - ParseResponse(getEventJson).attractions.should.be.a('array'); - ParseResponse(getEventJson).attractions[0].should.be.a('object'); - done(); - }); - - it('should set venue', function(done) { - ParseResponse(getEventJson).venue.should.be.a('object'); - done(); - }); - }); -}); diff --git a/test/discovery/v1/index.js b/test/discovery/v1/index.js index 5a2b56a..f7f7092 100644 --- a/test/discovery/v1/index.js +++ b/test/discovery/v1/index.js @@ -1,24 +1,22 @@ -var chai = require('chai'); -var should = chai.should(); -var v1 = require('../../../lib/discovery/v1'); +import v1 from '../../../lib/discovery/v1'; -describe('discovery.v1', function() { - it('should provide attraction', function(done) { +describe('discovery.v1', () => { + it('should provide attraction', done => { v1().should.have.property('attraction'); done(); }); - it('should provide category', function(done) { + it('should provide category', done => { v1().should.have.property('category'); done(); }); - it('should provide event', function(done) { + it('should provide event', done => { v1().should.have.property('event'); done(); }); - it('should provide venue', function(done) { + it('should provide venue', done => { v1().should.have.property('venue'); done(); }); diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index 402df2c..08aaf46 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,26 +1,21 @@ -var chai = require('chai'); -var should = chai.should(); -var nock = require('nock'); -var nockBack = nock.back; -var Find = require('../../../../lib/discovery/v1/venue/find'); +import {back as nockBack} from 'nock'; -describe('discovery.v1.venue.find', function() { - before(function() { +import Venue from '../../../../lib/discovery/v1/venue'; + +describe('discovery.v1.venue.find', () => { + before(() => { nockBack.fixtures = './test/fixtures/discovery/v1'; }); - describe('success', function() { - it('should find a venue', function(done) { + describe('success', () => { + it('should find a venue', done => { nockBack('venue/find-200.json', {}, function(nockDone) { - var find = Find('mock-api-key'); - find('475247') - .then((function(_this) { - return function(result) { + Venue('mock-api-key').find('475247') + .then((result) => { result.name.should.equal('Alamodome'); nockDone(); done(); - }; - })(this)); + }); }); }); }); diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js index c6bcde7..a58c185 100644 --- a/test/discovery/v1/venue/index.js +++ b/test/discovery/v1/venue/index.js @@ -1,9 +1,7 @@ -var chai = require('chai'); -var should = chai.should(); -var venue = require('../../../../lib/discovery/v1/venue'); +import venue from '../../../../lib/discovery/v1/venue'; -describe('discovery.v1.venue', function() { - it('should provide find', function(done) { +describe('discovery.v1.venue', () => { + it('should provide find', (done) => { venue().should.have.property('find'); done(); }); diff --git a/test/discovery/v1/venue/parse_response.js b/test/discovery/v1/venue/parse_response.js deleted file mode 100644 index ee286c0..0000000 --- a/test/discovery/v1/venue/parse_response.js +++ /dev/null @@ -1,68 +0,0 @@ -var chai = require('chai'); -var should = chai.should(); -var getVenueJson = require('../../../fixtures/discovery/v1/venue/find-200')[0].response; -var ParseResponse = require('../../../../lib/discovery/v1/venue/parse_response'); - -describe('discovery.v1.venue.parseResponse', function() { - describe('success', function() { - it('should return a Venue object', function(done) { - ParseResponse(getVenueJson).should.be.a('object'); - done(); - }); - - it('should set name', function(done) { - ParseResponse(getVenueJson).name.should.eq('Alamodome'); - done(); - }); - - it('should set id', function(done) { - ParseResponse(getVenueJson).id.should.eq('475247'); - done(); - }); - - it('should set country', function(done) { - ParseResponse(getVenueJson).country.should.eq('US'); - done(); - }); - - it('should set state', function(done) { - ParseResponse(getVenueJson).state.should.eq('TX'); - done(); - }); - - it('should set city', function(done) { - ParseResponse(getVenueJson).city.should.eq('San Antonio'); - done(); - }); - - it('should set postal_code', function(done) { - ParseResponse(getVenueJson).postal_code.should.eq('78203'); - done(); - }); - - it('should set latitude', function(done) { - ParseResponse(getVenueJson).latitude.should.eq('29.417054662'); - done(); - }); - - it('should set longitude', function(done) { - ParseResponse(getVenueJson).longitude.should.eq('-98.479151396'); - done(); - }); - - it('should set address_line_1', function(done) { - ParseResponse(getVenueJson).address_line_1.should.eq('100 Montana St'); - done(); - }); - - it('should set address_line_2', function(done) { - ParseResponse(getVenueJson).address_line_2.should.eq('San Antonio, TX'); - done(); - }); - - it('should set time_zone', function(done) { - ParseResponse(getVenueJson).time_zone.should.eq('America/Chicago'); - done(); - }); - }); -}); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 278db08..734b321 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,21 +1,31 @@ import {back as nockBack} from 'nock'; +import sdk from '../../../../lib'; import Event from '../../../../lib/discovery/v2/event'; +const api = sdk('mock-api-key'); + +const onResult = (done, nockDone) => (result) => { + result.items[0].name.should.equal('OSEA Membership Registration'); + nockDone(); + done(); +} + describe('discovery.v2.event.all', () => { before(() => { nockBack.fixtures = './test/fixtures/discovery/v2'; }); describe('success', () => { - it('should find an event', done => { - nockBack('event/all-200.json', {}, nockDone => { - Event('mock-api-key').all() - .then(events => { - events.items[0].name.should.equal('OSEA Membership Registration'); - nockDone(); - done(); - }); + it('should find an event using the fluent API', (done) => { + nockBack('event/all-200.json', {}, (nockDone) => { + api.discovery.v2.event.all().then(onResult(done, nockDone)) + }); + }); + + it('should find an event', (done) => { + nockBack('event/all-200.json', {}, (nockDone) => { + Event('mock-api-key').all().then(onResult(done, nockDone)) }); }); }); diff --git a/test/fixtures/discovery/v1/event/all-200.json b/test/fixtures/discovery/v1/event/all-200.json index 0a66f75..cc30ca3 100644 --- a/test/fixtures/discovery/v1/event/all-200.json +++ b/test/fixtures/discovery/v1/event/all-200.json @@ -2,7 +2,7 @@ { "scope": "https://app.ticketmaster.com", "method": "GET", - "path": "/discovery/v1/events/?apikey=mock-api-key", + "path": "/discovery/v1/events?apikey=mock-api-key", "status": 200, "headers": { "Access-Control-Allow-Headers": "origin, x-requested-with, accept", From 6c7f50103a2436b905c4530f55fc4c0abaf77ad3 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 1 Aug 2016 14:33:14 +0100 Subject: [PATCH 07/46] initial foray --- lib/helpers/result_helper.js | 2 +- package.json | 10 ++++++---- webpack.config.js | 37 +++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index 73e3c1b..0816100 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -1,4 +1,4 @@ -import Promise from 'bluebird'; +// import Promise from 'bluebird'; import requestAsync from './request_helper'; import config from '../config'; diff --git a/package.json b/package.json index d04cd85..e1bb2d8 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "ticketmaster", "version": "1.0.0", "description": "SDK for the Ticketmaster Open Platform", - "main": "dist/server/index.js", + "main": "dist/index.js", "jsnext:main": "lib/index.js", "scripts": { - "build": "webpack && npm run prod", + "build": "npm run prod", "dev": "webpack", "prod": "cross-env NODE_ENV=prod webpack", + "prod:assess": "cross-env NODE_ENV=prod webpack --display-modules --sort-modules-by size", "test": "mocha --compilers js:babel-core/register --recursive", "postversion": "./scripts/post-release.sh", "lint": "eslint ./lib ./test" @@ -27,6 +28,7 @@ "license": "MIT", "devDependencies": { "babel-core": "^6.11.4", + "babel-loader": "^6.2.4", "babel-preset-es2015": "^6.9.0", "chai": "3.5.0", "cross-env": "^2.0.0", @@ -38,10 +40,10 @@ "json-loader": "^0.5.4", "mocha": "2.5.3", "nock": "8.0.0", - "webpack": "^1.13.1" + "webpack": "^2.1.0-beta.20" }, "dependencies": { - "bluebird": "3.4.1", + "bluebird": "^3.4.1", "request": "2.74.0" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" diff --git a/webpack.config.js b/webpack.config.js index 93a826d..b1ce88e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,23 +1,29 @@ -var path = require('path'), - webpack = require('webpack'), - PROD = process.env.NODE_ENV && process.env.NODE_ENV.trim() === 'prod', - filename = 'ticketmaster-client-' + require('./package.json').version; +var path = require('path'); +var webpack = require('webpack'); +var env = process.env.NODE_ENV || 'development'; +var PROD = env === 'prod'; +var filename = 'ticketmaster-client-' + require('./package.json').version; module.exports = { - entry: './index.js', + entry: './lib/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: PROD ? [filename, '.min.js'].join('') : [filename, '.js'].join(''), - library: "TMAPI" // global + library: 'TMAPI' // global }, - devtool: PROD ? '' : '#cheap-module-inline-source-map', + devtool: PROD ? false : 'cheap-module-inline-source-map', node: { - fs: "empty", - net: "empty", - tls: "empty" + fs: 'empty', + net: 'empty', + tls: 'empty' }, module: { loaders: [ + { + test: /\.js$/, + loader: 'babel', + include: path.join(process.cwd(), 'lib') + }, { test: /\.json$/, loader: 'json' @@ -26,13 +32,10 @@ module.exports = { }, plugins: [ new webpack.NoErrorsPlugin(), - PROD ? new webpack.optimize.UglifyJsPlugin({ - compress: { - warnings: false - }, + new webpack.DefinePlugin({NODE_ENV: env}), + new webpack.optimize.UglifyJsPlugin({ + compress: {warnings: false}, comments: false - }) : new webpack.DefinePlugin({ - NODE_ENV: 'development' }) ] -}; \ No newline at end of file +}; From 0d5398b73b5009ad7ec23315c22ea609a1a797f5 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 1 Aug 2016 16:44:09 +0100 Subject: [PATCH 08/46] stripped out weightier elements like Bluebird --- .babelrc | 8 ++++++- docs/index.html | 19 ++++++++++++++++ lib/helpers/result_helper.js | 39 +++++++++++++++++++-------------- package.json | 12 +++++++--- test/discovery/v2/event/find.js | 10 ++++----- webpack.config.js | 18 +++++++++++---- 6 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 docs/index.html diff --git a/.babelrc b/.babelrc index 8eb1003..7ee2175 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,10 @@ { "compact": "true", - "presets": ["es2015"] + "plugins": ["lodash"], + "presets": ["es2015-webpack"], + "env": { + "test": { + "presets": ["es2015"] + } + } } diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..2771cd7 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,19 @@ + + + + + TMAPI + + + + + + + + diff --git a/lib/helpers/result_helper.js b/lib/helpers/result_helper.js index 0816100..73a7bf7 100644 --- a/lib/helpers/result_helper.js +++ b/lib/helpers/result_helper.js @@ -1,5 +1,8 @@ // import Promise from 'bluebird'; -import requestAsync from './request_helper'; +// import requestAsync from './request_helper'; +import fetch from 'isomorphic-fetch'; +import queryString from 'query-string'; + import config from '../config'; let params; @@ -95,27 +98,29 @@ class Result { * * @param url {string} * @param qs {string} - * @param method {string} + * @param options {object} * * @returns {promise} */ -const getData = ({url, qs, method = 'GET'}) => - requestAsync({url: [config.baseURL].concat(url).join('/'), method, qs}) - .then((response) => { - const result = JSON.parse(response.body); - - if (response.statusCode === 200) { - if (url[2]) { - return result; - } - - return new Result({ - items: result._embedded && result._embedded[url[1]], - page: result.page - }); +const getData = ({url, qs, options = {method: 'GET'}}) => { + return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) + .then((res) => { + if (res.status === 200) { + return res.json(); + } + + return res.json().then(Promise.reject.bind(Promise)); + }) + .then((json) => { + if (url[2]) { + return json; } - return Promise.reject(result); + return new Result({ + items: json._embedded && json._embedded[url[1]], + page: json.page + }); }); +}; export default getData; diff --git a/package.json b/package.json index e1bb2d8..bf22ddd 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "scripts": { "build": "npm run prod", "dev": "webpack", - "prod": "cross-env NODE_ENV=prod webpack", - "prod:assess": "cross-env NODE_ENV=prod webpack --display-modules --sort-modules-by size", - "test": "mocha --compilers js:babel-core/register --recursive", + "prod": "cross-env NODE_ENV=production webpack", + "prod:assess": "cross-env NODE_ENV=production webpack --display-modules --sort-modules-by size", + "test": "cross-env NODE_ENV=test mocha --compilers js:babel-register --recursive", "postversion": "./scripts/post-release.sh", "lint": "eslint ./lib ./test" }, @@ -29,7 +29,10 @@ "devDependencies": { "babel-core": "^6.11.4", "babel-loader": "^6.2.4", + "babel-plugin-lodash": "^3.2.6", "babel-preset-es2015": "^6.9.0", + "babel-preset-es2015-webpack": "^6.4.2", + "babel-register": "^6.11.6", "chai": "3.5.0", "cross-env": "^2.0.0", "eslint": "^3.1.1", @@ -37,13 +40,16 @@ "eslint-plugin-promise": "^2.0.0", "eslint-plugin-standard": "^2.0.0", "inherits": "^2.0.1", + "isomorphic-fetch": "^2.2.1", "json-loader": "^0.5.4", + "lodash-webpack-plugin": "^0.9.3", "mocha": "2.5.3", "nock": "8.0.0", "webpack": "^2.1.0-beta.20" }, "dependencies": { "bluebird": "^3.4.1", + "query-string": "^4.2.2", "request": "2.74.0" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index cd0def4..2065bfc 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -24,11 +24,11 @@ describe('discovery.v2.event.find', () => { Event('mock-api-key').find('vv17FZfdGkSrrMju', 'images') .then((result) => { result.images[0].should.deep.equal({ - "ratio": "3_2", - "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", - "width": 305, - "height": 203, - "fallback": true + 'ratio': '3_2', + 'url': 'http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg', + 'width': 305, + 'height': 203, + 'fallback': true }); nockDone(); done(); diff --git a/webpack.config.js b/webpack.config.js index b1ce88e..e856c90 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,15 +1,18 @@ var path = require('path'); var webpack = require('webpack'); +var LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); + var env = process.env.NODE_ENV || 'development'; -var PROD = env === 'prod'; +var PROD = env === 'production'; var filename = 'ticketmaster-client-' + require('./package.json').version; module.exports = { entry: './lib/index.js', output: { path: path.resolve(__dirname, 'dist'), - filename: PROD ? [filename, '.min.js'].join('') : [filename, '.js'].join(''), - library: 'TMAPI' // global + filename: PROD ? filename + '.min.js' : filename + '.js', + library: 'TMAPI', // global + libraryTarget: 'umd' }, devtool: PROD ? false : 'cheap-module-inline-source-map', node: { @@ -31,11 +34,18 @@ module.exports = { ] }, plugins: [ + new LodashModuleReplacementPlugin(), new webpack.NoErrorsPlugin(), + new webpack.optimize.OccurrenceOrderPlugin, new webpack.DefinePlugin({NODE_ENV: env}), + new webpack.LoaderOptionsPlugin({ + minimize: true, + debug: false + }), new webpack.optimize.UglifyJsPlugin({ compress: {warnings: false}, - comments: false + comments: false, + sourceMap: false }) ] }; From d9f48b437e0f99705d99b4bcee94f98ba1b5d4ca Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 00:51:30 +0100 Subject: [PATCH 09/46] updated deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bf22ddd..91095be 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "babel-register": "^6.11.6", "chai": "3.5.0", "cross-env": "^2.0.0", - "eslint": "^3.1.1", + "eslint": "^3.2.2", "eslint-config-standard": "^5.3.5", "eslint-plugin-promise": "^2.0.0", "eslint-plugin-standard": "^2.0.0", @@ -43,7 +43,7 @@ "isomorphic-fetch": "^2.2.1", "json-loader": "^0.5.4", "lodash-webpack-plugin": "^0.9.3", - "mocha": "2.5.3", + "mocha": "3.0.0", "nock": "8.0.0", "webpack": "^2.1.0-beta.20" }, From b7a03723466035f5556b316a9d5dacd51b3e2e0e Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 02:03:37 +0100 Subject: [PATCH 10/46] Fixed promise issues --- .../result_helper.js => commerce/page.js} | 55 ++--------- lib/commerce/{v2 => }/utils/all.js | 2 +- lib/commerce/{v2 => }/utils/find.js | 2 +- lib/commerce/utils/getData.js | 28 ++++++ lib/commerce/v2/offer/index.js | 2 +- lib/discovery/page.js | 91 +++++++++++++++++++ lib/discovery/{v2 => }/utils/all.js | 2 +- lib/discovery/{v2 => }/utils/find.js | 2 +- lib/discovery/utils/getData.js | 28 ++++++ lib/discovery/v1/attraction.js | 4 +- lib/discovery/v1/category.js | 4 +- lib/discovery/v1/event.js | 4 +- lib/discovery/v1/utils/all.js | 10 -- lib/discovery/v1/utils/find.js | 10 -- lib/discovery/v1/venue.js | 4 +- lib/discovery/v2/attraction.js | 4 +- lib/discovery/v2/classification.js | 4 +- lib/discovery/v2/event.js | 4 +- lib/discovery/v2/venue.js | 2 +- lib/helpers/request_helper.js | 12 --- test/discovery/v1/attraction/find.js | 3 +- test/discovery/v1/category/find.js | 3 +- test/discovery/v1/event/all.js | 3 +- test/discovery/v1/event/find.js | 10 +- test/discovery/v1/venue/find.js | 3 +- test/discovery/v2/attraction/all.js | 7 +- test/discovery/v2/attraction/find.js | 9 +- test/discovery/v2/classification/all.js | 11 ++- test/discovery/v2/event/all.js | 16 +++- test/discovery/v2/event/find.js | 25 ++--- test/discovery/v2/venue/find.js | 7 +- 31 files changed, 237 insertions(+), 134 deletions(-) rename lib/{helpers/result_helper.js => commerce/page.js} (59%) rename lib/commerce/{v2 => }/utils/all.js (77%) rename lib/commerce/{v2 => }/utils/find.js (74%) create mode 100644 lib/commerce/utils/getData.js create mode 100644 lib/discovery/page.js rename lib/discovery/{v2 => }/utils/all.js (77%) rename lib/discovery/{v2 => }/utils/find.js (75%) create mode 100644 lib/discovery/utils/getData.js delete mode 100644 lib/discovery/v1/utils/all.js delete mode 100644 lib/discovery/v1/utils/find.js delete mode 100644 lib/helpers/request_helper.js diff --git a/lib/helpers/result_helper.js b/lib/commerce/page.js similarity index 59% rename from lib/helpers/result_helper.js rename to lib/commerce/page.js index 73a7bf7..73afc01 100644 --- a/lib/helpers/result_helper.js +++ b/lib/commerce/page.js @@ -1,26 +1,21 @@ -// import Promise from 'bluebird'; -// import requestAsync from './request_helper'; -import fetch from 'isomorphic-fetch'; -import queryString from 'query-string'; - -import config from '../config'; +import getData from './utils/getData'; let params; /** - * Result object constructor + * Page object constructor * @param options * @constructor */ // TODO fix params -class Result { +class Page { constructor({items, page, params}) { this.items = items; this.page = page; } /** - * Method of Result object type + * Method of Page object type * Gets some page of results by it's number passed as param. * @param page {number} * @returns {promise} @@ -36,7 +31,7 @@ class Result { }; /** - * Method of Result object type + * Method of Page object type * (Iterator method) Gets next page of same type results * @param step {number} * @returns {promise} @@ -52,7 +47,7 @@ class Result { }; /** - * Method of Result object type + * Method of Page object type * (Iterator method) Gets previous page of same type results * @param step {number} * @returns {promise} @@ -68,7 +63,7 @@ class Result { }; /** - * Method of Result object type + * Method of Page object type * @returns {array|null} */ records() { @@ -76,7 +71,7 @@ class Result { }; /** - * Method of Result object type + * Method of Page object type * @returns {number} quantity of all items of the same type */ count() { @@ -84,7 +79,7 @@ class Result { }; /** - * Method of Result object type + * Method of Page object type * Checker if current result page is the last one * @returns {boolean} */ @@ -93,34 +88,4 @@ class Result { }; } -/** - * Main GET Data configuration function for API - * - * @param url {string} - * @param qs {string} - * @param options {object} - * - * @returns {promise} - */ -const getData = ({url, qs, options = {method: 'GET'}}) => { - return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) - .then((res) => { - if (res.status === 200) { - return res.json(); - } - - return res.json().then(Promise.reject.bind(Promise)); - }) - .then((json) => { - if (url[2]) { - return json; - } - - return new Result({ - items: json._embedded && json._embedded[url[1]], - page: json.page - }); - }); -}; - -export default getData; +export default Page; diff --git a/lib/commerce/v2/utils/all.js b/lib/commerce/utils/all.js similarity index 77% rename from lib/commerce/v2/utils/all.js rename to lib/commerce/utils/all.js index 8cc90bb..3bba53b 100644 --- a/lib/commerce/v2/utils/all.js +++ b/lib/commerce/utils/all.js @@ -1,4 +1,4 @@ -import getData from '../../../helpers/result_helper'; +import getData from './getData'; export default (apikey, type) => (options = {}) => { options.apikey = apikey; diff --git a/lib/commerce/v2/utils/find.js b/lib/commerce/utils/find.js similarity index 74% rename from lib/commerce/v2/utils/find.js rename to lib/commerce/utils/find.js index ab073f4..d1e7a59 100644 --- a/lib/commerce/v2/utils/find.js +++ b/lib/commerce/utils/find.js @@ -1,4 +1,4 @@ -import getData from '../../../helpers/result_helper'; +import getData from './getData'; export default (apikey, type) => (...path) => { const params = { diff --git a/lib/commerce/utils/getData.js b/lib/commerce/utils/getData.js new file mode 100644 index 0000000..f5bd713 --- /dev/null +++ b/lib/commerce/utils/getData.js @@ -0,0 +1,28 @@ +import fetch from 'isomorphic-fetch'; +import queryString from 'query-string'; + +import config from '../../config'; +import Page from '../page'; + +/** + * Main GET Data configuration function for API + * + * @param url {string} + * @param qs {string} + * @param options {object} + * + * @returns {promise} + */ +const getData = ({url, qs, options = {method: 'GET'}}) => { + return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) + .then((res) => { + if (res.status === 200) { + return res.json(); + } + + return res.json().then(Promise.reject.bind(Promise)); + }) + .then((json) => json.page ? new Page({items: json._embedded && json._embedded[url[1]], page: json.page}) : json); +}; + +export default getData; diff --git a/lib/commerce/v2/offer/index.js b/lib/commerce/v2/offer/index.js index 4bc3519..142ee2a 100644 --- a/lib/commerce/v2/offer/index.js +++ b/lib/commerce/v2/offer/index.js @@ -1,4 +1,4 @@ -import find from '../utils/find'; +import find from '../../utils/find'; export default (apikey) => ({ find: find(apikey, 'events') diff --git a/lib/discovery/page.js b/lib/discovery/page.js new file mode 100644 index 0000000..73afc01 --- /dev/null +++ b/lib/discovery/page.js @@ -0,0 +1,91 @@ +import getData from './utils/getData'; + +let params; + +/** + * Page object constructor + * @param options + * @constructor + */ +// TODO fix params +class Page { + constructor({items, page, params}) { + this.items = items; + this.page = page; + } + + /** + * Method of Page object type + * Gets some page of results by it's number passed as param. + * @param page {number} + * @returns {promise} + */ + getPage(page) { + if (page && this.page && page > 0 && page <= this.page.totalPages) { + params.qs.page = page; + + return getData(params); + } + + return Promise.reject({message: 'You should pass correct page number.', page}); + }; + + /** + * Method of Page object type + * (Iterator method) Gets next page of same type results + * @param step {number} + * @returns {promise} + */ + nextPage(step = 1) { + if (this.page && this.page.number <= this.page.totalPages) { + params.qs.page = this.page.number + step; + + return getData(params); + } + + return Promise.reject({message: 'No next page! You are on the last.', params}); + }; + + /** + * Method of Page object type + * (Iterator method) Gets previous page of same type results + * @param step {number} + * @returns {promise} + */ + previousPage(step = 1) { + if (this.page && this.page.number > 0) { + params.qs.page = this.page.number - step; + + return getData(params); + } + + return Promise.reject({message: 'No previous page! You are on the first one.', params}); + }; + + /** + * Method of Page object type + * @returns {array|null} + */ + records() { + return this.items; + }; + + /** + * Method of Page object type + * @returns {number} quantity of all items of the same type + */ + count() { + return this.page && this.page.totalElements || 0; + }; + + /** + * Method of Page object type + * Checker if current result page is the last one + * @returns {boolean} + */ + isLastPage() { + return this.page.number === this.page.totalPages; + }; +} + +export default Page; diff --git a/lib/discovery/v2/utils/all.js b/lib/discovery/utils/all.js similarity index 77% rename from lib/discovery/v2/utils/all.js rename to lib/discovery/utils/all.js index bdab8fc..4758c76 100644 --- a/lib/discovery/v2/utils/all.js +++ b/lib/discovery/utils/all.js @@ -1,4 +1,4 @@ -import getData from '../../../helpers/result_helper'; +import getData from './getData'; export default (apikey, type) => (options = {}) => { options.apikey = apikey; diff --git a/lib/discovery/v2/utils/find.js b/lib/discovery/utils/find.js similarity index 75% rename from lib/discovery/v2/utils/find.js rename to lib/discovery/utils/find.js index ab438c4..2a043ae 100644 --- a/lib/discovery/v2/utils/find.js +++ b/lib/discovery/utils/find.js @@ -1,4 +1,4 @@ -import getData from '../../../helpers/result_helper'; +import getData from './getData'; export default (apikey, type) => (...path) => { const params = { diff --git a/lib/discovery/utils/getData.js b/lib/discovery/utils/getData.js new file mode 100644 index 0000000..f5bd713 --- /dev/null +++ b/lib/discovery/utils/getData.js @@ -0,0 +1,28 @@ +import fetch from 'isomorphic-fetch'; +import queryString from 'query-string'; + +import config from '../../config'; +import Page from '../page'; + +/** + * Main GET Data configuration function for API + * + * @param url {string} + * @param qs {string} + * @param options {object} + * + * @returns {promise} + */ +const getData = ({url, qs, options = {method: 'GET'}}) => { + return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) + .then((res) => { + if (res.status === 200) { + return res.json(); + } + + return res.json().then(Promise.reject.bind(Promise)); + }) + .then((json) => json.page ? new Page({items: json._embedded && json._embedded[url[1]], page: json.page}) : json); +}; + +export default getData; diff --git a/lib/discovery/v1/attraction.js b/lib/discovery/v1/attraction.js index c4c0ce8..c91da36 100644 --- a/lib/discovery/v1/attraction.js +++ b/lib/discovery/v1/attraction.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'attractions'), diff --git a/lib/discovery/v1/category.js b/lib/discovery/v1/category.js index 5d2dc74..f7f7efc 100644 --- a/lib/discovery/v1/category.js +++ b/lib/discovery/v1/category.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'categories'), diff --git a/lib/discovery/v1/event.js b/lib/discovery/v1/event.js index 89c7276..86edf9c 100644 --- a/lib/discovery/v1/event.js +++ b/lib/discovery/v1/event.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'events'), diff --git a/lib/discovery/v1/utils/all.js b/lib/discovery/v1/utils/all.js deleted file mode 100644 index 1e32a28..0000000 --- a/lib/discovery/v1/utils/all.js +++ /dev/null @@ -1,10 +0,0 @@ -import getData from '../../../helpers/result_helper'; - -export default (apikey, type) => (options = {}) => { - options.apikey = apikey; - - return getData({ - url: ['discovery/v1', type], - qs: options - }); -}; diff --git a/lib/discovery/v1/utils/find.js b/lib/discovery/v1/utils/find.js deleted file mode 100644 index eab7b54..0000000 --- a/lib/discovery/v1/utils/find.js +++ /dev/null @@ -1,10 +0,0 @@ -import getData from '../../../helpers/result_helper'; - -export default (apikey, type) => (...path) => { - const params = { - url: ['discovery/v1', type, ...path], - qs: {apikey} - }; - - return getData(params); -}; diff --git a/lib/discovery/v1/venue.js b/lib/discovery/v1/venue.js index 3e4ba46..7e66c1e 100644 --- a/lib/discovery/v1/venue.js +++ b/lib/discovery/v1/venue.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'venues'), diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js index c4c0ce8..c91da36 100644 --- a/lib/discovery/v2/attraction.js +++ b/lib/discovery/v2/attraction.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'attractions'), diff --git a/lib/discovery/v2/classification.js b/lib/discovery/v2/classification.js index f1e4390..71211b2 100644 --- a/lib/discovery/v2/classification.js +++ b/lib/discovery/v2/classification.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'classifications'), diff --git a/lib/discovery/v2/event.js b/lib/discovery/v2/event.js index 89c7276..86edf9c 100644 --- a/lib/discovery/v2/event.js +++ b/lib/discovery/v2/event.js @@ -1,5 +1,5 @@ -import all from './utils/all'; -import find from './utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'events'), diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js index 835967f..f6dde26 100644 --- a/lib/discovery/v2/venue.js +++ b/lib/discovery/v2/venue.js @@ -1,4 +1,4 @@ -import find from './utils/find'; +import find from '../utils/find'; export default (apiKey) => ({ find: find(apiKey, 'venues') diff --git a/lib/helpers/request_helper.js b/lib/helpers/request_helper.js deleted file mode 100644 index 88652b4..0000000 --- a/lib/helpers/request_helper.js +++ /dev/null @@ -1,12 +0,0 @@ -import Promise from 'bluebird'; -import request from 'request'; - -const requestAsync = Promise.promisify(request.defaults({ - headers: { - 'Accept': 'application/json' - }, - withCredentials: false, - timeout: 30000 -})); - -export default requestAsync; diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index aa660cc..e7307aa 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -15,7 +15,8 @@ describe('discovery.v1.attraction.find', () => { result.name.should.equal('Monster Jam'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index 7b24a37..c55b75c 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -15,7 +15,8 @@ describe('discovery.v1.category.find', () => { result.name.should.equal('Sports'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 06b59c6..90d5226 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -15,7 +15,8 @@ describe('discovery.v1.event.all', () => { result.items[0].name.should.equal('OSEA Membership Registration'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index de81b87..d5d7960 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -15,7 +15,8 @@ describe('discovery.v1.event.find', () => { result.name.should.equal('Monster Jam'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); @@ -24,11 +25,12 @@ describe('discovery.v1.event.find', () => { it('should handle 404', done => { nockBack('event/find-404.json', {}, function(nockDone) { Event('mock-api-key').find('unknown-id') - .catch((response) => { - response.errors[0].code.should.equal('DIS1004'); + .then((result) => { + result.errors[0].code.should.equal('DIS1004'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index 08aaf46..967a531 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -15,7 +15,8 @@ describe('discovery.v1.venue.find', () => { result.name.should.equal('Alamodome'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index 01b6f0b..dcba7da 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -11,11 +11,12 @@ describe('discovery.v2.attraction.all', () => { it('should find an attraction', (done) => { nockBack('attraction/all-200.json', {}, nockDone => { Attraction('mock-api-key').all() - .then((attractions) => { - attractions.items[0].name.should.equal('!!!'); + .then((result) => { + result.items[0].name.should.equal('!!!'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 3285b1c..2c110a4 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -8,14 +8,15 @@ describe('discovery.v2.attraction.find', () => { }); describe('success', () => { - it('should find a attraction', done => { - nockBack('attraction/find-200.json', {}, function(nockDone) { + it('should find a attraction', (done) => { + nockBack('attraction/find-200.json', {}, (nockDone) => { Attraction('mock-api-key').find('K8vZ917Kew0') - .then(((_this => result => { + .then((result) => { result.name.should.equal('Susquehanna Breakdown Music Festival'); nockDone(); done(); - }))(this)); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index 7af4b45..578ae49 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -8,14 +8,15 @@ describe('discovery.v2.classification.all', () => { }); describe('success', () => { - it('should find an classification', done => { - nockBack('classification/all-200.json', {}, nockDone => { + it('should find an classification', (done) => { + nockBack('classification/all-200.json', {}, (nockDone) => { Classification('mock-api-key').all() - .then(classifications => { - classifications.items[0].should.not.be.an('undefined'); + .then((result) => { + result.items[0].should.not.be.an('undefined'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 734b321..8c0d75d 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -9,7 +9,13 @@ const onResult = (done, nockDone) => (result) => { result.items[0].name.should.equal('OSEA Membership Registration'); nockDone(); done(); -} +}; + +const onError = (done, nockDone) => (err) => { + // console.log('error caught', err); + nockDone(); + done(); +}; describe('discovery.v2.event.all', () => { before(() => { @@ -19,13 +25,17 @@ describe('discovery.v2.event.all', () => { describe('success', () => { it('should find an event using the fluent API', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - api.discovery.v2.event.all().then(onResult(done, nockDone)) + api.discovery.v2.event.all() + .then(onResult(done, nockDone)) + .catch(onError(done, nockDone)); }); }); it('should find an event', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - Event('mock-api-key').all().then(onResult(done, nockDone)) + Event('mock-api-key').all() + .then(onResult(done, nockDone)) + .catch(onError(done, nockDone)); }); }); }); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 2065bfc..1997ad7 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -8,19 +8,20 @@ describe('discovery.v2.event.find', () => { }); describe('success', () => { - it('should find an event', done => { - nockBack('event/find-200.json', {}, nockDone => { + it('should find an event', (done) => { + nockBack('event/find-200.json', {}, (nockDone) => { Event('mock-api-key').find('vv17FZfdGkSrrMju') - .then(result => { + .then((result) => { result.name.should.equal('Susquehanna Breakdown RV Pass'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); - it('should find images for an event', done => { - nockBack('event/findImages-200.json', {}, nockDone => { + it('should find images for an event', (done) => { + nockBack('event/findImages-200.json', {}, (nockDone) => { Event('mock-api-key').find('vv17FZfdGkSrrMju', 'images') .then((result) => { result.images[0].should.deep.equal({ @@ -32,20 +33,22 @@ describe('discovery.v2.event.find', () => { }); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); describe('not found', () => { - it('should handle 404', done => { - nockBack('event/find-404.json', {}, nockDone => { + it('should handle 404', (done) => { + nockBack('event/find-404.json', {}, (nockDone) => { Event('mock-api-key').find('unknown-id') - .catch(response => { + .catch((response) => { response.errors[0].code.should.equal('DIS1004'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index 181dba3..03df1a7 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -9,13 +9,14 @@ describe('discovery.v2.venue.find', () => { describe('success', () => { it('should find a venue', done => { - nockBack('venue/find-200.json', {}, nockDone => { + nockBack('venue/find-200.json', {}, (nockDone) => { Venue('mock-api-key').find('KovZpZAEA76A') - .then(result => { + .then((result) => { result.name.should.equal('The Pavilion at Montage Mountain'); nockDone(); done(); - }); + }) + .catch(() => done()); }); }); }); From 37b8be20dedd07efc6ba6688d7a654b3f32cd5f7 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 10:03:13 +0100 Subject: [PATCH 11/46] Added todos --- webpack.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.js b/webpack.config.js index e856c90..8ff45f8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,4 @@ +// TODO: split dev and production configs var path = require('path'); var webpack = require('webpack'); var LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); From 1172b4fa56bc1b7daf58ba05bf2c0001b869458f Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 18:20:02 +0100 Subject: [PATCH 12/46] Moar tests and a more full-featured demo --- docs/index.html | 22 +- lib/discovery/page.js | 62 +- lib/discovery/utils/all.js | 8 +- lib/discovery/utils/find.js | 2 +- lib/discovery/utils/getData.js | 21 +- test/discovery/v2/classification/all.js | 2 +- test/discovery/v2/classification/find.js | 3 +- test/discovery/v2/event/all.js | 27 +- test/discovery/v2/event/find.js | 6 +- test/discovery/v2/event/options.js | 27 + .../discovery/v2/event/all-200-options.json | 1008 +++++++++++++++++ 11 files changed, 1113 insertions(+), 75 deletions(-) create mode 100644 test/discovery/v2/event/options.js create mode 100644 test/fixtures/discovery/v2/event/all-200-options.json diff --git a/docs/index.html b/docs/index.html index 2771cd7..852a938 100644 --- a/docs/index.html +++ b/docs/index.html @@ -9,10 +9,24 @@ diff --git a/lib/discovery/page.js b/lib/discovery/page.js index 73afc01..8095446 100644 --- a/lib/discovery/page.js +++ b/lib/discovery/page.js @@ -1,7 +1,5 @@ import getData from './utils/getData'; -let params; - /** * Page object constructor * @param options @@ -9,25 +7,29 @@ let params; */ // TODO fix params class Page { - constructor({items, page, params}) { - this.items = items; + constructor({_embedded, page}, path, qs) { + const itemKey = Object.keys(_embedded)[0]; + + this.items = _embedded[itemKey]; this.page = page; + this.path = path; + this.qs = qs; } /** * Method of Page object type * Gets some page of results by it's number passed as param. - * @param page {number} + * @param n {number} * @returns {promise} */ - getPage(page) { - if (page && this.page && page > 0 && page <= this.page.totalPages) { - params.qs.page = page; + getAt(n) { + const qs = Object.assign({}, this.qs, {page: n}); - return getData(params); + if (n > 0 && n <= this.page.totalPages) { + return getData({path: this.path, qs}); } - return Promise.reject({message: 'You should pass correct page number.', page}); + return Promise.reject({message: 'You should pass correct page number.', qs}); }; /** @@ -36,14 +38,15 @@ class Page { * @param step {number} * @returns {promise} */ - nextPage(step = 1) { - if (this.page && this.page.number <= this.page.totalPages) { - params.qs.page = this.page.number + step; + getNext(step = 1) { + const n = this.page.number + step; + const qs = Object.assign({}, this.qs, {page: n}); - return getData(params); + if (n <= this.page.totalPages) { + return getData({path: this.path, qs}); } - return Promise.reject({message: 'No next page! You are on the last.', params}); + return Promise.reject({message: 'No next page! You are on the last.', qs}); }; /** @@ -52,22 +55,24 @@ class Page { * @param step {number} * @returns {promise} */ - previousPage(step = 1) { - if (this.page && this.page.number > 0) { - params.qs.page = this.page.number - step; + getPrev(step = 1) { + const n = this.page.number - step; + const qs = Object.assign({}, this.qs, {page: n}); - return getData(params); + if (n > 0) { + return getData({path: this.path, qs}); } - return Promise.reject({message: 'No previous page! You are on the first one.', params}); + return Promise.reject({message: 'No previous page! You are on the first one.', qs}); }; /** * Method of Page object type - * @returns {array|null} + * Checker if current result page is the last one + * @returns {boolean} */ - records() { - return this.items; + isLast() { + return this.page.number === this.page.totalPages; }; /** @@ -75,16 +80,7 @@ class Page { * @returns {number} quantity of all items of the same type */ count() { - return this.page && this.page.totalElements || 0; - }; - - /** - * Method of Page object type - * Checker if current result page is the last one - * @returns {boolean} - */ - isLastPage() { - return this.page.number === this.page.totalPages; + return this.page.totalElements; }; } diff --git a/lib/discovery/utils/all.js b/lib/discovery/utils/all.js index 4758c76..013c28e 100644 --- a/lib/discovery/utils/all.js +++ b/lib/discovery/utils/all.js @@ -1,11 +1,11 @@ import getData from './getData'; -export default (apikey, type) => (options = {}) => { - options.apikey = apikey; +export default (apikey, type) => (qs = {}) => { + qs.apikey = apikey; const params = { - url: ['discovery/v2', type], - qs: options + path: ['discovery/v2', type], + qs: qs }; return getData(params); diff --git a/lib/discovery/utils/find.js b/lib/discovery/utils/find.js index 2a043ae..047c945 100644 --- a/lib/discovery/utils/find.js +++ b/lib/discovery/utils/find.js @@ -2,7 +2,7 @@ import getData from './getData'; export default (apikey, type) => (...path) => { const params = { - url: ['discovery/v2', type, ...path], + path: ['discovery/v2', type, ...path], qs: {apikey} }; diff --git a/lib/discovery/utils/getData.js b/lib/discovery/utils/getData.js index f5bd713..a6bae1f 100644 --- a/lib/discovery/utils/getData.js +++ b/lib/discovery/utils/getData.js @@ -4,25 +4,22 @@ import queryString from 'query-string'; import config from '../../config'; import Page from '../page'; +const getURL = (path, qs) => { + return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}`; +}; + /** * Main GET Data configuration function for API * - * @param url {string} + * @param path {array} * @param qs {string} - * @param options {object} * * @returns {promise} */ -const getData = ({url, qs, options = {method: 'GET'}}) => { - return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) - .then((res) => { - if (res.status === 200) { - return res.json(); - } - - return res.json().then(Promise.reject.bind(Promise)); - }) - .then((json) => json.page ? new Page({items: json._embedded && json._embedded[url[1]], page: json.page}) : json); +const getData = ({path, qs}) => { + return fetch(getURL(path, qs)) + .then((res) => (res.status === 200) ? res.json() : res.json().then(Promise.reject.bind(Promise))) + .then((json) => json.page ? new Page(json, path, qs) : json); }; export default getData; diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index 578ae49..5ca1162 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -16,7 +16,7 @@ describe('discovery.v2.classification.all', () => { nockDone(); done(); }) - .catch(() => done()); + .catch((err) => done(err)); }); }); }); diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index b342fe0..4de9ca6 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -15,7 +15,8 @@ describe('discovery.v2.classification.find', () => { result.segment.name.should.equal('Arts & Theatre'); nockDone(); done(); - }); + }) + .catch((err) => done(err)); }); }); }); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 8c0d75d..4ceb255 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -5,37 +5,32 @@ import Event from '../../../../lib/discovery/v2/event'; const api = sdk('mock-api-key'); -const onResult = (done, nockDone) => (result) => { - result.items[0].name.should.equal('OSEA Membership Registration'); - nockDone(); +const onResult = (done) => (page) => { + page.items[0].name.should.equal('OSEA Membership Registration'); done(); }; -const onError = (done, nockDone) => (err) => { - // console.log('error caught', err); - nockDone(); - done(); -}; +nockBack.fixtures = './test/fixtures/discovery/v2'; describe('discovery.v2.event.all', () => { - before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); - describe('success', () => { it('should find an event using the fluent API', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { + nockDone(); + api.discovery.v2.event.all() - .then(onResult(done, nockDone)) - .catch(onError(done, nockDone)); + .then(onResult(done)) + .catch((err) => done(err)); }); }); it('should find an event', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { + nockDone(); + Event('mock-api-key').all() - .then(onResult(done, nockDone)) - .catch(onError(done, nockDone)); + .then(onResult(done)) + .catch((err) => done(err)); }); }); }); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 1997ad7..3fbc1db 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -16,7 +16,7 @@ describe('discovery.v2.event.find', () => { nockDone(); done(); }) - .catch(() => done()); + .catch((err) => done(err)); }); }); @@ -34,7 +34,7 @@ describe('discovery.v2.event.find', () => { nockDone(); done(); }) - .catch(() => done()); + .catch((err) => done(err)); }); }); }); @@ -48,7 +48,7 @@ describe('discovery.v2.event.find', () => { nockDone(); done(); }) - .catch(() => done()); + .catch((err) => done(err)); }); }); }); diff --git a/test/discovery/v2/event/options.js b/test/discovery/v2/event/options.js new file mode 100644 index 0000000..6c95636 --- /dev/null +++ b/test/discovery/v2/event/options.js @@ -0,0 +1,27 @@ +import {back as nockBack} from 'nock'; + +import Event from '../../../../lib/discovery/v2/event'; + +nockBack.fixtures = './test/fixtures/discovery/v2'; + +describe('discovery.v2.event.options', () => { + describe('options', () => { + it('works', (done) => { + nockBack('event/all-200-options.json', (nockDone) => { + nockDone(); + + Event('mock-api-key').all({page: 2, size: 5, sort: 'name,desc'}) + .then((page) => { + page.items.length.should.equal(5); + page.isLast().should.equal(false); + page.getAt(1).should.be.instanceOf(Promise); + page.getNext(1).should.be.instanceOf(Promise); + page.getPrev(1).should.be.instanceOf(Promise); + + done(); + }) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/fixtures/discovery/v2/event/all-200-options.json b/test/fixtures/discovery/v2/event/all-200-options.json new file mode 100644 index 0000000..ecc6d9e --- /dev/null +++ b/test/fixtures/discovery/v2/event/all-200-options.json @@ -0,0 +1,1008 @@ +[ + { + "scope": "https://app.ticketmaster.com", + "method": "GET", + "path": "/discovery/v2/events?apikey=mock-api-key&page=2&size=5&sort=name%2Cdesc", + "status": 200, + "headers": { + "Access-Control-Allow-Headers": "origin, x-requested-with, accept", + "Access-Control-Allow-Origin": "*", + "Date": "Sat, 16 Jan 2016 18:41:27 GMT", + "Content-Length": "3488", + "Access-Control-Max-Age": "3628800", + "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE", + "X-Application-Context": "application:default,jetson4", + "Connection": "keep-alive", + "Content-Type": "application/json;charset=utf-8", + "Server": "Apache-Coyote/1.1" + }, + "response": { + "_links": { + "self": { + "href": "/discovery/v2/events?size=5&sort=name%2Cdesc&page=2" + }, + "next": { + "href": "/discovery/v2/events?page=3&size=5&sort=name,desc" + }, + "prev": { + "href": "/discovery/v2/events?page=1&size=5&sort=name,desc" + } + }, + "_embedded": { + "events": [ + { + "name": "¿Qué tan altos son los edificios de Nueva York?", + "type": "event", + "id": "17AZv8G6CnMcD1x", + "test": false, + "url": "http://ticketmaster.com.mx/event/140050EAB7B7B2A2", + "locale": "en-us", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dbimages/252338a.jpg", + "width": 205, + "height": 115, + "fallback": false + } + ], + "sales": { + "public": { + "startDateTime": "2016-07-20T15:00:00Z", + "startTBD": false, + "endDateTime": "2016-08-24T23:30:00Z" + } + }, + "dates": { + "start": { + "localDate": "2016-08-24", + "localTime": "20:30:00", + "dateTime": "2016-08-25T01:30:00Z", + "dateTBD": false, + "dateTBA": false, + "timeTBA": false, + "noSpecificTime": false + }, + "timezone": "America/Mexico_City", + "status": { + "code": "onsale" + } + }, + "classifications": [ + { + "primary": true, + "segment": { + "id": "KZFzniwnSyZfZ7v7na", + "name": "Arts & Theatre" + }, + "genre": { + "id": "KnvZfZ7v7nt", + "name": "Espectaculo" + }, + "subGenre": { + "id": "KZazBEonSMnZfZ7v7lv", + "name": "Espectaculo" + } + } + ], + "promoter": { + "id": "3324", + "name": "MONDIAL PRICE 2", + "description": "MONDIAL PRICE 2 / NTL / MXC" + }, + "info": "Sinopsis:Tan sólo entre 2013 y 2014 se calcula que en México fueron asesinadas diariamente siete mujeres. ¿Qué tan altos son los edificios en Nueva York? desnuda el abismo social, jurisdiccional e incluso psíquico que se delinea a la par de una frontera y muro de contención por los cuales transitan insondables historias que muchas veces quedan sepultadas en las inagotables arenas del desierto Elenco:Pilar Couto Américo del Río* Leticia Pedrajo Estela Rivera Javier Sáncehez Medín Villatoro *Beneficiario del Programa de Creadores Escénicos 2015 del Fondo Nacional para la Cultura y las Artes", + "pleaseNote": "Conoce nuestras políticas de entrega. Límite de edad: Mayores de 16 años Pagan boleto a partir de: 16 años. Restricciones: No introducir alimentos ni bebidas,No tomar fotografía ni video Límite de acceso: Se recomienda llegar 15 minutos antes del evento Servicios: convenio con el estacionamiento del monumento a la madre presentando tu boleto de estacionamiento en la taquilla del teatro Duración aproximada: 60min. Página oficial: www.cultura.df.gob.mx/www.teatros.cultutra.df.gob.mx", + "priceRanges": [ + { + "type": "standard", + "currency": "MXN", + "min": 136.0, + "max": 136.0 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/17AZv8G6CnMcD1x?locale=en-us" + }, + "venues": [ + { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + ] + }, + "_embedded": { + "venues": [ + { + "name": "Teatro Benito Juárez", + "type": "venue", + "id": "KovZpZAd1taA", + "test": false, + "url": "http://ticketmaster.com.mx/venue/164154", + "locale": "en-us", + "postalCode": "08400", + "timezone": "America/Mexico_City", + "city": { + "name": "México" + }, + "state": { + "name": "Distrito Federal", + "stateCode": "DF" + }, + "country": { + "name": "Mexico", + "countryCode": "MX" + }, + "address": { + "line1": "Villalongin No. 15, Col. Cuauhtémoc" + }, + "markets": [ + { + "id": "401" + }, + { + "id": "402" + } + ], + "dmas": [ + { + "id": 801 + }, + { + "id": 802 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + } + } + ] + } + }, + { + "name": "¿Qué tan altos son los edificios de Nueva York?", + "type": "event", + "id": "17AZv8G6CnMcD1G", + "test": false, + "url": "http://ticketmaster.com.mx/event/140050EAB7B7B28C", + "locale": "en-us", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dbimages/252338a.jpg", + "width": 205, + "height": 115, + "fallback": false + } + ], + "sales": { + "public": { + "startDateTime": "2016-07-20T15:00:00Z", + "startTBD": false, + "endDateTime": "2016-08-23T23:30:00Z" + } + }, + "dates": { + "start": { + "localDate": "2016-08-23", + "localTime": "20:30:00", + "dateTime": "2016-08-24T01:30:00Z", + "dateTBD": false, + "dateTBA": false, + "timeTBA": false, + "noSpecificTime": false + }, + "timezone": "America/Mexico_City", + "status": { + "code": "onsale" + } + }, + "classifications": [ + { + "primary": true, + "segment": { + "id": "KZFzniwnSyZfZ7v7na", + "name": "Arts & Theatre" + }, + "genre": { + "id": "KnvZfZ7v7nt", + "name": "Espectaculo" + }, + "subGenre": { + "id": "KZazBEonSMnZfZ7v7lv", + "name": "Espectaculo" + } + } + ], + "promoter": { + "id": "3324", + "name": "MONDIAL PRICE 2", + "description": "MONDIAL PRICE 2 / NTL / MXC" + }, + "info": "Sinopsis:Tan sólo entre 2013 y 2014 se calcula que en México fueron asesinadas diariamente siete mujeres. ¿Qué tan altos son los edificios en Nueva York? desnuda el abismo social, jurisdiccional e incluso psíquico que se delinea a la par de una frontera y muro de contención por los cuales transitan insondables historias que muchas veces quedan sepultadas en las inagotables arenas del desierto Elenco:Pilar Couto Américo del Río* Leticia Pedrajo Estela Rivera Javier Sáncehez Medín Villatoro *Beneficiario del Programa de Creadores Escénicos 2015 del Fondo Nacional para la Cultura y las Artes", + "pleaseNote": "Conoce nuestras políticas de entrega. Límite de edad: Mayores de 16 años Pagan boleto a partir de: 16 años. Restricciones: No introducir alimentos ni bebidas,No tomar fotografía ni video Límite de acceso: Se recomienda llegar 15 minutos antes del evento Servicios: convenio con el estacionamiento del monumento a la madre presentando tu boleto de estacionamiento en la taquilla del teatro Duración aproximada: 60min. Página oficial: www.cultura.df.gob.mx/www.teatros.cultutra.df.gob.mx", + "priceRanges": [ + { + "type": "standard", + "currency": "MXN", + "min": 136.0, + "max": 136.0 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/17AZv8G6CnMcD1G?locale=en-us" + }, + "venues": [ + { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + ] + }, + "_embedded": { + "venues": [ + { + "name": "Teatro Benito Juárez", + "type": "venue", + "id": "KovZpZAd1taA", + "test": false, + "url": "http://ticketmaster.com.mx/venue/164154", + "locale": "en-us", + "postalCode": "08400", + "timezone": "America/Mexico_City", + "city": { + "name": "México" + }, + "state": { + "name": "Distrito Federal", + "stateCode": "DF" + }, + "country": { + "name": "Mexico", + "countryCode": "MX" + }, + "address": { + "line1": "Villalongin No. 15, Col. Cuauhtémoc" + }, + "markets": [ + { + "id": "401" + }, + { + "id": "402" + } + ], + "dmas": [ + { + "id": 801 + }, + { + "id": 802 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + } + } + ] + } + }, + { + "name": "¿Qué tan altos son los edificios de Nueva York?", + "type": "event", + "id": "17AZv8G6CnMsh1T", + "test": false, + "url": "http://ticketmaster.com.mx/event/140050EAB7C5B2BF", + "locale": "en-us", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dbimages/252338a.jpg", + "width": 205, + "height": 115, + "fallback": false + } + ], + "sales": { + "public": { + "startDateTime": "2016-07-20T15:00:00Z", + "startTBD": false, + "endDateTime": "2016-09-14T23:30:00Z" + } + }, + "dates": { + "start": { + "localDate": "2016-09-14", + "localTime": "20:30:00", + "dateTime": "2016-09-15T01:30:00Z", + "dateTBD": false, + "dateTBA": false, + "timeTBA": false, + "noSpecificTime": false + }, + "timezone": "America/Mexico_City", + "status": { + "code": "onsale" + } + }, + "classifications": [ + { + "primary": true, + "segment": { + "id": "KZFzniwnSyZfZ7v7na", + "name": "Arts & Theatre" + }, + "genre": { + "id": "KnvZfZ7v7nt", + "name": "Espectaculo" + }, + "subGenre": { + "id": "KZazBEonSMnZfZ7v7lv", + "name": "Espectaculo" + } + } + ], + "promoter": { + "id": "3324", + "name": "MONDIAL PRICE 2", + "description": "MONDIAL PRICE 2 / NTL / MXC" + }, + "info": "Sinopsis:Tan sólo entre 2013 y 2014 se calcula que en México fueron asesinadas diariamente siete mujeres. ¿Qué tan altos son los edificios en Nueva York? desnuda el abismo social, jurisdiccional e incluso psíquico que se delinea a la par de una frontera y muro de contención por los cuales transitan insondables historias que muchas veces quedan sepultadas en las inagotables arenas del desierto Elenco:Pilar Couto Américo del Río* Leticia Pedrajo Estela Rivera Javier Sáncehez Medín Villatoro *Beneficiario del Programa de Creadores Escénicos 2015 del Fondo Nacional para la Cultura y las Artes", + "pleaseNote": "Conoce nuestras políticas de entrega. Límite de edad: Mayores de 16 años Pagan boleto a partir de: 16 años. Restricciones: No introducir alimentos ni bebidas,No tomar fotografía ni video Límite de acceso: Se recomienda llegar 15 minutos antes del evento Servicios: convenio con el estacionamiento del monumento a la madre presentando tu boleto de estacionamiento en la taquilla del teatro Duración aproximada: 60min. Página oficial: www.cultura.df.gob.mx/www.teatros.cultutra.df.gob.mx", + "priceRanges": [ + { + "type": "standard", + "currency": "MXN", + "min": 136.0, + "max": 136.0 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/17AZv8G6CnMsh1T?locale=en-us" + }, + "venues": [ + { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + ] + }, + "_embedded": { + "venues": [ + { + "name": "Teatro Benito Juárez", + "type": "venue", + "id": "KovZpZAd1taA", + "test": false, + "url": "http://ticketmaster.com.mx/venue/164154", + "locale": "en-us", + "postalCode": "08400", + "timezone": "America/Mexico_City", + "city": { + "name": "México" + }, + "state": { + "name": "Distrito Federal", + "stateCode": "DF" + }, + "country": { + "name": "Mexico", + "countryCode": "MX" + }, + "address": { + "line1": "Villalongin No. 15, Col. Cuauhtémoc" + }, + "markets": [ + { + "id": "401" + }, + { + "id": "402" + } + ], + "dmas": [ + { + "id": 801 + }, + { + "id": 802 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + } + } + ] + } + }, + { + "name": "¿Qué tan altos son los edificios de Nueva York?", + "type": "event", + "id": "17AZv8G6CnMmh1g", + "test": false, + "url": "http://ticketmaster.com.mx/event/140050EAB7B9B2B5", + "locale": "en-us", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dbimages/252338a.jpg", + "width": 205, + "height": 115, + "fallback": false + } + ], + "sales": { + "public": { + "startDateTime": "2016-07-20T15:00:00Z", + "startTBD": false, + "endDateTime": "2016-09-07T23:30:00Z" + } + }, + "dates": { + "start": { + "localDate": "2016-09-07", + "localTime": "20:30:00", + "dateTime": "2016-09-08T01:30:00Z", + "dateTBD": false, + "dateTBA": false, + "timeTBA": false, + "noSpecificTime": false + }, + "timezone": "America/Mexico_City", + "status": { + "code": "onsale" + } + }, + "classifications": [ + { + "primary": true, + "segment": { + "id": "KZFzniwnSyZfZ7v7na", + "name": "Arts & Theatre" + }, + "genre": { + "id": "KnvZfZ7v7nt", + "name": "Espectaculo" + }, + "subGenre": { + "id": "KZazBEonSMnZfZ7v7lv", + "name": "Espectaculo" + } + } + ], + "promoter": { + "id": "3324", + "name": "MONDIAL PRICE 2", + "description": "MONDIAL PRICE 2 / NTL / MXC" + }, + "info": "Sinopsis:Tan sólo entre 2013 y 2014 se calcula que en México fueron asesinadas diariamente siete mujeres. ¿Qué tan altos son los edificios en Nueva York? desnuda el abismo social, jurisdiccional e incluso psíquico que se delinea a la par de una frontera y muro de contención por los cuales transitan insondables historias que muchas veces quedan sepultadas en las inagotables arenas del desierto Elenco:Pilar Couto Américo del Río* Leticia Pedrajo Estela Rivera Javier Sáncehez Medín Villatoro *Beneficiario del Programa de Creadores Escénicos 2015 del Fondo Nacional para la Cultura y las Artes", + "pleaseNote": "Conoce nuestras políticas de entrega. Límite de edad: Mayores de 16 años Pagan boleto a partir de: 16 años. Restricciones: No introducir alimentos ni bebidas,No tomar fotografía ni video Límite de acceso: Se recomienda llegar 15 minutos antes del evento Servicios: convenio con el estacionamiento del monumento a la madre presentando tu boleto de estacionamiento en la taquilla del teatro Duración aproximada: 60min. Página oficial: www.cultura.df.gob.mx/www.teatros.cultutra.df.gob.mx", + "priceRanges": [ + { + "type": "standard", + "currency": "MXN", + "min": 136.0, + "max": 136.0 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/17AZv8G6CnMmh1g?locale=en-us" + }, + "venues": [ + { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + ] + }, + "_embedded": { + "venues": [ + { + "name": "Teatro Benito Juárez", + "type": "venue", + "id": "KovZpZAd1taA", + "test": false, + "url": "http://ticketmaster.com.mx/venue/164154", + "locale": "en-us", + "postalCode": "08400", + "timezone": "America/Mexico_City", + "city": { + "name": "México" + }, + "state": { + "name": "Distrito Federal", + "stateCode": "DF" + }, + "country": { + "name": "Mexico", + "countryCode": "MX" + }, + "address": { + "line1": "Villalongin No. 15, Col. Cuauhtémoc" + }, + "markets": [ + { + "id": "401" + }, + { + "id": "402" + } + ], + "dmas": [ + { + "id": 801 + }, + { + "id": 802 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + } + } + ] + } + }, + { + "name": "¿Qué tan altos son los edificios de Nueva York?", + "type": "event", + "id": "17AZv8G6CnMmh1m", + "test": false, + "url": "http://ticketmaster.com.mx/event/140050EAB7B9B2AE", + "locale": "en-us", + "images": [ + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg", + "width": 305, + "height": 203, + "fallback": true + }, + { + "ratio": "4_3", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_CUSTOM.jpg", + "width": 305, + "height": 225, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_16_9.jpg", + "width": 640, + "height": 360, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_PORTRAIT_3_2.jpg", + "width": 640, + "height": 427, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RECOMENDATION_16_9.jpg", + "width": 100, + "height": 56, + "fallback": true + }, + { + "ratio": "3_2", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_3_2.jpg", + "width": 1024, + "height": 683, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_RETINA_LANDSCAPE_16_9.jpg", + "width": 1136, + "height": 639, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_16_9.jpg", + "width": 1024, + "height": 576, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_TABLET_LANDSCAPE_LARGE_16_9.jpg", + "width": 2048, + "height": 1152, + "fallback": true + }, + { + "ratio": "16_9", + "url": "http://s1.ticketm.net/dbimages/252338a.jpg", + "width": 205, + "height": 115, + "fallback": false + } + ], + "sales": { + "public": { + "startDateTime": "2016-07-20T15:00:00Z", + "startTBD": false, + "endDateTime": "2016-09-06T23:30:00Z" + } + }, + "dates": { + "start": { + "localDate": "2016-09-06", + "localTime": "20:30:00", + "dateTime": "2016-09-07T01:30:00Z", + "dateTBD": false, + "dateTBA": false, + "timeTBA": false, + "noSpecificTime": false + }, + "timezone": "America/Mexico_City", + "status": { + "code": "onsale" + } + }, + "classifications": [ + { + "primary": true, + "segment": { + "id": "KZFzniwnSyZfZ7v7na", + "name": "Arts & Theatre" + }, + "genre": { + "id": "KnvZfZ7v7nt", + "name": "Espectaculo" + }, + "subGenre": { + "id": "KZazBEonSMnZfZ7v7lv", + "name": "Espectaculo" + } + } + ], + "promoter": { + "id": "3324", + "name": "MONDIAL PRICE 2", + "description": "MONDIAL PRICE 2 / NTL / MXC" + }, + "info": "Sinopsis:Tan sólo entre 2013 y 2014 se calcula que en México fueron asesinadas diariamente siete mujeres. ¿Qué tan altos son los edificios en Nueva York? desnuda el abismo social, jurisdiccional e incluso psíquico que se delinea a la par de una frontera y muro de contención por los cuales transitan insondables historias que muchas veces quedan sepultadas en las inagotables arenas del desierto Elenco:Pilar Couto Américo del Río* Leticia Pedrajo Estela Rivera Javier Sáncehez Medín Villatoro *Beneficiario del Programa de Creadores Escénicos 2015 del Fondo Nacional para la Cultura y las Artes", + "pleaseNote": "Conoce nuestras políticas de entrega. Límite de edad: Mayores de 16 años Pagan boleto a partir de: 16 años. Restricciones: No introducir alimentos ni bebidas,No tomar fotografía ni video Límite de acceso: Se recomienda llegar 15 minutos antes del evento Servicios: convenio con el estacionamiento del monumento a la madre presentando tu boleto de estacionamiento en la taquilla del teatro Duración aproximada: 60min. Página oficial: www.cultura.df.gob.mx/www.teatros.cultutra.df.gob.mx", + "priceRanges": [ + { + "type": "standard", + "currency": "MXN", + "min": 136.0, + "max": 136.0 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/events/17AZv8G6CnMmh1m?locale=en-us" + }, + "venues": [ + { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + ] + }, + "_embedded": { + "venues": [ + { + "name": "Teatro Benito Juárez", + "type": "venue", + "id": "KovZpZAd1taA", + "test": false, + "url": "http://ticketmaster.com.mx/venue/164154", + "locale": "en-us", + "postalCode": "08400", + "timezone": "America/Mexico_City", + "city": { + "name": "México" + }, + "state": { + "name": "Distrito Federal", + "stateCode": "DF" + }, + "country": { + "name": "Mexico", + "countryCode": "MX" + }, + "address": { + "line1": "Villalongin No. 15, Col. Cuauhtémoc" + }, + "markets": [ + { + "id": "401" + }, + { + "id": "402" + } + ], + "dmas": [ + { + "id": 801 + }, + { + "id": 802 + } + ], + "_links": { + "self": { + "href": "/discovery/v2/venues/KovZpZAd1taA?locale=en-us" + } + } + } + ] + } + } + ] + }, + "page": { + "size": 5, + "totalElements": 112624, + "totalPages": 22525, + "number": 2 + } + } + } +] From dad0502e8eebf8d62056bd7a6602dfbda371b33e Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 18:22:35 +0100 Subject: [PATCH 13/46] Tweaked demo --- docs/index.html | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/index.html b/docs/index.html index 852a938..880a62a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,22 +10,18 @@ From 7501dd4625484009f165952d4a87884eb8980a0e Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 19:30:39 +0100 Subject: [PATCH 14/46] Added polyfill for Object.assign --- .babelrc | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.babelrc b/.babelrc index 7ee2175..e89f653 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "compact": "true", - "plugins": ["lodash"], + "plugins": ["lodash", "transform-object-assign"], "presets": ["es2015-webpack"], "env": { "test": { diff --git a/package.json b/package.json index 91095be..3a7cdf7 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "babel-core": "^6.11.4", "babel-loader": "^6.2.4", "babel-plugin-lodash": "^3.2.6", + "babel-plugin-transform-object-assign": "^6.8.0", "babel-preset-es2015": "^6.9.0", "babel-preset-es2015-webpack": "^6.4.2", "babel-register": "^6.11.6", From 4aab86537ced9d5c5aab956b8841accb08c55efa Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 20:03:36 +0100 Subject: [PATCH 15/46] Removed babel and webpack lodash plugins --- .babelrc | 2 +- package.json | 2 -- webpack.config.js | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.babelrc b/.babelrc index e89f653..cc7af89 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "compact": "true", - "plugins": ["lodash", "transform-object-assign"], + "plugins": ["transform-object-assign"], "presets": ["es2015-webpack"], "env": { "test": { diff --git a/package.json b/package.json index 3a7cdf7..ad076e7 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "devDependencies": { "babel-core": "^6.11.4", "babel-loader": "^6.2.4", - "babel-plugin-lodash": "^3.2.6", "babel-plugin-transform-object-assign": "^6.8.0", "babel-preset-es2015": "^6.9.0", "babel-preset-es2015-webpack": "^6.4.2", @@ -43,7 +42,6 @@ "inherits": "^2.0.1", "isomorphic-fetch": "^2.2.1", "json-loader": "^0.5.4", - "lodash-webpack-plugin": "^0.9.3", "mocha": "3.0.0", "nock": "8.0.0", "webpack": "^2.1.0-beta.20" diff --git a/webpack.config.js b/webpack.config.js index 8ff45f8..52abc67 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,6 @@ // TODO: split dev and production configs var path = require('path'); var webpack = require('webpack'); -var LodashModuleReplacementPlugin = require('lodash-webpack-plugin'); var env = process.env.NODE_ENV || 'development'; var PROD = env === 'production'; @@ -35,7 +34,6 @@ module.exports = { ] }, plugins: [ - new LodashModuleReplacementPlugin(), new webpack.NoErrorsPlugin(), new webpack.optimize.OccurrenceOrderPlugin, new webpack.DefinePlugin({NODE_ENV: env}), From e496088313a947f1120b5faa8cbe7dcb8aa7ef37 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 20:38:51 +0100 Subject: [PATCH 16/46] Added user safeguard --- docs/index.html | 19 +++++++++++++------ lib/index.js | 16 +++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/index.html b/docs/index.html index 880a62a..da780c8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -11,17 +11,24 @@ diff --git a/lib/index.js b/lib/index.js index 6490fed..b9e8259 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,10 +1,16 @@ import discovery from './discovery/index'; import commerce from './commerce/index'; -const API = (apikey) => ({ - apikey, - discovery: discovery(apikey), - commerce: commerce(apikey) -}); +const API = (apikey) => { + if(apikey === 'YOUR_KEY_HERE') { + return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register'); + } + + return { + apikey, + discovery: discovery(apikey), + commerce: commerce(apikey) + }; +}; export default API; From 5edbbf3788b592a850c9ec24f7689fa28c279aaa Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Tue, 2 Aug 2016 21:10:58 +0100 Subject: [PATCH 17/46] Removed support for 0.10.0 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eda6304..8fe77c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,5 @@ node_js: - "4.0" - "0.12" - "0.11" - - "0.10" - "iojs" From 1b8fcb827552c2d159f6ed7375a63385bd61c6dc Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 4 Aug 2016 10:46:32 +0100 Subject: [PATCH 18/46] Updated deps --- docs/index.html | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/index.html b/docs/index.html index da780c8..2d51593 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,7 +10,7 @@ + diff --git a/docs/test.js b/docs/test.js new file mode 100644 index 0000000..421d6cd --- /dev/null +++ b/docs/test.js @@ -0,0 +1,21 @@ +var tmapi = require('../dist/node'); + +var sdk = tmapi('YOUR_KEY_HERE'); + +function logNextPage(page) { + console.log(page.page.number, page.items.map(function(item) { + return item.name; + })); + + return page.getNext(); +} + +if (sdk) { + sdk.discovery.v2.event.all({page: 4, size: 5, city: 'London'}) + .then(logNextPage) + .then(logNextPage) + .then(logNextPage) + .catch(function(e) { + console.log(e); + }); +} diff --git a/package.json b/package.json index c60e9d8..e60195d 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,21 @@ { - "name": "ticketmaster", + "name": "tmapi", "version": "1.0.0", "description": "SDK for the Ticketmaster Open Platform", - "main": "dist/index.js", - "jsnext:main": "lib/index.js", + "main": "dist/node/tmapi.js", + "module": "lib/index.js", "scripts": { - "build": "npm run prod", - "dev": "webpack", + "clean": "rimraf ./dist", + "prebuild": "npm run clean", + "build": "npm run prod:web && npm run prod:node", "prod": "cross-env NODE_ENV=production webpack", - "prod:assess": "npm run prod -- --display-modules --sort-modules-by size", + "prod:node": "cross-env NODE_ENV=production babel lib -d dist/node", + "prod:web": "npm run prod -- --config ./config/webpack/webpack.config.web.babel.js", + "stats:web": "npm run prod:web -- --display-modules --sort-modules-by size", "test": "cross-env NODE_ENV=test mocha --require ./test/globals --compilers js:babel-register --recursive", - "postversion": "./scripts/post-release.sh", "lint": "eslint ./lib ./test", - "precommit": "npm run lint && npm test" + "precommit": "npm run lint && npm test", + "postversion": "./scripts/post-release.sh" }, "keywords": [ "ticketmaster", @@ -28,8 +31,10 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { + "babel-cli": "6.11.4", "babel-core": "6.11.4", "babel-loader": "6.2.4", + "babel-plugin-add-module-exports": "0.2.1", "babel-plugin-transform-object-assign": "6.8.0", "babel-preset-es2015": "6.9.0", "babel-preset-es2015-webpack": "6.4.2", @@ -42,9 +47,9 @@ "eslint-plugin-standard": "2.0.0", "husky": "0.11.6", "inherits": "2.0.1", - "json-loader": "0.5.4", "mocha": "3.0.1", "nock": "8.0.0", + "rimraf": "2.5.4", "webpack": "2.1.0-beta.20" }, "dependencies": { diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 52abc67..0000000 --- a/webpack.config.js +++ /dev/null @@ -1,50 +0,0 @@ -// TODO: split dev and production configs -var path = require('path'); -var webpack = require('webpack'); - -var env = process.env.NODE_ENV || 'development'; -var PROD = env === 'production'; -var filename = 'ticketmaster-client-' + require('./package.json').version; - -module.exports = { - entry: './lib/index.js', - output: { - path: path.resolve(__dirname, 'dist'), - filename: PROD ? filename + '.min.js' : filename + '.js', - library: 'TMAPI', // global - libraryTarget: 'umd' - }, - devtool: PROD ? false : 'cheap-module-inline-source-map', - node: { - fs: 'empty', - net: 'empty', - tls: 'empty' - }, - module: { - loaders: [ - { - test: /\.js$/, - loader: 'babel', - include: path.join(process.cwd(), 'lib') - }, - { - test: /\.json$/, - loader: 'json' - } - ] - }, - plugins: [ - new webpack.NoErrorsPlugin(), - new webpack.optimize.OccurrenceOrderPlugin, - new webpack.DefinePlugin({NODE_ENV: env}), - new webpack.LoaderOptionsPlugin({ - minimize: true, - debug: false - }), - new webpack.optimize.UglifyJsPlugin({ - compress: {warnings: false}, - comments: false, - sourceMap: false - }) - ] -}; From fdf1338919a0cae1a84e935ac95ac19e141e6064 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 4 Aug 2016 19:08:10 +0100 Subject: [PATCH 23/46] Minor clean-up to npm scripts --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index e60195d..d8d9aa3 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,8 @@ "clean": "rimraf ./dist", "prebuild": "npm run clean", "build": "npm run prod:web && npm run prod:node", - "prod": "cross-env NODE_ENV=production webpack", "prod:node": "cross-env NODE_ENV=production babel lib -d dist/node", - "prod:web": "npm run prod -- --config ./config/webpack/webpack.config.web.babel.js", + "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.web.babel.js", "stats:web": "npm run prod:web -- --display-modules --sort-modules-by size", "test": "cross-env NODE_ENV=test mocha --require ./test/globals --compilers js:babel-register --recursive", "lint": "eslint ./lib ./test", From 2609bf8d105af27a8319d13b250d7ba0d3d9a05b Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 4 Aug 2016 20:42:56 +0100 Subject: [PATCH 24/46] Fixed erroneous 'main' definition in packge.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8d9aa3..2ebba58 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "tmapi", "version": "1.0.0", "description": "SDK for the Ticketmaster Open Platform", - "main": "dist/node/tmapi.js", + "main": "dist/node/index.js", "module": "lib/index.js", "scripts": { "clean": "rimraf ./dist", From 04eb06b7f0edba975f487a05e62a096844351d70 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Thu, 4 Aug 2016 20:47:57 +0100 Subject: [PATCH 25/46] moved Mocha args into test/mocha.opts --- package.json | 2 +- test/mocha.opts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/mocha.opts diff --git a/package.json b/package.json index 2ebba58..94b9683 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "prod:node": "cross-env NODE_ENV=production babel lib -d dist/node", "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.web.babel.js", "stats:web": "npm run prod:web -- --display-modules --sort-modules-by size", - "test": "cross-env NODE_ENV=test mocha --require ./test/globals --compilers js:babel-register --recursive", + "test": "cross-env NODE_ENV=test mocha", "lint": "eslint ./lib ./test", "precommit": "npm run lint && npm test", "postversion": "./scripts/post-release.sh" diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..51e3f77 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,4 @@ +--require ./test/globals +--compilers js:babel-register +--recursive +--check-leaks From b5939174bbdbf8e3a422ff374c97d4291075e645 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Fri, 5 Aug 2016 14:03:54 +0100 Subject: [PATCH 26/46] Deduplicated utils --- .babelrc | 6 +- docs/index.html | 20 ++++- lib/commerce/page.js | 91 -------------------- lib/commerce/utils/all.js | 12 --- lib/commerce/utils/getData.js | 28 ------ lib/commerce/v2/index.js | 2 + lib/commerce/v2/{offer/index.js => offer.js} | 3 +- lib/discovery/utils/find.js | 10 --- lib/discovery/v1/attraction.js | 10 ++- lib/discovery/v1/category.js | 10 ++- lib/discovery/v1/event.js | 10 ++- lib/discovery/v1/index.js | 4 +- lib/discovery/v1/venue.js | 10 ++- lib/discovery/v2/attraction.js | 4 +- lib/discovery/v2/classification.js | 10 ++- lib/discovery/v2/event.js | 11 ++- lib/discovery/v2/index.js | 2 + lib/discovery/v2/venue.js | 6 +- lib/{discovery => }/page.js | 7 +- lib/{discovery => }/utils/all.js | 4 +- lib/{commerce => }/utils/find.js | 4 +- lib/{discovery => }/utils/getData.js | 2 +- package.json | 4 +- test/discovery/v2/event/find.js | 2 +- 24 files changed, 81 insertions(+), 191 deletions(-) delete mode 100644 lib/commerce/page.js delete mode 100644 lib/commerce/utils/all.js delete mode 100644 lib/commerce/utils/getData.js rename lib/commerce/v2/{offer/index.js => offer.js} (50%) delete mode 100644 lib/discovery/utils/find.js rename lib/{discovery => }/page.js (95%) rename lib/{discovery => }/utils/all.js (59%) rename lib/{commerce => }/utils/find.js (50%) rename lib/{discovery => }/utils/getData.js (94%) diff --git a/.babelrc b/.babelrc index 6362aa2..d91fd10 100644 --- a/.babelrc +++ b/.babelrc @@ -1,13 +1,9 @@ { "compact": "true", + "presets": ["es2015"], "plugins": ["transform-object-assign"], - "presets": ["es2015-webpack"], "env": { - "test": { - "presets": ["es2015"] - }, "production": { - "presets": ["es2015"], "plugins": ["add-module-exports"] } } diff --git a/docs/index.html b/docs/index.html index c461e81..ae4605f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,24 +10,38 @@ diff --git a/lib/commerce/page.js b/lib/commerce/page.js deleted file mode 100644 index 73afc01..0000000 --- a/lib/commerce/page.js +++ /dev/null @@ -1,91 +0,0 @@ -import getData from './utils/getData'; - -let params; - -/** - * Page object constructor - * @param options - * @constructor - */ -// TODO fix params -class Page { - constructor({items, page, params}) { - this.items = items; - this.page = page; - } - - /** - * Method of Page object type - * Gets some page of results by it's number passed as param. - * @param page {number} - * @returns {promise} - */ - getPage(page) { - if (page && this.page && page > 0 && page <= this.page.totalPages) { - params.qs.page = page; - - return getData(params); - } - - return Promise.reject({message: 'You should pass correct page number.', page}); - }; - - /** - * Method of Page object type - * (Iterator method) Gets next page of same type results - * @param step {number} - * @returns {promise} - */ - nextPage(step = 1) { - if (this.page && this.page.number <= this.page.totalPages) { - params.qs.page = this.page.number + step; - - return getData(params); - } - - return Promise.reject({message: 'No next page! You are on the last.', params}); - }; - - /** - * Method of Page object type - * (Iterator method) Gets previous page of same type results - * @param step {number} - * @returns {promise} - */ - previousPage(step = 1) { - if (this.page && this.page.number > 0) { - params.qs.page = this.page.number - step; - - return getData(params); - } - - return Promise.reject({message: 'No previous page! You are on the first one.', params}); - }; - - /** - * Method of Page object type - * @returns {array|null} - */ - records() { - return this.items; - }; - - /** - * Method of Page object type - * @returns {number} quantity of all items of the same type - */ - count() { - return this.page && this.page.totalElements || 0; - }; - - /** - * Method of Page object type - * Checker if current result page is the last one - * @returns {boolean} - */ - isLastPage() { - return this.page.number === this.page.totalPages; - }; -} - -export default Page; diff --git a/lib/commerce/utils/all.js b/lib/commerce/utils/all.js deleted file mode 100644 index 3bba53b..0000000 --- a/lib/commerce/utils/all.js +++ /dev/null @@ -1,12 +0,0 @@ -import getData from './getData'; - -export default (apikey, type) => (options = {}) => { - options.apikey = apikey; - - const params = { - url: ['commerce/v2', type], - qs: options - }; - - return getData(params); -}; diff --git a/lib/commerce/utils/getData.js b/lib/commerce/utils/getData.js deleted file mode 100644 index f5bd713..0000000 --- a/lib/commerce/utils/getData.js +++ /dev/null @@ -1,28 +0,0 @@ -import fetch from 'isomorphic-fetch'; -import queryString from 'query-string'; - -import config from '../../config'; -import Page from '../page'; - -/** - * Main GET Data configuration function for API - * - * @param url {string} - * @param qs {string} - * @param options {object} - * - * @returns {promise} - */ -const getData = ({url, qs, options = {method: 'GET'}}) => { - return fetch(`${[config.baseURL].concat(url).join('/')}?${queryString.stringify(qs)}`, options) - .then((res) => { - if (res.status === 200) { - return res.json(); - } - - return res.json().then(Promise.reject.bind(Promise)); - }) - .then((json) => json.page ? new Page({items: json._embedded && json._embedded[url[1]], page: json.page}) : json); -}; - -export default getData; diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js index 54d59e1..383bc9d 100644 --- a/lib/commerce/v2/index.js +++ b/lib/commerce/v2/index.js @@ -1,5 +1,7 @@ import offer from './offer'; +export const api = 'commerce/v2'; + export default (apikey) => ({ offer: offer(apikey) }); diff --git a/lib/commerce/v2/offer/index.js b/lib/commerce/v2/offer.js similarity index 50% rename from lib/commerce/v2/offer/index.js rename to lib/commerce/v2/offer.js index 142ee2a..5260c9d 100644 --- a/lib/commerce/v2/offer/index.js +++ b/lib/commerce/v2/offer.js @@ -1,5 +1,6 @@ import find from '../../utils/find'; +import {api} from './'; export default (apikey) => ({ - find: find(apikey, 'events') + find: find(api, apikey, 'events', 'offers') }); diff --git a/lib/discovery/utils/find.js b/lib/discovery/utils/find.js deleted file mode 100644 index 047c945..0000000 --- a/lib/discovery/utils/find.js +++ /dev/null @@ -1,10 +0,0 @@ -import getData from './getData'; - -export default (apikey, type) => (...path) => { - const params = { - path: ['discovery/v2', type, ...path], - qs: {apikey} - }; - - return getData(params); -}; diff --git a/lib/discovery/v1/attraction.js b/lib/discovery/v1/attraction.js index c91da36..34957c4 100644 --- a/lib/discovery/v1/attraction.js +++ b/lib/discovery/v1/attraction.js @@ -1,7 +1,9 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'attractions'), - find: find(apiKey, 'attractions') + all: all(api, apiKey, 'attractions'), + find: find(api, apiKey, 'attractions') }); diff --git a/lib/discovery/v1/category.js b/lib/discovery/v1/category.js index f7f7efc..3fa29a9 100644 --- a/lib/discovery/v1/category.js +++ b/lib/discovery/v1/category.js @@ -1,7 +1,9 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'categories'), - find: find(apiKey, 'categories') + all: all(api, apiKey, 'categories'), + find: find(api, apiKey, 'categories') }); diff --git a/lib/discovery/v1/event.js b/lib/discovery/v1/event.js index 86edf9c..7bc63c2 100644 --- a/lib/discovery/v1/event.js +++ b/lib/discovery/v1/event.js @@ -1,7 +1,9 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'events'), - find: find(apiKey, 'events') + all: all(api, apiKey, 'events'), + find: find(api, apiKey, 'events') }); diff --git a/lib/discovery/v1/index.js b/lib/discovery/v1/index.js index bf84e4d..ccf6f01 100644 --- a/lib/discovery/v1/index.js +++ b/lib/discovery/v1/index.js @@ -3,7 +3,9 @@ import category from './category'; import event from './event'; import venue from './venue'; -export default apiKey => ({ +export const api = 'discovery/v1'; + +export default (apiKey) => ({ attraction: attraction(apiKey), category: category(apiKey), event: event(apiKey), diff --git a/lib/discovery/v1/venue.js b/lib/discovery/v1/venue.js index 7e66c1e..c33fe1d 100644 --- a/lib/discovery/v1/venue.js +++ b/lib/discovery/v1/venue.js @@ -1,7 +1,9 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'venues'), - find: find(apiKey, 'venues') + all: all(api, apiKey, 'venues'), + find: find(api, apiKey, 'venues') }); diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js index c91da36..e3b3a60 100644 --- a/lib/discovery/v2/attraction.js +++ b/lib/discovery/v2/attraction.js @@ -1,5 +1,5 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; export default (apiKey) => ({ all: all(apiKey, 'attractions'), diff --git a/lib/discovery/v2/classification.js b/lib/discovery/v2/classification.js index 71211b2..0ebfd02 100644 --- a/lib/discovery/v2/classification.js +++ b/lib/discovery/v2/classification.js @@ -1,7 +1,9 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'classifications'), - find: find(apiKey, 'classifications') + all: all(api, apiKey, 'classifications'), + find: find(api, apiKey, 'classifications') }); diff --git a/lib/discovery/v2/event.js b/lib/discovery/v2/event.js index 86edf9c..3534d59 100644 --- a/lib/discovery/v2/event.js +++ b/lib/discovery/v2/event.js @@ -1,7 +1,10 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../../utils/all'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - all: all(apiKey, 'events'), - find: find(apiKey, 'events') + all: all(api, apiKey, 'events'), + find: find(api, apiKey, 'events'), + findImages: find(api, apiKey, 'events', 'images') }); diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2/index.js index 9e59a10..a48b00d 100644 --- a/lib/discovery/v2/index.js +++ b/lib/discovery/v2/index.js @@ -3,6 +3,8 @@ import classification from './classification'; import event from './event'; import venue from './venue'; +export const api = 'discovery/v2'; + export default (apiKey) => ({ attraction: attraction(apiKey), classification: classification(apiKey), diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js index f6dde26..106de43 100644 --- a/lib/discovery/v2/venue.js +++ b/lib/discovery/v2/venue.js @@ -1,5 +1,7 @@ -import find from '../utils/find'; +import find from '../../utils/find'; + +import {api} from './'; export default (apiKey) => ({ - find: find(apiKey, 'venues') + find: find(api, apiKey, 'venues') }); diff --git a/lib/discovery/page.js b/lib/page.js similarity index 95% rename from lib/discovery/page.js rename to lib/page.js index 8095446..f407298 100644 --- a/lib/discovery/page.js +++ b/lib/page.js @@ -5,7 +5,6 @@ import getData from './utils/getData'; * @param options * @constructor */ -// TODO fix params class Page { constructor({_embedded, page}, path, qs) { const itemKey = Object.keys(_embedded)[0]; @@ -20,7 +19,7 @@ class Page { * Method of Page object type * Gets some page of results by it's number passed as param. * @param n {number} - * @returns {promise} + * @returns {Promise} */ getAt(n) { const qs = Object.assign({}, this.qs, {page: n}); @@ -36,7 +35,7 @@ class Page { * Method of Page object type * (Iterator method) Gets next page of same type results * @param step {number} - * @returns {promise} + * @returns {Promise} */ getNext(step = 1) { const n = this.page.number + step; @@ -53,7 +52,7 @@ class Page { * Method of Page object type * (Iterator method) Gets previous page of same type results * @param step {number} - * @returns {promise} + * @returns {Promise} */ getPrev(step = 1) { const n = this.page.number - step; diff --git a/lib/discovery/utils/all.js b/lib/utils/all.js similarity index 59% rename from lib/discovery/utils/all.js rename to lib/utils/all.js index 013c28e..5206d5c 100644 --- a/lib/discovery/utils/all.js +++ b/lib/utils/all.js @@ -1,10 +1,10 @@ import getData from './getData'; -export default (apikey, type) => (qs = {}) => { +export default (api, apikey, type) => (qs = {}) => { qs.apikey = apikey; const params = { - path: ['discovery/v2', type], + path: [api, type], qs: qs }; diff --git a/lib/commerce/utils/find.js b/lib/utils/find.js similarity index 50% rename from lib/commerce/utils/find.js rename to lib/utils/find.js index d1e7a59..d2f06e5 100644 --- a/lib/commerce/utils/find.js +++ b/lib/utils/find.js @@ -1,8 +1,8 @@ import getData from './getData'; -export default (apikey, type) => (...path) => { +export default (api, apikey, type, ...path) => (eventId) => { const params = { - url: ['commerce/v2', type, ...path], + path: [api, type, eventId, ...path], qs: {apikey} }; diff --git a/lib/discovery/utils/getData.js b/lib/utils/getData.js similarity index 94% rename from lib/discovery/utils/getData.js rename to lib/utils/getData.js index a6bae1f..76cb810 100644 --- a/lib/discovery/utils/getData.js +++ b/lib/utils/getData.js @@ -1,7 +1,7 @@ import fetch from 'isomorphic-fetch'; import queryString from 'query-string'; -import config from '../../config'; +import config from '../config'; import Page from '../page'; const getURL = (path, qs) => { diff --git a/package.json b/package.json index 94b9683..4556e83 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,11 @@ "license": "MIT", "devDependencies": { "babel-cli": "6.11.4", - "babel-core": "6.11.4", + "babel-core": "6.13.1", "babel-loader": "6.2.4", "babel-plugin-add-module-exports": "0.2.1", "babel-plugin-transform-object-assign": "6.8.0", - "babel-preset-es2015": "6.9.0", + "babel-preset-es2015": "6.13.1", "babel-preset-es2015-webpack": "6.4.2", "babel-register": "6.11.6", "chai": "3.5.0", diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 3fbc1db..4bd2487 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -22,7 +22,7 @@ describe('discovery.v2.event.find', () => { it('should find images for an event', (done) => { nockBack('event/findImages-200.json', {}, (nockDone) => { - Event('mock-api-key').find('vv17FZfdGkSrrMju', 'images') + Event('mock-api-key').findImages('vv17FZfdGkSrrMju') .then((result) => { result.images[0].should.deep.equal({ 'ratio': '3_2', From 896a906fc746892806ae5a9aec496ff510872d07 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Fri, 5 Aug 2016 14:56:59 +0100 Subject: [PATCH 27/46] Minor tweaks --- docs/index.html | 24 +++++------------------- lib/commerce/v2/offer.js | 1 + lib/discovery/v2/attraction.js | 6 ++++-- lib/discovery/v2/venue.js | 2 ++ package.json | 1 + 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/docs/index.html b/docs/index.html index ae4605f..ab72c4a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,38 +10,24 @@ diff --git a/lib/commerce/v2/offer.js b/lib/commerce/v2/offer.js index 5260c9d..20c3d7b 100644 --- a/lib/commerce/v2/offer.js +++ b/lib/commerce/v2/offer.js @@ -1,4 +1,5 @@ import find from '../../utils/find'; + import {api} from './'; export default (apikey) => ({ diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js index e3b3a60..34957c4 100644 --- a/lib/discovery/v2/attraction.js +++ b/lib/discovery/v2/attraction.js @@ -1,7 +1,9 @@ import all from '../../utils/all'; import find from '../../utils/find'; +import {api} from './'; + export default (apiKey) => ({ - all: all(apiKey, 'attractions'), - find: find(apiKey, 'attractions') + all: all(api, apiKey, 'attractions'), + find: find(api, apiKey, 'attractions') }); diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js index 106de43..c33fe1d 100644 --- a/lib/discovery/v2/venue.js +++ b/lib/discovery/v2/venue.js @@ -1,7 +1,9 @@ +import all from '../../utils/all'; import find from '../../utils/find'; import {api} from './'; export default (apiKey) => ({ + all: all(api, apiKey, 'venues'), find: find(api, apiKey, 'venues') }); diff --git a/package.json b/package.json index 4556e83..47e9345 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test": "cross-env NODE_ENV=test mocha", "lint": "eslint ./lib ./test", "precommit": "npm run lint && npm test", + "postcommit": "npm run build", "postversion": "./scripts/post-release.sh" }, "keywords": [ From 922eaf169c51419919933786a3000045995eaab0 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Fri, 5 Aug 2016 16:43:19 +0100 Subject: [PATCH 28/46] Moar tests and refactored layout --- .babelrc | 4 ++- .eslintrc | 3 ++ lib/discovery/v2/attraction.js | 9 ------ lib/discovery/v2/classification.js | 9 ------ lib/discovery/v2/event.js | 10 ------- lib/discovery/v2/index.js | 37 ++++++++++++++++++------ lib/discovery/v2/venue.js | 9 ------ lib/utils/getData.js | 2 +- package.json | 1 + test/discovery/v2/attraction/all.js | 2 +- test/discovery/v2/attraction/find.js | 2 +- test/discovery/v2/attraction/index.js | 13 --------- test/discovery/v2/classification/all.js | 2 +- test/discovery/v2/classification/find.js | 2 +- test/discovery/v2/event/all.js | 6 ++-- test/discovery/v2/event/find.js | 2 +- test/discovery/v2/event/index.js | 13 --------- test/discovery/v2/event/options.js | 4 +-- test/discovery/v2/index.js | 13 +++++++-- test/discovery/v2/venue/find.js | 2 +- test/discovery/v2/venue/index.js | 8 ----- test/utils/all.js | 23 +++++++++++++++ test/utils/find.js | 31 ++++++++++++++++++++ 23 files changed, 111 insertions(+), 96 deletions(-) delete mode 100644 lib/discovery/v2/attraction.js delete mode 100644 lib/discovery/v2/classification.js delete mode 100644 lib/discovery/v2/event.js delete mode 100644 lib/discovery/v2/venue.js delete mode 100644 test/discovery/v2/attraction/index.js delete mode 100644 test/discovery/v2/event/index.js delete mode 100644 test/discovery/v2/venue/index.js create mode 100644 test/utils/all.js create mode 100644 test/utils/find.js diff --git a/.babelrc b/.babelrc index d91fd10..c28415d 100644 --- a/.babelrc +++ b/.babelrc @@ -1,8 +1,10 @@ { - "compact": "true", "presets": ["es2015"], "plugins": ["transform-object-assign"], "env": { + "test": { + "plugins": ["rewire"] + }, "production": { "plugins": ["add-module-exports"] } diff --git a/.eslintrc b/.eslintrc index edca18e..4b5f492 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,5 +9,8 @@ "should": true, "describe": true, "before": true, + "after": true, + "__Rewire__": true, + "__ResetDependency__": true } } diff --git a/lib/discovery/v2/attraction.js b/lib/discovery/v2/attraction.js deleted file mode 100644 index 34957c4..0000000 --- a/lib/discovery/v2/attraction.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); diff --git a/lib/discovery/v2/classification.js b/lib/discovery/v2/classification.js deleted file mode 100644 index 0ebfd02..0000000 --- a/lib/discovery/v2/classification.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'classifications'), - find: find(api, apiKey, 'classifications') -}); diff --git a/lib/discovery/v2/event.js b/lib/discovery/v2/event.js deleted file mode 100644 index 3534d59..0000000 --- a/lib/discovery/v2/event.js +++ /dev/null @@ -1,10 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events'), - findImages: find(api, apiKey, 'events', 'images') -}); diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2/index.js index a48b00d..298ac15 100644 --- a/lib/discovery/v2/index.js +++ b/lib/discovery/v2/index.js @@ -1,13 +1,32 @@ -import attraction from './attraction'; -import classification from './classification'; -import event from './event'; -import venue from './venue'; +import all from '../../utils/all'; +import find from '../../utils/find'; -export const api = 'discovery/v2'; +const api = 'discovery/v2'; + +export const Attraction = (apiKey) => ({ + all: all(api, apiKey, 'attractions'), + find: find(api, apiKey, 'attractions') +}); + +export const Classification = (apiKey) => ({ + all: all(api, apiKey, 'classifications'), + find: find(api, apiKey, 'classifications') +}); + +export const Event = (apiKey) => ({ + all: all(api, apiKey, 'events'), + find: find(api, apiKey, 'events'), + findImages: find(api, apiKey, 'events', 'images') +}); + +export const Venue = (apiKey) => ({ + all: all(api, apiKey, 'venues'), + find: find(api, apiKey, 'venues') +}); export default (apiKey) => ({ - attraction: attraction(apiKey), - classification: classification(apiKey), - event: event(apiKey), - venue: venue(apiKey) + attraction: Attraction(apiKey), + classification: Classification(apiKey), + event: Event(apiKey), + venue: Venue(apiKey) }); diff --git a/lib/discovery/v2/venue.js b/lib/discovery/v2/venue.js deleted file mode 100644 index c33fe1d..0000000 --- a/lib/discovery/v2/venue.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); diff --git a/lib/utils/getData.js b/lib/utils/getData.js index 76cb810..f1aba6a 100644 --- a/lib/utils/getData.js +++ b/lib/utils/getData.js @@ -4,7 +4,7 @@ import queryString from 'query-string'; import config from '../config'; import Page from '../page'; -const getURL = (path, qs) => { +export const getURL = (path, qs) => { return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}`; }; diff --git a/package.json b/package.json index 47e9345..a793f93 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "babel-core": "6.13.1", "babel-loader": "6.2.4", "babel-plugin-add-module-exports": "0.2.1", + "babel-plugin-rewire": "1.0.0-rc-5", "babel-plugin-transform-object-assign": "6.8.0", "babel-preset-es2015": "6.13.1", "babel-preset-es2015-webpack": "6.4.2", diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index dcba7da..a548027 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v2/attraction'; +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.all', () => { before(() => { diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 2c110a4..d991f82 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v2/attraction'; +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.find', () => { before(() => { diff --git a/test/discovery/v2/attraction/index.js b/test/discovery/v2/attraction/index.js deleted file mode 100644 index 29a3aad..0000000 --- a/test/discovery/v2/attraction/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import Attraction from '../../../../lib/discovery/v2/attraction'; - -describe('discovery.v2.attraction', () => { - it('should provide all', (done) => { - Attraction().should.have.property('all'); - done(); - }); - - it('should provide find', (done) => { - Attraction().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index 5ca1162..f48b070 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Classification from '../../../../lib/discovery/v2/classification'; +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.all', () => { before(() => { diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index 4de9ca6..3dd69b8 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Classification from '../../../../lib/discovery/v2/classification'; +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.find', () => { before(() => { diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index 4ceb255..ac256a9 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,9 +1,9 @@ import {back as nockBack} from 'nock'; -import sdk from '../../../../lib'; -import Event from '../../../../lib/discovery/v2/event'; +import tmapi from '../../../../lib'; +import {Event} from '../../../../lib/discovery/v2'; -const api = sdk('mock-api-key'); +const api = tmapi('mock-api-key'); const onResult = (done) => (page) => { page.items[0].name.should.equal('OSEA Membership Registration'); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 4bd2487..c049b3a 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v2/event'; +import {Event} from '../../../../lib/discovery/v2'; describe('discovery.v2.event.find', () => { before(() => { diff --git a/test/discovery/v2/event/index.js b/test/discovery/v2/event/index.js deleted file mode 100644 index cdbed0b..0000000 --- a/test/discovery/v2/event/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import event from '../../../../lib/discovery/v2/event'; - -describe('discovery.v2.event', () => { - it('should provide all', done => { - event().should.have.property('all'); - done(); - }); - - it('should provide find', done => { - event().should.have.property('find'); - done(); - }); -}); diff --git a/test/discovery/v2/event/options.js b/test/discovery/v2/event/options.js index 6c95636..ab481d0 100644 --- a/test/discovery/v2/event/options.js +++ b/test/discovery/v2/event/options.js @@ -1,12 +1,12 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v2/event'; +import {Event} from '../../../../lib/discovery/v2'; nockBack.fixtures = './test/fixtures/discovery/v2'; describe('discovery.v2.event.options', () => { describe('options', () => { - it('works', (done) => { + it('should produce a formatted query string from params', (done) => { nockBack('event/all-200-options.json', (nockDone) => { nockDone(); diff --git a/test/discovery/v2/index.js b/test/discovery/v2/index.js index 00376a3..03963ef 100644 --- a/test/discovery/v2/index.js +++ b/test/discovery/v2/index.js @@ -1,18 +1,25 @@ import v2 from '../../../lib/discovery/v2'; +const api = v2(); + describe('discovery.v2', () => { it('should provide attraction', (done) => { - v2().should.have.property('attraction'); + api.should.have.property('attraction'); + done(); + }); + + it('should provide classification', (done) => { + api.should.have.property('classification'); done(); }); it('should provide event', (done) => { - v2().should.have.property('event'); + api.should.have.property('event'); done(); }); it('should provide venue', (done) => { - v2().should.have.property('venue'); + api.should.have.property('venue'); done(); }); }); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index 03df1a7..e9c9a90 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Venue from '../../../../lib/discovery/v2/venue'; +import {Venue} from '../../../../lib/discovery/v2'; describe('discovery.v2.venue.find', () => { before(() => { diff --git a/test/discovery/v2/venue/index.js b/test/discovery/v2/venue/index.js deleted file mode 100644 index 1c2ecd5..0000000 --- a/test/discovery/v2/venue/index.js +++ /dev/null @@ -1,8 +0,0 @@ -import venue from '../../../../lib/discovery/v2/venue'; - -describe('discovery.v2.venue', () => { - it('should provide find', (done) => { - venue().should.have.property('find'); - done(); - }); -}); diff --git a/test/utils/all.js b/test/utils/all.js new file mode 100644 index 0000000..bf3d4bb --- /dev/null +++ b/test/utils/all.js @@ -0,0 +1,23 @@ +import all from '../../lib/utils/all'; + +let query; + +describe('utils.all', () => { + before(() => { + all.__Rewire__('getData', (params) => params); + + query = all('discovery/v2', 'a3b2c1d4e5f6', 'events'); + }); + + it('should parse params correctly', (done) => { + query({city: 'london'}).should.deep.equal({ + path: ['discovery/v2', 'events'], + qs: {city: 'london', apikey: 'a3b2c1d4e5f6'} + }); + done(); + }); + + after(() => { + all.__ResetDependency__('getData'); + }); +}); diff --git a/test/utils/find.js b/test/utils/find.js new file mode 100644 index 0000000..fb5e1d3 --- /dev/null +++ b/test/utils/find.js @@ -0,0 +1,31 @@ +import find from '../../lib/utils/find'; + +describe('utils.find', () => { + before(() => { + find.__Rewire__('getData', (params) => params); + }); + + it('should parse params for a resource', (done) => { + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events'); + query(1).should.deep.equal({ + path: ['discovery/v2', 'events', 1], + qs: {apikey: 'a3b2c1d4e5f6'} + }); + + done(); + }); + + it('should parse params for a sub-resource', (done) => { + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images'); + query(1).should.deep.equal({ + path: ['discovery/v2', 'events', 1, 'images'], + qs: {apikey: 'a3b2c1d4e5f6'} + }); + + done(); + }); + + after(() => { + find.__ResetDependency__('getData'); + }); +}); From 8903c65c40c4c93963dc73a77a394baacf277693 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Fri, 5 Aug 2016 17:35:08 +0100 Subject: [PATCH 29/46] Migrated v1 to new layout --- lib/discovery/v1.js | 32 +++++++++++++++++++++++++++ lib/discovery/v1/attraction.js | 9 -------- lib/discovery/v1/category.js | 9 -------- lib/discovery/v1/event.js | 9 -------- lib/discovery/v1/index.js | 13 ----------- lib/discovery/v1/venue.js | 9 -------- lib/discovery/{v2/index.js => v2.js} | 4 ++-- test/discovery/v1/attraction/find.js | 2 +- test/discovery/v1/attraction/index.js | 4 ++-- test/discovery/v1/category/find.js | 2 +- test/discovery/v1/category/index.js | 4 ++-- test/discovery/v1/event/all.js | 2 +- test/discovery/v1/event/find.js | 2 +- test/discovery/v1/event/index.js | 6 ++--- test/discovery/v1/venue/find.js | 2 +- test/discovery/v1/venue/index.js | 4 ++-- 16 files changed, 48 insertions(+), 65 deletions(-) create mode 100644 lib/discovery/v1.js delete mode 100644 lib/discovery/v1/attraction.js delete mode 100644 lib/discovery/v1/category.js delete mode 100644 lib/discovery/v1/event.js delete mode 100644 lib/discovery/v1/index.js delete mode 100644 lib/discovery/v1/venue.js rename lib/discovery/{v2/index.js => v2.js} (91%) diff --git a/lib/discovery/v1.js b/lib/discovery/v1.js new file mode 100644 index 0000000..7ce0598 --- /dev/null +++ b/lib/discovery/v1.js @@ -0,0 +1,32 @@ +import all from '../utils/all'; +import find from '../utils/find'; + +export const api = 'discovery/v1'; + +export const Attraction = (apiKey) => ({ + all: all(api, apiKey, 'attractions'), + find: find(api, apiKey, 'attractions') +}); + +export const Category = (apiKey) => ({ + all: all(api, apiKey, 'categories'), + find: find(api, apiKey, 'categories') +}); + +export const Event = (apiKey) => ({ + all: all(api, apiKey, 'events'), + find: find(api, apiKey, 'events'), + findImages: find(api, apiKey, 'events', 'images') +}); + +export const Venue = (apiKey) => ({ + all: all(api, apiKey, 'venues'), + find: find(api, apiKey, 'venues') +}); + +export default (apiKey) => ({ + attraction: Attraction(apiKey), + category: Category(apiKey), + event: Event(apiKey), + venue: Venue(apiKey) +}); diff --git a/lib/discovery/v1/attraction.js b/lib/discovery/v1/attraction.js deleted file mode 100644 index 34957c4..0000000 --- a/lib/discovery/v1/attraction.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); diff --git a/lib/discovery/v1/category.js b/lib/discovery/v1/category.js deleted file mode 100644 index 3fa29a9..0000000 --- a/lib/discovery/v1/category.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'categories'), - find: find(api, apiKey, 'categories') -}); diff --git a/lib/discovery/v1/event.js b/lib/discovery/v1/event.js deleted file mode 100644 index 7bc63c2..0000000 --- a/lib/discovery/v1/event.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events') -}); diff --git a/lib/discovery/v1/index.js b/lib/discovery/v1/index.js deleted file mode 100644 index ccf6f01..0000000 --- a/lib/discovery/v1/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import attraction from './attraction'; -import category from './category'; -import event from './event'; -import venue from './venue'; - -export const api = 'discovery/v1'; - -export default (apiKey) => ({ - attraction: attraction(apiKey), - category: category(apiKey), - event: event(apiKey), - venue: venue(apiKey) -}); diff --git a/lib/discovery/v1/venue.js b/lib/discovery/v1/venue.js deleted file mode 100644 index c33fe1d..0000000 --- a/lib/discovery/v1/venue.js +++ /dev/null @@ -1,9 +0,0 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; - -import {api} from './'; - -export default (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); diff --git a/lib/discovery/v2/index.js b/lib/discovery/v2.js similarity index 91% rename from lib/discovery/v2/index.js rename to lib/discovery/v2.js index 298ac15..4f0aa16 100644 --- a/lib/discovery/v2/index.js +++ b/lib/discovery/v2.js @@ -1,5 +1,5 @@ -import all from '../../utils/all'; -import find from '../../utils/find'; +import all from '../utils/all'; +import find from '../utils/find'; const api = 'discovery/v2'; diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index e7307aa..3b04807 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Attraction from '../../../../lib/discovery/v1/attraction'; +import {Attraction} from '../../../../lib/discovery/v1'; describe('discovery.v1.attraction.find', () => { before(() => { diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js index cc400f6..691c224 100644 --- a/test/discovery/v1/attraction/index.js +++ b/test/discovery/v1/attraction/index.js @@ -1,8 +1,8 @@ -import attraction from '../../../../lib/discovery/v1/attraction'; +import {Attraction} from '../../../../lib/discovery/v1'; describe('discovery.v1.attraction', () => { it('should provide find', done => { - attraction().should.have.property('find'); + Attraction().should.have.property('find'); done(); }); }); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index c55b75c..cb4aab8 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Category from '../../../../lib/discovery/v1/category'; +import {Category} from '../../../../lib/discovery/v1'; describe('discovery.v1.category.find', () => { before(() => { diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js index 008d7e5..11e58d2 100644 --- a/test/discovery/v1/category/index.js +++ b/test/discovery/v1/category/index.js @@ -1,8 +1,8 @@ -import category from '../../../../lib/discovery/v1/category'; +import {Category} from '../../../../lib/discovery/v1'; describe('discovery.v1.category', () => { it('should provide find', done => { - category().should.have.property('find'); + Category().should.have.property('find'); done(); }); }); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 90d5226..448a86c 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v1/event'; +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.all', () => { before(() => { diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index d5d7960..515bc06 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Event from '../../../../lib/discovery/v1/event'; +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.find', () => { before(() => { diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js index 18e2145..0d5dc68 100644 --- a/test/discovery/v1/event/index.js +++ b/test/discovery/v1/event/index.js @@ -1,13 +1,13 @@ -import event from '../../../../lib/discovery/v1/event'; +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event', () => { it('should provide find', done => { - event().should.have.property('find'); + Event().should.have.property('find'); done(); }); it('should provide all', done => { - event().should.have.property('all'); + Event().should.have.property('all'); done(); }); }); diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index 967a531..13cc6bc 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,6 +1,6 @@ import {back as nockBack} from 'nock'; -import Venue from '../../../../lib/discovery/v1/venue'; +import {Venue} from '../../../../lib/discovery/v1'; describe('discovery.v1.venue.find', () => { before(() => { diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js index a58c185..3a157ab 100644 --- a/test/discovery/v1/venue/index.js +++ b/test/discovery/v1/venue/index.js @@ -1,8 +1,8 @@ -import venue from '../../../../lib/discovery/v1/venue'; +import {Venue} from '../../../../lib/discovery/v1'; describe('discovery.v1.venue', () => { it('should provide find', (done) => { - venue().should.have.property('find'); + Venue().should.have.property('find'); done(); }); }); From 41acf39fec2c0be694d27660a4cf1eafee1411da Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Fri, 5 Aug 2016 18:13:34 +0100 Subject: [PATCH 30/46] waypoint --- .eslintrc | 5 +- lib/commerce/index.js | 4 +- lib/commerce/v2/index.js | 6 +-- lib/commerce/v2/offer.js | 6 +-- lib/config.js | 4 +- lib/discovery/index.js | 6 +-- lib/discovery/v1.js | 52 ++++++++++----------- lib/discovery/v2.js | 52 ++++++++++----------- lib/index.js | 14 +++--- lib/page.js | 40 ++++++++-------- lib/utils/all.js | 12 ++--- lib/utils/find.js | 10 ++-- lib/utils/getData.js | 18 ++++---- test/commerce/index.js | 10 ++-- test/commerce/v2/index.js | 10 ++-- test/commerce/v2/offer/find.js | 38 ++++++++-------- test/commerce/v2/offer/index.js | 10 ++-- test/discovery/index.js | 18 ++++---- test/discovery/v1/attraction/find.js | 24 +++++----- test/discovery/v1/attraction/index.js | 10 ++-- test/discovery/v1/category/find.js | 24 +++++----- test/discovery/v1/category/index.js | 10 ++-- test/discovery/v1/event/all.js | 24 +++++----- test/discovery/v1/event/find.js | 38 ++++++++-------- test/discovery/v1/event/index.js | 16 +++---- test/discovery/v1/index.js | 28 ++++++------ test/discovery/v1/venue/find.js | 24 +++++----- test/discovery/v1/venue/index.js | 10 ++-- test/discovery/v2/attraction/all.js | 24 +++++----- test/discovery/v2/attraction/find.js | 24 +++++----- test/discovery/v2/classification/all.js | 24 +++++----- test/discovery/v2/classification/find.js | 24 +++++----- test/discovery/v2/event/all.js | 36 +++++++-------- test/discovery/v2/event/find.js | 58 ++++++++++++------------ test/discovery/v2/event/options.js | 30 ++++++------ test/discovery/v2/index.js | 30 ++++++------ test/discovery/v2/venue/find.js | 24 +++++----- test/globals.js | 2 +- test/utils/all.js | 24 +++++----- test/utils/find.js | 32 ++++++------- 40 files changed, 428 insertions(+), 427 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4b5f492..df542e9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,9 @@ { "extends": "standard", "rules": { - "semi": [2, "always"], - "space-before-function-paren": [2, "never"] + "semi": [2, "never"], + "space-before-function-paren": [2, "never"], + "key-spacing": ["error", {"align": "value"}] }, "globals": { "it": true, diff --git a/lib/commerce/index.js b/lib/commerce/index.js index 2d10a12..9ea4c62 100644 --- a/lib/commerce/index.js +++ b/lib/commerce/index.js @@ -1,5 +1,5 @@ -import v2 from './v2'; +import v2 from './v2' export default (apiKey) => ({ v2: v2(apiKey) -}); +}) diff --git a/lib/commerce/v2/index.js b/lib/commerce/v2/index.js index 383bc9d..a1a0f4e 100644 --- a/lib/commerce/v2/index.js +++ b/lib/commerce/v2/index.js @@ -1,7 +1,7 @@ -import offer from './offer'; +import offer from './offer' -export const api = 'commerce/v2'; +export const api = 'commerce/v2' export default (apikey) => ({ offer: offer(apikey) -}); +}) diff --git a/lib/commerce/v2/offer.js b/lib/commerce/v2/offer.js index 20c3d7b..3f9c764 100644 --- a/lib/commerce/v2/offer.js +++ b/lib/commerce/v2/offer.js @@ -1,7 +1,7 @@ -import find from '../../utils/find'; +import find from '../../utils/find' -import {api} from './'; +import {api} from './' export default (apikey) => ({ find: find(api, apikey, 'events', 'offers') -}); +}) diff --git a/lib/config.js b/lib/config.js index 52e7d52..138c94a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,5 +1,5 @@ const config = { baseURL: 'https://app.ticketmaster.com' -}; +} -export default config; +export default config diff --git a/lib/discovery/index.js b/lib/discovery/index.js index 2c69d81..5dd2df6 100644 --- a/lib/discovery/index.js +++ b/lib/discovery/index.js @@ -1,7 +1,7 @@ -import v1 from './v1'; -import v2 from './v2'; +import v1 from './v1' +import v2 from './v2' export default (apiKey) => ({ v1: v1(apiKey), v2: v2(apiKey) -}); +}) diff --git a/lib/discovery/v1.js b/lib/discovery/v1.js index 7ce0598..da76612 100644 --- a/lib/discovery/v1.js +++ b/lib/discovery/v1.js @@ -1,32 +1,32 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../utils/all' +import find from '../utils/find' -export const api = 'discovery/v1'; +export const api = 'discovery/v1' -export const Attraction = (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); +export const Attraction = (apikey) => ({ + all: all(api, apikey, 'attractions'), + find: find(api, apikey, 'attractions') +}) -export const Category = (apiKey) => ({ - all: all(api, apiKey, 'categories'), - find: find(api, apiKey, 'categories') -}); +export const Category = (apikey) => ({ + all: all(api, apikey, 'categories'), + find: find(api, apikey, 'categories') +}) -export const Event = (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events'), - findImages: find(api, apiKey, 'events', 'images') -}); +export const Event = (apikey) => ({ + all: all(api, apikey, 'events'), + find: find(api, apikey, 'events'), + findImages: find(api, apikey, 'events', 'images') +}) -export const Venue = (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); +export const Venue = (apikey) => ({ + all: all(api, apikey, 'venues'), + find: find(api, apikey, 'venues') +}) -export default (apiKey) => ({ - attraction: Attraction(apiKey), - category: Category(apiKey), - event: Event(apiKey), - venue: Venue(apiKey) -}); +export default (apikey) => ({ + attraction: Attraction(apikey), + category: Category(apikey), + event: Event(apikey), + venue: Venue(apikey) +}) diff --git a/lib/discovery/v2.js b/lib/discovery/v2.js index 4f0aa16..75a477b 100644 --- a/lib/discovery/v2.js +++ b/lib/discovery/v2.js @@ -1,32 +1,32 @@ -import all from '../utils/all'; -import find from '../utils/find'; +import all from '../utils/all' +import find from '../utils/find' -const api = 'discovery/v2'; +const api = 'discovery/v2' -export const Attraction = (apiKey) => ({ - all: all(api, apiKey, 'attractions'), - find: find(api, apiKey, 'attractions') -}); +export const Attraction = (apikey) => ({ + all: all(api, apikey, 'attractions'), + find: find(api, apikey, 'attractions') +}) -export const Classification = (apiKey) => ({ - all: all(api, apiKey, 'classifications'), - find: find(api, apiKey, 'classifications') -}); +export const Classification = (apikey) => ({ + all: all(api, apikey, 'classifications'), + find: find(api, apikey, 'classifications') +}) -export const Event = (apiKey) => ({ - all: all(api, apiKey, 'events'), - find: find(api, apiKey, 'events'), - findImages: find(api, apiKey, 'events', 'images') -}); +export const Event = (apikey) => ({ + all: all(api, apikey, 'events'), + find: find(api, apikey, 'events'), + findImages: find(api, apikey, 'events', 'images') +}) -export const Venue = (apiKey) => ({ - all: all(api, apiKey, 'venues'), - find: find(api, apiKey, 'venues') -}); +export const Venue = (apikey) => ({ + all: all(api, apikey, 'venues'), + find: find(api, apikey, 'venues') +}) -export default (apiKey) => ({ - attraction: Attraction(apiKey), - classification: Classification(apiKey), - event: Event(apiKey), - venue: Venue(apiKey) -}); +export default (apikey) => ({ + attraction: Attraction(apikey), + classification: Classification(apikey), + event: Event(apikey), + venue: Venue(apikey) +}) diff --git a/lib/index.js b/lib/index.js index 16ed79d..9099277 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,16 +1,16 @@ -import discovery from './discovery/index'; -import commerce from './commerce/index'; +import discovery from './discovery/index' +import commerce from './commerce/index' const API = (apikey) => { if (apikey === 'YOUR_KEY_HERE') { - return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register'); + return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register') } return { apikey, discovery: discovery(apikey), - commerce: commerce(apikey) - }; -}; + commerce: commerce(apikey) + } +} -export default API; +export default API diff --git a/lib/page.js b/lib/page.js index f407298..4c48151 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,4 +1,4 @@ -import getData from './utils/getData'; +import getData from './utils/getData' /** * Page object constructor @@ -7,12 +7,12 @@ import getData from './utils/getData'; */ class Page { constructor({_embedded, page}, path, qs) { - const itemKey = Object.keys(_embedded)[0]; + const itemKey = Object.keys(_embedded)[0] - this.items = _embedded[itemKey]; - this.page = page; - this.path = path; - this.qs = qs; + this.items = _embedded[itemKey] + this.page = page + this.path = path + this.qs = qs } /** @@ -22,13 +22,13 @@ class Page { * @returns {Promise} */ getAt(n) { - const qs = Object.assign({}, this.qs, {page: n}); + const qs = Object.assign({}, this.qs, {page: n}) if (n > 0 && n <= this.page.totalPages) { - return getData({path: this.path, qs}); + return getData({path: this.path, qs}) } - return Promise.reject({message: 'You should pass correct page number.', qs}); + return Promise.reject({message: 'You should pass correct page number.', qs}) }; /** @@ -38,14 +38,14 @@ class Page { * @returns {Promise} */ getNext(step = 1) { - const n = this.page.number + step; - const qs = Object.assign({}, this.qs, {page: n}); + const n = this.page.number + step + const qs = Object.assign({}, this.qs, {page: n}) if (n <= this.page.totalPages) { - return getData({path: this.path, qs}); + return getData({path: this.path, qs}) } - return Promise.reject({message: 'No next page! You are on the last.', qs}); + return Promise.reject({message: 'No next page! You are on the last.', qs}) }; /** @@ -55,14 +55,14 @@ class Page { * @returns {Promise} */ getPrev(step = 1) { - const n = this.page.number - step; - const qs = Object.assign({}, this.qs, {page: n}); + const n = this.page.number - step + const qs = Object.assign({}, this.qs, {page: n}) if (n > 0) { - return getData({path: this.path, qs}); + return getData({path: this.path, qs}) } - return Promise.reject({message: 'No previous page! You are on the first one.', qs}); + return Promise.reject({message: 'No previous page! You are on the first one.', qs}) }; /** @@ -71,7 +71,7 @@ class Page { * @returns {boolean} */ isLast() { - return this.page.number === this.page.totalPages; + return this.page.number === this.page.totalPages }; /** @@ -79,8 +79,8 @@ class Page { * @returns {number} quantity of all items of the same type */ count() { - return this.page.totalElements; + return this.page.totalElements }; } -export default Page; +export default Page diff --git a/lib/utils/all.js b/lib/utils/all.js index 5206d5c..7b36377 100644 --- a/lib/utils/all.js +++ b/lib/utils/all.js @@ -1,12 +1,12 @@ -import getData from './getData'; +import getData from './getData' export default (api, apikey, type) => (qs = {}) => { - qs.apikey = apikey; + qs.apikey = apikey const params = { path: [api, type], - qs: qs - }; + qs: qs + } - return getData(params); -}; + return getData(params) +} diff --git a/lib/utils/find.js b/lib/utils/find.js index d2f06e5..32e93e3 100644 --- a/lib/utils/find.js +++ b/lib/utils/find.js @@ -1,10 +1,10 @@ -import getData from './getData'; +import getData from './getData' export default (api, apikey, type, ...path) => (eventId) => { const params = { path: [api, type, eventId, ...path], - qs: {apikey} - }; + qs: {apikey} + } - return getData(params); -}; + return getData(params) +} diff --git a/lib/utils/getData.js b/lib/utils/getData.js index f1aba6a..2d1c72e 100644 --- a/lib/utils/getData.js +++ b/lib/utils/getData.js @@ -1,12 +1,12 @@ -import fetch from 'isomorphic-fetch'; -import queryString from 'query-string'; +import fetch from 'isomorphic-fetch' +import queryString from 'query-string' -import config from '../config'; -import Page from '../page'; +import config from '../config' +import Page from '../page' export const getURL = (path, qs) => { - return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}`; -}; + return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}` +} /** * Main GET Data configuration function for API @@ -19,7 +19,7 @@ export const getURL = (path, qs) => { const getData = ({path, qs}) => { return fetch(getURL(path, qs)) .then((res) => (res.status === 200) ? res.json() : res.json().then(Promise.reject.bind(Promise))) - .then((json) => json.page ? new Page(json, path, qs) : json); -}; + .then((json) => json.page ? new Page(json, path, qs) : json) +} -export default getData; +export default getData diff --git a/test/commerce/index.js b/test/commerce/index.js index 054a96b..78dc9a9 100644 --- a/test/commerce/index.js +++ b/test/commerce/index.js @@ -1,8 +1,8 @@ -import commerce from '../../lib/commerce'; +import commerce from '../../lib/commerce' describe('commerce', () => { it('should provide v2', done => { - commerce().should.have.property('v2'); - done(); - }); -}); + commerce().should.have.property('v2') + done() + }) +}) diff --git a/test/commerce/v2/index.js b/test/commerce/v2/index.js index a1a7a87..9cd8e4f 100644 --- a/test/commerce/v2/index.js +++ b/test/commerce/v2/index.js @@ -1,8 +1,8 @@ -import v2 from '../../../lib/commerce/v2'; +import v2 from '../../../lib/commerce/v2' describe('commerce.v2', () => { it('should provide offer', done => { - v2().should.have.property('offer'); - done(); - }); -}); + v2().should.have.property('offer') + done() + }) +}) diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index 16e9287..4a3ef80 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -1,35 +1,35 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import Offer from '../../../../lib/commerce/v2/offer'; +import Offer from '../../../../lib/commerce/v2/offer' describe('commerce.v2.offer.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/commerce/v2'; - }); + nockBack.fixtures = './test/fixtures/commerce/v2' + }) describe('success', () => { it('should find offers', (done) => { nockBack('offer/find-200.json', {}, (nockDone) => { Offer('mock-api-key').find('vvG1iZKU5jIxKX', 'offers') .then((result) => { - result.limits.max.should.equal(14); - nockDone(); - done(); - }); - }); - }); - }); + result.limits.max.should.equal(14) + nockDone() + done() + }) + }) + }) + }) describe('not found', () => { it('should handle 500', (done) => { nockBack('offer/find-500.json', {}, (nockDone) => { Offer('mock-api-key').find('unknown-id', 'offers') .catch((response) => { - response.errors[0].code.should.equal('40001'); - nockDone(); - done(); - }); - }); - }); - }); -}); + response.errors[0].code.should.equal('40001') + nockDone() + done() + }) + }) + }) + }) +}) diff --git a/test/commerce/v2/offer/index.js b/test/commerce/v2/offer/index.js index 519822c..9bd52e0 100644 --- a/test/commerce/v2/offer/index.js +++ b/test/commerce/v2/offer/index.js @@ -1,8 +1,8 @@ -import event from '../../../../lib/commerce/v2/offer'; +import event from '../../../../lib/commerce/v2/offer' describe('commerce.v2.offer', () => { it('should provide find', (done) => { - event().should.have.property('find'); - done(); - }); -}); + event().should.have.property('find') + done() + }) +}) diff --git a/test/discovery/index.js b/test/discovery/index.js index e05d3f1..e2f32bb 100644 --- a/test/discovery/index.js +++ b/test/discovery/index.js @@ -1,15 +1,15 @@ -import discovery from '../../lib/discovery'; +import discovery from '../../lib/discovery' describe('discovery', () => { it('should provide v1', done => { - discovery().should.have.property('v1'); - done(); - }); -}); + discovery().should.have.property('v1') + done() + }) +}) describe('discovery', () => { it('should provide v2', done => { - discovery().should.have.property('v2'); - done(); - }); -}); + discovery().should.have.property('v2') + done() + }) +}) diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index 3b04807..3ba9669 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Attraction} from '../../../../lib/discovery/v1'; +import {Attraction} from '../../../../lib/discovery/v1' describe('discovery.v1.attraction.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1'; - }); + nockBack.fixtures = './test/fixtures/discovery/v1' + }) describe('success', () => { it('should find a attraction', done => { nockBack('attraction/find-200.json', {}, function(nockDone) { Attraction('mock-api-key').find('1542376') .then((result) => { - result.name.should.equal('Monster Jam'); - nockDone(); - done(); + result.name.should.equal('Monster Jam') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js index 691c224..ebcfe1f 100644 --- a/test/discovery/v1/attraction/index.js +++ b/test/discovery/v1/attraction/index.js @@ -1,8 +1,8 @@ -import {Attraction} from '../../../../lib/discovery/v1'; +import {Attraction} from '../../../../lib/discovery/v1' describe('discovery.v1.attraction', () => { it('should provide find', done => { - Attraction().should.have.property('find'); - done(); - }); -}); + Attraction().should.have.property('find') + done() + }) +}) diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index cb4aab8..5bc03f1 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Category} from '../../../../lib/discovery/v1'; +import {Category} from '../../../../lib/discovery/v1' describe('discovery.v1.category.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1'; - }); + nockBack.fixtures = './test/fixtures/discovery/v1' + }) describe('success', () => { it('should find a category', done => { nockBack('category/find-200.json', {}, nockDone => { Category('mock-api-key').find('10004') .then((result) => { - result.name.should.equal('Sports'); - nockDone(); - done(); + result.name.should.equal('Sports') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js index 11e58d2..8c7c8c4 100644 --- a/test/discovery/v1/category/index.js +++ b/test/discovery/v1/category/index.js @@ -1,8 +1,8 @@ -import {Category} from '../../../../lib/discovery/v1'; +import {Category} from '../../../../lib/discovery/v1' describe('discovery.v1.category', () => { it('should provide find', done => { - Category().should.have.property('find'); - done(); - }); -}); + Category().should.have.property('find') + done() + }) +}) diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 448a86c..79bccd2 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Event} from '../../../../lib/discovery/v1'; +import {Event} from '../../../../lib/discovery/v1' describe('discovery.v1.event.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1'; - }); + nockBack.fixtures = './test/fixtures/discovery/v1' + }) describe('success', () => { it('should find an event', done => { nockBack('event/all-200.json', {}, nockDone => { Event('mock-api-key').all() .then((result) => { - result.items[0].name.should.equal('OSEA Membership Registration'); - nockDone(); - done(); + result.items[0].name.should.equal('OSEA Membership Registration') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index 515bc06..4460740 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,37 +1,37 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Event} from '../../../../lib/discovery/v1'; +import {Event} from '../../../../lib/discovery/v1' describe('discovery.v1.event.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1'; - }); + nockBack.fixtures = './test/fixtures/discovery/v1' + }) describe('success', () => { it('should find an event', done => { nockBack('event/find-200.json', {}, function(nockDone) { Event('mock-api-key').find('3A004F38C8275108') .then((result) => { - result.name.should.equal('Monster Jam'); - nockDone(); - done(); + result.name.should.equal('Monster Jam') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); + .catch(() => done()) + }) + }) + }) describe('not found', () => { it('should handle 404', done => { nockBack('event/find-404.json', {}, function(nockDone) { Event('mock-api-key').find('unknown-id') .then((result) => { - result.errors[0].code.should.equal('DIS1004'); - nockDone(); - done(); + result.errors[0].code.should.equal('DIS1004') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js index 0d5dc68..7247aa3 100644 --- a/test/discovery/v1/event/index.js +++ b/test/discovery/v1/event/index.js @@ -1,13 +1,13 @@ -import {Event} from '../../../../lib/discovery/v1'; +import {Event} from '../../../../lib/discovery/v1' describe('discovery.v1.event', () => { it('should provide find', done => { - Event().should.have.property('find'); - done(); - }); + Event().should.have.property('find') + done() + }) it('should provide all', done => { - Event().should.have.property('all'); - done(); - }); -}); + Event().should.have.property('all') + done() + }) +}) diff --git a/test/discovery/v1/index.js b/test/discovery/v1/index.js index f7f7092..86d1777 100644 --- a/test/discovery/v1/index.js +++ b/test/discovery/v1/index.js @@ -1,23 +1,23 @@ -import v1 from '../../../lib/discovery/v1'; +import v1 from '../../../lib/discovery/v1' describe('discovery.v1', () => { it('should provide attraction', done => { - v1().should.have.property('attraction'); - done(); - }); + v1().should.have.property('attraction') + done() + }) it('should provide category', done => { - v1().should.have.property('category'); - done(); - }); + v1().should.have.property('category') + done() + }) it('should provide event', done => { - v1().should.have.property('event'); - done(); - }); + v1().should.have.property('event') + done() + }) it('should provide venue', done => { - v1().should.have.property('venue'); - done(); - }); -}); + v1().should.have.property('venue') + done() + }) +}) diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index 13cc6bc..b94f877 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Venue} from '../../../../lib/discovery/v1'; +import {Venue} from '../../../../lib/discovery/v1' describe('discovery.v1.venue.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1'; - }); + nockBack.fixtures = './test/fixtures/discovery/v1' + }) describe('success', () => { it('should find a venue', done => { nockBack('venue/find-200.json', {}, function(nockDone) { Venue('mock-api-key').find('475247') .then((result) => { - result.name.should.equal('Alamodome'); - nockDone(); - done(); + result.name.should.equal('Alamodome') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js index 3a157ab..df82223 100644 --- a/test/discovery/v1/venue/index.js +++ b/test/discovery/v1/venue/index.js @@ -1,8 +1,8 @@ -import {Venue} from '../../../../lib/discovery/v1'; +import {Venue} from '../../../../lib/discovery/v1' describe('discovery.v1.venue', () => { it('should provide find', (done) => { - Venue().should.have.property('find'); - done(); - }); -}); + Venue().should.have.property('find') + done() + }) +}) diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index a548027..049c6fd 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Attraction} from '../../../../lib/discovery/v2'; +import {Attraction} from '../../../../lib/discovery/v2' describe('discovery.v2.attraction.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find an attraction', (done) => { nockBack('attraction/all-200.json', {}, nockDone => { Attraction('mock-api-key').all() .then((result) => { - result.items[0].name.should.equal('!!!'); - nockDone(); - done(); + result.items[0].name.should.equal('!!!') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index d991f82..8b34129 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Attraction} from '../../../../lib/discovery/v2'; +import {Attraction} from '../../../../lib/discovery/v2' describe('discovery.v2.attraction.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find a attraction', (done) => { nockBack('attraction/find-200.json', {}, (nockDone) => { Attraction('mock-api-key').find('K8vZ917Kew0') .then((result) => { - result.name.should.equal('Susquehanna Breakdown Music Festival'); - nockDone(); - done(); + result.name.should.equal('Susquehanna Breakdown Music Festival') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index f48b070..bda9aac 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Classification} from '../../../../lib/discovery/v2'; +import {Classification} from '../../../../lib/discovery/v2' describe('discovery.v2.classification.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find an classification', (done) => { nockBack('classification/all-200.json', {}, (nockDone) => { Classification('mock-api-key').all() .then((result) => { - result.items[0].should.not.be.an('undefined'); - nockDone(); - done(); + result.items[0].should.not.be.an('undefined') + nockDone() + done() }) - .catch((err) => done(err)); - }); - }); - }); -}); + .catch((err) => done(err)) + }) + }) + }) +}) diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index 3dd69b8..a86ed57 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Classification} from '../../../../lib/discovery/v2'; +import {Classification} from '../../../../lib/discovery/v2' describe('discovery.v2.classification.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find a classification', done => { nockBack('classification/find-200.json', {}, nockDone => { Classification('mock-api-key').find('KZFzniwnSyZfZ7v7na') .then(result => { - result.segment.name.should.equal('Arts & Theatre'); - nockDone(); - done(); + result.segment.name.should.equal('Arts & Theatre') + nockDone() + done() }) - .catch((err) => done(err)); - }); - }); - }); -}); + .catch((err) => done(err)) + }) + }) + }) +}) diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index ac256a9..f39757a 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,37 +1,37 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import tmapi from '../../../../lib'; -import {Event} from '../../../../lib/discovery/v2'; +import tmapi from '../../../../lib' +import {Event} from '../../../../lib/discovery/v2' -const api = tmapi('mock-api-key'); +const api = tmapi('mock-api-key') const onResult = (done) => (page) => { - page.items[0].name.should.equal('OSEA Membership Registration'); - done(); -}; + page.items[0].name.should.equal('OSEA Membership Registration') + done() +} -nockBack.fixtures = './test/fixtures/discovery/v2'; +nockBack.fixtures = './test/fixtures/discovery/v2' describe('discovery.v2.event.all', () => { describe('success', () => { it('should find an event using the fluent API', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - nockDone(); + nockDone() api.discovery.v2.event.all() .then(onResult(done)) - .catch((err) => done(err)); - }); - }); + .catch((err) => done(err)) + }) + }) it('should find an event', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - nockDone(); + nockDone() Event('mock-api-key').all() .then(onResult(done)) - .catch((err) => done(err)); - }); - }); - }); -}); + .catch((err) => done(err)) + }) + }) + }) +}) diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index c049b3a..7c687b4 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -1,55 +1,55 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Event} from '../../../../lib/discovery/v2'; +import {Event} from '../../../../lib/discovery/v2' describe('discovery.v2.event.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find an event', (done) => { nockBack('event/find-200.json', {}, (nockDone) => { Event('mock-api-key').find('vv17FZfdGkSrrMju') .then((result) => { - result.name.should.equal('Susquehanna Breakdown RV Pass'); - nockDone(); - done(); + result.name.should.equal('Susquehanna Breakdown RV Pass') + nockDone() + done() }) - .catch((err) => done(err)); - }); - }); + .catch((err) => done(err)) + }) + }) it('should find images for an event', (done) => { nockBack('event/findImages-200.json', {}, (nockDone) => { Event('mock-api-key').findImages('vv17FZfdGkSrrMju') .then((result) => { result.images[0].should.deep.equal({ - 'ratio': '3_2', - 'url': 'http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg', - 'width': 305, - 'height': 203, + 'ratio': '3_2', + 'url': 'http://s1.ticketm.net/dam/c/8cf/a6653880-7899-4f67-8067-1f95f4d158cf_124761_ARTIST_PAGE_3_2.jpg', + 'width': 305, + 'height': 203, 'fallback': true - }); - nockDone(); - done(); + }) + nockDone() + done() }) - .catch((err) => done(err)); - }); - }); - }); + .catch((err) => done(err)) + }) + }) + }) describe('not found', () => { it('should handle 404', (done) => { nockBack('event/find-404.json', {}, (nockDone) => { Event('mock-api-key').find('unknown-id') .catch((response) => { - response.errors[0].code.should.equal('DIS1004'); - nockDone(); - done(); + response.errors[0].code.should.equal('DIS1004') + nockDone() + done() }) - .catch((err) => done(err)); - }); - }); - }); -}); + .catch((err) => done(err)) + }) + }) + }) +}) diff --git a/test/discovery/v2/event/options.js b/test/discovery/v2/event/options.js index ab481d0..48ecba0 100644 --- a/test/discovery/v2/event/options.js +++ b/test/discovery/v2/event/options.js @@ -1,27 +1,27 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Event} from '../../../../lib/discovery/v2'; +import {Event} from '../../../../lib/discovery/v2' -nockBack.fixtures = './test/fixtures/discovery/v2'; +nockBack.fixtures = './test/fixtures/discovery/v2' describe('discovery.v2.event.options', () => { describe('options', () => { it('should produce a formatted query string from params', (done) => { nockBack('event/all-200-options.json', (nockDone) => { - nockDone(); + nockDone() Event('mock-api-key').all({page: 2, size: 5, sort: 'name,desc'}) .then((page) => { - page.items.length.should.equal(5); - page.isLast().should.equal(false); - page.getAt(1).should.be.instanceOf(Promise); - page.getNext(1).should.be.instanceOf(Promise); - page.getPrev(1).should.be.instanceOf(Promise); + page.items.length.should.equal(5) + page.isLast().should.equal(false) + page.getAt(1).should.be.instanceOf(Promise) + page.getNext(1).should.be.instanceOf(Promise) + page.getPrev(1).should.be.instanceOf(Promise) - done(); + done() }) - .catch((err) => done(err)); - }); - }); - }); -}); + .catch((err) => done(err)) + }) + }) + }) +}) diff --git a/test/discovery/v2/index.js b/test/discovery/v2/index.js index 03963ef..f361e2f 100644 --- a/test/discovery/v2/index.js +++ b/test/discovery/v2/index.js @@ -1,25 +1,25 @@ -import v2 from '../../../lib/discovery/v2'; +import v2 from '../../../lib/discovery/v2' -const api = v2(); +const api = v2() describe('discovery.v2', () => { it('should provide attraction', (done) => { - api.should.have.property('attraction'); - done(); - }); + api.should.have.property('attraction') + done() + }) it('should provide classification', (done) => { - api.should.have.property('classification'); - done(); - }); + api.should.have.property('classification') + done() + }) it('should provide event', (done) => { - api.should.have.property('event'); - done(); - }); + api.should.have.property('event') + done() + }) it('should provide venue', (done) => { - api.should.have.property('venue'); - done(); - }); -}); + api.should.have.property('venue') + done() + }) +}) diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index e9c9a90..7ffad40 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock'; +import {back as nockBack} from 'nock' -import {Venue} from '../../../../lib/discovery/v2'; +import {Venue} from '../../../../lib/discovery/v2' describe('discovery.v2.venue.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2'; - }); + nockBack.fixtures = './test/fixtures/discovery/v2' + }) describe('success', () => { it('should find a venue', done => { nockBack('venue/find-200.json', {}, (nockDone) => { Venue('mock-api-key').find('KovZpZAEA76A') .then((result) => { - result.name.should.equal('The Pavilion at Montage Mountain'); - nockDone(); - done(); + result.name.should.equal('The Pavilion at Montage Mountain') + nockDone() + done() }) - .catch(() => done()); - }); - }); - }); -}); + .catch(() => done()) + }) + }) + }) +}) diff --git a/test/globals.js b/test/globals.js index 2ad049a..3840a18 100644 --- a/test/globals.js +++ b/test/globals.js @@ -1 +1 @@ -global.should = require('chai').should(); +global.should = require('chai').should() diff --git a/test/utils/all.js b/test/utils/all.js index bf3d4bb..81f9bc9 100644 --- a/test/utils/all.js +++ b/test/utils/all.js @@ -1,23 +1,23 @@ -import all from '../../lib/utils/all'; +import all from '../../lib/utils/all' -let query; +let query describe('utils.all', () => { before(() => { - all.__Rewire__('getData', (params) => params); + all.__Rewire__('getData', (params) => params) - query = all('discovery/v2', 'a3b2c1d4e5f6', 'events'); - }); + query = all('discovery/v2', 'a3b2c1d4e5f6', 'events') + }) it('should parse params correctly', (done) => { query({city: 'london'}).should.deep.equal({ path: ['discovery/v2', 'events'], - qs: {city: 'london', apikey: 'a3b2c1d4e5f6'} - }); - done(); - }); + qs: {city: 'london', apikey: 'a3b2c1d4e5f6'} + }) + done() + }) after(() => { - all.__ResetDependency__('getData'); - }); -}); + all.__ResetDependency__('getData') + }) +}) diff --git a/test/utils/find.js b/test/utils/find.js index fb5e1d3..083fb2d 100644 --- a/test/utils/find.js +++ b/test/utils/find.js @@ -1,31 +1,31 @@ -import find from '../../lib/utils/find'; +import find from '../../lib/utils/find' describe('utils.find', () => { before(() => { - find.__Rewire__('getData', (params) => params); - }); + find.__Rewire__('getData', (params) => params) + }) it('should parse params for a resource', (done) => { - const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events'); + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events') query(1).should.deep.equal({ path: ['discovery/v2', 'events', 1], - qs: {apikey: 'a3b2c1d4e5f6'} - }); + qs: {apikey: 'a3b2c1d4e5f6'} + }) - done(); - }); + done() + }) it('should parse params for a sub-resource', (done) => { - const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images'); + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images') query(1).should.deep.equal({ path: ['discovery/v2', 'events', 1, 'images'], - qs: {apikey: 'a3b2c1d4e5f6'} - }); + qs: {apikey: 'a3b2c1d4e5f6'} + }) - done(); - }); + done() + }) after(() => { - find.__ResetDependency__('getData'); - }); -}); + find.__ResetDependency__('getData') + }) +}) From b8b45018adc7d9df1702a71f2f3d908ef5303efa Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 6 Aug 2016 18:49:14 +0100 Subject: [PATCH 31/46] Better README --- README.md | 174 +++++++++++------- config/webpack/config.js | 24 +-- config/webpack/webpack.config.dev.babel.js | 15 ++ ....babel.js => webpack.config.prod.babel.js} | 14 +- docs/index.html | 2 +- lib/commerce/v2.js | 11 ++ lib/commerce/v2/index.js | 7 - lib/commerce/v2/offer.js | 7 - lib/index.js | 2 +- lib/page.js | 22 ++- package.json | 15 +- test/commerce/v2/offer/find.js | 2 +- test/commerce/v2/offer/index.js | 4 +- test/utils/all.js | 7 +- test/utils/find.js | 2 + 15 files changed, 184 insertions(+), 124 deletions(-) create mode 100644 config/webpack/webpack.config.dev.babel.js rename config/webpack/{webpack.config.web.babel.js => webpack.config.prod.babel.js} (59%) create mode 100644 lib/commerce/v2.js delete mode 100644 lib/commerce/v2/index.js delete mode 100644 lib/commerce/v2/offer.js diff --git a/README.md b/README.md index e3c8687..8bf1d5e 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,10 @@ Javascript SDK for the **[Ticketmaster Open Platform](http://developer.ticketmas Aims to wrap the Ticketmaster API with coverage for all Open Platform endpoints, featuring: - API key authentication support - Ticketmaster OAuth2 access key support - - Promises on all requests via Bluebird ## System Requirements - - [NodeJS](https://nodejs.org) (v0.10 or greater) + - [NodeJS](https://nodejs.org) (v0.12 or greater) ## Installation: @@ -28,74 +27,81 @@ git clone --branch git@github.com:ticketmaster-api/sdk-javascript.git For browser usage there are two files in **dist/** folder ```bash -./dist/ticketmaster-client-[version].js (raw with source-maps) -./dist/ticketmaster-client-[version].min.js (minified) +./dist/tmapi-[version].js (raw with source-maps) +./dist/tmapi-[version].min.js (minified) ``` Include one of them in to your project: ```html ... - - + + ... ``` -Use global variable **TMAPI** to make an API call (name can be changed in webpack settings during rebuild): +Use global variable **tmapi** to make an API call: ```javascript -TMAPI('your-api-key').discovery.v2.event.all() -.then(function(result) { - // "result" is an object of Ticketmaster events information -}); +tmapi('YOUR_API_KEY').discovery.v2.event.all() + .then(function(page) { + // "page" is an object of Ticketmaster events information + }); ``` +**Note** If you need to support browsers lacking native support for Promises you should supply a polyfill + ## Server: Require the package and make an API call: +ES5 ```javascript -var TM = require('ticketmaster'); -TM('your-api-key').discovery.v2.event.all() -.then(function(result) { - // "result" is an object of Ticketmaster events information -}); +var tmapi = require('tmapi'); + +tmapi('YOUR_API_KEY').discovery.v2.event.all() + .then(function(result) { + // see notes on the Result object below + }); ``` -Alternative syntax if you are only interested in a subset of the API: +ES6 +```javascript +import tmapi from 'tmapi'; + +tmapi('YOUR_API_KEY').discovery.v2.event.all() + .then((result) => {}) // see notes on the Result object below +``` + +Modules are also available individually: ```javascript -var EventAPI = require('ticketmaster').discovery.v2.event; -EventAPI('your-api-key').all() +import {Event} from 'tmapi/discovery/v2' + +Event('YOUR_API_KEY').all() + .then((result) => console.log(result.items)) ``` ## Rebuild source: In case you want to build your own bundle for client -`1`. Clone this repository +1. Clone this repository -```bash -git clone git@github.com:ticketmaster-api/sdk-javascript.git -``` -`2`. install dependencies + ```bash + git clone git@github.com:ticketmaster-api/sdk-javascript.git + ``` -```bash -npm install -``` -`3`. Run npm script: +1. install dependencies -- for raw (with source-maps) version of client lib use: -```bash -npm run-script dev -``` -- for minified version of client lib use: -```bash -npm run-script prod -``` -- or (for Windows users): -```bash -npm run-script win-prod -``` + ```bash + npm install + ``` + +1. Run npm script: + + ```bash + npm run build + ``` ## Error handling: @@ -108,16 +114,34 @@ npm run-script win-prod (provided only for sets which are result of **.all()** type methods) properties: --`result.items` - Array of Ticketmaster event information. --`result.page` - Additional general information object. + +- `result.items` - Array of Ticketmaster event information. +- `result.page` - Additional general information object. methods: --`result.getPage(index)` - Promise which returns a new Result object. --`result.nextPage()` - Promise which returns a new Result object. Can take additional param - step (1 by default). --`result.previousPage()` - Promise which returns a new Result object. Can take additional param - step (1 by default). --`result.records()` - returns an Array of this page's records --`result.count()` - returns the total count of items --`result.isLastPage()` - returns a Boolean if current Result is the last page + +- `result.getAt(index): Promise` + - Returns a Promise yielding a new Result object. + +- `result.getNext([step]): Promise` + - Returns a Promise yielding a new Result object. + - Can take additional `step` param (1 by default). + +- `result.getPrev([step]): Promise` + - Returns a Promise yielding a new Result object. + - Can take additional `step` param (1 by default). + +- `result.count(): Integer` + - Returns the total count of items matching your criteria + +- `result.pages(): Integer` + - Returns the total count of pages matching your criteria + +- `result.isFirst(): Boolean` + - Whether the current Result is the first page + +- `result.isLast(): Boolean` + - Whether the current Result is the last page ## Running Tests @@ -129,28 +153,38 @@ methods: Currently supports the following endpoints: - - Discovery API - - v1 - - Attraction - - Find - - Category - - Find - - Event - - All - - Find - - Venue - - Find - - v2 - - Attraction - - Find - - Event - - All - - Find - - Venue - - Find - -The goal is to implement all endpoints available @ http://developer.ticketmaster.com/. -Pull Requests gladly accepted! +### Discovery API +- v1 + - Attraction + - all + - find + - Category + - all + - find + - Event + - all + - find + - findImages + - Venue + - all + - find +- v2 + - Attraction + - all + - find + - Classification + - all + - find + - Event + - all + - find + - findImages + - Venue + - all {page, size, sort} + - find + +Our goal is to implement [all available endpoints](http://developer.ticketmaster.com/). +Pull Requests are gladly accepted! ## Contact Us diff --git a/config/webpack/config.js b/config/webpack/config.js index 552d853..d0924b0 100644 --- a/config/webpack/config.js +++ b/config/webpack/config.js @@ -1,31 +1,31 @@ -import path from 'path'; +import path from 'path' -import pkg from './../../package.json'; +import pkg from './../../package.json' function getFilename(suffix) { - return pkg.name + '-' + pkg.version + suffix; + return pkg.name + '-' + pkg.version + suffix } const settings = (options) => ({ - entry: './lib/index.js', + entry: './lib/index.js', output: Object.assign({}, { - filename: `node/${pkg.name}.js`, - library: pkg.name, + filename: `node/${pkg.name}.js`, + library: pkg.name, libraryTarget: 'umd', - path: path.resolve(process.cwd(), 'dist') + path: path.resolve(process.cwd(), 'dist') }, options.output), devtool: options.devtool, - module: { + module: { loaders: [ { - test: /\.js$/, - loader: 'babel', + test: /\.js$/, + loader: 'babel', include: path.join(process.cwd(), 'lib') } ] }, resolve: options.resolve, plugins: options.plugins -}); +}) -export {settings, getFilename}; +export {settings, getFilename} diff --git a/config/webpack/webpack.config.dev.babel.js b/config/webpack/webpack.config.dev.babel.js new file mode 100644 index 0000000..6953fa7 --- /dev/null +++ b/config/webpack/webpack.config.dev.babel.js @@ -0,0 +1,15 @@ +import webpack from 'webpack' + +import {settings, getFilename} from './config' + +const config = settings({ + output: { + filename: 'web/' + getFilename('.js') + }, + devtool: 'source-map', + plugins: [ + new webpack.NoErrorsPlugin() + ] +}) + +export default config diff --git a/config/webpack/webpack.config.web.babel.js b/config/webpack/webpack.config.prod.babel.js similarity index 59% rename from config/webpack/webpack.config.web.babel.js rename to config/webpack/webpack.config.prod.babel.js index af9349c..020546c 100644 --- a/config/webpack/webpack.config.web.babel.js +++ b/config/webpack/webpack.config.prod.babel.js @@ -1,6 +1,6 @@ -import webpack from 'webpack'; +import webpack from 'webpack' -import {settings, getFilename} from './config'; +import {settings, getFilename} from './config' const config = settings({ output: { @@ -10,14 +10,14 @@ const config = settings({ plugins: [ new webpack.LoaderOptionsPlugin({ minimize: true, - debug: false + debug: false }), new webpack.optimize.UglifyJsPlugin({ - compress: {warnings: false}, - comments: false, + compress: {warnings: false}, + comments: false, sourceMap: false }) ] -}); +}) -export default config; +export default config diff --git a/docs/index.html b/docs/index.html index ab72c4a..5fe5ceb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -10,7 +10,7 @@ + -... -``` - -Use global variable **tmapi** to make an API call: - -```javascript -tmapi('YOUR_API_KEY').discovery.v2.event.all() - .then(function(result) { - console.log(result.items) // See notes on the Result object below - }) - .catch(function(err) { - console.log(err) // NOTE: you must provide your own error handler - }) + ``` -**Note** If you need to support browsers lacking native support for Promises you should supply a polyfill +**Note** If you need to support browsers lacking native support for Promises you will need to supply a polyfill library ## Server: From 81b9d6be97475ec17d9f60657ac8181906859f67 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 8 Aug 2016 10:07:03 +0100 Subject: [PATCH 35/46] Added CONTRIBUTING.md --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ README.md | 37 ++----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..73e35fb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +## Rebuild source: + +In case you want to build your own bundle for client + +1. Clone this repository + + ```bash + git clone git@github.com:ticketmaster-api/sdk-javascript.git + ``` + +1. install dependencies + + ```bash + npm install + ``` + +1. Run npm script: + + ```bash + npm run build + ``` + +## Running Tests + + ```bash + npm test + ``` + +## Contact Us + +[internal only] Find us in #open-platform on Ticketmaster Slack! diff --git a/README.md b/README.md index 29b8703..f86e38b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Javascript SDK for the **[Ticketmaster Open Platform](http://developer.ticketmas Aims to wrap the Ticketmaster API with coverage for all Open Platform endpoints, featuring: - API key authentication support - - Ticketmaster OAuth2 access key support + - Ticketmaster OAuth2 access key support (coming soon) Currently supports the following endpoints: @@ -139,6 +139,7 @@ Event('YOUR_API_KEY').all() .catch((err) => console.log(err)) // NOTE: you must provide your own error handler ``` +See `/docs` for examples you can run ## Result object API: @@ -178,37 +179,3 @@ methods: ## Error handling: **NOTE:** no `.catch()` method is provided! You **must** supply your own. - -# Contributing - -## Rebuild source: - -In case you want to build your own bundle for client - -1. Clone this repository - - ```bash - git clone git@github.com:ticketmaster-api/sdk-javascript.git - ``` - -1. install dependencies - - ```bash - npm install - ``` - -1. Run npm script: - - ```bash - npm run build - ``` - -## Running Tests - - ```bash - npm test - ``` - -## Contact Us - -[internal only] Find us in #open-platform on Ticketmaster Slack! From b65cbbb4cba82fa8c5059d28792612aaf7ef0d15 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 8 Aug 2016 10:22:20 +0100 Subject: [PATCH 36/46] Updated deps --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77ec9c7..04fcccb 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "eslint-plugin-standard": "2.0.0", "husky": "0.11.6", "inherits": "2.0.1", - "mocha": "3.0.1", + "mocha": "3.0.2", "nock": "8.0.0", "rimraf": "2.5.4", "webpack": "2.1.0-beta.20" From 47aaa0d309ccdea20b82a6c2871376b458f97319 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Mon, 8 Aug 2016 10:34:26 +0100 Subject: [PATCH 37/46] Grudgingly re-adding semis so as not to make the PR too cray --- .eslintrc | 2 +- config/webpack/config.js | 10 ++--- config/webpack/webpack.config.dev.babel.js | 8 ++-- config/webpack/webpack.config.prod.babel.js | 8 ++-- lib/commerce/index.js | 4 +- lib/commerce/v2.js | 8 ++-- lib/config.js | 4 +- lib/discovery/index.js | 6 +-- lib/discovery/v1.js | 16 +++---- lib/discovery/v2.js | 16 +++---- lib/index.js | 12 ++--- lib/page.js | 44 +++++++++--------- lib/utils/all.js | 10 ++--- lib/utils/find.js | 8 ++-- lib/utils/getData.js | 18 ++++---- test/commerce/index.js | 10 ++--- test/commerce/v2/index.js | 10 ++--- test/commerce/v2/offer/find.js | 38 ++++++++-------- test/commerce/v2/offer/index.js | 10 ++--- test/discovery/index.js | 18 ++++---- test/discovery/v1/attraction/find.js | 24 +++++----- test/discovery/v1/attraction/index.js | 10 ++--- test/discovery/v1/category/find.js | 24 +++++----- test/discovery/v1/category/index.js | 10 ++--- test/discovery/v1/event/all.js | 24 +++++----- test/discovery/v1/event/find.js | 38 ++++++++-------- test/discovery/v1/event/index.js | 16 +++---- test/discovery/v1/index.js | 28 ++++++------ test/discovery/v1/venue/find.js | 24 +++++----- test/discovery/v1/venue/index.js | 10 ++--- test/discovery/v2/attraction/all.js | 24 +++++----- test/discovery/v2/attraction/find.js | 24 +++++----- test/discovery/v2/classification/all.js | 24 +++++----- test/discovery/v2/classification/find.js | 24 +++++----- test/discovery/v2/event/all.js | 36 +++++++-------- test/discovery/v2/event/find.js | 50 ++++++++++----------- test/discovery/v2/event/options.js | 30 ++++++------- test/discovery/v2/index.js | 30 ++++++------- test/discovery/v2/venue/find.js | 24 +++++----- test/globals.js | 2 +- test/utils/all.js | 20 ++++----- test/utils/find.js | 28 ++++++------ 42 files changed, 392 insertions(+), 392 deletions(-) diff --git a/.eslintrc b/.eslintrc index df542e9..174fb4c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "extends": "standard", "rules": { - "semi": [2, "never"], + "semi": [2, "always"], "space-before-function-paren": [2, "never"], "key-spacing": ["error", {"align": "value"}] }, diff --git a/config/webpack/config.js b/config/webpack/config.js index d0924b0..dc3f43a 100644 --- a/config/webpack/config.js +++ b/config/webpack/config.js @@ -1,9 +1,9 @@ -import path from 'path' +import path from 'path'; -import pkg from './../../package.json' +import pkg from './../../package.json'; function getFilename(suffix) { - return pkg.name + '-' + pkg.version + suffix + return pkg.name + '-' + pkg.version + suffix; } const settings = (options) => ({ @@ -26,6 +26,6 @@ const settings = (options) => ({ }, resolve: options.resolve, plugins: options.plugins -}) +}); -export {settings, getFilename} +export {settings, getFilename}; diff --git a/config/webpack/webpack.config.dev.babel.js b/config/webpack/webpack.config.dev.babel.js index 6953fa7..753a972 100644 --- a/config/webpack/webpack.config.dev.babel.js +++ b/config/webpack/webpack.config.dev.babel.js @@ -1,6 +1,6 @@ -import webpack from 'webpack' +import webpack from 'webpack'; -import {settings, getFilename} from './config' +import {settings, getFilename} from './config'; const config = settings({ output: { @@ -10,6 +10,6 @@ const config = settings({ plugins: [ new webpack.NoErrorsPlugin() ] -}) +}); -export default config +export default config; diff --git a/config/webpack/webpack.config.prod.babel.js b/config/webpack/webpack.config.prod.babel.js index 020546c..f5bfc8d 100644 --- a/config/webpack/webpack.config.prod.babel.js +++ b/config/webpack/webpack.config.prod.babel.js @@ -1,6 +1,6 @@ -import webpack from 'webpack' +import webpack from 'webpack'; -import {settings, getFilename} from './config' +import {settings, getFilename} from './config'; const config = settings({ output: { @@ -18,6 +18,6 @@ const config = settings({ sourceMap: false }) ] -}) +}); -export default config +export default config; diff --git a/lib/commerce/index.js b/lib/commerce/index.js index 9ea4c62..2d10a12 100644 --- a/lib/commerce/index.js +++ b/lib/commerce/index.js @@ -1,5 +1,5 @@ -import v2 from './v2' +import v2 from './v2'; export default (apiKey) => ({ v2: v2(apiKey) -}) +}); diff --git a/lib/commerce/v2.js b/lib/commerce/v2.js index b442ee2..d2a0ec3 100644 --- a/lib/commerce/v2.js +++ b/lib/commerce/v2.js @@ -1,11 +1,11 @@ -import find from '../utils/find' +import find from '../utils/find'; -const api = 'commerce/v2' +const api = 'commerce/v2'; export const Offer = (apikey) => ({ find: find(api, apikey, 'events', 'offers') -}) +}); export default (apikey) => ({ offer: Offer(apikey) -}) +}); diff --git a/lib/config.js b/lib/config.js index 138c94a..52e7d52 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,5 +1,5 @@ const config = { baseURL: 'https://app.ticketmaster.com' -} +}; -export default config +export default config; diff --git a/lib/discovery/index.js b/lib/discovery/index.js index 5dd2df6..2c69d81 100644 --- a/lib/discovery/index.js +++ b/lib/discovery/index.js @@ -1,7 +1,7 @@ -import v1 from './v1' -import v2 from './v2' +import v1 from './v1'; +import v2 from './v2'; export default (apiKey) => ({ v1: v1(apiKey), v2: v2(apiKey) -}) +}); diff --git a/lib/discovery/v1.js b/lib/discovery/v1.js index da76612..e5b41c1 100644 --- a/lib/discovery/v1.js +++ b/lib/discovery/v1.js @@ -1,32 +1,32 @@ -import all from '../utils/all' -import find from '../utils/find' +import all from '../utils/all'; +import find from '../utils/find'; -export const api = 'discovery/v1' +export const api = 'discovery/v1'; export const Attraction = (apikey) => ({ all: all(api, apikey, 'attractions'), find: find(api, apikey, 'attractions') -}) +}); export const Category = (apikey) => ({ all: all(api, apikey, 'categories'), find: find(api, apikey, 'categories') -}) +}); export const Event = (apikey) => ({ all: all(api, apikey, 'events'), find: find(api, apikey, 'events'), findImages: find(api, apikey, 'events', 'images') -}) +}); export const Venue = (apikey) => ({ all: all(api, apikey, 'venues'), find: find(api, apikey, 'venues') -}) +}); export default (apikey) => ({ attraction: Attraction(apikey), category: Category(apikey), event: Event(apikey), venue: Venue(apikey) -}) +}); diff --git a/lib/discovery/v2.js b/lib/discovery/v2.js index 75a477b..c84299a 100644 --- a/lib/discovery/v2.js +++ b/lib/discovery/v2.js @@ -1,32 +1,32 @@ -import all from '../utils/all' -import find from '../utils/find' +import all from '../utils/all'; +import find from '../utils/find'; -const api = 'discovery/v2' +const api = 'discovery/v2'; export const Attraction = (apikey) => ({ all: all(api, apikey, 'attractions'), find: find(api, apikey, 'attractions') -}) +}); export const Classification = (apikey) => ({ all: all(api, apikey, 'classifications'), find: find(api, apikey, 'classifications') -}) +}); export const Event = (apikey) => ({ all: all(api, apikey, 'events'), find: find(api, apikey, 'events'), findImages: find(api, apikey, 'events', 'images') -}) +}); export const Venue = (apikey) => ({ all: all(api, apikey, 'venues'), find: find(api, apikey, 'venues') -}) +}); export default (apikey) => ({ attraction: Attraction(apikey), classification: Classification(apikey), event: Event(apikey), venue: Venue(apikey) -}) +}); diff --git a/lib/index.js b/lib/index.js index c4b3798..7958439 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,16 +1,16 @@ -import discovery from './discovery/index' -import commerce from './commerce/index' +import discovery from './discovery/index'; +import commerce from './commerce/index'; const API = (apikey) => { if (apikey === 'YOUR_API_KEY') { - return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register') + return console.log('Please apply for your key at https://live-livenation.devportal.apigee.com/user/register'); } return { apikey, discovery: discovery(apikey), commerce: commerce(apikey) - } -} + }; +}; -export default API +export default API; diff --git a/lib/page.js b/lib/page.js index e6520d9..d560a20 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,4 +1,4 @@ -import getData from './utils/getData' +import getData from './utils/getData'; /** * Page object constructor @@ -7,12 +7,12 @@ import getData from './utils/getData' */ class Page { constructor({_embedded = [], page}, path, qs) { - const itemKey = Object.keys(_embedded)[0] + const itemKey = Object.keys(_embedded)[0]; - this.items = _embedded[itemKey] - this.page = page - this.path = path - this.qs = qs + this.items = _embedded[itemKey]; + this.page = page; + this.path = path; + this.qs = qs; } /** @@ -22,13 +22,13 @@ class Page { * @returns {Promise} */ getAt(n) { - const qs = Object.assign({}, this.qs, {page: n}) + const qs = Object.assign({}, this.qs, {page: n}); if (n >= 0 && n <= this.page.totalPages) { - return getData({path: this.path, qs}) + return getData({path: this.path, qs}); } - return Promise.reject({message: 'You should pass correct page number.', qs}) + return Promise.reject({message: 'You should pass correct page number.', qs}); }; /** @@ -38,14 +38,14 @@ class Page { * @returns {Promise} */ getNext(step = 1) { - const n = this.page.number + step - const qs = Object.assign({}, this.qs, {page: n}) + const n = this.page.number + step; + const qs = Object.assign({}, this.qs, {page: n}); if (n <= this.page.totalPages) { - return getData({path: this.path, qs}) + return getData({path: this.path, qs}); } - return Promise.reject({message: 'No next page! You are on the last.', qs}) + return Promise.reject({message: 'No next page! You are on the last.', qs}); }; /** @@ -55,18 +55,18 @@ class Page { * @returns {Promise} */ getPrev(step = 1) { - const n = this.page.number - step - const qs = Object.assign({}, this.qs, {page: n}) + const n = this.page.number - step; + const qs = Object.assign({}, this.qs, {page: n}); if (n >= 0) { - return getData({path: this.path, qs}) + return getData({path: this.path, qs}); } - return Promise.reject({message: 'No previous page! You are on the first one.', qs}) + return Promise.reject({message: 'No previous page! You are on the first one.', qs}); }; isFirst() { - return this.page.number === 0 + return this.page.number === 0; }; /** @@ -75,7 +75,7 @@ class Page { * @returns {boolean} */ isLast() { - return this.page.number === this.page.totalPages + return this.page.number === this.page.totalPages; }; /** @@ -83,7 +83,7 @@ class Page { * @returns {number} */ count() { - return this.page.totalElements + return this.page.totalElements; }; /** @@ -91,8 +91,8 @@ class Page { * @returns {number} */ pages() { - return this.page.totalPages + return this.page.totalPages; }; } -export default Page +export default Page; diff --git a/lib/utils/all.js b/lib/utils/all.js index 7b36377..06483a6 100644 --- a/lib/utils/all.js +++ b/lib/utils/all.js @@ -1,12 +1,12 @@ -import getData from './getData' +import getData from './getData'; export default (api, apikey, type) => (qs = {}) => { - qs.apikey = apikey + qs.apikey = apikey; const params = { path: [api, type], qs: qs - } + }; - return getData(params) -} + return getData(params); +}; diff --git a/lib/utils/find.js b/lib/utils/find.js index 32e93e3..2e883eb 100644 --- a/lib/utils/find.js +++ b/lib/utils/find.js @@ -1,10 +1,10 @@ -import getData from './getData' +import getData from './getData'; export default (api, apikey, type, ...path) => (eventId) => { const params = { path: [api, type, eventId, ...path], qs: {apikey} - } + }; - return getData(params) -} + return getData(params); +}; diff --git a/lib/utils/getData.js b/lib/utils/getData.js index 2d1c72e..f1aba6a 100644 --- a/lib/utils/getData.js +++ b/lib/utils/getData.js @@ -1,12 +1,12 @@ -import fetch from 'isomorphic-fetch' -import queryString from 'query-string' +import fetch from 'isomorphic-fetch'; +import queryString from 'query-string'; -import config from '../config' -import Page from '../page' +import config from '../config'; +import Page from '../page'; export const getURL = (path, qs) => { - return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}` -} + return `${[config.baseURL].concat(path).join('/')}?${queryString.stringify(qs)}`; +}; /** * Main GET Data configuration function for API @@ -19,7 +19,7 @@ export const getURL = (path, qs) => { const getData = ({path, qs}) => { return fetch(getURL(path, qs)) .then((res) => (res.status === 200) ? res.json() : res.json().then(Promise.reject.bind(Promise))) - .then((json) => json.page ? new Page(json, path, qs) : json) -} + .then((json) => json.page ? new Page(json, path, qs) : json); +}; -export default getData +export default getData; diff --git a/test/commerce/index.js b/test/commerce/index.js index 78dc9a9..054a96b 100644 --- a/test/commerce/index.js +++ b/test/commerce/index.js @@ -1,8 +1,8 @@ -import commerce from '../../lib/commerce' +import commerce from '../../lib/commerce'; describe('commerce', () => { it('should provide v2', done => { - commerce().should.have.property('v2') - done() - }) -}) + commerce().should.have.property('v2'); + done(); + }); +}); diff --git a/test/commerce/v2/index.js b/test/commerce/v2/index.js index 9cd8e4f..a1a7a87 100644 --- a/test/commerce/v2/index.js +++ b/test/commerce/v2/index.js @@ -1,8 +1,8 @@ -import v2 from '../../../lib/commerce/v2' +import v2 from '../../../lib/commerce/v2'; describe('commerce.v2', () => { it('should provide offer', done => { - v2().should.have.property('offer') - done() - }) -}) + v2().should.have.property('offer'); + done(); + }); +}); diff --git a/test/commerce/v2/offer/find.js b/test/commerce/v2/offer/find.js index eb2ec80..85d3125 100644 --- a/test/commerce/v2/offer/find.js +++ b/test/commerce/v2/offer/find.js @@ -1,35 +1,35 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Offer} from '../../../../lib/commerce/v2' +import {Offer} from '../../../../lib/commerce/v2'; describe('commerce.v2.offer.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/commerce/v2' - }) + nockBack.fixtures = './test/fixtures/commerce/v2'; + }); describe('success', () => { it('should find offers', (done) => { nockBack('offer/find-200.json', {}, (nockDone) => { Offer('mock-api-key').find('vvG1iZKU5jIxKX', 'offers') .then((result) => { - result.limits.max.should.equal(14) - nockDone() - done() - }) - }) - }) - }) + result.limits.max.should.equal(14); + nockDone(); + done(); + }); + }); + }); + }); describe('not found', () => { it('should handle 500', (done) => { nockBack('offer/find-500.json', {}, (nockDone) => { Offer('mock-api-key').find('unknown-id', 'offers') .catch((response) => { - response.errors[0].code.should.equal('40001') - nockDone() - done() - }) - }) - }) - }) -}) + response.errors[0].code.should.equal('40001'); + nockDone(); + done(); + }); + }); + }); + }); +}); diff --git a/test/commerce/v2/offer/index.js b/test/commerce/v2/offer/index.js index 62de92f..4d9a2cb 100644 --- a/test/commerce/v2/offer/index.js +++ b/test/commerce/v2/offer/index.js @@ -1,8 +1,8 @@ -import {Offer} from '../../../../lib/commerce/v2' +import {Offer} from '../../../../lib/commerce/v2'; describe('commerce.v2.offer', () => { it('should provide find', (done) => { - Offer().should.have.property('find') - done() - }) -}) + Offer().should.have.property('find'); + done(); + }); +}); diff --git a/test/discovery/index.js b/test/discovery/index.js index e2f32bb..e05d3f1 100644 --- a/test/discovery/index.js +++ b/test/discovery/index.js @@ -1,15 +1,15 @@ -import discovery from '../../lib/discovery' +import discovery from '../../lib/discovery'; describe('discovery', () => { it('should provide v1', done => { - discovery().should.have.property('v1') - done() - }) -}) + discovery().should.have.property('v1'); + done(); + }); +}); describe('discovery', () => { it('should provide v2', done => { - discovery().should.have.property('v2') - done() - }) -}) + discovery().should.have.property('v2'); + done(); + }); +}); diff --git a/test/discovery/v1/attraction/find.js b/test/discovery/v1/attraction/find.js index 3ba9669..3b04807 100644 --- a/test/discovery/v1/attraction/find.js +++ b/test/discovery/v1/attraction/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Attraction} from '../../../../lib/discovery/v1' +import {Attraction} from '../../../../lib/discovery/v1'; describe('discovery.v1.attraction.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1' - }) + nockBack.fixtures = './test/fixtures/discovery/v1'; + }); describe('success', () => { it('should find a attraction', done => { nockBack('attraction/find-200.json', {}, function(nockDone) { Attraction('mock-api-key').find('1542376') .then((result) => { - result.name.should.equal('Monster Jam') - nockDone() - done() + result.name.should.equal('Monster Jam'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v1/attraction/index.js b/test/discovery/v1/attraction/index.js index ebcfe1f..691c224 100644 --- a/test/discovery/v1/attraction/index.js +++ b/test/discovery/v1/attraction/index.js @@ -1,8 +1,8 @@ -import {Attraction} from '../../../../lib/discovery/v1' +import {Attraction} from '../../../../lib/discovery/v1'; describe('discovery.v1.attraction', () => { it('should provide find', done => { - Attraction().should.have.property('find') - done() - }) -}) + Attraction().should.have.property('find'); + done(); + }); +}); diff --git a/test/discovery/v1/category/find.js b/test/discovery/v1/category/find.js index 5bc03f1..cb4aab8 100644 --- a/test/discovery/v1/category/find.js +++ b/test/discovery/v1/category/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Category} from '../../../../lib/discovery/v1' +import {Category} from '../../../../lib/discovery/v1'; describe('discovery.v1.category.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1' - }) + nockBack.fixtures = './test/fixtures/discovery/v1'; + }); describe('success', () => { it('should find a category', done => { nockBack('category/find-200.json', {}, nockDone => { Category('mock-api-key').find('10004') .then((result) => { - result.name.should.equal('Sports') - nockDone() - done() + result.name.should.equal('Sports'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v1/category/index.js b/test/discovery/v1/category/index.js index 8c7c8c4..11e58d2 100644 --- a/test/discovery/v1/category/index.js +++ b/test/discovery/v1/category/index.js @@ -1,8 +1,8 @@ -import {Category} from '../../../../lib/discovery/v1' +import {Category} from '../../../../lib/discovery/v1'; describe('discovery.v1.category', () => { it('should provide find', done => { - Category().should.have.property('find') - done() - }) -}) + Category().should.have.property('find'); + done(); + }); +}); diff --git a/test/discovery/v1/event/all.js b/test/discovery/v1/event/all.js index 79bccd2..448a86c 100644 --- a/test/discovery/v1/event/all.js +++ b/test/discovery/v1/event/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Event} from '../../../../lib/discovery/v1' +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1' - }) + nockBack.fixtures = './test/fixtures/discovery/v1'; + }); describe('success', () => { it('should find an event', done => { nockBack('event/all-200.json', {}, nockDone => { Event('mock-api-key').all() .then((result) => { - result.items[0].name.should.equal('OSEA Membership Registration') - nockDone() - done() + result.items[0].name.should.equal('OSEA Membership Registration'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v1/event/find.js b/test/discovery/v1/event/find.js index 4460740..515bc06 100644 --- a/test/discovery/v1/event/find.js +++ b/test/discovery/v1/event/find.js @@ -1,37 +1,37 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Event} from '../../../../lib/discovery/v1' +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1' - }) + nockBack.fixtures = './test/fixtures/discovery/v1'; + }); describe('success', () => { it('should find an event', done => { nockBack('event/find-200.json', {}, function(nockDone) { Event('mock-api-key').find('3A004F38C8275108') .then((result) => { - result.name.should.equal('Monster Jam') - nockDone() - done() + result.name.should.equal('Monster Jam'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) + .catch(() => done()); + }); + }); + }); describe('not found', () => { it('should handle 404', done => { nockBack('event/find-404.json', {}, function(nockDone) { Event('mock-api-key').find('unknown-id') .then((result) => { - result.errors[0].code.should.equal('DIS1004') - nockDone() - done() + result.errors[0].code.should.equal('DIS1004'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v1/event/index.js b/test/discovery/v1/event/index.js index 7247aa3..0d5dc68 100644 --- a/test/discovery/v1/event/index.js +++ b/test/discovery/v1/event/index.js @@ -1,13 +1,13 @@ -import {Event} from '../../../../lib/discovery/v1' +import {Event} from '../../../../lib/discovery/v1'; describe('discovery.v1.event', () => { it('should provide find', done => { - Event().should.have.property('find') - done() - }) + Event().should.have.property('find'); + done(); + }); it('should provide all', done => { - Event().should.have.property('all') - done() - }) -}) + Event().should.have.property('all'); + done(); + }); +}); diff --git a/test/discovery/v1/index.js b/test/discovery/v1/index.js index 86d1777..f7f7092 100644 --- a/test/discovery/v1/index.js +++ b/test/discovery/v1/index.js @@ -1,23 +1,23 @@ -import v1 from '../../../lib/discovery/v1' +import v1 from '../../../lib/discovery/v1'; describe('discovery.v1', () => { it('should provide attraction', done => { - v1().should.have.property('attraction') - done() - }) + v1().should.have.property('attraction'); + done(); + }); it('should provide category', done => { - v1().should.have.property('category') - done() - }) + v1().should.have.property('category'); + done(); + }); it('should provide event', done => { - v1().should.have.property('event') - done() - }) + v1().should.have.property('event'); + done(); + }); it('should provide venue', done => { - v1().should.have.property('venue') - done() - }) -}) + v1().should.have.property('venue'); + done(); + }); +}); diff --git a/test/discovery/v1/venue/find.js b/test/discovery/v1/venue/find.js index b94f877..13cc6bc 100644 --- a/test/discovery/v1/venue/find.js +++ b/test/discovery/v1/venue/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Venue} from '../../../../lib/discovery/v1' +import {Venue} from '../../../../lib/discovery/v1'; describe('discovery.v1.venue.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v1' - }) + nockBack.fixtures = './test/fixtures/discovery/v1'; + }); describe('success', () => { it('should find a venue', done => { nockBack('venue/find-200.json', {}, function(nockDone) { Venue('mock-api-key').find('475247') .then((result) => { - result.name.should.equal('Alamodome') - nockDone() - done() + result.name.should.equal('Alamodome'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v1/venue/index.js b/test/discovery/v1/venue/index.js index df82223..3a157ab 100644 --- a/test/discovery/v1/venue/index.js +++ b/test/discovery/v1/venue/index.js @@ -1,8 +1,8 @@ -import {Venue} from '../../../../lib/discovery/v1' +import {Venue} from '../../../../lib/discovery/v1'; describe('discovery.v1.venue', () => { it('should provide find', (done) => { - Venue().should.have.property('find') - done() - }) -}) + Venue().should.have.property('find'); + done(); + }); +}); diff --git a/test/discovery/v2/attraction/all.js b/test/discovery/v2/attraction/all.js index 049c6fd..a548027 100644 --- a/test/discovery/v2/attraction/all.js +++ b/test/discovery/v2/attraction/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Attraction} from '../../../../lib/discovery/v2' +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find an attraction', (done) => { nockBack('attraction/all-200.json', {}, nockDone => { Attraction('mock-api-key').all() .then((result) => { - result.items[0].name.should.equal('!!!') - nockDone() - done() + result.items[0].name.should.equal('!!!'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v2/attraction/find.js b/test/discovery/v2/attraction/find.js index 8b34129..d991f82 100644 --- a/test/discovery/v2/attraction/find.js +++ b/test/discovery/v2/attraction/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Attraction} from '../../../../lib/discovery/v2' +import {Attraction} from '../../../../lib/discovery/v2'; describe('discovery.v2.attraction.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find a attraction', (done) => { nockBack('attraction/find-200.json', {}, (nockDone) => { Attraction('mock-api-key').find('K8vZ917Kew0') .then((result) => { - result.name.should.equal('Susquehanna Breakdown Music Festival') - nockDone() - done() + result.name.should.equal('Susquehanna Breakdown Music Festival'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/discovery/v2/classification/all.js b/test/discovery/v2/classification/all.js index bda9aac..f48b070 100644 --- a/test/discovery/v2/classification/all.js +++ b/test/discovery/v2/classification/all.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Classification} from '../../../../lib/discovery/v2' +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.all', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find an classification', (done) => { nockBack('classification/all-200.json', {}, (nockDone) => { Classification('mock-api-key').all() .then((result) => { - result.items[0].should.not.be.an('undefined') - nockDone() - done() + result.items[0].should.not.be.an('undefined'); + nockDone(); + done(); }) - .catch((err) => done(err)) - }) - }) - }) -}) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/discovery/v2/classification/find.js b/test/discovery/v2/classification/find.js index a86ed57..3dd69b8 100644 --- a/test/discovery/v2/classification/find.js +++ b/test/discovery/v2/classification/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Classification} from '../../../../lib/discovery/v2' +import {Classification} from '../../../../lib/discovery/v2'; describe('discovery.v2.classification.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find a classification', done => { nockBack('classification/find-200.json', {}, nockDone => { Classification('mock-api-key').find('KZFzniwnSyZfZ7v7na') .then(result => { - result.segment.name.should.equal('Arts & Theatre') - nockDone() - done() + result.segment.name.should.equal('Arts & Theatre'); + nockDone(); + done(); }) - .catch((err) => done(err)) - }) - }) - }) -}) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index f39757a..ac256a9 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,37 +1,37 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import tmapi from '../../../../lib' -import {Event} from '../../../../lib/discovery/v2' +import tmapi from '../../../../lib'; +import {Event} from '../../../../lib/discovery/v2'; -const api = tmapi('mock-api-key') +const api = tmapi('mock-api-key'); const onResult = (done) => (page) => { - page.items[0].name.should.equal('OSEA Membership Registration') - done() -} + page.items[0].name.should.equal('OSEA Membership Registration'); + done(); +}; -nockBack.fixtures = './test/fixtures/discovery/v2' +nockBack.fixtures = './test/fixtures/discovery/v2'; describe('discovery.v2.event.all', () => { describe('success', () => { it('should find an event using the fluent API', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - nockDone() + nockDone(); api.discovery.v2.event.all() .then(onResult(done)) - .catch((err) => done(err)) - }) - }) + .catch((err) => done(err)); + }); + }); it('should find an event', (done) => { nockBack('event/all-200.json', {}, (nockDone) => { - nockDone() + nockDone(); Event('mock-api-key').all() .then(onResult(done)) - .catch((err) => done(err)) - }) - }) - }) -}) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/discovery/v2/event/find.js b/test/discovery/v2/event/find.js index 7c687b4..8bb26e6 100644 --- a/test/discovery/v2/event/find.js +++ b/test/discovery/v2/event/find.js @@ -1,24 +1,24 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Event} from '../../../../lib/discovery/v2' +import {Event} from '../../../../lib/discovery/v2'; describe('discovery.v2.event.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find an event', (done) => { nockBack('event/find-200.json', {}, (nockDone) => { Event('mock-api-key').find('vv17FZfdGkSrrMju') .then((result) => { - result.name.should.equal('Susquehanna Breakdown RV Pass') - nockDone() - done() + result.name.should.equal('Susquehanna Breakdown RV Pass'); + nockDone(); + done(); }) - .catch((err) => done(err)) - }) - }) + .catch((err) => done(err)); + }); + }); it('should find images for an event', (done) => { nockBack('event/findImages-200.json', {}, (nockDone) => { @@ -30,26 +30,26 @@ describe('discovery.v2.event.find', () => { 'width': 305, 'height': 203, 'fallback': true - }) - nockDone() - done() + }); + nockDone(); + done(); }) - .catch((err) => done(err)) - }) - }) - }) + .catch((err) => done(err)); + }); + }); + }); describe('not found', () => { it('should handle 404', (done) => { nockBack('event/find-404.json', {}, (nockDone) => { Event('mock-api-key').find('unknown-id') .catch((response) => { - response.errors[0].code.should.equal('DIS1004') - nockDone() - done() + response.errors[0].code.should.equal('DIS1004'); + nockDone(); + done(); }) - .catch((err) => done(err)) - }) - }) - }) -}) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/discovery/v2/event/options.js b/test/discovery/v2/event/options.js index 48ecba0..ab481d0 100644 --- a/test/discovery/v2/event/options.js +++ b/test/discovery/v2/event/options.js @@ -1,27 +1,27 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Event} from '../../../../lib/discovery/v2' +import {Event} from '../../../../lib/discovery/v2'; -nockBack.fixtures = './test/fixtures/discovery/v2' +nockBack.fixtures = './test/fixtures/discovery/v2'; describe('discovery.v2.event.options', () => { describe('options', () => { it('should produce a formatted query string from params', (done) => { nockBack('event/all-200-options.json', (nockDone) => { - nockDone() + nockDone(); Event('mock-api-key').all({page: 2, size: 5, sort: 'name,desc'}) .then((page) => { - page.items.length.should.equal(5) - page.isLast().should.equal(false) - page.getAt(1).should.be.instanceOf(Promise) - page.getNext(1).should.be.instanceOf(Promise) - page.getPrev(1).should.be.instanceOf(Promise) + page.items.length.should.equal(5); + page.isLast().should.equal(false); + page.getAt(1).should.be.instanceOf(Promise); + page.getNext(1).should.be.instanceOf(Promise); + page.getPrev(1).should.be.instanceOf(Promise); - done() + done(); }) - .catch((err) => done(err)) - }) - }) - }) -}) + .catch((err) => done(err)); + }); + }); + }); +}); diff --git a/test/discovery/v2/index.js b/test/discovery/v2/index.js index f361e2f..03963ef 100644 --- a/test/discovery/v2/index.js +++ b/test/discovery/v2/index.js @@ -1,25 +1,25 @@ -import v2 from '../../../lib/discovery/v2' +import v2 from '../../../lib/discovery/v2'; -const api = v2() +const api = v2(); describe('discovery.v2', () => { it('should provide attraction', (done) => { - api.should.have.property('attraction') - done() - }) + api.should.have.property('attraction'); + done(); + }); it('should provide classification', (done) => { - api.should.have.property('classification') - done() - }) + api.should.have.property('classification'); + done(); + }); it('should provide event', (done) => { - api.should.have.property('event') - done() - }) + api.should.have.property('event'); + done(); + }); it('should provide venue', (done) => { - api.should.have.property('venue') - done() - }) -}) + api.should.have.property('venue'); + done(); + }); +}); diff --git a/test/discovery/v2/venue/find.js b/test/discovery/v2/venue/find.js index 7ffad40..e9c9a90 100644 --- a/test/discovery/v2/venue/find.js +++ b/test/discovery/v2/venue/find.js @@ -1,23 +1,23 @@ -import {back as nockBack} from 'nock' +import {back as nockBack} from 'nock'; -import {Venue} from '../../../../lib/discovery/v2' +import {Venue} from '../../../../lib/discovery/v2'; describe('discovery.v2.venue.find', () => { before(() => { - nockBack.fixtures = './test/fixtures/discovery/v2' - }) + nockBack.fixtures = './test/fixtures/discovery/v2'; + }); describe('success', () => { it('should find a venue', done => { nockBack('venue/find-200.json', {}, (nockDone) => { Venue('mock-api-key').find('KovZpZAEA76A') .then((result) => { - result.name.should.equal('The Pavilion at Montage Mountain') - nockDone() - done() + result.name.should.equal('The Pavilion at Montage Mountain'); + nockDone(); + done(); }) - .catch(() => done()) - }) - }) - }) -}) + .catch(() => done()); + }); + }); + }); +}); diff --git a/test/globals.js b/test/globals.js index 3840a18..2ad049a 100644 --- a/test/globals.js +++ b/test/globals.js @@ -1 +1 @@ -global.should = require('chai').should() +global.should = require('chai').should(); diff --git a/test/utils/all.js b/test/utils/all.js index 7a4c57c..b37a378 100644 --- a/test/utils/all.js +++ b/test/utils/all.js @@ -1,22 +1,22 @@ -import all from '../../lib/utils/all' +import all from '../../lib/utils/all'; describe('utils.all', () => { before(() => { - all.__Rewire__('getData', (params) => params) - }) + all.__Rewire__('getData', (params) => params); + }); it('should parse params correctly', (done) => { - const query = all('discovery/v2', 'a3b2c1d4e5f6', 'events') + const query = all('discovery/v2', 'a3b2c1d4e5f6', 'events'); query({city: 'london'}).should.deep.equal({ path: ['discovery/v2', 'events'], qs: {city: 'london', apikey: 'a3b2c1d4e5f6'} - }) + }); - done() - }) + done(); + }); after(() => { - all.__ResetDependency__('getData') - }) -}) + all.__ResetDependency__('getData'); + }); +}); diff --git a/test/utils/find.js b/test/utils/find.js index 9303e53..8f9af0d 100644 --- a/test/utils/find.js +++ b/test/utils/find.js @@ -1,33 +1,33 @@ -import find from '../../lib/utils/find' +import find from '../../lib/utils/find'; describe('utils.find', () => { before(() => { - find.__Rewire__('getData', (params) => params) - }) + find.__Rewire__('getData', (params) => params); + }); it('should parse params for a resource', (done) => { - const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events') + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events'); query(1).should.deep.equal({ path: ['discovery/v2', 'events', 1], qs: {apikey: 'a3b2c1d4e5f6'} - }) + }); - done() - }) + done(); + }); it('should parse params for a sub-resource', (done) => { - const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images') + const query = find('discovery/v2', 'a3b2c1d4e5f6', 'events', 'images'); query(1).should.deep.equal({ path: ['discovery/v2', 'events', 1, 'images'], qs: {apikey: 'a3b2c1d4e5f6'} - }) + }); - done() - }) + done(); + }); after(() => { - find.__ResetDependency__('getData') - }) -}) + find.__ResetDependency__('getData'); + }); +}); From 4c3180a185f18b6aa432e1179883582dd738fe49 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 27 Aug 2016 17:50:54 +0100 Subject: [PATCH 38/46] Renamed tmapi as ticketmaster, updated deps --- README.md | 26 +++++++++++++------------- docs/node/es5/sdk.js | 4 ++-- docs/node/es6/sdk.js | 4 ++-- docs/web/index.html | 8 ++++---- package.json | 23 +++++++++++------------ test/discovery/v2/event/all.js | 4 ++-- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f86e38b..2bfc7af 100644 --- a/README.md +++ b/README.md @@ -63,25 +63,25 @@ For client-side JS applications, a **dist/** folder exists for comprising ```bash -./dist/tmapi-[version].js # uncompressed with source-maps -./dist/tmapi-[version].min.js # minified +./dist/ticketmaster-[version].js # uncompressed with source-maps +./dist/ticketmaster-[version].min.js # minified ``` -Use the global variable **tmapi** to make an API call: +Use the global variable **ticketmaster** to make an API call: ```html ... - + ``` @@ -93,9 +93,9 @@ Require the package and make an API call: ES5 ```javascript -var tmapi = require('tmapi'); +var ticketmaster = require('ticketmaster'); -tmapi('YOUR_API_KEY').discovery.v2.event.all() +ticketmaster('YOUR_API_KEY').discovery.v2.event.all() .then(function(result) { console.log(result.items) // See notes on the Result object below }) @@ -106,9 +106,9 @@ tmapi('YOUR_API_KEY').discovery.v2.event.all() ES6 ```javascript -import tmapi from 'tmapi'; +import ticketmaster from 'ticketmaster'; -tmapi('YOUR_API_KEY').discovery.v2.event.all() +ticketmaster('YOUR_API_KEY').discovery.v2.event.all() .then((result) => { console.log(result.items) // See notes on the Result object below }) @@ -119,7 +119,7 @@ Modules are also available individually: ES5 ```javascript -var Event = require('tmapi/discovery/v2').Event +var Event = require('ticketmaster/discovery/v2').Event Event('YOUR_API_KEY').all() .then(function(result) { @@ -132,7 +132,7 @@ Event('YOUR_API_KEY').all() ES6 ```javascript -import {Event} from 'tmapi/discovery/v2' +import {Event} from 'ticketmaster/discovery/v2' Event('YOUR_API_KEY').all() .then((result) => console.log(result.items)) // See notes on the Result object below diff --git a/docs/node/es5/sdk.js b/docs/node/es5/sdk.js index a65f429..a4c1474 100644 --- a/docs/node/es5/sdk.js +++ b/docs/node/es5/sdk.js @@ -1,6 +1,6 @@ -var tmapi = require('../../../dist/node/index'); +var ticketmaster = require('../../../dist/node/index'); -var sdk = tmapi('YOUR_API_KEY'); +var sdk = ticketmaster('YOUR_API_KEY'); function logNextPage(page) { console.log(page.page.number, page.items.map(function(item) { diff --git a/docs/node/es6/sdk.js b/docs/node/es6/sdk.js index 68c911b..9368f25 100644 --- a/docs/node/es6/sdk.js +++ b/docs/node/es6/sdk.js @@ -1,6 +1,6 @@ -import tmapi from '../../../dist/node' +import ticketmaster from '../../../dist/node' -const sdk = tmapi('YOUR_API_KEY') +const sdk = ticketmaster('YOUR_API_KEY') const logNextPage = (page) => { console.log(page.page.number, page.items.map(({name}) => name)) diff --git a/docs/web/index.html b/docs/web/index.html index be05bdf..449c8a2 100644 --- a/docs/web/index.html +++ b/docs/web/index.html @@ -7,10 +7,10 @@ - + diff --git a/package.json b/package.json index 04fcccb..22a03aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "tmapi", - "version": "1.0.0", + "name": "ticketmaster", + "version": "2.0.0", "description": "SDK for the Ticketmaster Open Platform", "main": "dist/node/index.js", "module": "lib/index.js", @@ -32,19 +32,18 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { - "babel-cli": "6.11.4", - "babel-core": "6.13.2", - "babel-loader": "6.2.4", + "babel-cli": "6.14.0", + "babel-core": "6.14.0", + "babel-loader": "6.2.5", "babel-plugin-add-module-exports": "0.2.1", - "babel-plugin-rewire": "1.0.0-rc-5", + "babel-plugin-rewire": "1.0.0-rc-6", "babel-plugin-transform-object-assign": "6.8.0", - "babel-preset-es2015": "6.13.2", - "babel-preset-es2015-webpack": "6.4.2", - "babel-register": "6.11.6", + "babel-preset-es2015": "6.14.0", + "babel-register": "6.14.0", "chai": "3.5.0", "cross-env": "2.0.0", - "eslint": "3.2.2", - "eslint-config-standard": "5.3.5", + "eslint": "3.4.0", + "eslint-config-standard": "6.0.0", "eslint-plugin-promise": "2.0.1", "eslint-plugin-standard": "2.0.0", "husky": "0.11.6", @@ -55,7 +54,7 @@ "webpack": "2.1.0-beta.20" }, "dependencies": { - "query-string": "4.2.2", + "query-string": "4.2.3", "isomorphic-fetch": "2.2.1" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" diff --git a/test/discovery/v2/event/all.js b/test/discovery/v2/event/all.js index f39757a..375238e 100644 --- a/test/discovery/v2/event/all.js +++ b/test/discovery/v2/event/all.js @@ -1,9 +1,9 @@ import {back as nockBack} from 'nock' -import tmapi from '../../../../lib' +import ticketmaster from '../../../../lib' import {Event} from '../../../../lib/discovery/v2' -const api = tmapi('mock-api-key') +const api = ticketmaster('mock-api-key') const onResult = (done) => (page) => { page.items[0].name.should.equal('OSEA Membership Registration') From 8f4069e1627edc9dfdab66a70219d539b080c744 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 27 Aug 2016 18:12:24 +0100 Subject: [PATCH 39/46] Bumped package version to 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 276e656..be489ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ticketmaster", - "version": "1.0.0", + "version": "2.0.0", "description": "SDK for the Ticketmaster Open Platform", "main": "dist/node/index.js", "module": "lib/index.js", From 23cdabe2dba4b774ad9916fff3383053b1666b08 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 27 Aug 2016 18:16:27 +0100 Subject: [PATCH 40/46] Small improvements to docs --- README.md | 8 ++++---- docs/web/index.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 85cc03e..89d6eb6 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ Include one of them in to your project: ... ``` -Use global variable **TMAPI** to make an API call (name can be changed in webpack settings during rebuild): +Use global variable **ticketmaster** to make an API call (name can be changed in webpack settings during rebuild): ```javascript -TMAPI('your-api-key').discovery.v2.event.all() +ticketmaster('your-api-key').discovery.v2.event.all() .then(function(result) { // "result" is an object of Ticketmaster events information }); @@ -56,8 +56,8 @@ TMAPI('your-api-key').discovery.v2.event.all() Require the package and make an API call: ```javascript -var TM = require('ticketmaster'); -TM('your-api-key').discovery.v2.event.all() +var ticketmaster = require('ticketmaster'); +ticketmaster('your-api-key').discovery.v2.event.all() .then(function(result) { // "result" is an object of Ticketmaster events information }); diff --git a/docs/web/index.html b/docs/web/index.html index 449c8a2..1501778 100644 --- a/docs/web/index.html +++ b/docs/web/index.html @@ -2,7 +2,7 @@ - TMAPI + Ticketmaster API From f0dcf707b7bf099c94d540e422cda686c1ddf437 Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Sat, 27 Aug 2016 18:21:37 +0100 Subject: [PATCH 41/46] Fixed docs example --- docs/web/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/web/index.html b/docs/web/index.html index 1501778..3a8001b 100644 --- a/docs/web/index.html +++ b/docs/web/index.html @@ -7,7 +7,7 @@ - + - + + ... ``` -Use global variable **ticketmaster** to make an API call (name can be changed in webpack settings during rebuild): +Use global variable **ticketmaster** to make an API call: ```javascript -ticketmaster('your-api-key').discovery.v2.event.all() -.then(function(result) { - // "result" is an object of Ticketmaster events information -}); +ticketmaster('YOUR_API_KEY').discovery.v2.event.all() + .then(function(result) { + console.log(result.items) // See notes on the Result object below + }) + .catch(function(err) { + console.log(err) // NOTE: you must provide your own error handler + }) ``` +**Note** If you need to support browsers lacking native support for Promises you should supply a +polyfill such as [es6-promise](https://www.npmjs.com/package/es6-promise) + ## Server: Require the package and make an API call: +ES5 ```javascript var ticketmaster = require('ticketmaster'); -ticketmaster('your-api-key').discovery.v2.event.all() -.then(function(result) { - // "result" is an object of Ticketmaster events information -}); -``` -Alternative syntax if you are only interested in a subset of the API: +ticketmaster('YOUR_API_KEY').discovery.v2.event.all() + .then(function(result) { + console.log(result.items) // See notes on the Result object below + }) + .catch(function(err) { + console.log(err) // NOTE: you must provide your own error handler + }) +``` +ES6 ```javascript -var EventAPI = require('ticketmaster').discovery.v2.event; -EventAPI('your-api-key').all() +import ticketmaster from 'ticketmaster'; + +ticketmaster('YOUR_API_KEY').discovery.v2.event.all() + .then((result) => { + console.log(result.items) // See notes on the Result object below + }) + .catch((err) => console.log(err)) // NOTE: you must provide your own error handler ``` -## Rebuild source: +Modules are also available individually: -In case you want to build your own bundle for client +ES5 +```javascript +var Event = require('ticketmaster/discovery/v2').Event + +Event('YOUR_API_KEY').all() + .then(function(result) { + console.log(result.items) // See notes on the Result object below + }) + .catch(function(err) { + console.log(err) // NOTE: you must provide your own error handler + }) +``` -`1`. Clone this repository +ES6 +```javascript +import {Event} from 'ticketmaster/discovery/v2' -```bash -git clone git@github.com:ticketmaster-api/sdk-javascript.git +Event('YOUR_API_KEY').all() + .then((result) => console.log(result.items)) // See notes on the Result object below + .catch((err) => console.log(err)) // NOTE: you must provide your own error handler ``` -`2`. install dependencies -```bash -npm install -``` -`3`. Run npm script: -- for raw (with source-maps) version of client lib use: -```bash -npm run-script dev -``` -- for minified version of client lib use: -```bash -npm run-script prod -``` -- or (for Windows users): -```bash -npm run-script win-prod -``` +## Result object API: + +(provided only for sets which are result of **.all()** type methods) + +properties: + +- `result.items` - Array of Ticketmaster event information. +- `result.page` - Additional general information object. + +methods: + +- `result.getAt(index): Promise` + - Returns a Promise yielding a new Result object. + +- `result.getNext([step]): Promise` + - Returns a Promise yielding a new Result object. + - Can take additional `step` param (1 by default). + +- `result.getPrev([step]): Promise` + - Returns a Promise yielding a new Result object. + - Can take additional `step` param (1 by default). + +- `result.count(): Integer` + - Returns the total count of items matching your criteria + +- `result.pages(): Integer` + - Returns the total count of pages matching your criteria + +- `result.isFirst(): Boolean` + - Whether the current Result is the first page + +- `result.isLast(): Boolean` + - Whether the current Result is the last page ## Error handling: -**Be aware:** no **.catch()** method provided! You should write it by your own. +**NOTE:** no `.catch()` method is provided! You **must** supply your own. +# Contributing -## Result object API: +## Rebuild source: -(provided only for sets which are result of **.all()** type methods) +In case you want to build your own bundle for client -properties: --`result.items` - Array of Ticketmaster event information. --`result.page` - Additional general information object. +1. Clone this repository -methods: --`result.getPage(index)` - Promise which returns a new Result object. --`result.nextPage()` - Promise which returns a new Result object. Can take additional param - step (1 by default). --`result.previousPage()` - Promise which returns a new Result object. Can take additional param - step (1 by default). --`result.records()` - returns an Array of this page's records --`result.count()` - returns the total count of items --`result.isLastPage()` - returns a Boolean if current Result is the last page + ```bash + git clone git@github.com:ticketmaster-api/sdk-javascript.git + ``` + +1. install dependencies + + ```bash + npm install + ``` + +1. Run npm script: + + ```bash + npm run build + ``` ## Running Tests @@ -127,33 +204,6 @@ methods: npm test ``` -## Status - -Currently supports the following endpoints: - - - Discovery API - - v1 - - Attraction - - Find - - Category - - Find - - Event - - All - - Find - - Venue - - Find - - v2 - - Attraction - - Find - - Event - - All - - Find - - Venue - - Find - -The goal is to implement all endpoints available @ http://developer.ticketmaster.com/. -Pull Requests gladly accepted! - ## Contact Us [internal only] Find us in #open-platform on Ticketmaster Slack! From c8af7a36ade22bd281a9acb8d7c196bff1c5da2a Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Wed, 31 Aug 2016 11:50:45 +0100 Subject: [PATCH 43/46] Added dynamic docs generation to keep file references in sync across releases --- .gitignore | 1 + config/docs/index.html | 41 +++++++++++++++++++++ config/webpack/webpack.config.prod.babel.js | 12 +++++- docs/web/index.html | 35 ------------------ package.json | 27 +++++++------- 5 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 config/docs/index.html delete mode 100644 docs/web/index.html diff --git a/.gitignore b/.gitignore index 3e32e7b..9f6d15d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ node_modules/ npm-debug.log .tmp/ dist/ +docs/web/* coverage/ diff --git a/config/docs/index.html b/config/docs/index.html new file mode 100644 index 0000000..4050b21 --- /dev/null +++ b/config/docs/index.html @@ -0,0 +1,41 @@ + + + + + <%= htmlWebpackPlugin.options.title %> + + + + + +

Open your console...

+ + + diff --git a/config/webpack/webpack.config.prod.babel.js b/config/webpack/webpack.config.prod.babel.js index f5bfc8d..b1d3e92 100644 --- a/config/webpack/webpack.config.prod.babel.js +++ b/config/webpack/webpack.config.prod.babel.js @@ -1,12 +1,16 @@ import webpack from 'webpack'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import {version} from '../../package.json'; import {settings, getFilename} from './config'; const config = settings({ + devtool: false, + output: { filename: 'web/' + getFilename('.min.js') }, - devtool: false, + plugins: [ new webpack.LoaderOptionsPlugin({ minimize: true, @@ -16,6 +20,12 @@ const config = settings({ compress: {warnings: false}, comments: false, sourceMap: false + }), + new HtmlWebpackPlugin({ + title: 'Ticketmaster SDK: ' + version, + filename: '../docs/web/index.html', + template: 'config/docs/index.html', + inject: 'head' }) ] }); diff --git a/docs/web/index.html b/docs/web/index.html deleted file mode 100644 index 3a8001b..0000000 --- a/docs/web/index.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - - Ticketmaster API - - - - - - - - diff --git a/package.json b/package.json index 5001474..bf49ec5 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "clean": "rimraf ./dist", "build": "npm run prod:web && npm run prod:node", "prod:node": "cross-env NODE_ENV=production babel lib -d dist/node", - "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.web.babel.js", + "prod:web": "cross-env NODE_ENV=production webpack --config ./config/webpack/webpack.config.prod.babel.js", "stats:web": "npm run prod:web -- --display-modules --sort-modules-by size", "test": "cross-env NODE_ENV=test mocha", "lint": "eslint ./lib ./test", @@ -31,29 +31,30 @@ "author": "Adam Meghji", "license": "MIT", "devDependencies": { - "babel-cli": "6.11.4", - "babel-core": "6.13.1", - "babel-loader": "6.2.4", + "babel-cli": "6.14.0", + "babel-core": "6.14.0", + "babel-loader": "6.2.5", "babel-plugin-add-module-exports": "0.2.1", + "babel-plugin-rewire": "1.0.0-rc-7", "babel-plugin-transform-object-assign": "6.8.0", - "babel-preset-es2015": "6.13.1", - "babel-preset-es2015-webpack": "6.4.2", - "babel-register": "6.11.6", + "babel-preset-es2015": "6.14.0", + "babel-register": "6.14.0", "chai": "3.5.0", - "cross-env": "2.0.0", - "eslint": "3.2.2", - "eslint-config-standard": "5.3.5", - "eslint-plugin-promise": "2.0.0", + "cross-env": "2.0.1", + "eslint": "3.4.0", + "eslint-config-standard": "6.0.0", + "eslint-plugin-promise": "2.0.1", "eslint-plugin-standard": "2.0.0", + "html-webpack-plugin": "2.22.0", "husky": "0.11.6", "inherits": "2.0.1", - "mocha": "3.0.1", + "mocha": "3.0.2", "nock": "8.0.0", "rimraf": "2.5.4", "webpack": "2.1.0-beta.20" }, "dependencies": { - "query-string": "4.2.2", + "query-string": "4.2.3", "isomorphic-fetch": "2.2.1" }, "homepage": "https://github.com/ticketmaster-api/sdk-javascript" From de44ebf963372934adbb9dd636b025fc66a2248c Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Wed, 31 Aug 2016 13:14:15 +0100 Subject: [PATCH 44/46] amends to docs example --- config/docs/index.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/docs/index.html b/config/docs/index.html index 4050b21..12b7938 100644 --- a/config/docs/index.html +++ b/config/docs/index.html @@ -3,13 +3,19 @@ <%= htmlWebpackPlugin.options.title %> - From eaffaa7483582a2f2a6e0a2490e32f4b675ebf0c Mon Sep 17 00:00:00 2001 From: Oliver Turner Date: Wed, 31 Aug 2016 13:15:14 +0100 Subject: [PATCH 45/46] amends to docs example --- config/docs/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/docs/index.html b/config/docs/index.html index 12b7938..ed781db 100644 --- a/config/docs/index.html +++ b/config/docs/index.html @@ -19,7 +19,7 @@ -

Open your console...

+

Logging to console...