Class: Carousel::Client
- Inherits:
-
Object
- Object
- Carousel::Client
- 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
- KEYS_MAP =
{ "stockid" => "upc" }
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#password ⇒ Object
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
-
#request_uri ⇒ Object
Returns the value of attribute request_uri.
-
#response ⇒ Object
Returns the value of attribute response.
-
#type ⇒ Object
Returns the value of attribute type.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #build_path(path) ⇒ Object
- #get_inventory ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#inventory_response(request) ⇒ Object
gets the raw inventory response from the provider then converts provider specific language to match a uniform API, stored on @response, and returns.
- #mapped_inventory(upcs, inventory) ⇒ Object
- #order_request(order) ⇒ Object
- #send_order_request(order) ⇒ Object
- #upcs(inventory) ⇒ Object
Constructor Details
#initialize(username, password, options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 |
# File 'lib/carousel/client.rb', line 16 def initialize(username, password, = {}) raise "Username is required" unless username raise "Password is required" unless password @username = username @password = password @options = .merge!() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def @options end |
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def path @path end |
#request_uri ⇒ Object
Returns the value of attribute request_uri.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def request_uri @request_uri end |
#response ⇒ Object
Returns the value of attribute response.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def response @response end |
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def type @type end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/carousel/client.rb', line 14 def username @username end |
Instance Method Details
#build_path(path) ⇒ Object
50 51 52 |
# File 'lib/carousel/client.rb', line 50 def build_path(path) "/#{env_path}/default.asp#{path}" end |
#get_inventory ⇒ Object
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) inventory_response(request) end |
#inventory_response(request) ⇒ Object
gets the raw inventory response from the provider then converts provider specific language to match a uniform API, stored on @response, and returns
39 40 41 42 43 |
# File 'lib/carousel/client.rb', line 39 def inventory_response(request) response = post(request) response.response = map_results(response.response['stock']) response end |
#mapped_inventory(upcs, inventory) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/carousel/client.rb', line 58 def mapped_inventory(upcs, inventory) inventory.collect do |stock| if upcs.include?(stock["upc"]) { quantity: stock["qty"].to_i } end end.compact end |
#order_request(order) ⇒ Object
45 46 47 48 |
# File 'lib/carousel/client.rb', line 45 def order_request(order) @path = build_path(Order::PATH) Order.new(self).build_order_request(order) end |
#send_order_request(order) ⇒ Object
25 26 27 28 |
# File 'lib/carousel/client.rb', line 25 def send_order_request(order) request = order_request(order) post(request) end |
#upcs(inventory) ⇒ Object
54 55 56 |
# File 'lib/carousel/client.rb', line 54 def upcs(inventory) inventory.collect { |s| s["upc"] } end |