Class: Tazapay::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/tazapay/client.rb
Overview
Instance Method Summary
collapse
Instance Method Details
#handle_error(response_body, response_code) ⇒ Object
31
32
33
|
# File 'lib/tazapay/client.rb', line 31
def handle_error(response_body, response_code)
raise Tazapay::Error.new(response_body, response_code)
end
|
#interpret_response(resp) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/tazapay/client.rb', line 21
def interpret_response(resp)
body = resp.body.empty? ? "" : JSON.parse(resp.body)
response = {
body: body,
code: resp.status
}
handle_error(response[:body], response[:code]) unless resp.status >= 200 && resp.status < 300
body
end
|
#send_request(method:, path:, headers: default_headers, body: {}) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/tazapay/client.rb', line 11
def send_request(method:, path:, headers: , body: {})
conn = prepare_connection()
case method.to_s
when "get" then response = conn.get(path)
when "post" then response = conn.post(path, body.to_json)
when "put" then response = conn.put(path, body.to_json)
end
interpret_response(response)
end
|