Class: Vertpig::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vertpig/client.rb

Constant Summary collapse

HOST =
'https://www.vertpig.com/api/v1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/vertpig/client.rb', line 11

def initialize(attrs = {})
  @key    = attrs[:key]
  @secret = attrs[:secret]
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/vertpig/client.rb', line 9

def key
  @key
end

#secretObject (readonly)

Returns the value of attribute secret.



9
10
11
# File 'lib/vertpig/client.rb', line 9

def secret
  @secret
end

Instance Method Details

#get(path, params = {}, headers = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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