Module: WeighflowCli

Defined in:
lib/weighflow_cli.rb,
lib/weighflow_cli/cli.rb,
lib/weighflow_cli/client.rb,
lib/weighflow_cli/version.rb,
lib/weighflow_cli/rendering.rb,
lib/weighflow_cli/cli_weights.rb,
lib/weighflow_cli/credentials.rb,
lib/weighflow_cli/order_handler.rb

Defined Under Namespace

Modules: Credentials, OrderHandler, Rendering Classes: Cli, CliWeights, Client, Configuration, Error

Constant Summary collapse

ROOT_PATH =
File.expand_path('~/.weighflow_cli').freeze
VERSION =
"0.2.11"

Class Method Summary collapse

Class Method Details

.clientObject

Creates an instance of the API client lib for direct access to the api



70
71
72
# File 'lib/weighflow_cli.rb', line 70

def self.client    
  @client ||= Client.new(configuration)  
end

.configurationObject

This can be used to set the secret and url for api credentials this setting can be done at the console, via

weighflow_cli 

or through in code if using the gem within your own code by supplying a block and passing in the credientials.



58
59
60
61
62
63
64
65
# File 'lib/weighflow_cli.rb', line 58

def self.configuration
 if block_given?
   configuration = Configuration.new
   yield(configuration)      
   @config = configuration.to_h
 end      
 @config ||= Credentials.load_config!    
end

.create_weight(params: {}) ⇒ Object



101
102
103
# File 'lib/weighflow_cli.rb', line 101

def self.create_weight(params: {})
  client.create_weight(params: params)
end

.data_pathObject

Provide an override to relocate data directory



35
36
37
38
39
40
# File 'lib/weighflow_cli.rb', line 35

def self.data_path     
  return @data_path if defined?(@data_path)
  @data_path ||= ENV.fetch('WEIGHFLOW_CLI_PATH') { File.join(WeighflowCli::ROOT_PATH, 'data') }
  ensure_data_path
  @data_path
end

.ensure_data_pathObject

Ensure data path



44
45
46
# File 'lib/weighflow_cli.rb', line 44

def self.ensure_data_path
  Dir.mkdir(data_path) unless Dir.exists?(data_path)
end

.find_order(external_id) ⇒ Object

Find a specific order based on the external_id given withing the orders + Helps to pull order details when needed.



87
88
89
# File 'lib/weighflow_cli.rb', line 87

def self.find_order(external_id)
  WeighflowCli::OrderHandler.find_order(external_id)
end

.list(indexes_only: false) ⇒ Object



92
93
94
# File 'lib/weighflow_cli.rb', line 92

def self.list(indexes_only: false)
  WeighflowCli::OrderHandler.list(indexes_only: indexes_only)
end

.pullObject

Pull down the orders and store in the local repository data path

  • This is used to management order changes



79
80
81
# File 'lib/weighflow_cli.rb', line 79

def self.pull
  WeighflowCli::OrderHandler.pull
end

.void_weight(weight_id, reason) ⇒ Object



105
106
107
# File 'lib/weighflow_cli.rb', line 105

def self.void_weight(weight_id, reason)
  client.void_weight(weight_id, reason)
end

.weightsObject



96
97
98
# File 'lib/weighflow_cli.rb', line 96

def self.weights
  client.weights
end