relic_link 1.1.0 → 1.2.0

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: 933d2d2f0ea7389569d273f910d7c81ccd0abb7f4db84353ba52a537a44fcff8
4
+ data.tar.gz: 927197b6cf76cc074e4a01bf945f9970005e1c10322ec260f3117022fa39c9ef
5
5
  SHA512:
6
- metadata.gz: 9b6b44e95aab707016e1825eecd7f952f63bdceb299b5622fa6d61b27e8930b7559066eab6fd35f83aa4be2131713bab4c17097cb86f46abe878d7bba3228480
7
- data.tar.gz: cf4eec64ecffecffb3e4d0e313c5fc0f6c66d5135103be65ddffa4c8251c9d960afbaa706c945290e5c6ce160eaeb18f39a2e4d5055db212906ce8811d1a1e08
6
+ metadata.gz: d1a53aefa0bd7708f790901dd03d25446b04702dabf7037abeacdef38127365ba9d5f9ffd37969a5604ca254ed73f08f2fa6908b7eda5cba6427e9e49c314d18
7
+ data.tar.gz: 5b1286b258c58bd9fcaf29123da22a944a6942a455b955bfe1b7e4e9b8f1951500c495b13e364d58ce3141cc8a8fe323482904b756f7b2f72726cf81d826d657
data/.rubocop.yml CHANGED
@@ -8,6 +8,9 @@ Layout/AccessModifierIndentation:
8
8
  Metrics/BlockLength:
9
9
  Enabled: false
10
10
 
11
+ Metrics/MethodLength:
12
+ Max: 15
13
+
11
14
  Style/GlobalStdStream:
12
15
  Enabled: false
13
16
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.2.4
data/Gemfile CHANGED
@@ -5,10 +5,10 @@ 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.65'
13
13
 
14
14
  gem 'vcr', '~> 6.2'
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.0)
5
5
  faraday (~> 2.7)
6
6
  faraday-mashify (~> 0.1)
7
7
  hashie (~> 5.0)
@@ -11,68 +11,73 @@ GEM
11
11
  specs:
12
12
  ast (2.4.2)
13
13
  diff-lcs (1.5.1)
14
- faraday (2.9.0)
14
+ faraday (2.10.1)
15
15
  faraday-net_http (>= 2.0, < 3.2)
16
+ logger
16
17
  faraday-mashify (0.1.1)
17
18
  faraday (~> 2.0)
18
19
  hashie
19
- faraday-net_http (3.1.0)
20
+ faraday-net_http (3.1.1)
20
21
  net-http
21
22
  hashie (5.0.0)
22
- json (2.7.1)
23
+ json (2.7.2)
23
24
  language_server-protocol (3.17.0.3)
25
+ logger (1.6.0)
24
26
  net-http (0.4.1)
25
27
  uri
26
- parallel (1.24.0)
27
- parser (3.3.0.5)
28
+ parallel (1.26.1)
29
+ parser (3.3.4.2)
28
30
  ast (~> 2.4.1)
29
31
  racc
30
- racc (1.7.3)
32
+ racc (1.8.1)
31
33
  rainbow (3.1.1)
32
- rake (13.1.0)
33
- regexp_parser (2.9.0)
34
- rexml (3.2.6)
34
+ rake (13.2.1)
35
+ regexp_parser (2.9.2)
36
+ rexml (3.3.4)
37
+ strscan
35
38
  rspec (3.13.0)
36
39
  rspec-core (~> 3.13.0)
37
40
  rspec-expectations (~> 3.13.0)
38
41
  rspec-mocks (~> 3.13.0)
39
42
  rspec-core (3.13.0)
40
43
  rspec-support (~> 3.13.0)
41
- rspec-expectations (3.13.0)
44
+ rspec-expectations (3.13.1)
42
45
  diff-lcs (>= 1.2.0, < 2.0)
43
46
  rspec-support (~> 3.13.0)
44
- rspec-mocks (3.13.0)
47
+ rspec-mocks (3.13.1)
45
48
  diff-lcs (>= 1.2.0, < 2.0)
46
49
  rspec-support (~> 3.13.0)
47
50
  rspec-support (3.13.1)
48
- rubocop (1.61.0)
51
+ rubocop (1.65.1)
49
52
  json (~> 2.3)
50
53
  language_server-protocol (>= 3.17.0)
51
54
  parallel (~> 1.10)
52
55
  parser (>= 3.3.0.2)
53
56
  rainbow (>= 2.2.2, < 4.0)
54
- regexp_parser (>= 1.8, < 3.0)
57
+ regexp_parser (>= 2.4, < 3.0)
55
58
  rexml (>= 3.2.5, < 4.0)
56
- rubocop-ast (>= 1.30.0, < 2.0)
59
+ rubocop-ast (>= 1.31.1, < 2.0)
57
60
  ruby-progressbar (~> 1.7)
58
61
  unicode-display_width (>= 2.4.0, < 3.0)
59
- rubocop-ast (1.31.1)
60
- parser (>= 3.3.0.4)
62
+ rubocop-ast (1.32.0)
63
+ parser (>= 3.3.1.0)
61
64
  ruby-progressbar (1.13.0)
65
+ strscan (3.1.0)
62
66
  unicode-display_width (2.5.0)
63
67
  uri (0.13.0)
64
68
  vcr (6.2.0)
65
69
 
66
70
  PLATFORMS
67
71
  arm64-darwin-21
72
+ arm64-darwin-23
68
73
  x86_64-linux
69
74
 
70
75
  DEPENDENCIES
71
- rake (~> 13.1)
76
+ rake (~> 13.2)
72
77
  relic_link!
73
78
  rspec (~> 3.13)
74
- rubocop (~> 1.61)
79
+ rubocop (~> 1.65)
75
80
  vcr (~> 6.2)
76
81
 
77
82
  BUNDLED WITH
78
- 2.4.7
83
+ 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.0)
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.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!
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,29 @@ 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
17
  f.params[:title] = 'coh3'
18
18
 
19
- f.use ::RelicLink::Coh3::Faraday::Response::RaiseError
19
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseHttpError
20
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseStatsError
21
+ f.response :mashify
22
+ f.response :json
23
+ f.use ::RelicLink::Faraday::Response::WrapError
24
+ f.response :logger, logger if logger
25
+ end
26
+ end
27
+
28
+ def replays
29
+ @replays ||= ::Faraday.new(
30
+ url: 'https://coh3-api.reliclink.com/game/Replay'
31
+ ) do |f|
32
+ f.params[:callNum] = rand(5..354)
33
+
34
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseHttpError
35
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseReplayError
20
36
  f.response :mashify
21
37
  f.response :json
22
38
  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
@@ -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.0'
5
5
  end
data/lib/relic_link.rb CHANGED
@@ -11,7 +11,9 @@ 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'
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.0
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-08-09 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,9 @@ 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
86
89
  - lib/relic_link/coh3/util.rb
87
90
  - lib/relic_link/errors/server_error.rb
88
91
  - lib/relic_link/faraday/request.rb
@@ -114,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
- rubygems_version: 3.4.12
120
+ rubygems_version: 3.5.10
118
121
  signing_key:
119
122
  specification_version: 4
120
123
  summary: Wrapper for Relic APIs