relic_link 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0a6925bd59c93badd256bc6e31c23cf2ecd58827b93b604f2ce4fd954924ee5
4
- data.tar.gz: 68e0f9f49e38f2c5d7b6e870684828c21bc88e9d4ecd56c4a7d6245e94462d43
3
+ metadata.gz: f946c4d09c17dbdd9522d22cfea4e8ff935cffdca59728b34e398d4e35986ece
4
+ data.tar.gz: 75924b2a77be65290e8ff3d312d6ba619b733b4276fe38e178e0c3fb49b224d6
5
5
  SHA512:
6
- metadata.gz: 9b6b44e95aab707016e1825eecd7f952f63bdceb299b5622fa6d61b27e8930b7559066eab6fd35f83aa4be2131713bab4c17097cb86f46abe878d7bba3228480
7
- data.tar.gz: cf4eec64ecffecffb3e4d0e313c5fc0f6c66d5135103be65ddffa4c8251c9d960afbaa706c945290e5c6ce160eaeb18f39a2e4d5055db212906ce8811d1a1e08
6
+ metadata.gz: eea1940ab9da3a557aa941028f4635ff089d4fe8506a1b822e460984b2098076163386019497aca46248182e518f91c767a8f3ccd90f9f328b8fc1f0fc6c123e
7
+ data.tar.gz: '0975d7c5e3173c1d876f0bd7e48b86db108635254ed6abe698a3987a65ec8f8b37a4f05ad9eccec53f1b31a06f730c26b36249b47f7081a087e983f15fcd9729'
data/.rubocop.yml CHANGED
@@ -1,3 +1,7 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
6
  TargetRubyVersion: 3.1
3
7
  NewCops: enable
@@ -8,6 +12,39 @@ Layout/AccessModifierIndentation:
8
12
  Metrics/BlockLength:
9
13
  Enabled: false
10
14
 
15
+ Metrics/MethodLength:
16
+ Max: 15
17
+
18
+ Rake/Desc:
19
+ Enabled: false
20
+
21
+ RSpec/AnyInstance:
22
+ Enabled: false
23
+
24
+ RSpec/ContextWording:
25
+ Enabled: false
26
+
27
+ RSpec/ExampleLength:
28
+ Max: 10
29
+
30
+ RSpec/HookArgument:
31
+ Enabled: false
32
+
33
+ RSpec/MessageChain:
34
+ Enabled: false
35
+
36
+ RSpec/MessageSpies:
37
+ Enabled: false
38
+
39
+ RSpec/MultipleExpectations:
40
+ Enabled: false
41
+
42
+ RSpec/MultipleMemoizedHelpers:
43
+ Enabled: false
44
+
45
+ RSpec/NestedGroups:
46
+ Enabled: false
47
+
11
48
  Style/GlobalStdStream:
12
49
  Enabled: false
13
50
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.4
data/Gemfile CHANGED
@@ -5,10 +5,12 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in relic_link.gemspec
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 13.1'
8
+ gem 'rake', '~> 13.2'
9
9
 
10
10
  gem 'rspec', '~> 3.13'
11
11
 
12
- gem 'rubocop', '~> 1.61'
12
+ gem 'rubocop', '~> 1.66'
13
+ gem 'rubocop-rake'
14
+ gem 'rubocop-rspec'
13
15
 
14
- gem 'vcr', '~> 6.2'
16
+ gem 'vcr', '~> 6.3'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relic_link (1.1.0)
4
+ relic_link (1.2.1)
5
5
  faraday (~> 2.7)
6
6
  faraday-mashify (~> 0.1)
7
7
  hashie (~> 5.0)
@@ -10,69 +10,78 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
+ base64 (0.2.0)
13
14
  diff-lcs (1.5.1)
14
- faraday (2.9.0)
15
- faraday-net_http (>= 2.0, < 3.2)
15
+ faraday (2.11.0)
16
+ faraday-net_http (>= 2.0, < 3.4)
17
+ logger
16
18
  faraday-mashify (0.1.1)
17
19
  faraday (~> 2.0)
18
20
  hashie
19
- faraday-net_http (3.1.0)
21
+ faraday-net_http (3.3.0)
20
22
  net-http
21
23
  hashie (5.0.0)
22
- json (2.7.1)
24
+ json (2.7.2)
23
25
  language_server-protocol (3.17.0.3)
