-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,7 @@ DEPENDENCIES | |
csv | ||
encrypted_credentials! | ||
faraday | ||
logger | ||
pry | ||
rack | ||
rake | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
class ShoppingList | ||
LineItem = Struct.new(:country, :region, :locality, :quantity, :nearby_rate_centers) | ||
|
||
attr_reader :line_items | ||
attr_reader :line_items, :cities, :min_stock, :max_stock | ||
|
||
def initialize(line_items:) | ||
@line_items = Array(line_items) | ||
def initialize(**options) | ||
@line_items = Array(options.fetch(:line_items)) | ||
@cities = options[:cities] | ||
@min_stock = options[:min_stock] | ||
@max_stock = options[:max_stock] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "optparse" | ||
require_relative "../config/application" | ||
|
||
class OptionsParser | ||
class MissingArgumentError < StandardError; end | ||
|
||
Options = Struct.new(:dry_run, :verbose) | ||
|
||
attr_reader :parser, :options | ||
|
||
def initialize(**options) | ||
@parser = options.fetch(:parser) { default_parser } | ||
@options = Options.new | ||
end | ||
|
||
def parse | ||
parser.parse! | ||
check_environment!("APP_ENV", "SOMLENG_API_KEY", "SKYETEL_USERNAME", "SKYETEL_PASSWORD", "MIN_STOCK", "MAX_STOCK") | ||
options | ||
end | ||
|
||
def help | ||
parser.help | ||
end | ||
|
||
private | ||
|
||
def check_environment!(*keys) | ||
Array(keys).each do |key| | ||
raise MissingArgumentError.new("missing env var: #{key}") unless ENV.key?(key) | ||
end | ||
end | ||
|
||
def default_parser | ||
OptionParser.new do |opts| | ||
opts.banner = "Usage: somleng-skyetel [options]" | ||
opts.on("--[no-]dry-run [FLAG]", "Dry run only. No phone numbers will be actually purchased.", TrueClass) { |o| options.dry_run = o.nil? ? true : o } | ||
opts.on("--[no-]verbose [FLAG]", "Run verbosely", TrueClass) { |o| options.verbose = o.nil? ? true : o } | ||
end | ||
end | ||
end | ||
|
||
def parse_options | ||
parser = OptionsParser.new | ||
parser.parse | ||
rescue OptionsParser::MissingArgumentError => e | ||
puts e.message | ||
puts parser.help | ||
exit(1) | ||
end | ||
|
||
options = parse_options | ||
|
||
RestockInventory.call(dry_run: options.dry_run, verbose: options.verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters