Class: Api2cart::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/api2cart/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, store_key, proxy: nil) ⇒ Store

Returns a new instance of Store.



5
6
7
8
9
# File 'lib/api2cart/store.rb', line 5

def initialize(api_key, store_key, proxy: nil)
  self.api_key = api_key
  self.store_key = store_key
  self.proxy = proxy
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/api2cart/store.rb', line 11

def method_missing(method_name, *args)
  request_url = RequestUrlComposer.new(api_key, store_key, method_name, args.first).compose_request_url

  api2cart_client = Client.new(request_url, proxy)
  api2cart_client.make_request!

  if api2cart_client.successful?
    api2cart_client.result
  else
    raise api2cart_client.error_message
  end
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/api2cart/store.rb', line 3

def api_key
  @api_key
end

#proxyObject

Returns the value of attribute proxy.



3
4
5
# File 'lib/api2cart/store.rb', line 3

def proxy
  @proxy
end

#store_keyObject

Returns the value of attribute store_key.



3
4
5
# File 'lib/api2cart/store.rb', line 3

def store_key
  @store_key
end