Class: Trebbianno::Client

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

Constant Summary collapse

TEST_HOST =
"54.235.241.72"
LIVE_HOST =
"54.235.241.72"
PORT =
4081

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



13
14
15
16
17
18
19
20
# File 'lib/trebbianno/client.rb', line 13

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.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def password
  @password
end

#pathObject

Returns the value of attribute path.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def path
  @path
end

#request_uriObject

Returns the value of attribute request_uri.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def request_uri
  @request_uri
end

#responseObject

Returns the value of attribute response.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def response
  @response
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def type
  @type
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/trebbianno/client.rb', line 11

def username
  @username
end

Instance Method Details

#get_inventoryObject



28
29
30
31
32
# File 'lib/trebbianno/client.rb', line 28

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

#mapped_inventory(upcs, inventory) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/trebbianno/client.rb', line 43

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



34
35
36
37
# File 'lib/trebbianno/client.rb', line 34

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

#send_order_request(order) ⇒ Object



22
23
24
25
26
# File 'lib/trebbianno/client.rb', line 22

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

#upcs(inventory) ⇒ Object



39
40
41
# File 'lib/trebbianno/client.rb', line 39

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