26
+ logger (1.6.1)
24
27
  net-http (0.4.1)
25
28
  uri
26
- parallel (1.24.0)
27
- parser (3.3.0.5)
29
+ parallel (1.26.3)
30
+ parser (3.3.5.0)
28
31
  ast (~> 2.4.1)
29
32
  racc
30
- racc (1.7.3)
33
+ racc (1.8.1)
31
34
  rainbow (3.1.1)
32
- rake (13.1.0)
33
- regexp_parser (2.9.0)
34
- rexml (3.2.6)
35
+ rake (13.2.1)
36
+ regexp_parser (2.9.2)
35
37
  rspec (3.13.0)
36
38
  rspec-core (~> 3.13.0)
37
39
  rspec-expectations (~> 3.13.0)
38
40
  rspec-mocks (~> 3.13.0)
39
- rspec-core (3.13.0)
41
+ rspec-core (3.13.1)
40
42
  rspec-support (~> 3.13.0)
41
- rspec-expectations (3.13.0)
43
+ rspec-expectations (3.13.3)
42
44
  diff-lcs (>= 1.2.0, < 2.0)
43
45
  rspec-support (~> 3.13.0)
44
- rspec-mocks (3.13.0)
46
+ rspec-mocks (3.13.1)
45
47
  diff-lcs (>= 1.2.0, < 2.0)
46
48
  rspec-support (~> 3.13.0)
47
49
  rspec-support (3.13.1)
48
- rubocop (1.61.0)
50
+ rubocop (1.66.1)
49
51
  json (~> 2.3)
50
52
  language_server-protocol (>= 3.17.0)
51
53
  parallel (~> 1.10)
52
54
  parser (>= 3.3.0.2)
53
55
  rainbow (>= 2.2.2, < 4.0)
54
- regexp_parser (>= 1.8, < 3.0)
55
- rexml (>= 3.2.5, < 4.0)
56
- rubocop-ast (>= 1.30.0, < 2.0)
56
+ regexp_parser (>= 2.4, < 3.0)
57
+ rubocop-ast (>= 1.32.2, < 2.0)
57
58
  ruby-progressbar (~> 1.7)
58
59
  unicode-display_width (>= 2.4.0, < 3.0)
59
- rubocop-ast (1.31.1)
60
- parser (>= 3.3.0.4)
60
+ rubocop-ast (1.32.3)
61
+ parser (>= 3.3.1.0)
62
+ rubocop-rake (0.6.0)
63
+ rubocop (~> 1.0)
64
+ rubocop-rspec (3.0.5)
65
+ rubocop (~> 1.61)
61
66
  ruby-progressbar (1.13.0)
62
67
  unicode-display_width (2.5.0)
63
- uri (0.13.0)
64
- vcr (6.2.0)
68
+ uri (0.13.1)
69
+ vcr (6.3.1)
70
+ base64
65
71
 
66
72
  PLATFORMS
67
73
  arm64-darwin-21
74
+ arm64-darwin-23
68
75
  x86_64-linux
69
76
 
70
77
  DEPENDENCIES
71
- rake (~> 13.1)
78
+ rake (~> 13.2)
72
79
  relic_link!
73
80
  rspec (~> 3.13)
74
- rubocop (~> 1.61)
75
- vcr (~> 6.2)
81
+ rubocop (~> 1.66)
82
+ rubocop-rake
83
+ rubocop-rspec
84
+ vcr (~> 6.3)
76
85
 
77
86
  BUNDLED WITH
