Skip to content

Commit 6ef61bf

Browse files
authored
Merge pull request #29 from predicthq/add_user_agent_header
Add user agent header
2 parents 1ea9e93 + 7862965 commit 6ef61bf

File tree

10 files changed

+29
-57
lines changed

10 files changed

+29
-57
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ node_modules
3939

4040
#dist # Ugh, bower!
4141

42-
42+
package-lock.json

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
".gitignore",
2828
".babelrc"
2929
],
30-
"version": "0.0.19"
30+
"version": "0.0.20"
3131
}

build.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var UglifyJS = require("uglify-js")
88
var chalk = require('chalk')
99
var filesize = require("filesize")
1010
var fs = require("fs")
11-
11+
var package = require('./package')
1212
var _ = require('lodash')
1313

1414
var browserify = require('browserify')
@@ -23,7 +23,8 @@ b.transform('babelify')
2323
b.transform('brfs')
2424

2525
b.transform(envify({
26-
ENDPOINT_URL: 'https://api.predicthq.com'
26+
ENDPOINT_URL: 'https://api.predicthq.com',
27+
VERSION: package.version
2728
}))
2829

2930
console.info(chalk.green('\tBuild process started..\n'))

dist/predicthq.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.PredictHQ = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.PredictHQ = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
22
(function (global){
33
'use strict';
44

@@ -22116,6 +22116,7 @@ var Client = function () {
2211622116
options = options || {};
2211722117

2211822118
this.baseUrl = options.endpoint || "https://api.predicthq.com";
22119+
this.version = "0.0.20";
2211922120

2212022121
if (typeof this.baseUrl == 'undefined') throw "No endpoint URL set";
2212122122

@@ -22143,6 +22144,7 @@ var Client = function () {
2214322144
_createClass(Client, [{
2214422145
key: "request",
2214522146
value: function request(method, path, returnClass, options) {
22147+
var _this = this;
2214622148

2214722149
var access_token = this.options.access_token;
2214822150

@@ -22160,7 +22162,8 @@ var Client = function () {
2216022162
method: method,
2216122163
headers: {
2216222164
'Authorization': 'Bearer ' + access_token,
22163-
'Accept': 'application/json'
22165+
'Accept': 'application/json',
22166+
'X-User-Agent': "PHQ-JS-SDK/" + _this.version
2216422167
}
2216522168
}).then(function (response) {
2216622169
return response.json();
@@ -22342,9 +22345,7 @@ function _inherits(subClass, superClass) {
2234222345
if (typeof superClass !== "function" && superClass !== null) {
2234322346
throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof(superClass)));
2234422347
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
22345-
} /*
22346-
22347-
*/
22348+
}
2234822349

2234922350
var Accounts = function (_BaseEndpoint) {
2235022351
_inherits(Accounts, _BaseEndpoint);
@@ -22362,13 +22363,6 @@ var Accounts = function (_BaseEndpoint) {
2236222363

2236322364
return this.client.get("/v1/accounts/" + _account + "/");
2236422365
}
22365-
}, {
22366-
key: "subscriptions",
22367-
value: function subscriptions() {
22368-
var account = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'self';
22369-
22370-
return this.client.get("/v1/accounts/" + account + "/subscriptions/");
22371-
}
2237222366
}]);
2237322367

2237422368
return Accounts;
@@ -23011,4 +23005,4 @@ _.trim;
2301123005
exports.logger = _loglevel2.default;
2301223006

2301323007
},{"../dist/lodash.custom":1,"loglevel":61}]},{},[71])(71)
23014-
});
23008+
});

