8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/billy_api/client.rb', line 8
def self.request(request_method, url, id = nil, payload = {}, &block)
url = "#{url}/#{id}" if request_method == :get && !id.nil?
response = RestClient::Request.execute(
{
method: request_method,
url: BASE_URL + url,
headers: {
'X-Access-Token' => BillyApi.configuration.api_key,
'Content-Type' => 'application/json'
}
}.merge(request_method == :get ? {} : { payload: MultiJson.dump(payload) })
)
if block_given?
yield MultiJson.load(response.body)
else
return MultiJson.load(response.body)
end
rescue RuntimeError => e puts e.response.body
raise e
end
|