class Vertpig::Client
Constants
- HOST
Attributes
key[R]
secret[R]
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/vertpig/client.rb, line 11 def initialize(attrs = {}) @key = attrs[:key] @secret = attrs[:secret] end
Public Instance Methods
get(path, params = {}, headers = {})
click to toggle source
# File lib/vertpig/client.rb, line 16 def get(path, params = {}, headers = {}) nonce = Time.now.to_i response = connection.get do |req| url = "#{HOST}/#{path}" req.params.merge!(params) req.url(url) if key req.params[:apikey] = key req.params[:nonce] = nonce req.headers[:apisign] = signature( connection.build_exclusive_url(req.path, req.params), nonce) end end JSON.parse(response.body)['result'] end
Private Instance Methods
connection()
click to toggle source
# File lib/vertpig/client.rb, line 39 def connection @connection ||= Faraday.new(:url => HOST) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end
signature(url, nonce)
click to toggle source
# File lib/vertpig/client.rb, line 35 def signature(url, nonce) OpenSSL::HMAC.hexdigest('sha512', secret, "#{url}") end