6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/itbit/api.rb', line 6
def self.request(verb, path, options = { })
timestamp = (Time.now.to_f * 1000).round.to_s
nonce = timestamp
prefix = Itbit.sandbox ? 'beta-api' : 'api'
payload = options.empty? || verb == :get ? nil : JSON.dump(options)
query = options.any? && verb == :get ? "?#{options.to_query}" : ''
url = "https://#{prefix}.itbit.com/v1#{path}#{query}"
signature = sign_message(verb, url, payload, nonce, timestamp)
= {
authorization: "#{Itbit.client_key}:#{signature}",
x_auth_timestamp: timestamp,
x_auth_nonce: nonce,
content_type: 'application/json'
}
response = RestClient::Request
.execute(:method => verb, :url => url, :payload => payload, :headers => )
JSON.parse(response.to_str) if response.to_str.presence
end
|