From aef0bb6682eec2663918ace3501e89210c2384fd Mon Sep 17 00:00:00 2001 From: Sriram Balachandran Date: Wed, 5 Sep 2018 12:05:45 -0700 Subject: [PATCH] Added get active listings helper function --- lib/etsyjs/shop.js | 22 ++++++++++++++++++++++ src/etsyjs/shop.coffee | 15 ++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/etsyjs/shop.js b/lib/etsyjs/shop.js index 61f492d..eb523f2 100644 --- a/lib/etsyjs/shop.js +++ b/lib/etsyjs/shop.js @@ -43,6 +43,28 @@ }])); }; + Shop.prototype.activeListings = function(_arg, cb) { + var limit, offset, params, secret, token, _ref; + token = _arg.token, secret = _arg.secret, limit = _arg.limit, offset = _arg.offset; + params = {}; + if (limit != null) { + params.limit = limit; + } + if (offset != null) { + params.offset = offset; + } + return (_ref = this.client).get.apply(_ref, ["/shops/" + this.shopId + "/listings/active", token, secret].concat(__slice.call(params), [function(err, status, body, headers) { + if (err) { + return cb(err); + } + if (status !== 200) { + return cb(new Error('Get active listings error')); + } else { + return cb(null, body, headers); + } + }])); + }; + return Shop; })(); diff --git a/src/etsyjs/shop.coffee b/src/etsyjs/shop.coffee index b8ac4a7..cbb05d1 100644 --- a/src/etsyjs/shop.coffee +++ b/src/etsyjs/shop.coffee @@ -25,4 +25,17 @@ class Shop else cb null, body, headers -module.exports = Shop \ No newline at end of file + # Retrieves Listings associated to a Shop that are active + # '/shops/:shop_id/listings/active' GET + activeListings: ({token, secret, limit, offset}, cb) -> + params = {} + params.limit = limit if limit? + params.offset = offset if offset? + @client.get "/shops/#{@shopId}/listings/active", token, secret, params..., (err, status, body, headers) -> + return cb(err) if err + if status isnt 200 + cb(new Error('Get active listings error')) + else + cb null, body, headers + +module.exports = Shop