Skip to content

Commit

Permalink
Merge pull request #63 from ostdotcom/develop
Browse files Browse the repository at this point in the history
Redemptions API.
  • Loading branch information
Shlok Gilda authored Mar 4, 2020
2 parents ff54174 + 08fbbab commit 366447b
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ notifications:
on_success: always
on_failure: always
node_js:
- "10"
- "9"
- "8"
- "7"
before_install:
- sudo apt-get update
- sudo apt-get install nodejs
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[OST Javascript SDK v2.2.3](https://github.com/ostdotcom/ost-sdk-js/tree/v2.2.3)
---

* Added redemptions module to call user redemptions management OST APIs.
* Added redeemable SKUs module to call redeemable SKUs OST APIs.

[OST Javascript SDK v2.2.2](https://github.com/ostdotcom/ost-sdk-js/tree/v2.2.2)
---

Expand Down
94 changes: 93 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ The preferred way to install the OST JavaScript SDK is to use the npm package ma
.then(function(res) { console.log(JSON.stringify(res)); })
.catch(function(err) { console.log(JSON.stringify(err)); });
```

### Devices Module

* Initialize Devices service object to perform device specific actions.
Expand Down Expand Up @@ -737,3 +737,95 @@ For executing transactions, you need to understand the 4 modules described below
let resp = webhooksService.verifySignature(version, stringifiedData,requestTimestamp, signature, webhookSecret);
console.log(resp);
```

### Redemption Modules

Two modules of redemption, "Redeemable SKUs" and "User Redemptions", are described below.

#### Redeemable SKUs Module

* Initialize Redeemable SKUs service object to perform redeemable skus specific actions.

```js
const redeemableSkusService = ostObj.services.redeemable_skus;
```
* Get Redeemable SKU detail using the redeemable sku id.

```js
// Mandatory API parameters
// Fetch details of following redeemable sku.
let redeemableSkuId = 'c2c__';
redeemableSkusService.get({ redeemable_sku_id: redeemableSkuId })
.then(function(res) { console.log(JSON.stringify(res)); })
.catch(function(err) { console.log(JSON.stringify(err)); });
```

* Get Redeemable SKUs List. Pagination is supported by this API.

```js
// Mandatory API parameters
// NOTE: No mandatory parameters.
// Optional API parameters
// Limit.
let limit = 10;
// Array of redeemable SKU ids.
let redeemableSkuIds = ['1001', '1002'];
// Pagination identifier from the previous API call response. Not needed for page one.
let paginationIdentifier = 'e77y___';
redeemableSkusService.getList({limit: limit, pagination_identifier: paginationIdentifier, redeemable_sku_ids: redeemableSkuIds })
.then(function(res) { console.log(JSON.stringify(res)); })
.catch(function(err) { console.log(JSON.stringify(err)); });
```

#### User Redemptions Module

* Initialize Redemptions service object to perform user redemption specific actions.

```js
const redemptionsService = ostObj.services.redemptions;
```

* Get User redemption details using the userId and redemptionId.

```js
// Mandatory API parameters
// UserId of user for whom redemption details needs to be fetched.
let userId = 'c2c__';
// Unique identifier of the redemption of user.
let redemptionId = 'c2c__';
redemptionsService.get({ user_id: userId, redemption_id: redemptionId })
.then(function(res) { console.log(JSON.stringify(res)); })
.catch(function(err) { console.log(JSON.stringify(err)); });
```

* Get User Redemptions List. Pagination is supported by this API.

```js
// Mandatory API parameters
let userId = 'c2c__';
// Optional API parameters
// Limit.
let limit = 10;
// Array of user redemption uuids.
let redemptionIds = ['a743___', 'a743___'];
// Pagination identifier from the previous API call response. Not needed for page one.
let paginationIdentifier = 'e77y___';
redemptionsService.getList({ user_id: userId, limit: limit, pagination_identifier: paginationIdentifier, redemption_ids: redemptionIds })
.then(function(res) { console.log(JSON.stringify(res)); })
.catch(function(err) { console.log(JSON.stringify(err)); });
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.2
2.2.3
36 changes: 35 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ ValidateKlass.prototype = {
}
},

/**
* Get redeemable sku id from params.
*
* @param {object} params
* @param {string} params.redeemable_sku_id
*/
getRedeemableSkuId: function (params) {
const oThis = this;
if (oThis.isValid(params.redeemable_sku_id)) {
var redeemableSkuId = params.redeemable_sku_id;
delete params.redeemable_sku_id;
return redeemableSkuId
} else {
throw new Error('redeemable_sku_id missing or invalid in request params');
}
},

/**
* Get redemption uid from params.
*
* @param {object} params
* @param {string} params.redemption_id
*/
getRedemptionId: function (params) {
const oThis = this;
if (oThis.isValid(params.redemption_id)) {
let redemption_id = params.redemption_id;
delete params.redemption_id;
return redemption_id
} else {
throw new Error('redemption_id missing or invalid in request params.');
}
},


/**
* Get webhook id from params.
Expand Down Expand Up @@ -170,4 +204,4 @@ ValidateKlass.prototype = {

};

module.exports = new ValidateKlass();
module.exports = new ValidateKlass();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ostdotcom/ost-sdk-js",
"version": "2.2.2",
"version": "2.2.3",
"description": "OST Platform SDK for JavaScript.",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions services/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const rootPrefix = ".."
, transactionsKlass = require(rootPrefix + '/services/transactions')
, baseTokensKlass = require(rootPrefix + '/services/base_tokens')
, webhooksKlass = require(rootPrefix + '/services/webhooks')
, redemptionsKlass = require(rootPrefix + '/services/redemptions')
, redeemableSkusKlass = require(rootPrefix + '/services/redeemable_skus')
;

// hide request object
Expand Down Expand Up @@ -51,6 +53,8 @@ const manifest = function (params) {
oThis.transactions = new transactionsKlass(_requestObj);
oThis.base_tokens = new baseTokensKlass(_requestObj);
oThis.webhooks = new webhooksKlass(_requestObj);
oThis.redemptions = new redemptionsKlass(_requestObj);
oThis.redeemable_skus = new redeemableSkusKlass(_requestObj);

return oThis;
};
Expand Down Expand Up @@ -81,7 +85,11 @@ manifest.prototype = {

base_tokens: null,

webhooks: null
webhooks: null,

redemptions: null,

redeemable_skus: null,
};

module.exports = manifest;
module.exports = manifest;
66 changes: 66 additions & 0 deletions services/redeemable_skus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use strict";

/**
* Redeemable SKUs Service
*
* @module services/redeemable_skus
*/

const rootPrefix = ".."
, validate = require(rootPrefix + '/lib/validate')
;

// hide request object
var _requestObj = null;

/**
* Redeemable SKUs Service constructor.
*
* @constructor
*/
const redeemable_skus = function (requestObj) {
const oThis = this;

// Assign request object.
_requestObj = requestObj;

// Define the url prefix.
oThis.urlPrefix = '/redeemable-skus';

return oThis;
};

redeemable_skus.prototype = {
/**
* Get redeemable skus list.
*
* @param {object} params
*
* @returns {*}
*/
getList: function(params) {
const oThis = this;

params = params || {};

return _requestObj.get(oThis.urlPrefix, params);
},

/**
* Get redeemable sku by redeemable sku id.
*
* @param {object} params
*
* @returns {*}
*/
get: function(params) {
const oThis = this;

params = params || {};

return _requestObj.get(oThis.urlPrefix + "/" + validate.getRedeemableSkuId(params), params);
}

};

module.exports = redeemable_skus;
67 changes: 67 additions & 0 deletions services/redemptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use strict";

/**
* Redemptions Service
*
* @module services/redemptions
*/

const rootPrefix = ".."
, validate = require(rootPrefix + '/lib/validate')
;

// hide request object
var _requestObj = null;

/**
* Redemptions Service constructor
*
* @constructor
*/
const redemptions = function (requestObj) {
const oThis = this;

// Assign request object
_requestObj = requestObj;

// Define the url prefix
oThis.urlPrefix = '/users';
oThis.redemptionsUrlPrefix = '/redemptions';

return oThis;
};

redemptions.prototype = {
/**
* Get user redemptions list.
*
* @param {object} params
*
* @returns {*}
*/
getList: function(params) {
const oThis = this;

params = params || {};

return _requestObj.get(oThis.urlPrefix + "/" + validate.getUserId(params) + oThis.redemptionsUrlPrefix, params);
},

/**
* Get user redemption by redemption id.
*
* @param {object} params
*
* @returns {*}
*/
get: function(params) {
const oThis = this;

params = params || {};

return _requestObj.get(oThis.urlPrefix + "/" + validate.getUserId(params) + oThis.redemptionsUrlPrefix + '/' + validate.getRedemptionId(params), params);
}

};

module.exports = redemptions;
2 changes: 1 addition & 1 deletion services/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const users = function (requestObj) {

// Define the url prefix
oThis.urlPrefix = '/users';
oThis.redemptionsUrlPrefix = '/redemptions';

return oThis;
};
Expand Down Expand Up @@ -72,7 +73,6 @@ users.prototype = {

return _requestObj.get(oThis.urlPrefix + "/" + validate.getUserId(params), params);
}

};

module.exports = users;
Loading

0 comments on commit 366447b

Please sign in to comment.