Module: CoinGate
- Defined in:
- lib/coingate.rb,
lib/coingate/version.rb,
lib/coingate/api_error.rb,
lib/coingate/error_handler.rb
Defined Under Namespace
Modules: Merchant
Classes: APIError, AuthTokenMissing, BadAuthToken, BadEnvironment, BadRequest, InternalServerError, NotFound, OrderIsNotValid, OrderNotFound, PageNotFound, RateLimitException, RecordNotFound, Unauthorized, UnprocessableEntity
Constant Summary
collapse
- VERSION =
'2.0.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.auth_token ⇒ Object
Returns the value of attribute auth_token.
15
16
17
|
# File 'lib/coingate.rb', line 15
def auth_token
@auth_token
end
|
.environment ⇒ Object
Returns the value of attribute environment.
15
16
17
|
# File 'lib/coingate.rb', line 15
def environment
@environment
end
|
Class Method Details
.api_request(url, request_method = :post, params = {}, authentication = {}) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/coingate.rb', line 21
def api_request(url, request_method = :post, params = {}, authentication = {})
auth_token = authentication[:auth_token] || self.auth_token
environment = authentication[:environment] || self.environment || 'live'
if auth_token.nil?
CoinGate.raise_error(400, {'reason' => 'AuthTokenMissing'})
end
environments = %w(live sandbox)
unless environments.include?(environment)
CoinGate.raise_error(400, {'reason' => 'BadEnvironment', 'message' => "Environment does not exist. Available environments: #{environments.join(', ')}"})
end
url = (
case environment
when 'sandbox'
'https://api-sandbox.coingate.com/v2'
else
'https://api.coingate.com/v2'
end) + url
= {
Authorization: "Token #{auth_token}"
}
begin
response = case request_method
when :get
RestClient.get(url, )
when :post
RestClient.post(url, params, .merge('Content-Type' => 'application/x-www-form-urlencoded'))
end
[response.code, JSON.parse(response.to_str)]
rescue => e
response = begin
JSON.parse(e.response)
rescue
{'reason' => nil, 'message' => e.response}
end
CoinGate.raise_error(e.http_code, response)
end
end
|
.config {|_self| ... } ⇒ Object
17
18
19
|
# File 'lib/coingate.rb', line 17
def config
yield self
end
|
2
3
4
|
# File 'lib/coingate/error_handler.rb', line 2
def self.format_error(error)
"#{error['reason']} #{error['message']}"
end
|
.raise_error(http_code, error = {}) ⇒ Object