Class: Delivery::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/delivery/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
# File 'lib/delivery/client.rb', line 11

def initialize(client_id, options={})
  @client_id = client_id

  options[:base_uri] ||= 'https://api.delivery.com'
  @base_uri = options[:base_uri]
end

Instance Attribute Details

#base_uriObject

Returns the value of attribute base_uri.



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

def base_uri
  @base_uri
end

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

Instance Method Details

#info(id) ⇒ Object



24
25
26
27
28
# File 'lib/delivery/client.rb', line 24

def info id
  options = {query: {client_id: client_id}}
  response = self.class.get("#{base_uri}/merchant/#{id}", options)
  Hashie::Mash.new(JSON.parse(response.body))
end

#search(address) ⇒ Object



18
19
20
21
22
# File 'lib/delivery/client.rb', line 18

def search address
  options = {query: {client_id: client_id, address: address}}
  response = self.class.get("#{base_uri}/merchant/search/delivery", options)
  Hashie::Mash.new(JSON.parse(response.body))
end