Class: Scene7::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/scene7/client.rb

Constant Summary collapse

CONFIG_FIELDS =
[:subdomain, :user, :password, :app_name, :app_version].freeze
NAMESPACE =
"http://www.scene7.com/IpsApi/xsd/2010-01-31"

Class Method Summary collapse

Class Method Details

.clientObject



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

def client
  Savon::Client.new do
    wsdl.namespace = NAMESPACE
    wsdl.endpoint  = configuration.endpoint
  end
end

.company_handleObject



47
48
49
# File 'lib/scene7/client.rb', line 47

def company_handle
  @@company_handle ||= Company.find_by_name(configuration.app_name).handle
end

.configure(options) ⇒ Object



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

def configure(options)
  params = CONFIG_FIELDS.map { |field| options[field] }

  @@configuration = Config.new(*params)

  self
end

.headerObject



39
40
41
42
43
44
45
# File 'lib/scene7/client.rb', line 39

def header
  if configuration.blank?
    raise 'Call Scene7::Client.configure with your configuration first.'
  else
    configuration.header
  end
end

.input_for_action(action) ⇒ Object



51
52
53
# File 'lib/scene7/client.rb', line 51

def input_for_action(action)
  action.to_s.camelize(:lower) + 'Param'
end

.perform_request(action, body_params) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/scene7/client.rb', line 31

def perform_request(action, body_params)
  client.request(:ns, action) do
    soap.input  = [input_for_action(action), {:xmlns => "http://www.scene7.com/IpsApi/xsd/2010-01-31" }]
    soap.header = header
    soap.body   = body_params
  end
end

.reset_configurationObject



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

def reset_configuration
  @@configuration = nil
  @@company_handle = nil
end