tangocard 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +60 -0
- data/lib/tangocard/account.rb +61 -6
- data/lib/tangocard/brand.rb +64 -2
- data/lib/tangocard/order.rb +25 -26
- data/lib/tangocard/raas.rb +56 -4
- data/lib/tangocard/response.rb +0 -2
- data/lib/tangocard/reward.rb +28 -3
- data/lib/tangocard/version.rb +1 -1
- metadata +3 -3
- data/README.rdoc +0 -10
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGYwODkzOWEyZGFkNjZkZTliNzQyZWJhNDU4NGE0NDY4NTJlMWZjNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTRkNDVlOGFlM2E4NTJjZTgyNGE2ZjMzMzA0YTQ2Y2IwNDdmZTliNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWJhMDlkMTBiNzllZWM3YmI3YWRjZGNkMjBiN2YxMWQwZmI0YTdjYjVkNzU0
|
10
|
+
YTRjNjNmNWJlZDZjY2NlZmNlYjFhMGJlYmQ4NWMwNGM5MGFiZmYyNTVjZDgz
|
11
|
+
YTgwMmUwZTkyMTEwZmM5ZDcyYzdiZWM3Yjc3MDA3ODgyZWYxMzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGNiYThjYTE2NzNlODhhMDYxNTE0YjI1OTFjMTk3OWFiNjdkZmEwNDcxOTFk
|
14
|
+
NTdlMjgzZmM2ZjdhYzhmZjVlNWEwYzRjZGE2ZDk2NTYwYjc1ZTIyYTkxNTA1
|
15
|
+
YzdkNDNhZTE3Yjg0ZTRkNGYzZTk3OTRhMGM3YzE5OTRiNzhkZWQ=
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Tangocard
|
2
|
+
|
3
|
+
Ruby Wrapper for Tango Card RaaS API.
|
4
|
+
|
5
|
+
Tango Card provides a RaaS API for developers (https://github.com/tangocarddev/RaaS). This gem provides commonsense Ruby
|
6
|
+
objects to wrap the JSON endpoints of the RaaS API.
|
7
|
+
|
8
|
+
## Information
|
9
|
+
|
10
|
+
* RDoc documentation [available on RubyDoc.info](http://rubydoc.info/github/bonusly/tangocard/master/frames)
|
11
|
+
* Source code [available on GitHub](https://github.com/bonusly/tangocard)
|
12
|
+
|
13
|
+
## Getting Help
|
14
|
+
|
15
|
+
* Please report bugs on the [issue tracker](https://github.com/bonusly/tangocard/issues)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
### Rails 3
|
20
|
+
|
21
|
+
Add the `tangocard` gem to your `Gemfile`:
|
22
|
+
|
23
|
+
```
|
24
|
+
gem 'tangocard'
|
25
|
+
```
|
26
|
+
|
27
|
+
Create an initializer, e.g. `config/initializers/tangocard.rb`:
|
28
|
+
|
29
|
+
```
|
30
|
+
Tangocard.configure do |c|
|
31
|
+
c.name = "BonuslyXYZ"
|
32
|
+
c.key = "Dnv9ehvff29"
|
33
|
+
c.base_uri = "https://sandbox.tangocard.com"
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
There are three required configuration parameters:
|
38
|
+
|
39
|
+
* `name` - The API account name you receive from Tango Card
|
40
|
+
* `key` - The API account key you receive from Tango Card
|
41
|
+
* `base_uri` - This defaults to the Tango Card sandbox. For production, you must specify the base URI for the produciton RaaS API
|
42
|
+
|
43
|
+
There are also three optional configuration parameters:
|
44
|
+
|
45
|
+
* `default_brands` - An array of strings for the brands you want to retrieve with Tangocard::Brand.default_brands. The strings should match the unique brand `description` fields exactly.
|
46
|
+
* `local_images` - An array of local image names/URIs that you want to display instead of the default Tango Card-provided `image_url`. `image_url is sometimes blank, so this can be handy in those cases.
|
47
|
+
* `sku_blacklist` - Reward SKUs that are blacklisted, ie. should never be returned as a purchasable reward.
|
48
|
+
|
49
|
+
## Getting Started
|
50
|
+
|
51
|
+
This gem provides two tools:
|
52
|
+
|
53
|
+
1. A simple wrapper for the Tango Card RaaS API, consisting of two classes: `Tangocard::Raas` and `Tangocard::Response`.
|
54
|
+
2. Models for each of the Tango Card objects: Accounts, Brands, Rewards, and Orders. These provide a greater level of abstraction and ease of use.
|
55
|
+
|
56
|
+
## Notes and Credits
|
57
|
+
|
58
|
+
This project is developed and maintained by Smartly, Inc. - makers of http://bonus.ly.
|
59
|
+
|
60
|
+
This project uses the MIT-LICENSE.
|
data/lib/tangocard/account.rb
CHANGED
@@ -1,29 +1,57 @@
|
|
1
|
-
# Wrapper for Tangocard RaaS Account
|
2
|
-
# https://github.com/tangocarddev/RaaS#account-resources
|
3
1
|
class Tangocard::Account
|
4
2
|
attr_reader :customer, :identifier, :email, :available_balance
|
5
3
|
|
6
4
|
private_class_method :new
|
7
5
|
|
8
|
-
#
|
6
|
+
# Find account given customer and identifier. Raises Tangocard::AccountNotFoundException on failure.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
# >> Tangocard::Account.find('bonusly', 'test')
|
10
|
+
# => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=1200>
|
11
|
+
#
|
12
|
+
# Arguments:
|
13
|
+
# customer: (String)
|
14
|
+
# identifier: (String)
|
9
15
|
def self.find(customer, identifier)
|
10
16
|
response = Tangocard::Raas.show_account({'customer' => customer, 'identifier' => identifier})
|
11
17
|
if response.success?
|
12
18
|
new(response.parsed_response['account'])
|
13
19
|
else
|
14
|
-
raise Tangocard::AccountNotFoundException, "
|
20
|
+
raise Tangocard::AccountNotFoundException, "#{response.error_message}"
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
24
|
+
# Create account given customer, identifier, and email.
|
25
|
+
# Raises Tangocard::AccountCreateFailedException on failure.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
# >> Tangocard::Account.create('bonusly', 'test', 'dev@bonus.ly')
|
29
|
+
# => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=0>
|
30
|
+
#
|
31
|
+
# Arguments:
|
32
|
+
# customer: (String)
|
33
|
+
# identifier: (String)
|
34
|
+
# email: (String)
|
18
35
|
def self.create(customer, identifier, email)
|
19
36
|
response = Tangocard::Raas.create_account({'customer' => customer, 'identifier' => identifier, 'email' => email})
|
20
37
|
if response.success?
|
21
38
|
new(response.parsed_response['account'])
|
22
39
|
else
|
23
|
-
raise Tangocard::AccountCreateFailedException, "
|
40
|
+
raise Tangocard::AccountCreateFailedException, "#{response.error_message}"
|
24
41
|
end
|
25
42
|
end
|
26
43
|
|
44
|
+
# Find account, or create if account not found.
|
45
|
+
# Raises Tangocard::AccountCreateFailedException on failure.
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
# >> Tangocard::Account.find_or_create('bonusly', 'test', 'dev@bonus.ly')
|
49
|
+
# => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=0>
|
50
|
+
#
|
51
|
+
# Arguments:
|
52
|
+
# customer: (String)
|
53
|
+
# identifier: (String)
|
54
|
+
# email: (String)
|
27
55
|
def self.find_or_create(customer, identifier, email)
|
28
56
|
begin
|
29
57
|
find(customer, identifier)
|
@@ -32,7 +60,6 @@ class Tangocard::Account
|
|
32
60
|
end
|
33
61
|
end
|
34
62
|
|
35
|
-
# {"identifier"=>"test1", "email"=>"test@test.com", "customer"=>"bonusly", "available_balance"=>0}
|
36
63
|
def initialize(params)
|
37
64
|
@customer = params['customer']
|
38
65
|
@email = params['email']
|
@@ -44,6 +71,34 @@ class Tangocard::Account
|
|
44
71
|
@available_balance
|
45
72
|
end
|
46
73
|
|
74
|
+
# Add funds to the account.
|
75
|
+
#
|
76
|
+
# Example:
|
77
|
+
# >> account.fund(10000, '128.128.128.128', Hash (see example below))
|
78
|
+
# => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=0>
|
79
|
+
#
|
80
|
+
# Arguments:
|
81
|
+
# amount: (Integer)
|
82
|
+
# client_ip: (String)
|
83
|
+
# credit_card: (Hash) - see https://github.com/tangocarddev/RaaS/blob/master/fund_create.schema.json for details
|
84
|
+
#
|
85
|
+
# Credit Card Hash Example:
|
86
|
+
#
|
87
|
+
# {
|
88
|
+
# 'number' => '4111111111111111',
|
89
|
+
# 'expiration' => '01/17',
|
90
|
+
# 'security_code' => '123',
|
91
|
+
# 'billing_address' => {
|
92
|
+
# 'f_name' => 'Jane',
|
93
|
+
# 'l_name' => 'User',
|
94
|
+
# 'address' => '123 Main Street',
|
95
|
+
# 'city' => 'Anytown',
|
96
|
+
# 'state' => 'NY',
|
97
|
+
# 'zip' => '11222',
|
98
|
+
# 'country' => 'USA',
|
99
|
+
# 'email' => 'jane@company.com'
|
100
|
+
# }
|
101
|
+
# }
|
47
102
|
def fund!(amount, client_ip, credit_card)
|
48
103
|
params = {
|
49
104
|
'amount' => amount,
|
data/lib/tangocard/brand.rb
CHANGED
@@ -1,16 +1,43 @@
|
|
1
|
-
# Documentation: https://github.com/tangocarddev/RaaS
|
2
1
|
class Tangocard::Brand
|
3
2
|
attr_reader :description, :rewards
|
4
3
|
|
4
|
+
# Return an array of all brands.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# >> Tangocard::Brand.all
|
8
|
+
# => [#<Tangocard::Brand:0x007f9a6f9d3030 ...>, #<Tangocard::Brand:0x007f9a6f9d3030 ...>, ...]
|
9
|
+
#
|
10
|
+
# Arguments:
|
11
|
+
# none
|
5
12
|
def self.all
|
6
13
|
result = Tangocard::Raas.rewards_index.parsed_response
|
7
14
|
result['brands'].map{|p| Tangocard::Brand.new(p)}
|
8
15
|
end
|
9
16
|
|
17
|
+
# Return an array of default brands. Must set default_brands in your Tangocard initializer (see README).
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# >> Tangocard::Brand.default_brands
|
21
|
+
# => [#<Tangocard::Brand:0x007f9a6f9d3030 ...>, #<Tangocard::Brand:0x007f9a6f9d3030 ...>, ...]
|
22
|
+
#
|
23
|
+
# Arguments:
|
24
|
+
# none
|
10
25
|
def self.default_brands
|
11
26
|
self.all.select{|b| Tangocard.configuration.default_brands.include?(b.description)}
|
12
27
|
end
|
13
28
|
|
29
|
+
# Find a brand by its :description field.
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# >> Tangocard::Brand.find("Amazon.com")
|
33
|
+
# => #<Tangocard::Brand:0x007f9a6fb076e0 @description="Amazon.com",
|
34
|
+
# @image_url="http://static-integration.tangocard.com/graphics/item-images/amazon-gift-card.png",
|
35
|
+
# @rewards=[#<Tangocard::Reward:0x007f9a6fb07618 @description="Amazon.com Gift Card (Custom)",
|
36
|
+
# @sku="AMZN-E-V-STD", @currency_type="USD", @unit_price=-1, @available=true, @min_price=100,
|
37
|
+
# @max_price=100000>]>
|
38
|
+
#
|
39
|
+
# Arguments:
|
40
|
+
# brand_name: (String)
|
14
41
|
def self.find(brand_name)
|
15
42
|
self.all.select{|b| b.description == brand_name}.first
|
16
43
|
end
|
@@ -21,19 +48,54 @@ class Tangocard::Brand
|
|
21
48
|
@rewards = params['rewards'].map{|p| Tangocard::Reward.new(p)}
|
22
49
|
end
|
23
50
|
|
24
|
-
#
|
51
|
+
# Return the image_url for the brand. For some brands, there is no image_url. You can set :local_images in your
|
52
|
+
# Tangocard initializer to provide a local image for a specified brand. See the README for details.
|
53
|
+
#
|
54
|
+
# Example:
|
55
|
+
# >> amazon_brand.image_url
|
56
|
+
# => "http://static-integration.tangocard.com/graphics/item-images/amazon-gift-card.png"
|
57
|
+
#
|
58
|
+
# Arguments:
|
59
|
+
# none
|
25
60
|
def image_url
|
26
61
|
Tangocard.configuration.local_images[description] || @image_url
|
27
62
|
end
|
28
63
|
|
64
|
+
# Return the rewards that are purchasable given a balance (in cents).
|
65
|
+
#
|
66
|
+
# Example:
|
67
|
+
# >> itunes_brand.purchasable_rewards(1000)
|
68
|
+
# => [#<Tangocard::Reward:0x007f9a6fd29810 @description="iTunes Gift Card $10", @sku="APPL-E-1000-STD",
|
69
|
+
# @currency_type="USD", @unit_price=1000, @available=true, @min_price=0, @max_price=0>]
|
70
|
+
#
|
71
|
+
# Arguments:
|
72
|
+
# balance_in_cents: (Integer)
|
29
73
|
def purchasable_rewards(balance_in_cents)
|
30
74
|
rewards.select{|r| r.purchasable?(balance_in_cents) && !Tangocard.configuration.sku_blacklist.include?(r.sku)}
|
31
75
|
end
|
32
76
|
|
77
|
+
# True if there are any purchasable rewards given a balance in cents, false otherwise.
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
# >> itunes_brand.has_purchasable_rewards?(1000)
|
81
|
+
# => true
|
82
|
+
#
|
83
|
+
# Arguments:
|
84
|
+
# balance_in_cents: (Integer)
|
33
85
|
def has_purchasable_rewards?(balance_in_cents)
|
34
86
|
purchasable_rewards(balance_in_cents).any?
|
35
87
|
end
|
36
88
|
|
89
|
+
# True if this is a brand with variable-price rewards.
|
90
|
+
#
|
91
|
+
# Example:
|
92
|
+
# >> itunes_brand.variable_price?
|
93
|
+
# => false
|
94
|
+
# >> amazon_brand.variable_price?
|
95
|
+
# => true
|
96
|
+
#
|
97
|
+
# Arguments:
|
98
|
+
# none
|
37
99
|
def variable_price?
|
38
100
|
rewards.select{|r| r.variable_price? }.any?
|
39
101
|
end
|
data/lib/tangocard/order.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# Wrapper for Tangocard RaaS Order
|
2
|
-
# https://github.com/tangocarddev/RaaS#order-resources
|
3
1
|
class Tangocard::Order
|
4
2
|
attr_reader :order_id,
|
5
3
|
:account_identifier,
|
@@ -13,29 +11,14 @@ class Tangocard::Order
|
|
13
11
|
|
14
12
|
private_class_method :new
|
15
13
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# "reward_message"=>"testing",
|
25
|
-
# "reward_subject"=>"RaaS Sandbox Test",
|
26
|
-
# "reward_from"=>"Elliott",
|
27
|
-
# "delivered_at"=>"2013-08-15T17:42:18+00:00",
|
28
|
-
# "recipient"=> {
|
29
|
-
# "name"=>"Elliott",
|
30
|
-
# "email"=>"elliott@tangocard.com"
|
31
|
-
# },
|
32
|
-
# "reward"=> {
|
33
|
-
# "token"=>"520d12fa655b54.34581245",
|
34
|
-
# "number"=>"1111111111111256"
|
35
|
-
# }
|
36
|
-
# }
|
37
|
-
#}
|
38
|
-
|
14
|
+
# Return an array of all orders.
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
# >> Tangocard::Order.all
|
18
|
+
# => [#<Tangocard::Order:0x007f9a6c4bca68 ...>, #<Tangocard::Order:0x007f9a6c4bca68 ...>, ...]
|
19
|
+
#
|
20
|
+
# Arguments:
|
21
|
+
# params: (Hash - optional, see https://github.com/tangocarddev/RaaS#retrieve-a-list-of-historical-orders for details)
|
39
22
|
def self.all(params = {})
|
40
23
|
response = Tangocard::Raas.orders_index(params)
|
41
24
|
if response.success?
|
@@ -45,15 +28,31 @@ class Tangocard::Order
|
|
45
28
|
end
|
46
29
|
end
|
47
30
|
|
31
|
+
# Find an order by order_id. Raises Tangocard::OrderNotFoundException on failure.
|
32
|
+
#
|
33
|
+
# Example:
|
34
|
+
# >> Tangocard::Order.find("113-08258652-15")
|
35
|
+
# => #<Tangocard::Order:0x007f9a6e3a90c0 @order_id="113-08258652-15", @account_identifier="ElliottTest", @customer="ElliottTest", @sku="APPL-E-1500-STD", @amount=1500, @reward_message="testing", @reward_subject="RaaS Sandbox Test", @reward_from="Elliott", @delivered_at="2013-08-15T17:42:18+00:00", @recipient={"name"=>"Elliott", "email"=>"elliott@tangocard.com"}, @reward={"token"=>"520d12fa655b54.34581245", "number"=>"1111111111111256"}>
|
36
|
+
#
|
37
|
+
# Arguments:
|
38
|
+
# order_id: (String)
|
48
39
|
def self.find(order_id)
|
49
40
|
response = Tangocard::Raas.show_order({'order_id' => order_id})
|
50
41
|
if response.success?
|
51
42
|
new(response.parsed_response['order'])
|
52
43
|
else
|
53
|
-
raise Tangocard::OrderNotFoundException, "
|
44
|
+
raise Tangocard::OrderNotFoundException, "#{response.error_message}"
|
54
45
|
end
|
55
46
|
end
|
56
47
|
|
48
|
+
# Create a new order. Raises Tangocard::OrderCreateFailedException on failure.
|
49
|
+
#
|
50
|
+
# Example:
|
51
|
+
# >> Tangocard::Order.create(params)
|
52
|
+
# => #<Tangocard::Order:0x007f9a6c4bca68 ...>
|
53
|
+
#
|
54
|
+
# Arguments:
|
55
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#place-an-order for details)
|
57
56
|
def self.create(params)
|
58
57
|
response = Tangocard::Raas.create_order(params)
|
59
58
|
if response.success?
|
data/lib/tangocard/raas.rb
CHANGED
@@ -1,35 +1,87 @@
|
|
1
|
-
# Documentation: https://github.com/tangocarddev/RaaS
|
2
1
|
class Tangocard::Raas
|
3
2
|
include HTTParty
|
4
3
|
base_uri Tangocard.configuration.base_uri
|
5
4
|
|
6
|
-
#
|
5
|
+
# Create a new account. Returns Tangocard::Response object.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# >> Tangocard::Raas.create_account(params)
|
9
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
10
|
+
#
|
11
|
+
# Arguments:
|
12
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#create-a-new-platform-account for details)
|
7
13
|
def self.create_account(params)
|
8
14
|
Tangocard::Response.new(post('/raas/v1/accounts', {:body => params.to_json}.merge(basic_auth_param)))
|
9
15
|
end
|
10
16
|
|
17
|
+
# Gets account details. Returns Tangocard::Response object.
|
18
|
+
#
|
19
|
+
# Example:
|
20
|
+
# >> Tangocard::Raas.show_account(params)
|
21
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
22
|
+
#
|
23
|
+
# Arguments:
|
24
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#get-the-information-for-a-specific-platform-account for details)
|
11
25
|
def self.show_account(params)
|
12
26
|
Tangocard::Response.new(get("/raas/v1/accounts/#{params['customer']}/#{params['identifier']}", basic_auth_param))
|
13
27
|
end
|
14
28
|
|
15
|
-
#
|
29
|
+
# Funds an account. Returns Tangocard::Response object.
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# >> Tangocard::Raas.fund_account(params)
|
33
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
34
|
+
#
|
35
|
+
# Arguments:
|
36
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#fund-a-platforms-account for details)
|
16
37
|
def self.fund_account(params)
|
17
38
|
Tangocard::Response.new(post('/raas/v1/funds', {:body => params.to_json}.merge(basic_auth_param)))
|
18
39
|
end
|
19
40
|
|
41
|
+
# Retrieve all rewards. Returns Tangocard::Response object.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# >> Tangocard::Raas.rewards_index
|
45
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
46
|
+
#
|
47
|
+
# Arguments:
|
48
|
+
# none
|
20
49
|
def self.rewards_index
|
21
50
|
Tangocard::Response.new(get('/raas/v1/rewards', basic_auth_param))
|
22
51
|
end
|
23
52
|
|
24
|
-
#
|
53
|
+
# Create an order. Returns Tangocard::Response object.
|
54
|
+
#
|
55
|
+
# Example:
|
56
|
+
# >> Tangocard::Raas.create_order(params)
|
57
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
58
|
+
#
|
59
|
+
# Arguments:
|
60
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#place-an-order for details)
|
25
61
|
def self.create_order(params)
|
26
62
|
Tangocard::Response.new(post('/raas/v1/orders', {:body => params.to_json}.merge(basic_auth_param)))
|
27
63
|
end
|
28
64
|
|
65
|
+
# Get order details. Returns Tangocard::Response object.
|
66
|
+
#
|
67
|
+
# Example:
|
68
|
+
# >> Tangocard::Raas.show_order(params)
|
69
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
70
|
+
#
|
71
|
+
# Arguments:
|
72
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#retrieve-a-historical-order for details)
|
29
73
|
def self.show_order(params)
|
30
74
|
Tangocard::Response.new(get("/raas/v1/orders/#{params['order_id']}", basic_auth_param))
|
31
75
|
end
|
32
76
|
|
77
|
+
# Retrieve a list of historical orders. Returns Tangocard::Response object.
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
# >> Tangocard::Raas.orders_index
|
81
|
+
# => #<Tangocard::Response:0x007f9a6c4bca68 ...>
|
82
|
+
#
|
83
|
+
# Arguments:
|
84
|
+
# params: (Hash - see https://github.com/tangocarddev/RaaS#retrieve-a-list-of-historical-orders for details)
|
33
85
|
def self.orders_index(params = {})
|
34
86
|
query_string = ""
|
35
87
|
if params.any?
|
data/lib/tangocard/response.rb
CHANGED
data/lib/tangocard/reward.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# Documentation: https://github.com/tangocarddev/RaaS
|
2
1
|
class Tangocard::Reward
|
3
2
|
attr_reader :description, :sku, :currency_type, :unit_price, :available, :min_price, :max_price
|
4
3
|
|
@@ -12,10 +11,28 @@ class Tangocard::Reward
|
|
12
11
|
@max_price = params['max_price'].to_i
|
13
12
|
end
|
14
13
|
|
14
|
+
# Is this a variable-priced reward?
|
15
|
+
#
|
16
|
+
# Example:
|
17
|
+
# >> reward.variable_price?
|
18
|
+
# => true # reward is variable-priced
|
19
|
+
#
|
20
|
+
# Arguments:
|
21
|
+
# none
|
15
22
|
def variable_price?
|
16
23
|
self.unit_price == -1
|
17
24
|
end
|
18
25
|
|
26
|
+
# Is this reward purchasable given a certain number of cents available to purchase it?
|
27
|
+
# True if reward is available and user has enough cents
|
28
|
+
# False if reward is unavailable OR user doesn't have enough cents
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
# >> reward.purchasable?(500)
|
32
|
+
# => true # reward is available and costs <= 500 cents
|
33
|
+
#
|
34
|
+
# Arguments:
|
35
|
+
# balance_in_cents: (Integer)
|
19
36
|
def purchasable?(balance_in_cents)
|
20
37
|
return false unless available
|
21
38
|
|
@@ -26,9 +43,17 @@ class Tangocard::Reward
|
|
26
43
|
end
|
27
44
|
end
|
28
45
|
|
29
|
-
|
46
|
+
# Converts price in cents for given field to Money object using currency_type
|
47
|
+
#
|
48
|
+
# Example:
|
49
|
+
# >> reward.to_money(:unit_price)
|
50
|
+
# => #<Money fractional:5000 currency:USD>
|
51
|
+
#
|
52
|
+
# Arguments:
|
53
|
+
# field_name: (Symbol - must be :min_price, :max_price, or :unit_price)
|
54
|
+
def to_money(field_name)
|
30
55
|
return nil unless [:min_price, :max_price, :unit_price].include?(field_name)
|
31
56
|
|
32
|
-
Money.new(self.send(field_name),
|
57
|
+
Money.new(self.send(field_name), currency_type)
|
33
58
|
end
|
34
59
|
end
|
data/lib/tangocard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tangocard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Crawford-Marks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -89,7 +89,7 @@ files:
|
|
89
89
|
- lib/tangocard.rb
|
90
90
|
- MIT-LICENSE
|
91
91
|
- Rakefile
|
92
|
-
- README.
|
92
|
+
- README.md
|
93
93
|
homepage: http://bonus.ly
|
94
94
|
licenses: []
|
95
95
|
metadata: {}
|
data/README.rdoc
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
= Tangocard
|
2
|
-
|
3
|
-
Ruby Wrapper for Tango Card RaaS API.
|
4
|
-
|
5
|
-
Tango Card provides a RaaS API for developers (https://github.com/tangocarddev/RaaS). This gem provides commonsense Ruby
|
6
|
-
objects to wrap the JSON endpoints of the RaaS API.
|
7
|
-
|
8
|
-
This project is developed and maintained by Smartly, Inc. - makers of http://bonus.ly.
|
9
|
-
|
10
|
-
This project uses the MIT-LICENSE.
|