Skip to content

Commit e577933

Browse files
author
Tyler Nappy
authored
Merge pull request #25 from button/ty/DLC-4556
added Links API
2 parents 1e3bd70 + 8ecef2d commit e577933

File tree

7 files changed

+198
-1
lines changed

7 files changed

+198
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Current Version
22
-
33

4+
2.8.0 December 5, 2017
5+
- Add Links API
6+
47
2.7.0 November 6, 2017
58
- Add get orders by button ref
69

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,32 @@ client.customers.get('customer-1234', function(err, res) {
300300
});
301301
```
302302

303+
### Links
304+
305+
##### Create
306+
307+
```javascript
308+
client.links.create({
309+
url: "https://www.jet.com",
310+
experience: {
311+
btn_pub_ref: "my-pub-ref",
312+
btn_pub_user: "user-id"
313+
}
314+
}, function(err, res) {
315+
// ...
316+
});
317+
```
318+
319+
##### Get Info
320+
321+
```javascript
322+
client.links.getInfo({
323+
url: "https://www.jet.com"
324+
}, function(err, res) {
325+
// ...
326+
});
327+
```
328+
303329
## Utils
304330

305331
Utils houses generic helpers useful in a Button Integration.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function client(apiKey, config) {
6767
return {
6868
accounts: resources.accounts(requestOptions, maybePromiseRequest),
6969
customers: resources.customers(requestOptions, maybePromiseRequest),
70+
links: resources.links(requestOptions, maybePromiseRequest),
7071
merchants: resources.merchants(requestOptions, maybePromiseRequest),
7172
orders: resources.orders(requestOptions, maybePromiseRequest)
7273
};

lib/resources/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
accounts: require('./accounts'),
55
customers: require('./customers'),
6+
links: require('./links'),
67
merchants: require('./merchants'),
78
orders: require('./orders')
89
};

lib/resources/links.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
var merge = require('../merge');
4+
5+
function links(requestOptions, maybePromiseRequest) {
6+
return {
7+
create: function create(link, callback) {
8+
//
9+
// Creates a link.
10+
//
11+
// @param {Object} link object of link information
12+
// @callback invoked iff config.promise isn't valid
13+
// @returns {Object=} a promise or undefined, depending on
14+
// `config.promise`
15+
//
16+
var options = merge(requestOptions, {
17+
method: 'POST',
18+
path: '/v1/links'
19+
});
20+
21+
return maybePromiseRequest(options, link, callback);
22+
},
23+
getInfo: function getInfo(link, callback) {
24+
//
25+
// Gets information for a link.
26+
//
27+
// @param {Object} link object of link information
28+
// @callback invoked iff config.promise isn't valid
29+
// @returns {Object=} a promise or undefined, depending on
30+
// `config.promise`
31+
//
32+
var options = merge(requestOptions, {
33+
method: 'POST',
34+
path: '/v1/links/info'
35+
});
36+
37+
return maybePromiseRequest(options, link, callback);
38+
}
39+
};
40+
}
41+
42+
module.exports = links;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@button/button-client-node",
3-
"version": "2.7.0",
3+
"version": "2.8.0",
44
"description": "node.js client for the Button Order API",
55
"repository": {
66
"type": "git",

test/lib/resources/links-test.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
'use strict';
2+
3+
var expect = require('expect.js');
4+
var nock = require('nock');
5+
var Q = require('q');
6+
7+
var client = require('../../../index');
8+
9+
describe('lib/resources/links', function() {
10+
11+
before(function() {
12+
nock.disableNetConnect();
13+
14+
var config = {
15+
promise: function(resolver) { return Q.Promise(resolver); }
16+
};
17+
18+
this.callbackClient = client('sk-XXX').links;
19+
this.promiseClient = client('sk-XXX', config).links;
20+
});
21+
22+
after(function() {
23+
nock.enableNetConnect();
24+
});
25+
26+
describe('#create', function() {
27+
28+
beforeEach(function() {
29+
this.url = 'https://www.jet.com/';
30+
this.experience = {
31+
btn_pub_ref: 'my-pub-ref',
32+
btn_pub_user: 'user-id'
33+
};
34+
35+
this.payload = {
36+
url: this.url,
37+
experience: this.experience
38+
};
39+
40+
this.link = {
41+
merchant_id: 'org-XXX',
42+
affiliate: null,
43+
links: {
44+
universal: 'https://r.bttn.io?btn_pub_ref=my-pub-ref&btn_pub_user=user-id&btn_url=https%3A%2F%2Fwww.jet.com&btn_ref=org-XXX'
45+
}
46+
};
47+
48+
this.scope = nock('https://api.usebutton.com:443')
49+
.post('/v1/links', this.payload)
50+
.reply(200, { meta: { status: 'ok' }, 'object': this.link });
51+
});
52+
53+
it('creates a link with a callback', function(done) {
54+
this.callbackClient.create(this.payload, function(err, res) {
55+
expect(err).to.be(null);
56+
expect(res.data).to.eql(this.link);
57+
this.scope.done();
58+
done();
59+
}.bind(this));
60+
});
61+
62+
it('creates a link with a promise', function(done) {
63+
this.promiseClient.create(this.payload).then(function(result) {
64+
expect(result.data).to.eql(this.link);
65+
this.scope.done();
66+
done();
67+
}.bind(this)).catch(done);
68+
});
69+
70+
});
71+
72+
describe('#getInfo', function() {
73+
74+
beforeEach(function() {
75+
this.url = 'https://www.jet.com/';
76+
77+
this.payload = {
78+
url: this.url
79+
};
80+
81+
this.link = {
82+
organization_id: 'org-XXX',
83+
approved: true,
84+
ios_support: {
85+
app_to_web: true,
86+
app_to_app: true,
87+
web_to_web: true,
88+
web_to_app: false,
89+
web_to_app_with_install: false
90+
},
91+
android_support: {
92+
app_to_web: true,
93+
app_to_app: true,
94+
web_to_web: true,
95+
web_to_app: false,
96+
web_to_app_with_install: false
97+
}
98+
};
99+
100+
this.scope = nock('https://api.usebutton.com:443')
101+
.post('/v1/links/info', this.payload)
102+
.reply(200, { meta: { status: 'ok' }, 'object': this.link });
103+
});
104+
105+
it('gets information for a link with a callback', function(done) {
106+
this.callbackClient.getInfo(this.payload, function(err, res) {
107+
expect(err).to.be(null);
108+
expect(res.data).to.eql(this.link);
109+
this.scope.done();
110+
done();
111+
}.bind(this));
112+
});
113+
114+
it('gets information for a link with a promise', function(done) {
115+
this.promiseClient.getInfo(this.payload).then(function(result) {
116+
expect(result.data).to.eql(this.link);
117+
this.scope.done();
118+
done();
119+
}.bind(this)).catch(done);
120+
});
121+
122+
});
123+
124+
});

0 commit comments

Comments
 (0)