sc2cli 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.gitlab-ci.yml +37 -0
  4. data/Gemfile +13 -0
  5. data/LICENSE.txt +21 -0
  6. data/Rakefile +13 -0
  7. data/bin/console +16 -0
  8. data/bin/setup +18 -0
  9. data/exe/sc2 +44 -0
  10. data/lib/sc2cli.rb +7 -0
  11. data/lib/sc2cli/shared.rb +15 -0
  12. data/lib/sc2cli/shared/api.rb +79 -0
  13. data/lib/sc2cli/shared/cache.rb +112 -0
  14. data/lib/sc2cli/shared/configuration.rb +119 -0
  15. data/lib/sc2cli/shared/console.rb +69 -0
  16. data/lib/sc2cli/shared/names.rb +101 -0
  17. data/lib/sc2cli/shared/region.rb +112 -0
  18. data/lib/sc2cli/shared/season.rb +123 -0
  19. data/lib/sc2cli/shared/token.rb +139 -0
  20. data/lib/sc2cli/subcommands.rb +9 -0
  21. data/lib/sc2cli/subcommands/history.rb +114 -0
  22. data/lib/sc2cli/subcommands/history/historymatch.rb +118 -0
  23. data/lib/sc2cli/subcommands/history/historymatches.rb +72 -0
  24. data/lib/sc2cli/subcommands/ladder.rb +120 -0
  25. data/lib/sc2cli/subcommands/ladder/ladderdetails.rb +110 -0
  26. data/lib/sc2cli/subcommands/ladder/ladderdetailsmembership.rb +64 -0
  27. data/lib/sc2cli/subcommands/ladder/ladderdetailsrank.rb +101 -0
  28. data/lib/sc2cli/subcommands/ladder/ladderdetailsteam.rb +114 -0
  29. data/lib/sc2cli/subcommands/ladder/ladderdetailsteammember.rb +110 -0
  30. data/lib/sc2cli/subcommands/ladder/ladderdetailsteammembers.rb +85 -0
  31. data/lib/sc2cli/subcommands/ladder/ladderdetailsteams.rb +85 -0
  32. data/lib/sc2cli/subcommands/ladder/laddersummary.rb +82 -0
  33. data/lib/sc2cli/subcommands/league.rb +190 -0
  34. data/lib/sc2cli/subcommands/league/leaguetier.rb +112 -0
  35. data/lib/sc2cli/subcommands/league/leaguetiers.rb +79 -0
  36. data/lib/sc2cli/subcommands/raw.rb +89 -0
  37. data/lib/sc2cli/subcommands/season.rb +74 -0
  38. data/lib/sc2cli/version.rb +13 -0
  39. data/sc2cli.gemspec +36 -0
  40. metadata +85 -0
