Skip to content

Commit

Permalink
Merge pull request #21 from OpenSTFoundation/ashutosh/balances_model_…
Browse files Browse the repository at this point in the history
…and_cache

SDK now supports API-v1.1.0
  • Loading branch information
Rachin Kapoor committed Jul 2, 2018
2 parents 01282e4 + 174dfb5 commit 0852159
Show file tree
Hide file tree
Showing 93 changed files with 6,794 additions and 4,389 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ install:
- npm install -g mocha
before_script:
script:
- mocha --timeout 120000 test/v0/* --exit
- mocha --timeout 120000 test/v1/* --exit
after_script:
- mocha --timeout 120000 test/v1_1/* --exit
after_script:
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 v1.1.0](https://github.com/OpenSTFoundation/ost-sdk-js/tree/v1.1.0) July 02 2018
---

* Added balance module to v1 API
* Added ledger module to v1 API

[OST Javascript SDK v1.0.0](https://github.com/OpenSTFoundation/ost-sdk-js/tree/v1.0.0) May 17 2018
---

Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const OSTSDK = require('@ostdotcom/ost-sdk-js');
Initialize the SDK object:

```node.js
// the latest valid API endpoint is "https://sandboxapi.ost.com/v1/", this may change in the future
// the latest valid API endpoint is "https://sandboxapi.ost.com/v1.1/", this may change in the future
const ostObj = new OSTSDK({apiKey: <api_key>, apiSecret: <api_secret>, apiEndpoint: <api_endpoint>});
```

Expand Down Expand Up @@ -181,5 +181,31 @@ List Transfers:
transferService.list({}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Balance Module

```node.js
const balanceService = ostObj.services.balances;
```

Get Balance of user:

```node.js
balanceService.get({id: '38895b82-737e-4b23-b111-fec96e52f3b2'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Ledger Module

```node.js
const ledgerService = ostObj.services.ledger;
```

Get ledger for user:

```node.js
ledgerService.get({id: '38895b82-737e-4b23-b111-fec96e52f3b2'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

## OST API v0 (Previous Version)
To refer to the readme documentation of API v1 [Please Follow This Link](README_V1.md)

To refer to the readme documentation of API v0 [Please Follow This Link](README_V0.md)
185 changes: 185 additions & 0 deletions README_V1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# OST JavaScript SDK
The official [OST JavaScript SDK](https://dev.ost.com/).

## Requirements

To use this node module, developers will need to:
1. Sign-up on [https://kit.ost.com](https://kit.ost.com).
2. Launch a branded token economy with the OST KIT Economy Planner.
3. Obtain an API Key and API Secret from [https://kit.ost.com/developer-api-console](https://kit.ost.com/developer-api-console).

## Documentation

[https://dev.ost.com/](https://dev.ost.com/)

## Installation

Install OST JavaScript SDK

```bash
> npm install @ostdotcom/ost-sdk-js
```

## Example Usage

Require the SDK:

```node.js
const OSTSDK = require('@ostdotcom/ost-sdk-js');
```

Initialize the SDK object:

```node.js
// the latest valid API endpoint is "https://sandboxapi.ost.com/v1/", this may change in the future
const ostObj = new OSTSDK({apiKey: <api_key>, apiSecret: <api_secret>, apiEndpoint: <api_endpoint>});
```

### Users Module

```node.js
const userService = ostObj.services.users;
```

Create a new user:

```node.js
userService.create({name: 'Alice'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Edit an existing user:

```node.js
userService.edit({id: '1234-1928-1081dsds-djhksjd', name: 'Bob'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get an existing user:

```node.js
userService.get({id: '1234-1928-1081dsds-djhksjd'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get a list of users and other data:

```node.js
userService.list({}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Airdrops Module

```node.js
const airdropService = ostObj.services.airdrops;
```

Execute Airdrop:

```node.js
airdropService.execute({amount: 1, user_ids: 'f87346e4-61f6-4d55-8cb8-234c65437b01'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get Airdrop Status:

```node.js
airdropService.get({id: 'ecd9b0b2-a0f4-422c-95a4-f25f8fc88334'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

List Airdrop

```node.js
airdropService.list({page_no: 1, limit: 50, current_status: 'processing,complete'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```


### Token Module

```node.js
const tokenService = ostObj.services.token;
```

Get details:

```node.js
tokenService.get({}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Actions Module


```node.js
const actionService = ostObj.services.actions;
```

Create a new action:

```node.js
actionService.create({name: 'Voteup', kind: 'user_to_user', currency: 'USD', arbitrary_amount: false, amount: 1.01, commission_percent: 1}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Edit an action:

```node.js
actionService.edit({id: 22599, name: 'Like'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get an action:

```node.js
actionService.get({id: 22599}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

List actions:

```node.js
actionService.list({}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Transaction Module

```node.js
const transactionService = ostObj.services.transactions;
```

Execute Transaction:

```node.js
transactionService.execute({from_user_id:'0a201640-77a7-49c8-b289-b6b5d7325323', to_user_id:'24580db2-bf29-4d73-bf5a-e1d0cf8c8928', action_id:'22599'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get Transaction Status:

```node.js
transactionService.get({id: '84d97848-074f-4a9a-a214-19076cfe9dd1'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

List Transactions:

```node.js
transactionService.list({page_no: 1, limit: 10}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

### Transfer Module

```node.js
const transferService = ostObj.services.transfers;
```

Execute ST Prime Transfer:

```node.js
transferService.execute({to_address:'0xd2b789293674faEE51bEb2d0338d15401dEbfdE3', amount:1}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

Get Transfer Status:

```node.js
transferService.get({id: '38895b82-737e-4b23-b111-fec96e52f3b2'}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

List Transfers:

```node.js
transferService.list({}).then(function(res) { console.log(JSON.stringify(res)); }).catch(function(err) { console.log(JSON.stringify(err)); });
```

## OST API v0 (Previous Version)
To refer to the readme documentation of API v0 [Please Follow This Link](README_V0.md)
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.1.0
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
*/

