Skip to content

Commit 1e3bd70

Browse files
authored
Merge pull request #24 from button/yunchi/btnref
Add GET /v1/order/btn-ref/{btnRef}
2 parents 9ce35c2 + 166c553 commit 1e3bd70

5 files changed

Lines changed: 58 additions & 1 deletion

File tree

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.7.0 November 6, 2017
5+
- Add get orders by button ref
6+
47
2.6.0 July 19, 2017
58
- Add `customers` resource
69

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ client.orders.get('btnorder-XXX', function(err, res) {
240240
});
241241
```
242242

243+
##### Get by Button Ref
244+
245+
```javascript
246+
var client = require('@button/button-client-node')('sk-XXX');
247+
248+
client.orders.getByBtnRef('srctok-XXX', function (err, res) {
249+
// ...
250+
});
251+
```
252+
243253
##### Update
244254

245255
```javascript

lib/resources/orders.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ function orders(requestOptions, maybePromiseRequest) {
2020

2121
return maybePromiseRequest(options, callback);
2222
},
23+
getByBtnRef: function get(btnRef, callback) {
24+
//
25+
// Lists orders by btn_ref.
26+
//
27+
// @param {string} btnRef the button attribution token
28+
// @callback invoked iff config.promise isn't valid
29+
// @returns {Object=} a promise or undefined, depending on
30+
// `config.promise`
31+
var options = merge(requestOptions, {
32+
method: 'GET',
33+
path: '/v1/order/btn-ref/' + btnRef
34+
});
35+
36+
return maybePromiseRequest(options, callback);
37+
},
2338
create: function create(order, callback) {
2439
//
2540
// Creates an order.

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.6.0",
3+
"version": "2.7.0",
44
"description": "node.js client for the Button Order API",
55
"repository": {
66
"type": "git",

test/lib/resources/orders-test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@ describe('lib/resources/orders', function() {
5252

5353
});
5454

55+
describe('#getByBtnRef', function() {
56+
57+
beforeEach(function() {
58+
this.btnRef = 'srctok-XXX';
59+
this.order = { 'button_order_id': 'srctok-XXX' };
60+
this.scope = nock('https://api.usebutton.com:443')
61+
.get('/v1/order/btn-ref/' + this.btnRef)
62+
.reply(200, { meta: { status: 'ok' }, 'objects': [this.order] });
63+
});
64+
65+
it('gets an order with a callback', function(done) {
66+
this.callbackClient.getByBtnRef(this.btnRef, function(err, res) {
67+
expect(err).to.be(null);
68+
expect(res.data[0]).to.eql(this.order);
69+
this.scope.done();
70+
done();
71+
}.bind(this));
72+
});
73+
74+
it('gets an order with a promise', function(done) {
75+
this.promiseClient.getByBtnRef(this.btnRef).then(function(result) {
76+
expect(result.data[0]).to.eql(this.order);
77+
this.scope.done();
78+
done();
79+
}.bind(this)).catch(done);
80+
});
81+
82+
});
83+
5584
describe('#create', function() {
5685

5786
beforeEach(function() {

0 commit comments

Comments
 (0)