@@ -0,0 +1,9 @@
1
+ ###############################################################################
2
+
3
+ require_relative 'subcommands/history'
4
+ require_relative 'subcommands/ladder'
5
+ require_relative 'subcommands/league'
6
+ require_relative 'subcommands/raw'
7
+ require_relative 'subcommands/season'
8
+
9
+ ###############################################################################
@@ -0,0 +1,114 @@
1
+ ###############################################################################
2
+
3
+ require 'optparse'
4
+
5
+ ###############################################################################
6
+
7
+ require_relative 'history/historymatch'
8
+ require_relative 'history/historymatches'
9
+
10
+ ###############################################################################
11
+
12
+ module SC2Cli
13
+
14
+ ###############################################################################
15
+
16
+ module Subcommands
17
+
18
+ ###############################################################################
19
+
20
+ class History
21
+
22
+ ###############################################################################
23
+
24
+ @@console = Shared::Console.instance
25
+
26
+ ###############################################################################
27
+
28
+ @@prefix = "/sc2/legacy/profile"
29
+ @@suffix = "/matches"
30
+
31
+ ###############################################################################
32
+
33
+ @configuration
34
+
35
+ ###############################################################################
36
+
37
+ @id
38
+ @region
39
+
40
+ ###############################################################################
41
+
42
+ def initialize(configuration:, options:)
43
+ @configuration = configuration
44
+
45
+ id = nil
46
+ name = nil
47
+ region = nil
48
+
49
+ OptionParser.new do |opts|
50
+ opts.banner = "Usage: #{$0} #{self.class.name.split("::").last.downcase} [options]"
51
+
52
+ opts.on("-h", "--help", "Prints this help") do
53
+ @@console.info(opts)
54
+ exit
55
+ end
56
+
57
+ opts.on("-i", "--id ID", Integer, "Player profile ID.") do |value|
58
+ id = value
59
+ end
60
+
61
+ opts.on("-n", "--name NAME", String, "Player name. Must exist in names file.") do |value|
62
+ name = value
63
+ end
64
+
65
+ opts.on("-r", "--region REGION", String, "Region name, such as 'eu' or 'us'. Use configuration region by default.") do |value|
66
+ region = Shared::Region.new(name: value)
67
+ end
68
+ end.parse!
69
+
70
+ if name.kind_of?(String) then
71
+ name = Shared::Names.new(configuration: @configuration, name: name)
72
+ id = name.id
73
+ region ||= name.region
74
+ end
75
+
76
+ region ||= @configuration.region
77
+
78
+ @@console.fatal("Player profile ID or name must be specified!") unless id.kind_of?(Integer)
79
+
80
+ @id = id
81
+ @region = region
82
+ end
83
+
84
+ ###############################################################################
85
+
86
+ def run
87
+ @@console.info("Finding match history:")
88
+ @@console.info(" - ID : #{@id.to_s}")
89
+ @@console.info(" - Region: #{@region.description}")
90
+
91
+ path = "#{@@prefix}/#{@region.id.to_s}/#{@region.realm.to_s}/#{@id.to_s}#{@@suffix}"
92
+
93
+ api = Shared::Api.new(configuration: @configuration, region: @region)
94
+
95
+ result = api.get(path: path)
96
+
97
+ matches = HistoryShared::HistoryMatches.new(json: result)
98
+
99
+ @@console.info(matches.to_s)
100
+ end
101
+
102
+ ###############################################################################
103
+
104
+ end
105
+
106
+ ###############################################################################
107
+
108
+ end
109
+
110
+ ###############################################################################
111
+
112
+ end
113
+
114
+ ###############################################################################
@@ -0,0 +1,118 @@
1
+ ###############################################################################
2
+
3
+ module SC2Cli
4
+
5
+ ###############################################################################
6
+
7
+ module Subcommands
8
+
9
+ ###############################################################################
10
+
11
+ module HistoryShared
12
+
13
+ ###############################################################################
14
+
15
+ class HistoryMatch
16
+
17
+ ###############################################################################
18
+
19
+ @@console = Shared::Console.instance
20
+
21
+ ###############################################################################
22
+
23
+ @@decision_colour_default = 247
24
+
25
+ @@decision_colour = {
26
+ "Win" => 40,
27
+ "Loss" => 160,
28
+ "Left" => 184,
29
+ "Observer" => 33
30
+ }
31
+
32
+ ###############################################################################
33
+
34
+ @@speed = "Unknown"
35
+
36
+ ###############################################################################
37
+
38
+ attr_reader :date
39
+ attr_reader :descision
40
+ attr_reader :map
41
+ attr_reader :speed
42
+ attr_reader :type
43
+
44
+ ###############################################################################
45
+
46
+ def initialize(json:)
47
+ @@console.fatal("Returned history information has a match with a missing date/time!") unless json.key?("date")
48
+ @@console.fatal("Returned history information has a match with a missing decision!") unless json.key?("decision")
49
+ @@console.fatal("Returned history information has a match with a missing map!") unless json.key?("map")
50
+ @@console.fatal("Returned history information has a match with a missing type!") unless json.key?("type")
51
+
52
+ date = json["date"]
53
+
54
+ @@console.fatal("Returned history information has a match with a date/time that is not an integer!") unless date.kind_of?(Integer)
55
+ @@console.fatal("Returned history information has a match with a date/time that is invalid!") unless date >= 0
56
+
57
+ decision = json["decision"]
58
+
59
+ @@console.fatal("Returned history information has a match with a decision that is not a string!") unless decision.kind_of?(String)
60
+ @@console.fatal("Returned history information has a match with a decision that is blank!") if decision.empty?
61
+
62
+ map = json["map"]
63
+
64
+ @@console.fatal("Returned history information has a match with a map that is not a string!") unless map.kind_of?(String)
65
+ @@console.fatal("Returned history information has a match with a map that is blank!") if map.empty?
66
+
67
+ type = json["type"]
68
+
69
+ @@console.fatal("Returned history information has a match with a type that is not a string!") unless type.kind_of?(String)
70
+ @@console.fatal("Returned history information has a match with a type that is blank!") if type.empty?
71
+
72
+ @date = Time.at(date)
73
+ @decision = decision
74
+ @map = map
75
+ @type = type
76
+
77
+ if json.key?("speed") then
78
+ speed = json["speed"]
79
+ if speed.kind_of?(String) then
80
+ @speed = speed unless speed.empty?
81
+ end
82
+ end
83
+
84
+ @speed ||= @@speed
85
+ end
86
+
87
+ ###############################################################################
88
+
89
+ def to_s
90
+ result = String.new
91
+
92
+ colour = @@decision_colour.key?(@decision) ? @@decision_colour[@decision] : @@decision_colour_default
93
+ date = @date.strftime("%Y-%m-%d %H:%M:%S")
94
+ decision = "%10.10s" % @decision
95
+ map = "%-36.36s" % @map
96
+ type = "%10.10s" % @type
97
+
98
+ result = "#{@@console.format(colour: colour, message: decision)} #{type} #{map} #{date}\n"
99
+ return result
100
+ end
101
+
102
+ ###############################################################################
103
+
104
+ end
105
+
106
+ ###############################################################################
107
+
108
+ end
109
+
110
+ ###############################################################################
111
+
112
+ end
113
+
114
+ ###############################################################################
115
+
116
+ end
117
+
118
+ ###############################################################################
@@ -0,0 +1,72 @@
1
+ ###############################################################################
2
+
3
+ module SC2Cli
4
+
5
+ ###############################################################################
6
+
7
+ module Subcommands
8
+
9
+ ###############################################################################
10
+
11
+ module HistoryShared
12
+
13
+ ###############################################################################
14
+
15
+ class HistoryMatches
16
+
17
+ ###############################################################################
18
+
19
+ @matches
20
+
21
+ ###############################################################################
22
+
23
+ def initialize(json:)
24
+ @matches = Array.new
25
+
26
+ if json.key?("matches") then
27
+ matches = json["matches"]
28
+ @@console.fatal("Returned history information matches is not an array!") unless matches.kind_of?(Array)
29
+
30
+ matches.each do |match|
31
+ match = HistoryMatch.new(json: match)
32
+ add(match: match)
33
+ end
34
+ end
35
+ end
36
+
37
+ ###############################################################################
38
+
39
+ def add(match:)
40
+ @matches << match if match.kind_of?(HistoryMatch)
41
+ @matches.sort_by!{ |match| match.date }.reverse!
42
+ end
43
+
44
+ ###############################################################################
45
+
46
+ def to_s
47
+ result = String.new
48
+
49
+ @matches.each do |match|
50
+ result += match.to_s
51
+ end
52
+
53
+ return result
54
+ end
55
+
56
+ ###############################################################################
57
+
58
+ end
59
+
60
+ ###############################################################################
61
+
62
+ end
63
+
64
+ ###############################################################################
65
+
66
+ end
67
+
68
+ ###############################################################################
69
+
70
+ end
71
+
72
+ ###############################################################################
@@ -0,0 +1,120 @@
1
+ ###############################################################################
2
+
3
+ require 'optparse'
4
+
5
+ ###############################################################################
6
+
7
+ require_relative 'ladder/ladderdetails'
8
+ require_relative 'ladder/ladderdetailsmembership'
9
+ require_relative 'ladder/ladderdetailsrank'
10
+ require_relative 'ladder/ladderdetailsteam'
11
+ require_relative 'ladder/ladderdetailsteammembers'
12
+ require_relative 'ladder/ladderdetailsteammember'
13
+ require_relative 'ladder/ladderdetailsteams'
14
+ require_relative 'ladder/laddersummary'
15
+
16
+ ###############################################################################
17
+
18
+ module SC2Cli
19
+
20
+ ###############################################################################
21
+
22
+ module Subcommands
23
+
24
+ ###############################################################################
25
+
26
+ class Ladder
27
+
28
+ ###############################################################################
29
+
30
+ @@console = Shared::Console.instance
31
+
32
+ ###############################################################################
33
+
34
+ @@prefix = "/sc2/profile"
35
+ @@suffix = "/ladder/summary"
36
+
37
+ ###############################################################################
38
+
39
+ @configuration
40
+
41
+ ###############################################################################
42
+
43
+ @id
44
+ @region
45
+
46
+ ###############################################################################
47
+
48
+ def initialize(configuration:, options:)
49
+ @configuration = configuration
50
+
51
+ id = nil
52
+ name = nil
53
+ region = nil
54
+
55
+ OptionParser.new do |opts|
56
+ opts.banner = "Usage: #{$0} #{self.class.name.split("::").last.downcase} [options]"
57
+
58
+ opts.on("-h", "--help", "Prints this help") do
59
+ @@console.info(opts)
60
+ exit
61
+ end
62
+
63
+ opts.on("-i", "--id ID", Integer, "Player profile ID.") do |value|
64
+ id = value
65
+ end
66
+
67
+ opts.on("-n", "--name NAME", String, "Player name. Must exist in names file.") do |value|
68
+ name = value
69
+ end
70
+
71
+ opts.on("-r", "--region REGION", String, "Region name, such as 'eu' or 'us'. Use configuration region by default.") do |value|
72
+ region = Shared::Region.new(name: value)
73
+ end
74
+ end.parse!
75
+
76
+ if name.kind_of?(String) then
77
+ name = Shared::Names.new(configuration: @configuration, name: name)
78
+ id = name.id
79
+ region ||= name.region
80
+ end
81
+
82
+ region ||= @configuration.region
83
+
84
+ @@console.fatal("Player profile ID or name must be specified!") unless id.kind_of?(Integer)
85
+
86
+ @id = id
87
+ @region = region
88
+ end
89
+
90
+ ###############################################################################
91
+
92
+ def run
93
+ @@console.info("Finding ladder summary:")
94
+ @@console.info(" - ID : #{@id.to_s}")
95
+ @@console.info(" - Region: #{@region.description}")
96
+
97
+ path = "#{@@prefix}/#{@region.id.to_s}/#{@region.realm.to_s}/#{@id.to_s}#{@@suffix}"
98
+
99
+ api = Shared::Api.new(configuration: @configuration, region: @region)
100
+
101
+ result = api.get(path: path)
102
+
103
+ ladders = LadderShared::LadderSummary.new(json: result, api: api, player: @id)
104
+
105
+ @@console.info(ladders.to_s)
106
+ end
107
+
108
+ ###############################################################################
109
+
110
+ end
111
+
112
+ ###############################################################################
113
+
114
+ end
115
+
116
+ ###############################################################################
117
+
118
+ end
119
+
120
+ ###############################################################################
@@ -0,0 +1,110 @@
1
+ ###############################################################################
2
+
3
+ module SC2Cli
4
+
5
+ ###############################################################################
6
+
7
+ module Subcommands
8
+
9
+ ###############################################################################
10
+
11
+ module LadderShared
12
+
13
+ ###############################################################################
14
+
15
+ class LadderDetails
16
+
17
+ ###############################################################################
18
+
19
+ @@console = Shared::Console.instance
20
+
21
+ ###############################################################################
22
+
23
+ @@prefix = "/sc2/profile"
24
+ @@suffix = "/ladder"
25
+
26
+ ###############################################################################
27
+
28
+ @teams
29
+
30
+ ###############################################################################
31
+
32
+ attr_reader :id
33
+ attr_reader :membership
34
+ attr_reader :player
35
+ attr_reader :rank
36
+ attr_reader :region
37
+
38
+ ###############################################################################
39
+
40
+ def initialize(id:, api:, player:)
41
+ @@console.fatal("Cannot find ladder details for ladder with an ID that is not an integer!") unless id.kind_of?(Integer)
42
+ @@console.fatal("Cannot find ladder details for ladder with an ID that is not valid!") unless id > 0
43
+
44
+ @id = id
45
+ @player = player
46
+ @region = api.region
47
+
48
+ lookup(api: api)
49
+ end
50
+
51
+ ###############################################################################
52
+
53
+ def to_s
54
+ result = String.new
55
+
56
+ result += "-------------------------------------------------------------------------------\n"
57
+ result += @membership.to_s
58
+ result += "-------------------------------------------------------------------------------\n"
59
+ result += @teams.with_member(player: @player).to_s
60
+ result += "Ranks/Pools for this player:\n"
61
+ result += @rank.to_s
62
+
63
+ return result
64
+ end
65
+
66
+ ###############################################################################
67
+
68
+ private
69
+
70
+ ###############################################################################
71
+
72
+ def lookup(api:)
73
+ @@console.info("Finding ladder details:")
74
+ @@console.info(" - ID : #{@id.to_s}")
75
+ @@console.info(" - Player: #{@player.to_s}")
76
+ @@console.info(" - Region: #{@region.description}")
77
+
78
+ path = "#{@@prefix}/#{@region.id.to_s}/#{@region.realm.to_s}/#{@player.to_s}#{@@suffix}/#{@id.to_s}"
79
+
80
+ result = api.get(path: path)
81
+
82
+ @@console.fatal("Failed to get ladder details: current membership information missing!") unless result.key?("currentLadderMembership")
83
+
84
+ membership = result["currentLadderMembership"]
85
+
86
+ rank = result.key?("ranksAndPools") ? result["ranksAndPools"] : Array.new
87
+ teams = result.key?("ladderTeams") ? result["ladderTeams"] : Array.new
88
+
89
+ @membership = LadderDetailsMembership.new(json: membership)
90
+ @rank = LadderDetailsRank.new(json: rank)
91
+ @teams = LadderDetailsTeams.new(json: teams)
92
+ end
93
+
94
+ ###############################################################################
95
+
96
+ end
97
+
98
+ ###############################################################################
99
+
100
+ end
101
+
102
+ ###############################################################################
103
+
104
+ end
105
+
106
+ ###############################################################################
107
+
108
+ end
109
+
110
+ ###############################################################################