module WeighflowCli::OrderHandler
Public Class Methods
find_order(external_id)
click to toggle source
Find a single order with details from the stored repository
# 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)
click to toggle source
List all orders currently in stored repository
# 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
pull()
click to toggle source
Pull order data from Weighflow and store in local repository
# 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)
click to toggle source
Process multiple api calls in threads
# 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