Skip to content

Commit

Permalink
Merge pull request #75 from ostdotcom/develop
Browse files Browse the repository at this point in the history
Redemptions API.
  • Loading branch information
kedarchandrayan authored Mar 4, 2020
2 parents b454be6 + 9ad9980 commit bdf4fca
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[OST Ruby SDK v2.2.3](https://github.com/ostdotcom/ost-sdk-ruby/tree/v2.2.3)
---

* Added redemptions module to call redemptions management OST APIs.
* Added redeemable sku module to call redeemable sku management OST APIs.

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

Expand Down
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ For executing transactions, you need to understand the 4 modules described below
price_point = 0.020606673
# Price point needs to be passed in atto. Multiply the price point with 10^18. Also, this value should be a string.
intended_price_point_in_atto = "%.f" % ((price_point * 10**18)
intended_price_point_in_atto = "%.f" % ((price_point * 10**18))
# Amount of Fiat to be transferred.
transfer_amount_in_fiat = 0.1
Expand Down Expand Up @@ -730,3 +730,102 @@ For executing transactions, you need to understand the 4 modules described below
signature_params[:webhook_secret] = 'mySecret'
response = webhooks_service.verify_signature(signature_params)
```


### 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.

```ruby
redeemable_skus_service = ost_sdk.services.redeemable_skus
```
* Get Redeemable SKU detail using the redeemable sku id.

```ruby
# Mandatory API parameters
# Fetch details of following redeemable sku.
redeemable_sku_id = '1'
get_params = {}
get_params[:redeemable_sku_id] = redeemable_sku_id
response = redeemable_skus_service.get(get_params)
```

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

```ruby
# Mandatory API parameters
# NOTE: No mandatory parameters.
# Optional API parameters
# Limit.
limit = 10
# Array of redeemable SKU ids.
redeemable_sku_ids = ['1001', '1002']
# Pagination identifier from the previous API call response. Not needed for page one.
pagination_identifier = 'eyJwY___'
get_params = {}
get_params[:redeemable_sku_ids] = redeemable_sku_ids
get_params[:limit] = limit
get_params[:pagination_identifier] = pagination_identifier
response = redeemable_skus_service.get_list(get_params)
```
#### User Redemptions Module

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

```ruby
redemptions_service = ost_sdk.services.redemptions
```

* Get User redemption details using the userId and redemptionId.

```ruby
# Mandatory API parameters
# UserId of user for whom redemption details needs to be fetched.
user_id = 'ee8___'
# Unique identifier of the redemption of user.
redemption_id = 'r43___'
get_params = {}
get_params[:user_id] = user_id
get_params[:redemption_id] = redemption_id
response = redemptions_service.get(get_params)
```

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

```ruby
# Mandatory API parameters
user_id = 'ee8___'
# Optional API parameters
# Limit.
limit = 10
# Array of user redemption uuids.
redemption_ids = ['a743___', 'a743___']
# Pagination identifier from the previous API call response. Not needed for page one.
pagination_identifier = 'eyJwY___'
get_params = {}
get_params[:user_id] = user_id
get_params[:redemption_ids] = redemption_ids
get_params[:limit] = limit
get_params[:pagination_identifier] = pagination_identifier
response = redemptions_service.get_list(get_params)
```
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
2 changes: 2 additions & 0 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Config
OST_KIT_COMPANY_USER_ID = ENV['OST_KIT_COMPANY_USER_ID']
OST_KIT_AUX_CHAIN_ID = ENV['OST_KIT_AUX_CHAIN_ID']
OST_KIT_TRANSACTION_ID = ENV['OST_KIT_TRANSACTION_ID']
OST_KIT_REDEMPTION_ID = ENV['OST_KIT_REDEMPTION_ID']
OST_KIT_REDEEMABLE_SKU_ID = ENV['OST_KIT_REDEEMABLE_SKU_ID']
OST_KIT_USER_ID = ENV['OST_KIT_USER_ID']
OST_KIT_USER_DEVICE_ADDRESS = ENV['OST_KIT_USER_DEVICE_ADDRESS']
OST_KIT_SESSION_ADDRESS = ENV['OST_KIT_SESSION_ADDRESS']
Expand Down
2 changes: 2 additions & 0 deletions lib/ost-sdk-ruby/saas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require_relative 'saas/manifest'
require_relative 'saas/price_points'
require_relative 'saas/recovery_owners'
require_relative 'saas/redemptions'
require_relative 'saas/redeemable_skus'
require_relative 'saas/rules'
require_relative 'saas/sessions'
require_relative 'saas/tokens'
Expand Down
24 changes: 24 additions & 0 deletions lib/ost-sdk-ruby/saas/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ def get_webhook_id!(params)
get_value_for_key!(params, "webhook_id")
end

# Get redemption_id key from params hash and delete it
#
# Arguments:
# params: (Hash)
#
# Returns:
# redemption_id: (String)
#
def get_redemption_id!(params)
get_value_for_key!(params, "redemption_id")
end

# Get redeemable_sku_id key from params hash and delete it
#
# Arguments:
# params: (Hash)
#
# Returns:
# redeemable_sku_id: (String)
#
def get_redeemable_sku_id!(params)
get_value_for_key!(params, "redeemable_sku_id")
end

# Get chain_id key from params hash and delete it
#
# Arguments:
Expand Down
6 changes: 4 additions & 2 deletions lib/ost-sdk-ruby/saas/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Saas

class Manifest

attr_reader :balance, :chains, :device_managers, :devices, :price_points, :recovery_owners, :rules,
:sessions, :tokens, :transactions, :users, :base_tokens, :webhooks
attr_reader :balance, :chains, :device_managers, :devices, :price_points, :recovery_owners, :redemptions,
:redeemable_skus, :rules, :sessions, :tokens, :transactions, :users, :base_tokens, :webhooks

# Initialize
#
Expand All @@ -24,6 +24,8 @@ def initialize(params)
@devices = OSTSdk::Saas::Devices.new(params)
@price_points = OSTSdk::Saas::PricePoints.new(params)
@recovery_owners = OSTSdk::Saas::RecoveryOwners.new(params)
@redemptions = OSTSdk::Saas::Redemptions.new(params)
@redeemable_skus = OSTSdk::Saas::RedeemableSkus.new(params)

@rules = OSTSdk::Saas::Rules.new(params)
@sessions = OSTSdk::Saas::Sessions.new(params)
Expand Down
43 changes: 43 additions & 0 deletions lib/ost-sdk-ruby/saas/redeemable_skus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module OSTSdk

module Saas

class RedeemableSkus < OSTSdk::Saas::Base

# Initialize
#
# Arguments:
# api_base_url: (String)
# api_key: (String)
# api_secret: (String)
# api_spec: (Boolean)
# config: (Hash)
#
def initialize(params)
super
@url_prefix = '/redeemable-skus'
end

# Get redeemable sku detail
#
# Returns:
# response: (Hash)
#
def get(params = {})
http_helper.send_get_request("#{@url_prefix}/#{get_redeemable_sku_id!(params)}", params)
end

# List redeemable sku details
#
# Returns:
# response: (Hash)
#
def get_list(params = {})
http_helper.send_get_request("#{@url_prefix}", params)
end

end

end

end
44 changes: 44 additions & 0 deletions lib/ost-sdk-ruby/saas/redemptions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module OSTSdk

module Saas

class Redemptions < OSTSdk::Saas::Base

# Initialize
#
# Arguments:
# api_base_url: (String)
# api_key: (String)
# api_secret: (String)
# api_spec: (Boolean)
# config: (Hash)
#
def initialize(params)
super
@url_prefix = '/users'
@url_suffix = '/redemptions'
end

# Get redemption detail
#
# Returns:
# response: (Hash)
#
def get(params = {})
http_helper.send_get_request("#{@url_prefix}/#{get_user_id!(params)}#{@url_suffix}/#{get_redemption_id!(params)}", params)
end

# List redemptions of a user
#
# Returns:
# response: (Hash)
#
def get_list(params = {})
http_helper.send_get_request("#{@url_prefix}/#{get_user_id!(params)}#{@url_suffix}", params)
end

end

end

end
24 changes: 24 additions & 0 deletions lib/ost-sdk-ruby/test/redeemable_skus_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative "../../../lib/ost-sdk-ruby/util"
require_relative "../../../lib/ost-sdk-ruby/saas"
require "test/unit"
require_relative "../../../lib/config"

class RedeemableSkusTest < Test::Unit::TestCase

def redeemable_skus_service
@redeemable_skus_service ||= Config::OST_SDK.services.redeemable_skus
end

def test_redeemable_skus_get
result = redeemable_skus_service.get(redeemable_sku_id: Config::OST_KIT_REDEEMABLE_SKU_ID)
puts "result=>#{result}" unless result["success"]
assert_equal(result["success"], true)
end

def test_redeemable_skus_get_list
result = redeemable_skus_service.get_list()
puts "result=>#{result}" unless result["success"]
assert_equal(result["success"], true)
end

end
24 changes: 24 additions & 0 deletions lib/ost-sdk-ruby/test/redemptions_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative "../../../lib/ost-sdk-ruby/util"
require_relative "../../../lib/ost-sdk-ruby/saas"
require "test/unit"
require_relative "../../../lib/config"

class RedemptionsTest < Test::Unit::TestCase

def redemptions_service
@redemptions_service ||= Config::OST_SDK.services.redemptions
end

def test_redemptions_get
result = redemptions_service.get(user_id: Config::OST_KIT_USER_ID, redemption_id: Config::OST_KIT_REDEMPTION_ID)
puts "result=>#{result}" unless result["success"]
assert_equal(result["success"], true )
end

def test_redemptions_get_list
result = redemptions_service.get_list(user_id: Config::OST_KIT_USER_ID)
puts "result=>#{result}" unless result["success"]
assert_equal(result["success"], true )
end

end
2 changes: 1 addition & 1 deletion lib/ost-sdk-ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OSTSdk

VERSION = "2.2.2"
VERSION = "2.2.3"

end

0 comments on commit bdf4fca

Please sign in to comment.