tangocard 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ac03de16035232e603b426c59ccd6224e782122
4
- data.tar.gz: de61de3f8a4a361274a3a7689382b69f28972a94
3
+ metadata.gz: 7f7d4ed6be48184c160a1fdba063b0a4927dce67
4
+ data.tar.gz: eab7f8d2e7558c42e1fc45f5a110eb2f52fe6457
5
5
  SHA512:
6
- metadata.gz: d736487bb1c755343ba712a77eccc2db7de51036dc5eb73f40b8a913827a811db4baba37fa3c516e1b90ecc224eb89087cb9810e3cff7e63756b1cb977d74143
7
- data.tar.gz: 6dde06d834effdbe683bdcbcb32d52a98175388e7a0b710a743bd57bcfdb9bbc6ef374cd8e0ee28887a501da5296909006ae8b21a73618e96b5e2b945cc050dc
6
+ metadata.gz: 232120b85c5a52108958f0534abda04c4069cb07c7d489a7cfb227eb81071207b0767528c481c1da34b7a265fe081daf7aa265ec67faf36c3119926254c2bfec
7
+ data.tar.gz: 1a7d9eecaf0a0ca4b0d39a08169061c31f5dc7ebe42accd322f66cc7e25dff1dcbe3498df486eff127bce04ce7aa1a0d44d872c6023f72981884b13c9b8e28da
@@ -20,7 +20,7 @@ module Tangocard
20
20
  end
21
21
 
22
22
  def self.configuration
23
- @configuration ||= Configuration.new
23
+ @configuration ||= Configuration.new
24
24
  end
25
25
 
26
26
  def self.configure
@@ -40,5 +40,7 @@ require 'tangocard/brand'
40
40
  require 'tangocard/order'
41
41
  require 'tangocard/order_create_failed_exception'
42
42
  require 'tangocard/order_not_found_exception'
43
+ require 'tangocard/raas_exception'
43
44
  require 'tangocard/reward'
44
45
  require 'tangocard/exchange_rate'
46
+
@@ -22,7 +22,9 @@ class Tangocard::Brand
22
22
  # Arguments:
23
23
  # none
24
24
  def self.all
25
- Tangocard::Raas.rewards_index.parsed_response['brands'].map{|p| Tangocard::Brand.new(p)}
25
+ rewards_index = Tangocard::Raas.rewards_index
26
+ raise Tangocard::RaasException.new("Tangocard error with response code #{rewards_index.code}") unless rewards_index.success?
27
+ rewards_index.parsed_response['brands'].map{|p| Tangocard::Brand.new(p)}
26
28
  end
27
29
 
28
30
  # Find a brand by its :description field.
@@ -12,7 +12,7 @@ class Tangocard::Raas
12
12
  # Arguments:
13
13
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-account for details)
14
14
  def self.create_account(params)
15
- Tangocard::Response.new(post(endpoint + '/accounts', {:body => params.to_json}.merge(basic_auth_param)))
15
+ Tangocard::Response.new(post_request('/accounts', { body: params.to_json }))
16
16
  end
17
17
 
18
18
  # Gets account details. Returns Tangocard::Response object.
@@ -24,7 +24,7 @@ class Tangocard::Raas
24
24
  # Arguments:
25
25
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#get-account for details)
26
26
  def self.show_account(params)
27
- Tangocard::Response.new(get(endpoint + "/accounts/#{params['customer']}/#{params['identifier']}", basic_auth_param))
27
+ Tangocard::Response.new(get_request("/accounts/#{params['customer']}/#{params['identifier']}"))
28
28
  end
29
29
 
30
30
  # Funds an account. Returns Tangocard::Response object.
@@ -36,7 +36,7 @@ class Tangocard::Raas
36
36
  # Arguments:
37
37
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-fund for details)
38
38
  def self.cc_fund_account(params)
39
- Tangocard::Response.new(post(endpoint + '/cc_fund', {:body => params.to_json}.merge(basic_auth_param)))
39
+ Tangocard::Response.new(post_request('/cc_fund', { body: params.to_json }))
40
40
  end
41
41
 
42
42
  # Registers a credit card to an account. Returns Tangocard::Response object.
@@ -48,7 +48,7 @@ class Tangocard::Raas
48
48
  # Arguments:
49
49
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-registration for details)
50
50
  def self.register_credit_card(params)
51
- Tangocard::Response.new(post(endpoint + '/cc_register', {:body => params.to_json}.merge(basic_auth_param)))
51
+ Tangocard::Response.new(post_request('/cc_register', { body: params.to_json }))
52
52
  end
53
53
 
54
54
  # Deletes a credit card from an account. Returns Tangocard::Response object.
@@ -60,7 +60,7 @@ class Tangocard::Raas
60
60
  # Arguments:
61
61
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-cc-un-registration for details)
62
62
  def self.delete_credit_card(params)
63
- Tangocard::Response.new(post(endpoint + '/cc_unregister', {:body => params.to_json}.merge(basic_auth_param)))
63
+ Tangocard::Response.new(post_request('/cc_unregister', { body: params.to_json }))
64
64
  end
65
65
 
66
66
  # Retrieve all rewards. Returns Tangocard::Response object.
@@ -75,11 +75,11 @@ class Tangocard::Raas
75
75
  if Tangocard.configuration.use_cache
76
76
  clear_cache! if cache_expired?
77
77
 
