Class: Lomadee::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/lomadee/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(application_id, sandbox = false, country = "BR") ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lomadee/base.rb', line 5

def initialize(application_id, sandbox = false, country = "BR")
  raise "You need to inform your :application_id" if application_id.nil?

  @env = (sandbox) ? 'sandbox' : 'bws'
  @country = country

  @application_id = application_id

  @uris = {
    :offers => "findOfferList",
    :products => "findProductList",
    :categories => "findCategoryList",
    :create_link => "createLinks"
  }

  @params = {
    :category => "categoryId",
    :product => "productId",
    :barcode => "barcode",
    :keyword => "keyword"
  }

  @data = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



32
33
34
35
36
37
38
39
40
# File 'lib/lomadee/base.rb', line 32

def method_missing(method, *args, &block)
  if @uris.map {|v, k| v }.include? method
    @data.merge!(args[0])
    fetch_api(method)
  else
    @data.merge!({method => args[0]})
    self
  end
end