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