dist/predicthq.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "predicthq",
3-
"version": "0.0.19",
3+
"version": "0.0.20",
44
"description": "PredictHQ Event Intelligence",
55
"main": "dist/predicthq.js",
66
"scripts": {
7-
"lint": " node node_modules/eslint/bin/eslint.js ./src/",
8-
"test": "NODE_ENV=test node_modules/mocha/bin/mocha --require babel-core/register test",
9-
"test_browser": "ACCESS_TOKEN=$(node -r dotenv/config -e 'console.log(process.env.TEST_USER_PASSWORD_ACCESS_TOKEN)'); ACCOUNT_ID=$(node -r dotenv/config -e 'console.log(process.env.TEST_ACCOUNT_ID)'); ENDPOINT_URL=$(node -r dotenv/config -e 'console.log(process.env.ENDPOINT_URL)'); node_modules/mocha-phantomjs/bin/mocha-phantomjs --web-security no -b -R dot test/browser/runner.html?endpoint=${ENDPOINT_URL}\\&token=${ACCESS_TOKEN}\\&account_id=${ACCOUNT_ID}",
7+
"lint": "node node_modules/eslint/bin/eslint.js ./src/",
8+
"test": "VERSION=$npm_package_version NODE_ENV=test node_modules/mocha/bin/mocha --require babel-core/register test",
9+
"test_browser": "VERSION=$npm_package_version ACCESS_TOKEN=$(node -r dotenv/config -e 'console.log(process.env.TEST_USER_PASSWORD_ACCESS_TOKEN)'); ACCOUNT_ID=$(node -r dotenv/config -e 'console.log(process.env.TEST_ACCOUNT_ID)'); ENDPOINT_URL=$(node -r dotenv/config -e 'console.log(process.env.ENDPOINT_URL)'); node_modules/mocha-phantomjs/bin/mocha-phantomjs --web-security no -b -R dot test/browser/runner.html?endpoint=${ENDPOINT_URL}\\&token=${ACCESS_TOKEN}\\&account_id=${ACCOUNT_ID}",
1010
"update": "node node_modules/npm-check-updates/bin/npm-check-updates --upgradeAll",
1111
"build": "NODE_ENV=production node node_modules/browserify/bin/cmd.js src/client.js -t babelify | node_modules/uglify-js/bin/uglifyjs -o dist/predicthq.js; node build.js",
1212
"list_lodash_methods": "node_modules/lodash-modularize/bin/lodash-modularize src/**/**/*.js --list -g _",
1313
"lodash": "lodash_methods=$(npm run --silent list_lodash_methods | sed -e \"s/\\x1b\\[.\\{1,5\\}m//g\"); node_modules/lodash-cli/bin/lodash -o dist/lodash.custom.js include=$lodash_methods",
14-
"coverage": "node_modules/.bin/babel-node node_modules/babel-istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- test",
15-
"coverage_to_travis": "node_modules/.bin/babel-node node_modules/babel-istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
14+
"coverage": "VERSION=$npm_package_version node_modules/.bin/babel-node node_modules/babel-istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- test",
15+
"coverage_to_travis": "VERSION=$npm_package_version node_modules/.bin/babel-node node_modules/babel-istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
1616
"patch": "node_modules/mversion/bin/version patch -m"
1717
},
1818
"repository": {

src/client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Client {
2626
options = options || {}
2727

2828
this.baseUrl = options.endpoint || process.env.ENDPOINT_URL
29+
this.version = process.env.VERSION
2930

3031
if (typeof(this.baseUrl) == 'undefined')
3132
throw "No endpoint URL set"
@@ -71,7 +72,8 @@ class Client {
7172
method: method,
7273
headers: {
7374
'Authorization': 'Bearer ' + access_token,
74-
'Accept': 'application/json'
75+
'Accept': 'application/json',
76+
'X-User-Agent': `PHQ-JS-SDK/${this.version}`
7577
}
7678
}).then(function(response) {
7779
return response.json()

src/endpoints/v1/accounts.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
3-
*/
4-
51
import {_} from "../../utils"
62

73
import {ResultSet} from "../../resultset"
@@ -19,10 +15,6 @@ class Accounts extends BaseEndpoint {
1915
return this.client.get(`/v1/accounts/${account}/`)
2016
}
2117

22-
subscriptions(account = 'self'){
23-
return this.client.get(`/v1/accounts/${account}/subscriptions/`)
24-
}
25-
2618
}
2719

28-
export default Accounts
20+
export default Accounts

test/test_accounts.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Client from '../src/client'
1414
logger.getLogger("predicthq.client").setLevel('DEBUG')
1515

1616
let test_client_credentials_access_token = process.env.TEST_CLIENT_CREDENTIALS_ACCESS_TOKEN
17-
let test_user_password_access_token = process.env.TEST_USER_PASSWORD_ACCESS_TOKEN
1817

1918
describe('Accounts', () => {
2019

@@ -31,22 +30,6 @@ describe('Accounts', () => {
3130

3231
}).catch(done)
3332

34-
}),
35-
36-
it('Subscriptions', (done) => {
37-
38-
let c = new Client({ access_token : test_user_password_access_token})
39-
40-
c.accounts.subscriptions()
41-
.then((results)=>{
42-
43-
expect(_.keys(results)).toEqual(['app_subscription', 'api_subscription'])
44-
45-
done()
46-
47-
}).catch(done)
48-
4933
})
5034

5135
})
52-

test/test_events_search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Events', () => {
149149
c.events.count({'rank_level': [5], 'category': 'sports'})
150150
.then((results)=> {
151151

152-
expect(_.keys(results.toDict())).toEqual([ 'count', 'top_rank', 'rank_levels', 'categories', 'labels' ])
152+
expect(_.keys(results.toDict())).toEqual([ 'count', 'top_rank', 'top_local_rank', 'rank_levels', 'local_rank_levels', 'categories', 'labels' ])
153153

154154
expect(results.toDict()['count']).toBeGreaterThan(10000)
155155

0 commit comments

Comments
 (0)