Module: White
- Includes:
- HTTParty
- Defined in:
- lib/white.rb,
lib/white/charge.rb,
lib/white/version.rb,
lib/white/errors/white_error.rb,
lib/white/errors/banking_error.rb,
lib/white/errors/request_error.rb,
lib/white/errors/processing_error.rb,
lib/white/errors/authentication_error.rb
Defined Under Namespace
Classes: AuthenticationError, BankingError, Charge, ProcessingError, RequestError, WhiteError
Constant Summary
collapse
- VERSION =
'2.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
62
63
64
|
# File 'lib/white.rb', line 62
def api_key
@api_key
end
|
Class Method Details
.api_url(url = '') ⇒ Object
15
16
17
|
# File 'lib/white.rb', line 15
def self.api_url(url='')
@api_base + url
end
|
.get(url, query = {}) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/white.rb', line 54
def self.get(url, query={})
options = {basic_auth: {username: api_key, password: ''}}
options.merge!({query: query})
response = HTTParty.get(url, options)
JSON.parse(response.body);
end
|
.handle_response(response) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/white.rb', line 19
def self.handle_response(response)
body = JSON.parse(response.body);
if response.code.between?(200, 299) and !body.key?('error')
return body
end
case body['error']['type']
when 'banking'
raise White::BankingError.new(body['error']['message'], body['error']['code'], response.code)
when 'authentication'
raise White::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
when 'processing'
raise White::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
when 'request'
raise White::RequestError.new(body['error']['message'], body['error']['code'], response.code)
end
raise White::WhiteError.new(body['error']['message'], body['error']['code'], response.code)
end
|
.post(url, body = {}) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/white.rb', line 46
def self.post(url, body={})
options = {basic_auth: {username: api_key, password: ''}}
options.merge!({body: body})
response = HTTParty.post(url, options)
self.handle_response(response)
end
|