78
- @@rewards_response ||= Tangocard::Response.new(get(endpoint + '/rewards', basic_auth_param))
78
+ @@rewards_response ||= Tangocard::Response.new(get_request('/rewards'))
79
79
  @@rewards_response_expires_at = (Time.now.to_i + Tangocard.configuration.cache_ttl) if cache_expired?
80
80
  @@rewards_response
81
81
  else
82
- Tangocard::Response.new(get(endpoint + '/rewards', basic_auth_param))
82
+ Tangocard::Response.new(get_request('/rewards'))
83
83
  end
84
84
  end
85
85
 
@@ -92,7 +92,7 @@ class Tangocard::Raas
92
92
  # Arguments:
93
93
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#create-order for details)
94
94
  def self.create_order(params)
95
- Tangocard::Response.new(post(endpoint + '/orders', {:body => params.to_json}.merge(basic_auth_param)))
95
+ Tangocard::Response.new(post_request('/orders', { body: params.to_json }))
96
96
  end
97
97
 
98
98
  # Get order details. Returns Tangocard::Response object.
@@ -104,7 +104,7 @@ class Tangocard::Raas
104
104
  # Arguments:
105
105
  # params: (Hash - see https://www.tangocard.com/docs/raas-api/#get-order for details)
106
106
  def self.show_order(params)
107
- Tangocard::Response.new(get(endpoint + "/orders/#{params['order_id']}", basic_auth_param))
107
+ Tangocard::Response.new(get_request("/orders/#{params['order_id']}"))
108
108
  end
109
109
 
110
110
  # Retrieve a list of historical orders. Returns Tangocard::Response object.
@@ -119,12 +119,12 @@ class Tangocard::Raas
119
119
  query_string = ""
120
120
  if params.any?
121
121
  query_string = "?"
122
- params.keys.each_with_index do |k,i|
122
+ params.keys.each_with_index do |k, i|
123
123
  query_string += "&" unless i == 0
124
124
  query_string += "#{k}=#{params[k]}"
125
125
  end
126
126
  end
127
- Tangocard::Response.new(get(endpoint + "/orders#{query_string}", basic_auth_param))
127
+ Tangocard::Response.new(get_request("/orders#{query_string}"))
128
128
  end
129
129
 
130
130
  def self.clear_cache!
@@ -135,7 +135,7 @@ class Tangocard::Raas
135
135
  private
136
136
 
137
137
  def self.basic_auth_param
138
- {:basic_auth => {:username => Tangocard.configuration.name, :password => Tangocard.configuration.key}}
138
+ { basic_auth: { username: Tangocard.configuration.name, password: Tangocard.configuration.key } }
139
139
  end
140
140
 
141
141
  def self.use_cache_ttl?
@@ -147,6 +147,14 @@ class Tangocard::Raas
147
147
  end
148
148
 
149
149
  def self.endpoint
150
- Tangocard.configuration.base_uri + '/raas/v1.1'
150
+ "#{Tangocard.configuration.base_uri}/raas/v1.1"
151
+ end
152
+
153
+ def self.get_request(path)
154
+ get("#{endpoint}#{path}", basic_auth_param)
155
+ end
156
+
157
+ def self.post_request(path, params)
158
+ post("#{endpoint}#{path}", basic_auth_param.merge(params))
151
159
  end
152
160
  end
@@ -0,0 +1,2 @@
1
+ class Tangocard::RaasException < StandardError
2
+ end
@@ -7,22 +7,28 @@ class Tangocard::Response
7
7
  end
8
8
 
9
9
  def success?
10
- parsed_response['success'] rescue false
10
+ safe_response['success'] || false
11
11
  end
12
12
 
13
13
  def error_message
14
- parsed_response['error_message'] rescue 'UNKNOWN ERROR MESSAGE'
14
+ safe_response['error_message']
15
15
  end
16
16
 
17
17
  def denial_message
18
- parsed_response['denial_message'] rescue 'UNKNOWN DENIAL MESSSAGE'
18
+ safe_response['denial_message']
19
19
  end
20
20
 
21
21
  def denial_code
22
- parsed_response['denial_code'] rescue 'UNKNOWN DENIAL CODE'
22
+ safe_response['denial_code']
23
23
  end
24
24
 
25
25
  def invalid_inputs
26
- parsed_response['invalid_inputs'] rescue 'UNKNOWN INVALID INPUTS'
26
+ safe_response['invalid_inputs']
27
+ end
28
+
29
+ private
30
+
31
+ def safe_response
32
+ parsed_response || {}
27
33
  end
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Tangocard
2
- VERSION = '6.1.0'
2
+ VERSION = '6.2.0'
3
3
  end
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: 6.1.0
4
+ version: 6.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: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -56,28 +56,14 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.14'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.14'
69
- - !ruby/object:Gem::Dependency
70
- name: rr
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  description: |-
@@ -105,6 +91,7 @@ files:
105
91
  - lib/tangocard/order_create_failed_exception.rb
106
92
  - lib/tangocard/order_not_found_exception.rb
107
93
  - lib/tangocard/raas.rb
94
+ - lib/tangocard/raas_exception.rb
108
95
  - lib/tangocard/response.rb
109
96
  - lib/tangocard/reward.rb
110
97
  - lib/tangocard/version.rb
@@ -132,3 +119,4 @@ signing_key:
132
119
  specification_version: 4
133
120
  summary: Ruby Wrapper for Tango Card RaaS API.
134
121
  test_files: []
122
+ has_rdoc: