Class: Gyftwrapper::API

Inherits:
Object
  • Object
show all
Includes:
Resultable
Defined in:
lib/gyftwrapper/api.rb

Constant Summary collapse

CALLS =
{
  purchase_card: '/reseller/purchase/card',
  get_merchants: '/reseller/merchants'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

Returns a new instance of API.



20
21
22
23
# File 'lib/gyftwrapper/api.rb', line 20

def initialize
  self.result = Result.new
  self.config = parse_config_file
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/gyftwrapper/api.rb', line 18

def config
  @config
end

#resultObject

Returns the value of attribute result.



18
19
20
# File 'lib/gyftwrapper/api.rb', line 18

def result
  @result
end

Instance Method Details

#get_merchantsObject



33
34
35
36
37
38
# File 'lib/gyftwrapper/api.rb', line 33

def get_merchants
  send_request do
    response = RestClient.get(url_for(:get_merchants), 'x-sig-timestamp' => timestamp)
    self.result = JSON.parse(response)['details'].map{|m| OpenStruct.new(m)}
  end
end

#purchase_card(params) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/gyftwrapper/api.rb', line 25

def purchase_card(params)
  send_request do
    response = RestClient.post(url_for(:purchase_card), params.merge(default_params), 'x-sig-timestamp' => timestamp)
    self.result.response = OpenStruct.new(JSON.parse(response))
    self.result.successful!
  end
end