Class: Carousel::Client

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

Constant Summary collapse

TEST_HOST =
"web.carousel.eu"
TEST_PATH =
"carouselwms"
LIVE_HOST =
"web.carousel.eu"
LIVE_PATH =
"carouselwms"
PORT =
443

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
# File 'lib/carousel/client.rb', line 15

def initialize(username, password, options = {})
  raise "Username is required" unless username
  raise "Password is required" unless password

  @username = username
  @password = password
  @options  = default_options.merge!(options)
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



13
14
15
# File 'lib/carousel/client.rb', line 13

def password
  @password
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/carousel/client.rb', line 13

def path
  @path
end

#request_uriObject

Returns the value of attribute request_uri.



13
14
15
# File 'lib/carousel/client.rb', line 13

def request_uri
  @request_uri
end

#responseObject

Returns the value of attribute response.



13
14
15
# File 'lib/carousel/client.rb', line 13

def response
  @response
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/carousel/client.rb', line 13

def type
  @type
end

#usernameObject

Returns the value of attribute username.



13
14
15
# File 'lib/carousel/client.rb', line 13

def username
  @username
end

Instance Method Details

#build_path(path) ⇒ Object



41
42
43
# File 'lib/carousel/client.rb', line 41

def build_path(path)
  "/#{env_path}/default.asp#{path}"
end

#get_inventoryObject



30
31
32
33
34
# File 'lib/carousel/client.rb', line 30

def get_inventory
  request = Inventory.new(self).build_inventory_request
  @path   = build_path(Inventory::PATH)
  post(request).response['stock']
end

#mapped_inventory(upcs, inventory) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/carousel/client.rb', line 49

def mapped_inventory(upcs, inventory)
  inventory.collect do |stock| 
    if upcs.include?(stock["stockid"][0])
      { quantity: stock["qty"][0].to_i }
    end
  end.compact
end

#order_request(order) ⇒ Object



36
37
38
39
# File 'lib/carousel/client.rb', line 36

def order_request(order)
  @path = build_path(Order::PATH)
  Order.new(self).build_order_request(order)
end

#send_order_request(order) ⇒ Object



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

def send_order_request(order)
  request  = order_request(order)
  @path    = build_path(Order::PATH)
  post(request)
end

#upcs(inventory) ⇒ Object



45
46
47
# File 'lib/carousel/client.rb', line 45

def upcs(inventory)
  inventory.collect { |s| s["stockid"][0] }
end