Class: SC2Cli::Subcommands::History
- Inherits:
-
Object
- Object
- SC2Cli::Subcommands::History
- Defined in:
- lib/sc2cli/subcommands/history.rb
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(configuration:, options:) ⇒ History
constructor
A new instance of History.
- #run ⇒ Object
Constructor Details
#initialize(configuration:, options:) ⇒ History
Returns a new instance of History.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sc2cli/subcommands/history.rb', line 42 def initialize(configuration:, options:) @configuration = configuration id = nil name = nil region = nil OptionParser.new do |opts| opts. = "Usage: #{$0} #{self.class.name.split("::").last.downcase} [options]" opts.on("-h", "--help", "Prints this help") do @@console.info(opts) exit end opts.on("-i", "--id ID", Integer, "Player profile ID.") do |value| id = value end opts.on("-n", "--name NAME", String, "Player name. Must exist in names file.") do |value| name = value end opts.on("-r", "--region REGION", String, "Region name, such as 'eu' or 'us'. Use configuration region by default.") do |value| region = Shared::Region.new(name: value) end end.parse! if name.kind_of?(String) then name = Shared::Names.new(configuration: @configuration, name: name) id = name.id region ||= name.region end region ||= @configuration.region @@console.fatal("Player profile ID or name must be specified!") unless id.kind_of?(Integer) @id = id @region = region end |
Instance Method Details
#run ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sc2cli/subcommands/history.rb', line 86 def run @@console.info("Finding match history:") @@console.info(" - ID : #{@id.to_s}") @@console.info(" - Region: #{@region.description}") path = "#{@@prefix}/#{@region.id.to_s}/#{@region.realm.to_s}/#{@id.to_s}#{@@suffix}" api = Shared::Api.new(configuration: @configuration, region: @region) result = api.get(path: path) matches = HistoryShared::HistoryMatches.new(json: result) @@console.info(matches.to_s) end |