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
46
47
48
49
50
|
# File 'lib/smartcoin/api_resource.rb', line 14
def api_request(url, method, params=nil)
url = "#{BASE_URL}#{url}"
if method == :get && params
params_encoded = encode(params)
url = "#{url}?#{params_encoded}"
params = nil
end
access_keys = SmartCoin.access_keys.split(':')
api_key = access_keys[0]
api_secret = access_keys[1]
begin
response = RestClient::Request.new(
method: method,
url: url,
user: api_key,
password: api_secret,
payload: params,
headers: { accept: :json,
content_type: :json },
verify_ssl: OpenSSL::SSL::VERIFY_PEER,
ssl_ca_file: SSL_BUNDLE_PATH
).execute
rescue RestClient::ExceptionWithResponse => e
if rcode = e.http_code and rbody = e.http_body
rbody = JSON.parse(rbody)
rbody = Util.symbolize_names(rbody)
raise SmartCoinError.new(rcode, rbody, rbody[:error], rbody[:error][:message])
else
raise e
end
rescue RestClient::Exception => e
raise e
end
JSON.parse(response.to_str)
end
|