const rootPrefix = "."
, serviceV0ManifestKlass = require(rootPrefix + '/services/v0/manifest')
, serviceV1ManifestKlass = require(rootPrefix + '/services/v1/manifest')
, serviceV0ManifestKlass = require(rootPrefix + '/services/v0/manifest')
, serviceV1ManifestKlass = require(rootPrefix + '/services/v1/manifest')
, serviceV1_1ManifestKlass = require(rootPrefix + '/services/v1_1/manifest')
;

const OSTSDK = function (params) {
Expand All @@ -21,11 +22,13 @@ const OSTSDK = function (params) {
oThis.apiEndpointMajorVersion = (apiEndpointVersion.split('.')[0] || '');

// Provide access to version specific API endpoints
if (oThis.apiEndpointMajorVersion == '') {
if (apiEndpointVersion == '') {
//console.warn("You are using an deprecated version of OST API. Please update to the latest version.");
oThis.services = new serviceV0ManifestKlass(params);
} else if (oThis.apiEndpointMajorVersion == 'v1') {
} else if (apiEndpointVersion == 'v1') {
oThis.services = new serviceV1ManifestKlass(params);
} else if (apiEndpointVersion == 'v1.1') {
oThis.services = new serviceV1_1ManifestKlass(params);
} else {
throw new Error('Api endpoint is invalid');
}
Expand Down
15 changes: 14 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ const queryString = require('query-string')
, crypto = require('crypto')
, https = require('https')
, http = require('http')
, url = require('url');
, url = require('url')
;

const rootPrefix = ".."
, validate = require(rootPrefix + '/lib/validate')
, version = require(rootPrefix + '/package.json').version
, httpUserAgent = "ost-sdk-js " + version
;

let DEBUG = ( "true" === process.env.OST_SDK_DEBUG );

/**
* Generate query signature
Expand Down Expand Up @@ -169,6 +171,12 @@ RequestKlass.prototype = {
options.path = options.path + "?" + requestData;
}

if ( DEBUG ) {
console.log("------------------------------");
console.log("request OPTIONS \n", JSON.stringify( options ) );
console.log("requestData \n", requestData );
}

return new Promise(async function (onResolve, onReject) {
var chunkedResponseData = '';

Expand All @@ -182,6 +190,11 @@ RequestKlass.prototype = {

response.on('end', function () {
var parsedResponse = oThis._parseResponse(chunkedResponseData, response);
if ( DEBUG ) {
console.log("parsedResponse \n", JSON.stringify( parsedResponse ) );
console.log("------------------------------");
}

if (parsedResponse.success) {
onResolve(parsedResponse);
} else {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ostdotcom/ost-sdk-js",
"version": "1.0.0",
"version": "1.1.0",
"description": "The official OST Javascript SDK",
"main": "index.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
"url": "https://github.com/OpenSTFoundation/ost-sdk-js/issues"
},
"dependencies": {
"query-string": "^6.0.0"
"query-string": "6.0.0"
},
"devDependencies": {
"chai": "4.1.2",
Expand Down
8 changes: 7 additions & 1 deletion services/v1/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ manifest.prototype = {
transfers: null,

// Services at /users endpoint
users: null
users: null,

// Services at /balances endpoint
balances: null,

// Services at /ledger endpoint
ledger: null

};

Expand Down
Loading

0 comments on commit 0852159

Please sign in to comment.