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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5e7e044e438a27214a1f52ab892e144e101b07ae056c52466a36f2122420e90
4
+ data.tar.gz: 252edb3d02524d197632731c0d81e45a942e68202f73c0ac33976c423a85567e
5
+ SHA512:
6
+ metadata.gz: a97ed19c46035b255f515f7ca8f74a2562c3170aa4bbd654effd28820aab4c4265c453c149c5a2630cda18694bf86863ebc0c145e294014d30211cc14ee7d66d
7
+ data.tar.gz: b4fc2a0d6928b5feb0d0179837b7e6c3557a561001965bfd163a9a40c0a1f72e1305596f54531bd6853b435b5feb66a61307c660423c39a86ad9aea0f60bcc07
data/.gitignore ADDED
@@ -0,0 +1,28 @@
1
+ ###############################################################################
2
+
3
+ **/*.DS_Store
4
+ **/*.swp
5
+ **/*.tmp
6
+ **/*~
7
+
8
+ ###############################################################################
9
+
10
+ .idea
11
+
12
+ ###############################################################################
13
+
14
+ /.bundle/
15
+ /.yardoc
16
+ /_yardoc/
17
+ /coverage/
18
+ /doc/
19
+ /pkg/
20
+ /spec/reports/
21
+ /tmp/
22
+
23
+ ###############################################################################
24
+
25
+ /archlinux/
26
+ !/archlinux/PKGBUILD
27
+
28
+ ###############################################################################
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,37 @@
1
+ ###############################################################################
2
+
3
+ image: ruby
4
+
5
+ ###############################################################################
6
+
7
+ stages:
8
+ - test
9
+ - publish
10
+
11
+ ###############################################################################
12
+
13
+ test:
14
+ stage : test
15
+ script:
16
+ - echo "-- Beginning Test --"
17
+ - echo "-- Tests not implemented yet --"
18
+
19
+ ###############################################################################
20
+
21
+ deploy:
22
+ rules:
23
+ - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
24
+ stage: publish
25
+ script:
26
+ - echo "-- Beginning Publish --"
27
+ - test -n "${GEM_HOST_API_KEY}"
28
+ - echo "RubyGems API key found!"
29
+ - hash rake
30
+ - hash ruby
31
+ - hash gem
32
+ - echo "-- Publishing Gem --"
33
+ - rake release
34
+ - echo "-- Listing Sums --"
35
+ - sha256sum "pkg"/*.gem
36
+
37
+ ###############################################################################
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ ###############################################################################
2
+
3
+ # frozen_string_literal: true
4
+
5
+ ###############################################################################
6
+
7
+ source "https://rubygems.org"
8
+
9
+ ###############################################################################
10
+
11
+ gemspec
12
+
13
+ ###############################################################################
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Richard Lees, BITServices Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ ###############################################################################
2
+
3
+ # frozen_string_literal: true
4
+
5
+ ###############################################################################
6
+
7
+ require "bundler/gem_tasks"
8
+
9
+ ###############################################################################
10
+
11
+ task default: %i[]
12
+
13
+ ###############################################################################
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ ###############################################################################
3
+
4
+ # frozen_string_literal: true
5
+
6
+ ###############################################################################
7
+
8
+ require "bundler/setup"
9
+ require "irb"
10
+ require "terraform-wrapper"
11
+
12
+ ###############################################################################
13
+
14
+ IRB.start(__FILE__)
15
+
16
+ ###############################################################################
data/bin/setup ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env bash
2
+ ###############################################################################
3
+
4
+ set -euo pipefail
5
+
6
+ ###############################################################################
7
+
8
+ IFS=$'\n\t'
9
+
10
+ ###############################################################################
11
+
12
+ set -vx
13
+
14
+ ###############################################################################
15
+
16
+ bundle install
17
+
18
+ ###############################################################################
data/exe/sc2 ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ ###############################################################################
3
+
4
+ require 'sc2cli'
5
+
6
+ ###############################################################################
7
+
8
+ module SC2Cli
9
+
10
+ ###############################################################################
11
+
12
+ console = Shared::Console.instance
13
+ subcommands = Subcommands.constants.select{|constant| Subcommands.const_get(constant).is_a?(Class)}.to_h{|constant| [constant.to_s.downcase, constant.to_s]}
14
+
15
+ ###############################################################################
16
+
17
+ console.info("StarCraft 2 CLI, version: #{VERSION}")
18
+ console.info("Available subcommands: #{subcommands.keys.sort.join(", ")}")
19
+ console.fatal("Usage: #{$0} subcommand [options]") if ARGV.length < 1
20
+
21
+ ###############################################################################
22
+
23
+ subcommand = ARGV[0]
24
+
25
+ console.fatal("Subcommand cannot be blank!") if subcommand.empty?
26
+ console.fatal("Subcommand not recognised: #{subcommand}!") unless subcommands.key?(subcommand)
27
+ console.info("Subcommand is: #{subcommand}")
28
+
29
+ options = ARGV.drop(1)
30
+
31
+ ###############################################################################
32
+
33
+ configuration = Shared::Configuration.new
34
+
35
+ ###############################################################################
36
+
37
+ runner = Subcommands::const_get(subcommands[subcommand]).new(configuration: configuration, options: options)
38
+ runner.run
39
+
40
+ ###############################################################################
41
+
42
+ end
43
+
44
+ ###############################################################################
data/lib/sc2cli.rb ADDED
@@ -0,0 +1,7 @@
1
+ ###############################################################################
2
+
3
+ require_relative 'sc2cli/shared'
4
+ require_relative 'sc2cli/subcommands'
5
+ require_relative 'sc2cli/version'
6
+
7
+ ###############################################################################
@@ -0,0 +1,15 @@
1
+ ###############################################################################
2
+
3
+ require_relative 'shared/console'
4
+
5
+ ###############################################################################
6
+
7
+ require_relative 'shared/api'
8
+ require_relative 'shared/cache'
9
+ require_relative 'shared/configuration'
10
+ require_relative 'shared/names'
11
+ require_relative 'shared/region'
12
+ require_relative 'shared/season'
13
+ require_relative 'shared/token'
14
+
15
+ ###############################################################################
@@ -0,0 +1,79 @@
1
+ ###############################################################################
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+
6
+ ###############################################################################
7
+
8
+ module SC2Cli
9
+
10
+ ###############################################################################
11
+
12
+ module Shared
13
+
14
+ ###############################################################################
15
+
16
+ class Api
17
+
18
+ ###############################################################################
19
+
20
+ @@console = Console.instance
21
+
22
+ ###############################################################################
23
+
24
+ @token
25
+
26
+ ###############################################################################
27
+
28
+ attr_reader :region
29
+
30
+ ###############################################################################
31
+
32
+ def initialize(configuration:, region: nil)
33
+ @region = region || configuration.region
34
+ @token = Token.new(configuration: configuration, region: @region)
35
+ end
36
+
37
+ ###############################################################################
38
+
39
+ def get(path: "/")
40
+ @@console.fatal("Path for API request cannot be blank!") if path.empty?
41
+ @@console.fatal("Path for API request: #{path} does NOT begin with '/'!") unless path.chars.first == "/"
42
+
43
+ server = @region.api_server
44
+
45
+ @token.refresh unless @token.check
46
+
47
+ uri = URI("https://#{server}#{path}")
48
+
49
+ @@console.info("Making API request to: #{uri.to_s}")
50
+
51
+ request = Net::HTTP::Get.new(uri)
52
+ request["Authorization"] = "Bearer #{@token.token}"
53
+
54
+ http = Net::HTTP.new(uri.hostname, uri.port)
55
+ http.use_ssl = true
56
+
57
+ response = http.request(request)
58
+
59
+ @@console.fatal("Blizzard API returned: #{response.code}, not 200 for reqest!") if response.code != "200"
60
+ @@console.fatal("Response body from Blizzard API is not permitted!") if not response.class.body_permitted?
61
+ @@console.fatal("Response body from Blizzard API is empty!") if response.body.nil?
62
+
63
+ body = JSON.parse(response.body)
64
+ return body
65
+ end
66
+
67
+ ###############################################################################
68
+
69
+ end
70
+
71
+ ###############################################################################
72
+
73
+ end
74
+
75
+ ###############################################################################
76
+
77
+ end
78
+
79
+ ###############################################################################
@@ -0,0 +1,112 @@
1
+ ###############################################################################
2
+
3
+ require 'yaml'
4
+
5
+ ###############################################################################
6
+
7
+ module SC2Cli
8
+
9
+ ###############################################################################
10
+
11
+ module Shared
12
+
13
+ ###############################################################################
14
+
15
+ class Cache
16
+
17
+ ###############################################################################
18
+
19
+ @@console = Console.instance
20
+
21
+ ###############################################################################
22
+
23
+ @@prefix = "cache."
24
+ @@suffix = ".yaml"
25
+
26
+ ###############################################################################
27
+
28
+ @path
29
+
30
+ ###############################################################################
31
+
32
+ attr_reader :base
33
+ attr_reader :expires
34
+ attr_reader :region
35
+ attr_reader :token
36
+
37
+ ###############################################################################
38
+
39
+ def initialize(configuration:, region: nil)
40
+ @region = region || configuration.region
41
+ @base = configuration.base
42
+
43
+ @path = File.join(@base, "#{@@prefix}#{region.name}#{@@suffix}")
44
+
45
+ load
46
+ end
47
+
48
+ ###############################################################################
49
+
50
+ def update(token:, expires:)
51
+ @token = token
52
+ @expires = expires
53
+
54
+ save
55
+ end
56
+
57
+ ###############################################################################
58
+
59
+ private
60
+
61
+ ###############################################################################
62
+
63
+ def load
64
+ token = nil
65
+ expires = nil
66
+
67
+ if File.file?(@path)
68
+ @@console.info("Reading cache: #{@path}")
69
+ yaml = YAML.load(File.read(@path))
70
+
71
+ if yaml.key?("token") then
72
+ token = yaml["token"]
73
+
74
+ @@console.fatal("Error in cache! 'token' must be a string!") unless token.kind_of?(String)
75
+ @@console.fatal("Error in cache! 'token' must not be blank!") if token.empty?
76
+
77
+ @@console.fatal("Error in cache! 'token' set but 'expires' missing!") unless yaml.key?("expires")
78
+
79
+ expires = yaml["expires"]
80
+
81
+ @@console.fatal("Error in cache! 'expires' must be a integer!") unless expires.kind_of?(Integer)
82
+ end
83
+ end
84
+
85
+ @token = token
86
+ @expires = expires.kind_of?(Integer) ? Time.at(expires) : nil
87
+ end
88
+
89
+ ###############################################################################
90
+
91
+ def save
92
+ yaml = Hash.new
93
+
94
+ yaml["token"] = @token
95
+ yaml["expires"] = @expires.to_i
96
+
97
+ File.write(@path, yaml.to_yaml)
98
+ end
99
+
100
+ ###############################################################################
101
+
102
+ end
103
+
104
+ ###############################################################################
105
+
106
+ end
107
+
108
+ ###############################################################################
109
+
110
+ end
111
+
112
+ ###############################################################################
@@ -0,0 +1,119 @@
1
+ ###############################################################################
2
+
3
+ require 'yaml'
4
+
5
+ ###############################################################################
6
+
7
+ module SC2Cli
8
+
9
+ ###############################################################################
10
+
11
+ module Shared
12
+
13
+ ###############################################################################
14
+
15
+ class Configuration
16
+
17
+ ###############################################################################
18
+
19
+ @@console = Console.instance
20
+
21
+ ###############################################################################
22
+
23
+ @@file = "configuration.yaml"
24
+ @@folder = ".sc2cli"
25
+
26
+ ###############################################################################
27
+
28
+ attr_reader :base
29
+ attr_reader :client
30
+ attr_reader :region
31
+ attr_reader :secret
32
+
33
+ ###############################################################################
34
+
35
+ def initialize
36
+ home = Dir.home
37
+
38
+ @@console.fatal("Home folder could not be determined!") if home.empty?
39
+ @@console.fatal("Home folder: #{home} does not exist!") unless File.directory?(home)
40
+
41
+ base = File.join(home, @@folder)
42
+
43
+ @@console.fatal("Base folder: #{base} does not exist!") unless File.directory?(base)
44
+
45
+ @base = base
46
+
47
+ path = File.join(base, @@file)
48
+
49
+ load(path: path)
50
+ end
51
+
52
+ ###############################################################################
53
+
54
+ def auth
55
+ result = false
56
+
57
+ if not (client.nil? or secret.nil?) then
58
+ result = true
59
+ end
60
+
61
+ return result
62
+ end
63
+
64
+ ###############################################################################
65
+
66
+ private
67
+
68
+ ###############################################################################
69
+
70
+ def load(path:)
71
+ client = nil
72
+ secret = nil
73
+ region = nil
74
+
75
+ if File.file?(path)
76
+ @@console.info("Reading configuration: #{path}")
77
+ yaml = YAML.load(File.read(path))
78
+
79
+ if yaml.key?("client") then
80
+ client = yaml["client"]
81
+
82
+ @@console.fatal("Error in configuration! 'client' must be a string!") unless client.kind_of?(String)
83
+ @@console.fatal("Error in configuration! 'client' must not be blank!") if client.empty?
84
+
85
+ @@console.fatal("Error in configuration! 'client' set but 'secret' missing!") unless yaml.key?("secret")
86
+
87
+ secret = yaml["secret"]
88
+
89
+ @@console.fatal("Error in configuration! 'secret' must be a string!") unless secret.kind_of?(String)
90
+ @@console.fatal("Error in configuration! 'secret' must not be blank!") if secret.empty?
91
+ end
92
+
93
+ if yaml.key?("region") then
94
+ region_name = yaml["region"]
95
+
96
+ @@console.fatal("Error in configuration! 'region' must be a string!") unless region.kind_of?(String)
97
+ @@console.fatal("Error in configuration! 'region' must not be blank!") if region.empty?
98
+ end
99
+ end
100
+
101
+ @region = Region.new(name: region)
102
+
103
+ @client = client
104
+ @secret = secret
105
+ end
106
+
107
+ ###############################################################################
108
+
109
+ end
110
+
111
+ ###############################################################################
112
+
113
+ end
114
+
115
+ ###############################################################################
116
+
117
+ end
118
+
119
+ ###############################################################################