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
|
# File 'lib/smartcoin/shipping.rb', line 6
def self.calculator(params)
method = :get
url = BASE_SHIPPING_URL + '/shipping_calculator/'
begin
response = RestClient::Request.new(
method: method,
url: url,
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).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
end
|