Skip to content

Commit 81f300b

Browse files
author
Abhay Kumar Singh
authored
Merge pull request #3 from OpenSTFoundation/develop
Preparing for release v0.9.2
2 parents 5abdee4 + 9b081f0 commit 81f300b

File tree

12 files changed

+281
-136
lines changed

12 files changed

+281
-136
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ build-iPhoneSimulator/
3939
/.bundle/
4040
/vendor/bundle
4141
/lib/bundler/man/
42+
.idea
4243

4344
# for a library or gem, you might want to ignore these files since the code is
4445
# intended to run in multiple environments; otherwise, check them in:

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018 Puneet Khushwani
1+
Copyright (c) 2018 OST.com Ltd.
22

33
MIT License
44

README.md

Lines changed: 132 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,136 @@
11
# Ost::Sdk::Ruby
22

3+
A Ruby wrapper for the [OST Developers API](https://dev.ost.com/).
4+
5+
## Requirements
6+
7+
To use this gem, developers will need to:
8+
1. Sign-up on [https://kit.ost.com](https://kit.ost.com).
9+
2. Launch a branded token economy with the OST KIT Economy Planner.
10+
3. Obtain an API Key and API Secret from [https://kit.ost.com/developer-api-console](https://kit.ost.com/developer-api-console).
11+
12+
## Documentation
13+
14+
[https://dev.ost.com/](https://dev.ost.com/)
15+
316
## Installation
417

5-
Add this line to your application's Gemfile:
6-
7-
gem 'ost-sdk-ruby'
8-
9-
And then execute:
10-
11-
$ bundle
12-
13-
Or install it yourself as:
14-
15-
$ gem install ost-sdk-ruby
16-
17-
## Usage
18-
19-
1. TransactionKind Module
20-
21-
environment = 'sandbox' # possible values sandbox / production
22-
23-
credentials = OSTSdk::Util::APICredentials.new('2fb1cd4ff54f8d842805', '018215e8eeda1084ebcf1fefb5b702799a2d52d0cda955209d98e65bd55a69e0')
24-
25-
obj = OSTSdk::Saas::TransactionKind.new(environment, credentials)
26-
27-
obj.list()
28-
29-
obj.create(name: 'ABC', kind: 'user_to_user', value_currency_type: 'usd', value_in_usd: '1.1', value_in_bt: '1.1', commission_percent: '0.0')
30-
31-
obj.edit(client_transaction_id: '12', name: 'test_1_1_1')
32-
33-
2. Address Module
34-
35-
environment = 'sandbox' # possible values sandbox / production
36-
37-
credentials = OSTSdk::Util::APICredentials.new('2fb1cd4ff54f8d842805', '018215e8eeda1084ebcf1fefb5b702799a2d52d0cda955209d98e65bd55a69e0')
38-
39-
obj = OSTSdk::Saas::Addresses.new(environment, credentials)
40-
41-
obj.fetch_balances(balance_types: ['ost', 'ostPrime', 'eth', 'FRC'], address_uuid: '0xddA2cB099235F657b77b8ABf055725c88cbc6112')
42-
43-
3. User Module
44-
45-
obj = OSTSdk::Saas::Users.new(environment, credentials)
46-
47-
obj.create(name: 'test test')
48-
49-
obj.edit(name: 'test test', address_uuid: '0xddA2cB099235F657b77b8ABf055725c88cbc6112')
50-
51-
obj.list()
52-
53-
## Contributing
54-
55-
1. Fork it ( https://github.com/[my-github-username]/ost-sdk-ruby/fork )
56-
2. Create your feature branch (`git checkout -b my-new-feature`)
57-
3. Commit your changes (`git commit -am 'Add some feature'`)
58-
4. Push to the branch (`git push origin my-new-feature`)
59-
5. Create a new Pull Request
18+
Install OST Ruby SDK
19+
20+
```bash
21+
> gem install ost-sdk-ruby
22+
```
23+
24+
## Example Usage
25+
26+
Require the OST Ruby SDK:
27+
28+
```ruby
29+
require('ost-sdk-ruby')
30+
```
31+
32+
Set variables for initializing SDK objects:
33+
34+
```ruby
35+
environment = 'sandbox'
36+
credentials = OSTSdk::Util::APICredentials.new(<api_key>, <api_secret>)
37+
```
38+
39+
### Transaction Kind Module
40+
41+
Initialize a `TransactionKind` object to perform transaction-related actions:
42+
43+
```ruby
44+
ostTransactionKindObject = OSTSdk::Saas::TransactionKind.new(environment, credentials)
45+
```
46+
47+
Create new transaction kinds:
48+
49+
```ruby
50+
ostTransactionKindObject.create(name: 'Like', kind: 'user_to_user', currency_type: 'usd', currency_value: '1.25', commission_percent: '12')
51+
```
52+
53+
```ruby
54+
ostTransactionKindObject.create(name: 'Grant', kind: 'company_to_user', currency_type: 'bt', currency_value: '12', commission_percent: '0')
55+
```
56+
57+
```ruby
58+
ostTransactionKindObject.create(name: 'Buy', kind: 'user_to_company', currency_type: 'bt', currency_value: '100', commission_percent: '0')
59+
```
60+
61+
Get a list of existing transaction kinds and other data:
62+
63+
```ruby
64+
ostTransactionKindObject.list()
65+
```
66+
67+
Edit an existing transaction kind:
68+
69+
```ruby
70+
ostTransactionKindObject.edit(client_transaction_id: '12', name: 'New Transaction Kind')
71+
```
72+
73+
Execute a branded token transfer by transaction kind:
74+
75+
```ruby
76+
ostTransactionKindObject.execute(from_uuid: '1234-1928-1081dsds-djhksjd', to_uuid: '1234-1928-1081-1223232', transaction_kind: 'Purchase')
77+
```
78+
79+
Get the status of an executed transaction:
80+
81+
```ruby
82+
ostTransactionKindObject.status(transaction_uuids: ['5f79063f-e22a-4d28-99d7-dd095f02c72e'])
83+
```
84+
85+
### Users Module
86+
87+
Initialize a `Users` object to perform user specific actions:
88+
89+
```ruby
90+
ostUsersObject = OSTSdk::Saas::Users.new(environment, credentials)
91+
```
92+
93+
Create a new user:
94+
95+
```ruby
96+
ostUsersObject.create(name: 'Alice')
97+
```
98+
99+
Get a list of users and other data:
100+
101+
```ruby
102+
ostUsersObject.list()
103+
```
104+
105+
Edit an existing user:
106+
107+
```ruby
108+
ostUsersObject.edit(uuid: '1234-1928-1081dsds-djhksjd', name: 'Bob')
109+
```
110+
111+
Airdrop branded tokens to users:
112+
113+
```ruby
114+
ostUsersObject.airdrop_tokens(amount: 100, list_type: 'all')
115+
```
116+
117+
As airdropping tokens is an asynchronous task, you can check the airdrop's status:
118+
119+
```ruby
120+
ostUsersObject.get_airdrop_status(airdrop_uuid: '1234-1928-1081dsds-djhksjd')
121+
```
122+
123+
### Request Specs
124+
125+
To obtain request/API specification, pass in `true` for the optional `api_spec` parameter when initializing a `TransactionKind` or `Users` module object:
126+
127+
```ruby
128+
ostTransactionKindObject = OSTSdk::Saas::TransactionKind.new(environment, credentials, true)
129+
```
130+
131+
And then call a method:
132+
133+
```ruby
134+
> ostTransactionKindObject.list()
135+
=> #<OSTSdk::Util::Result:0x007ffccab36c98 @error=nil, @error_message=nil, @error_data=nil, @error_display_text=nil, @error_display_heading=nil, @message=nil, @http_code=200, @data={:request_uri=>"https://sandboxapi.ost.com/transaction-types/list", :request_type=>"GET", :request_params=>"request_timestamp=<request_epoch_timestamp>&signature=<signature>&api_key=<api_key>"}>
136+
```

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.9.2

lib/ost-sdk-ruby/saas.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require_relative 'saas/base'
22
require_relative 'saas/transaction_kind'
3-
require_relative 'saas/addresses'
43
require_relative 'saas/users'
54

65
module OSTSdk

lib/ost-sdk-ruby/saas/addresses.rb

Lines changed: 0 additions & 31 deletions
This file was deleted.

lib/ost-sdk-ruby/saas/base.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ class Base
1010

1111
# Initialize
1212
#
13-
# @param [Hash] params (mandatory) is a Hash
13+
# Arguments:
14+
# environment: (String)
15+
# credentials: (OSTSdk::Util::APICredentials)
16+
# api_spec: (Boolean)
1417
#
15-
def initialize(environment, credentials)
18+
def initialize(environment, credentials, api_spec)
1619

1720
fail 'missing param environment' if environment.nil?
1821
fail 'missing/invalid param credentials' if credentials.nil? ||
1922
credentials.class != OSTSdk::Util::APICredentials
2023

21-
@http_helper = OSTSdk::Util::HTTPHelper.new(environment, credentials)
24+
@http_helper = OSTSdk::Util::HTTPHelper.new(environment, credentials, api_spec)
2225

2326
end
2427

lib/ost-sdk-ruby/saas/transaction_kind.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ class TransactionKind < OSTSdk::Saas::Base
99
# Arguments:
1010
# environment: (String)
1111
# credentials: (OSTSdk::Util::APICredentials)
12+
# api_spec: (Boolean)
1213
#
13-
def initialize(environment, credentials)
14+
def initialize(environment, credentials, api_spec = false)
1415
super
15-
@url_prefix = '/transaction/kind'
16+
@url_prefix = '/transaction-types'
1617
end
1718

1819
# Fetches the list of all transaction types
@@ -21,7 +22,7 @@ def initialize(environment, credentials)
2122
# response: (OSTSdk::Util::Result)
2223
#
2324
def list(params = {})
24-
http_helper.send_get_request("#{@url_prefix}/get-all", params)
25+
http_helper.send_get_request("#{@url_prefix}/list", params)
2526
end
2627

2728
# Creates a new transaction type
@@ -33,7 +34,7 @@ def list(params = {})
3334
# response: (OSTSdk::Util::Result)
3435
#
3536
def create(params)
36-
http_helper.send_post_request("#{@url_prefix}/new", params)
37+
http_helper.send_post_request("#{@url_prefix}/create", params)
3738
end
3839

3940
# Updates an existing transaction type
@@ -48,6 +49,30 @@ def edit(params)
4849
http_helper.send_post_request("#{@url_prefix}/edit", params)
4950
end
5051

52+
# Execute transfer BT by tx kind
53+
#
54+
# Arguments:
55+
# params: (Hash)
56+
#
57+
# Returns:
58+
# response: (OSTSdk::Util::Result)
59+
#
60+
def execute(params)
61+
http_helper.send_post_request("#{@url_prefix}/execute", params)
62+
end
63+
64+
# Get details of a transaction(s)
65+
#
66+
# Arguments:
67+
# params: (Hash)
68+
#
69+
# Returns:
70+
# response: (OSTSdk::Util::Result)
71+
#
72+
def status(params)
73+
http_helper.send_post_request("#{@url_prefix}/status", params)
74+
end
75+
5176
end
5277

5378
end

lib/ost-sdk-ruby/saas/users.rb

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class Users < OSTSdk::Saas::Base
99
# Arguments:
1010
# environment: (String)
1111
# credentials: (OSTSdk::Util::APICredentials)
12+
# api_spec: (Boolean)
1213
#
13-
def initialize(environment, credentials)
14+
def initialize(environment, credentials, api_spec = false)
1415
super
1516
@url_prefix = '/users'
1617
end
@@ -39,7 +40,25 @@ def edit(params = {})
3940
# response: (OSTSdk::Util::Result)
4041
#
4142
def list(params = {})
42-
http_helper.send_post_request("#{@url_prefix}/list", params)
43+
http_helper.send_get_request("#{@url_prefix}/list", params)
44+
end
45+
46+
# Airdrop Branded Token to list of users
47+
#
48+
# Returns:
49+
# response: (OSTSdk::Util::Result)
50+
#
51+
def airdrop_tokens(params = {})
52+
http_helper.send_post_request("#{@url_prefix}/airdrop/drop", params)
53+
end
54+
55+
# Get status of an Airdrop request for users.
56+
#
57+
# Returns:
58+
# response: (OSTSdk::Util::Result)
59+
#
60+
def get_airdrop_status(params = {})
61+
http_helper.send_get_request("#{@url_prefix}/airdrop/status", params)
4362
end
4463

4564
end

0 commit comments

Comments
 (0)