Module: WeighflowCli::OrderHandler

Defined in:
lib/weighflow_cli/order_handler.rb

Defined Under Namespace

Modules: Handlers Classes: Finder, OrderRepository

Class Method Summary collapse

Class Method Details

.find_order(external_id) ⇒ Object

Find a single order with details from the stored repository



42
43
44
45
# File 'lib/weighflow_cli/order_handler.rb', line 42

def self.find_order(external_id)
  finder = Finder.new
  finder.find_order(external_id)
end

.list(indexes_only: false) ⇒ Object

List all orders currently in stored repository



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/weighflow_cli/order_handler.rb', line 53

def self.list(indexes_only: false)
  result = []
  finder = Finder.new
  finder.for_each_index do |index|             
    if indexes_only
      result << index.index
    else
      result << index.data
    end
  end
  result
end

.pullObject

Pull order data from Weighflow and store in local repository



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/weighflow_cli/order_handler.rb', line 10

def self.pull
  ##
  # api methods to collect orders
  method_names = [:commodity_outbound_truck, 
                  :commodity_inbound_truck,
                  :bulk_inventory_outbound_truck, 
                  :bulk_inventory_inbound_truck]
  #
  # collect orders using threads
  results = threaded_api_query(method_names)
  #
  # flatten order array of hashes       
  orders = results.map { |orders| orders[:orders] }.flatten 
  #
  # Store in repository
  diff = OrderRepository.new(orders)      
  diff.perform      
end

.threaded_api_query(method_names) ⇒ Object

Process multiple api calls in threads



32
33
34
35
36
# File 'lib/weighflow_cli/order_handler.rb', line 32

def self.threaded_api_query(method_names)
  method_names.map do |name|
    Thread.new { WeighflowCli.client.send(name) }
  end.map(&:value)
end