class WeighflowCli::Client
Public Class Methods
new(config = {})
click to toggle source
# File lib/weighflow_cli/client.rb, line 7 def initialize(config = {}) self.class.headers auth_headers(config[:secret].to_s) self.class.base_uri config[:url].to_s end
Public Instance Methods
auth_headers(token)
click to toggle source
# File lib/weighflow_cli/client.rb, line 12 def auth_headers(token) { 'Authorization' => "Token #{token}"} end
bulk_inventory_inbound_truck()
click to toggle source
# File lib/weighflow_cli/client.rb, line 46 def bulk_inventory_inbound_truck find_orders(selection: 'II') end
bulk_inventory_outbound_truck()
click to toggle source
# File lib/weighflow_cli/client.rb, line 51 def bulk_inventory_outbound_truck find_orders(selection: 'OI') end
commodity_inbound_truck()
click to toggle source
# File lib/weighflow_cli/client.rb, line 42 def commodity_inbound_truck find_orders(selection: 'IC') end
commodity_outbound_truck()
click to toggle source
# File lib/weighflow_cli/client.rb, line 38 def commodity_outbound_truck find_orders(selection: 'OC') end
create_weight(params: {})
click to toggle source
# File lib/weighflow_cli/client.rb, line 22 def create_weight(params: {}) response = self.class.post('/weights', body: params) render_json(response) end
status()
click to toggle source
# File lib/weighflow_cli/client.rb, line 17 def status response = self.class.get('/') render_json(response) end
void_weight(weight_id, reason)
click to toggle source
# File lib/weighflow_cli/client.rb, line 27 def void_weight(weight_id, reason) response = self.class.delete("/weights/#{weight_id}", body: { reason: reason }) render_json(response) end
weights()
click to toggle source
# File lib/weighflow_cli/client.rb, line 32 def weights response = self.class.get('/weights') render_json(response) end
Private Instance Methods
find_orders(selection: 'OC')
click to toggle source
# File lib/weighflow_cli/client.rb, line 58 def find_orders(selection: 'OC') response = self.class.get('/orders', query: { s: selection }) render_json(response) end
render_error(response)
click to toggle source
# File lib/weighflow_cli/client.rb, line 63 def render_error(response) raise Error, "Problem accessing Weighflow API #{response.code} : #{response.body}" end
render_json(response)
click to toggle source
# File lib/weighflow_cli/client.rb, line 67 def render_json(response) render_error(response) unless response.success? JSON.parse(response.body, symbolize_names: true) end