Class: SynergyWholesale::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/synergy_wholesale/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapter

Returns a new instance of Adapter.



8
9
10
11
12
13
# File 'lib/synergy_wholesale/adapter.rb', line 8

def initialize
  @client = Savon.client(
    wsdl:       SynergyWholesale.wsdl_path,
    namespaces: { 'xmlns:enc' => 'http://schemas.xmlsoap.org/soap/encoding/' }
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/synergy_wholesale/adapter.rb', line 6

def client
  @client
end

Instance Method Details

#add_param(key, value) ⇒ Object



15
16
17
# File 'lib/synergy_wholesale/adapter.rb', line 15

def add_param(key, value)
  params[key] = value
end

#add_params(*params) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/synergy_wholesale/adapter.rb', line 19

def add_params(*params)
  return if params.blank?

  if params.size == 1 && params.first.is_a?(Hash)
    params.first.each { |key, value| add_param key, value }
  else
    raise 'params are required to be key/value combinations'
  end
end

#call(action) ⇒ Object



36
37
38
# File 'lib/synergy_wholesale/adapter.rb', line 36

def call(action)
  client.call(action, message: { request: params })
end

#paramsObject



29
30
31
32
33
34
# File 'lib/synergy_wholesale/adapter.rb', line 29

def params
  @params ||= {
    'resellerID' => SynergyWholesale.reseller_id,
    'apiKey'     => SynergyWholesale.api_key
  }
end