Class: Blastramp::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/blastramp/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vendor_code, vendor_access_key) ⇒ Session

Returns a new instance of Session.



6
7
8
9
10
# File 'lib/blastramp/session.rb', line 6

def initialize(vendor_code, vendor_access_key)
  self.vendor_code = vendor_code
  self.vendor_access_key = vendor_access_key
  self.endpoint = nil
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



4
5
6
# File 'lib/blastramp/session.rb', line 4

def endpoint
  @endpoint
end

#vendor_access_keyObject

Returns the value of attribute vendor_access_key.



3
4
5
# File 'lib/blastramp/session.rb', line 3

def vendor_access_key
  @vendor_access_key
end

#vendor_codeObject

Returns the value of attribute vendor_code.



3
4
5
# File 'lib/blastramp/session.rb', line 3

def vendor_code
  @vendor_code
end

Instance Method Details

#clientObject

Returns the Savon::Client used to connect to Blastramp



13
14
15
16
17
# File 'lib/blastramp/session.rb', line 13

def client      
  @client ||= Savon::Client.new do
    wsdl.document = self.endpoint
  end
end

#inventory_countsObject

Provides access to the inventory counts



20
21
22
# File 'lib/blastramp/session.rb', line 20

def inventory_counts
  @inventory_counts ||= InventoryCountQuery.new(self)
end

#request(ep, action, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blastramp/session.rb', line 24

def request(ep, action, &block)
  self.endpoint = ep
  response = client.request :soap, action, &block
  response_hash = response.to_hash
  action = action.snake_case
  response_key = "#{action}_response".intern
  result_key = "#{action}_result".intern

  if response_hash[response_key] && response_hash[response_key][result_key]
    response_hash[response_key][result_key]
  else
    {}
  end
end