5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/xotelia/connection.rb', line 5
def call_api(call_type, call_method, json_data = nil)
json_data_converted = json_data ? json_data.to_json : ''
endpoint = "/api/#{call_method}"
conn = Faraday.new(:url => URL) do |faraday|
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end
response = conn.send(call_type) do |req|
req.url endpoint
req.['Content-Type'] = 'application/json'
req.['Authorization'] = "Bearer #{self.api_token}"
req.body = json_data_converted if req.method == :post
end
JSON.parse(response.body)
end
|