Class: Payassist::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/payassist/client.rb
Overview
Instance Method Summary
collapse
Instance Method Details
#handle_error(response_body, response_code) ⇒ Object
36
37
38
|
# File 'lib/payassist/client.rb', line 36
def handle_error(response_body, response_code)
raise Payassist::Error.new(response_body, response_code)
end
|
#interpret_response(resp) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/payassist/client.rb', line 26
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(path:, headers: {}, body: {}, method: :post) ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/payassist/client.rb', line 16
def send_request(path:, headers: {}, body: {}, method: :post)
conn = faraday_with_block(url: Payassist.config.base_url)
conn. = ()
case method.to_s
when "get" then response = conn.get(path, body)
when "post" then response = conn.post(path, body.to_json)
end
interpret_response(response)
end
|