6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/colombo/request.rb', line 6
def request(method=:get, uri='/', params={}, &block)
params[:client_id] = self.client_id
params[:api_key] = self.api_key
url = self.endpoint + uri
if method.to_sym == :get
params = { :params => params }
params[:client_id] = self.client_id
params[:api_key] = self.api_key
else
url += "?client_id=#{self.client_id}&api_key=#{self.api_key}"
end
response = nil
begin
response = RestClient.send(method, url, params)
rescue => e
$stderr.puts e.inspect
raise
end
response = JSON.parse(response)
if response['status'].to_s.downcase == 'ok'
if block_given?
block.call(response)
return
else
return response
end
end
raise response['error_message']
end
|