tremendous 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js DELETED
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- var _ = require('lodash');
4
- var request = require('request');
5
- var jwt = require('jsonwebtoken');
6
-
7
- var Tremendous = module.exports = function(accessToken, uri) {
8
- if (_.isNil(accessToken)) {
9
- throw new Error('Tremendous "Access Token" required');
10
- } else if (_.isNil(uri)) {
11
- throw new Error('Tremendous "URI" required');
12
- } else {
13
- this.accessToken = accessToken;
14
- this.uri = uri;
15
- }
16
- };
17
-
18
- // Organizations
19
- Tremendous.prototype.createOrganization = _.partial(client, 'organizations', "POST");
20
- Tremendous.prototype.getOrganizations = _.partial(client, 'organizations', "GET", {});
21
-
22
- // products
23
- Tremendous.prototype.getProducts = _.partial(client, 'products', "GET");
24
-
25
- // Orders
26
- Tremendous.prototype.createOrder = _.partial(client, 'orders', "POST");
27
- Tremendous.prototype.getOrders = _.partial(client, 'orders', "GET");
28
- Tremendous.prototype.getOrder = function(id, callback) {
29
- return client.call(this, 'orders/' + id, "GET", {}, callback);
30
- };
31
-
32
- // Gifts
33
- Tremendous.prototype.getReward = function(id, callback) {
34
- return client.call(this, 'rewards/' + id, "GET", {}, callback);
35
- };
36
-
37
- // FundingSources
38
- Tremendous.prototype.getFundingSources = _.partial(client, 'funding_sources', "GET");
39
-
40
- // Tokenize for the embedded client
41
- Tremendous.prototype.tokenizeEmbed = function(payload) {
42
- return jwt.sign(payload, this.accessToken, {algorithm: "HS256"});
43
- };
44
-
45
- function client(path, method, options, callback) {
46
- var data = _.merge({}, {
47
- url: this.uri + path,
48
- method: method,
49
- headers: {
50
- "User-agent": "Tremendous Node v2.0.0",
51
- "authorization": "Bearer " + this.accessToken
52
- },
53
- json: true
54
- }, method == "GET" ? {qs: options} : {json: options});
55
-
56
- return request(data, handleResponse(callback));
57
- };
58
-
59
- function handleResponse(callback) {
60
- function handler(err, res, body) {
61
- if (err) {
62
- callback(err, null);
63
- } else if (res.statusCode != 200) {
64
- callback(body, null);
65
- } else {
66
- callback(null, body);
67
- }
68
- }
69
-
70
- // If a callback is not specified, noop.
71
- return callback ? handler : function() {};
72
- };