78
- 2.4.7
87
+ 2.5.17
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RelicLink
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/relic_link.svg)](https://badge.fury.io/rb/relic_link) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/relic_link/v1.1.0)
3
+ [![Gem Version](https://badge.fury.io/rb/relic_link.svg)](https://badge.fury.io/rb/relic_link) [![Documentation](https://img.shields.io/badge/View-Documentation-blue.svg)](https://rubydoc.info/github/ryantaylor/relic_link/v1.2.1)
4
4
 
5
5
  A client wrapper for Relic APIs. Currently supports the Company of Heroes 3 leaderboard, stats, and recent matches API.
6
6
 
@@ -29,7 +29,7 @@ client.recent_match_history(profile_ids: [8230])
29
29
  client.recent_match_history_by_profile_id(8230)
30
30
  client.personal_stats(profile_ids: [8230])
31
31
  ```
32
- Consult the [documentation](https://rubydoc.info/github/ryantaylor/relic_link/v1.1.0) for all endpoints that have been discovered and are currently queryable. Note that Relic does not publish official documentation for their endpoints, so the functionality here is based on best estimates and is subject to change without warning. Please open an issue if you are aware of endpoints that are not exposed in this library!
32
+ Consult the [documentation](https://rubydoc.info/github/ryantaylor/relic_link/v1.2.1) for all endpoints that have been discovered and are currently queryable. Note that Relic does not publish official documentation for their endpoints, so the functionality here is based on best estimates and is subject to change without warning. Please open an issue if you are aware of endpoints that are not exposed in this library!
33
33
 
34
34
  ## Contributing
35
35
 
@@ -14,7 +14,7 @@ module RelicLink
14
14
  # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
15
15
  # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
16
16
  def available_leaderboards
17
- get('getAvailableLeaderboards')
17
+ get(stats, 'getAvailableLeaderboards')
18
18
  end
19
19
 
20
20
  # Retrieve the leaderboard with the given ID. For your convenience
@@ -42,7 +42,7 @@ module RelicLink
42
42
  def leaderboard(options = {})
43
43
  raise ArgumentError, 'Required argument :leaderboard_id missing' if options[:leaderboard_id].nil?
44
44
 
45
- get('getLeaderboard2', format_sort_key(options))
45
+ get(stats, 'getLeaderboard2', format_sort_key(options))
46
46
  end
47
47
 
48
48
  private
@@ -33,7 +33,7 @@ module RelicLink
33
33
  raise ArgumentError, 'Missing one of required arguments :profile_ids, :aliases, or :profile_names'
34
34
  end
35
35
 
36
- get('getRecentMatchHistory', array_params(options))
36
+ get(stats, 'getRecentMatchHistory', array_params(options))
37
37
  end
38
38
 
39
39
  # Retrieve the match history information for the given profile ID. Profile
@@ -51,7 +51,7 @@ module RelicLink
51
51
  def recent_match_history_by_profile_id(profile_id)
52
52
  raise ArgumentError, 'Required argument :profile_id missing' if profile_id.nil?
53
53
 
54
- get('getRecentMatchHistoryByProfileId', { profile_id: })
54
+ get(stats, 'getRecentMatchHistoryByProfileId', { profile_id: })
55
55
  end
56
56
  end
57
57
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Api
6
+ module Endpoints
7
+ # Endpoint definitions for the internal CoH3 replays API.
8
+ module Replays
9
+ # Request a signed download URL for a replay at the given +path+, using the given
10
+ # authentication +token+. Path values can be retrieved from any endpoint that returns
11
+ # a player's game history, by looking for a +matchurls+ key in the JSON response.
12
+ # Note that this is a protected internal endpoint, which means a request without a
13
+ # valid token will return an authentication error. Tokens can be extracted from the
14
+ # game client by setting up a man-in-the-middle proxy between your game client and
15
+ # the Relic servers, but be warned that tokens expire quickly and this endpoint may
16
+ # change at any time. Use at your own risk!
17
+ #
18
+ # Relic generally keeps a player's 10 most recent replay files, and files older than
19
+ # that are removed from storage and inaccessible. When this happens, the replay is
20
+ # considered expired and requests for that path will raise an error.
21
+ #
22
+ # @option options [String] :token
23
+ # Valid CoH3 game client authentication token (required)
24
+ # @option options [String] :path
25
+ # Path to a CoH3 replay file stored on Relic's infrastructure (required)
26
+ #
27
+ # @raise [ArgumentError] if one of the required parameters are not provided.
28
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
29
+ # @raise [RelicLink::Errors::UnauthorizedError] if the +token+ provided is invalid.
30
+ # @raise [Errors::ExpiredPath] if the file at the +path+ provided has expired or does not exist.
31
+ def replay_url(options = {})
32
+ validate_options!(options)
33
+ get(replays, 'requestSignedReplayDownloadUri', {
34
+ connect_id: options[:token],
35
+ key: options[:path],
36
+ sessionID: options[:token]
37
+ })
38
+ end
39
+
40
+ private
41
+
42
+ def validate_options!(options)
43
+ missing = []
44
+ missing << 'token' if options[:token].nil?
45
+ missing << 'path' if options[:path].nil?
46
+ missing_str = missing.map { |s| ":#{s}" }.join(', ')
47
+
48
+ raise ArgumentError, "Missing required params #{missing_str}" unless missing.empty?
49
+
50
+ true
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -33,7 +33,7 @@ module RelicLink
33
33
  raise ArgumentError, 'Missing one of required params :profile_ids, :aliases, or :profile_names'
34
34
  end
35
35
 
36
- get('getPersonalStat', array_params(options))
36
+ get(stats, 'getPersonalStat', array_params(options))
37
37
  end
38
38
  end
39
39
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'endpoints/leaderboards'
4
4
  require_relative 'endpoints/matches'
5
+ require_relative 'endpoints/replays'
5
6
  require_relative 'endpoints/stats'
6
7
 
7
8
  module RelicLink
@@ -10,6 +11,7 @@ module RelicLink
10
11
  module Endpoints
11
12
  include Leaderboards
12
13
  include Matches
14
+ include Replays
13
15
  include Stats
14
16
  end
15
17
  end
@@ -5,6 +5,8 @@ module RelicLink
5
5
  module Api
6
6
  # Errors specific to the Relic CoH3 API.
7
7
  module Errors
8
+ # Raised when querying for a replay URL with a path that has expired.
9
+ class ExpiredPath < RelicError; end
8
10
  # Raised when querying for a leaderboard that doesn't exist.
9
11
  class NotFound < RelicError; end
10
12
  # Raised when querying for aliases that don't exist.
@@ -10,13 +10,33 @@ module RelicLink
10
10
  module Connection
11
11
  private
12
12
 
13
- def connection
14
- @connection ||= ::Faraday.new(
13
+ def stats
14
+ @stats ||= ::Faraday.new(
15
15
  url: 'https://coh3-api.reliclink.com/community/leaderboard'
16
16
  ) do |f|
17
+ ::Faraday::Mashify::Middleware.mash_class = ResponseMash
18
+
17
19
  f.params[:title] = 'coh3'
18
20
 
19
- f.use ::RelicLink::Coh3::Faraday::Response::RaiseError
21
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseHttpError
22
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseStatsError
23
+ f.response :mashify
24
+ f.response :json
25
+ f.use ::RelicLink::Faraday::Response::WrapError
26
+ f.response :logger, logger if logger
27
+ end
28
+ end
29
+
30
+ def replays
31
+ @replays ||= ::Faraday.new(
32
+ url: 'https://coh3-api.reliclink.com/game/Replay'
33
+ ) do |f|
34
+ ::Faraday::Mashify::Middleware.mash_class = ResponseMash
35
+
36
+ f.params[:callNum] = rand(5..354)
37
+
38
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseHttpError
39
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseReplayError
20
40
  f.response :mashify
21
41
  f.response :json
22
42
  f.use ::RelicLink::Faraday::Response::WrapError
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Faraday
6
+ module Response
7
+ # Middleware to catch CoH3 API errors and raise them as exceptions.
8
+ class RaiseHttpError < ::Faraday::Middleware
9
+ def on_complete(env)
10
+ raise RelicLink::Errors::BadRequestError, env.response if env.status == 400
11
+ raise RelicLink::Errors::UnauthorizedError, env.response if env.status == 401
12
+ raise RelicLink::Errors::RateLimitError, env.response if env.status == 429
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Faraday
6
+ module Response
7
+ # Middleware to catch CoH3 API errors and raise them as exceptions.
8
+ class RaiseReplayError < ::Faraday::Middleware
9
+ def on_complete(env)
10
+ return unless env.success?
11
+
12
+ body = env.body
13
+ return unless body
14
+
15
+ raise RelicLink::Coh3::Api::Errors::ExpiredPath.new('path has expired', env.response) if body.first == 1
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -5,11 +5,8 @@ module RelicLink
5
5
  module Faraday
6
6
  module Response
7
7
  # Middleware to catch CoH3 API errors and raise them as exceptions.
8
- class RaiseError < ::Faraday::Middleware
8
+ class RaiseStatsError < ::Faraday::Middleware
9
9
  def on_complete(env)
10
- raise RelicLink::Errors::BadRequestError, env.response if env.status == 400
11
- raise RelicLink::Errors::RateLimitError, env.response if env.status == 429
12
-
13
10
  return unless env.success?
14
11
 
15
12
  body = env.body
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Faraday
6
+ # Wrapper for +Hashie::Mash+ that disables conflict warnings.
7
+ class ResponseMash < Hashie::Mash
8
+ disable_warnings
9
+ end
10
+ end
11
+ end
12
+ end
@@ -29,6 +29,13 @@ module RelicLink
29
29
  end
30
30
  end
31
31
 
32
+ # Raised when a 401 is returned in an API response
33
+ class UnauthorizedError < HttpRequestError
34
+ def initialize(response)
35
+ super('unauthorized', response)
36
+ end
37
+ end
38
+
32
39
  # Raised when a 429 is returned in an API response.
33
40
  class RateLimitError < HttpRequestError
34
41
  def initialize(response)
@@ -5,7 +5,7 @@ module RelicLink
5
5
  # Wrapper for HTTP client +GET+ requests. You should never
6
6
  # have to use this directly.
7
7
  module Request
8
- def get(path, options = {})
8
+ def get(connection, path, options = {})
9
9
  connection.get(path) do |req|
10
10
  req.params = req.params.merge(options)
11
11
  end.body
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelicLink
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.1'
5
5
  end
data/lib/relic_link.rb CHANGED
@@ -11,12 +11,15 @@ require_relative 'relic_link/errors/server_error'
11
11
  require_relative 'relic_link/coh3/api/errors/relic_error'
12
12
  require_relative 'relic_link/coh3/api/error'
13
13
  require_relative 'relic_link/coh3/api/errors'
14
- require_relative 'relic_link/coh3/faraday/response/raise_error'
14
+ require_relative 'relic_link/coh3/faraday/response/raise_http_error'
15
+ require_relative 'relic_link/coh3/faraday/response/raise_replay_error'
16
+ require_relative 'relic_link/coh3/faraday/response/raise_stats_error'
15
17
  require_relative 'relic_link/faraday/response/wrap_error'
16
18
 
17
19
  require_relative 'relic_link/coh3/util'
18
20
  require_relative 'relic_link/coh3/api/endpoints'
19
21
  require_relative 'relic_link/faraday/request'
22
+ require_relative 'relic_link/coh3/faraday/response_mash'
20
23
  require_relative 'relic_link/coh3/faraday/connection'
21
24
  require_relative 'relic_link/coh3/client'
22
25
  require_relative 'relic_link/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relic_link
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryantaylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -75,6 +75,7 @@ files:
75
75
  - lib/relic_link/coh3/api/endpoints/leaderboards/ids.rb
76
76
  - lib/relic_link/coh3/api/endpoints/leaderboards/sort.rb
77
77
  - lib/relic_link/coh3/api/endpoints/matches.rb
78
+ - lib/relic_link/coh3/api/endpoints/replays.rb
78
79
  - lib/relic_link/coh3/api/endpoints/stats.rb
79
80
  - lib/relic_link/coh3/api/error.rb
80
81
  - lib/relic_link/coh3/api/errors.rb
@@ -82,7 +83,10 @@ files:
82
83
  - lib/relic_link/coh3/client.rb
83
84
  - lib/relic_link/coh3/config.rb
84
85
  - lib/relic_link/coh3/faraday/connection.rb
85
- - lib/relic_link/coh3/faraday/response/raise_error.rb
86
+ - lib/relic_link/coh3/faraday/response/raise_http_error.rb
87
+ - lib/relic_link/coh3/faraday/response/raise_replay_error.rb
88
+ - lib/relic_link/coh3/faraday/response/raise_stats_error.rb
89
+ - lib/relic_link/coh3/faraday/response_mash.rb
86
90
  - lib/relic_link/coh3/util.rb
87
91
  - lib/relic_link/errors/server_error.rb
88
92
  - lib/relic_link/faraday/request.rb
@@ -114,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  - !ruby/object:Gem::Version
115
119
  version: '0'
116
120
  requirements: []
117
- rubygems_version: 3.4.12
121
+ rubygems_version: 3.5.10
118
122
  signing_key:
119
123
  specification_version: 4
120
124
  summary: Wrapper for Relic APIs