Class: Trebbianno::Client
- Inherits:
-
Object
- Object
- Trebbianno::Client
- Defined in:
- lib/trebbianno/client.rb
Constant Summary collapse
- TEST_HOST =
"54.235.241.72"- LIVE_HOST =
"54.235.241.72"- PORT =
4081- KEYS_MAP =
{ "stockid" => "upc" }
Instance Attribute Summary collapse
-
#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
- #get_inventory ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Client
constructor
A new instance of Client.
- #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.
14 15 16 17 18 19 20 21 |
# File 'lib/trebbianno/client.rb', line 14 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
#password ⇒ Object
Returns the value of attribute password.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def path @path end |
#request_uri ⇒ Object
Returns the value of attribute request_uri.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def request_uri @request_uri end |
#response ⇒ Object
Returns the value of attribute response.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def response @response end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def type @type end |
#username ⇒ Object
Returns the value of attribute username.
12 13 14 |
# File 'lib/trebbianno/client.rb', line 12 def username @username end |
Instance Method Details
#get_inventory ⇒ Object
29 30 31 32 33 |
# File 'lib/trebbianno/client.rb', line 29 def get_inventory request = Inventory.new(self).build_inventory_request @path = Inventory::PATH map_results(post(request).response['stock']) end |
#mapped_inventory(upcs, inventory) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/trebbianno/client.rb', line 44 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
35 36 37 38 |
# File 'lib/trebbianno/client.rb', line 35 def order_request(order) @path = Order::PATH Order.new(self).build_order_request(order) end |
#send_order_request(order) ⇒ Object
23 24 25 26 27 |
# File 'lib/trebbianno/client.rb', line 23 def send_order_request(order) request = order_request(order) @path = Order::PATH post(request) end |
#upcs(inventory) ⇒ Object
40 41 42 |
# File 'lib/trebbianno/client.rb', line 40 def upcs(inventory) inventory.collect { |s| s["upc"] } end |