relic_link 0.1.2 → 1.1.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: d2c116d6c2b0d54175c3bd00e7989271a969cda9f449e9a4ed2cf39e9680a830
4
- data.tar.gz: 7fc992b307a307571689b9b882a749f98b9b704e91c33e96a1efc2ab98283148
3
+ metadata.gz: b0a6925bd59c93badd256bc6e31c23cf2ecd58827b93b604f2ce4fd954924ee5
4
+ data.tar.gz: 68e0f9f49e38f2c5d7b6e870684828c21bc88e9d4ecd56c4a7d6245e94462d43
5
5
  SHA512:
6
- metadata.gz: fe144e6f63b10cf4692c796860aa35d682d4e9738aab9ac0af471465ec7415628d36825581f2f505f07b40af7013052cfd8d82e647c5113b250325b8424127e8
7
- data.tar.gz: 9c84ca93917faf1262bbdcd49446ec5d6bf813df88e984bf33c19c3665a37c3b7b34b6056485e8fb9cb45c06fb71a236c2a810633eeff6d8e63cd09b30260973
6
+ metadata.gz: 9b6b44e95aab707016e1825eecd7f952f63bdceb299b5622fa6d61b27e8930b7559066eab6fd35f83aa4be2131713bab4c17097cb86f46abe878d7bba3228480
7
+ data.tar.gz: cf4eec64ecffecffb3e4d0e313c5fc0f6c66d5135103be65ddffa4c8251c9d960afbaa706c945290e5c6ce160eaeb18f39a2e4d5055db212906ce8811d1a1e08
data/.rubocop.yml CHANGED
@@ -2,6 +2,9 @@ AllCops:
2
2
  TargetRubyVersion: 3.1
3
3
  NewCops: enable
4
4
 
5
+ Layout/AccessModifierIndentation:
6
+ EnforcedStyle: outdent
7
+
5
8
  Metrics/BlockLength:
6
9
  Enabled: false
7
10
 
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.0'
8
+ gem 'rake', '~> 13.1'
9
9
 
10
- gem 'rspec', '~> 3.0'
10
+ gem 'rspec', '~> 3.13'
11
11
 
12
- gem 'rubocop', '~> 1.21'
12
+ gem 'rubocop', '~> 1.61'
13
13
 
14
- gem 'vcr', '~> 6.1'
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 (0.1.1)
4
+ relic_link (1.1.0)
5
5
  faraday (~> 2.7)
6
6
  faraday-mashify (~> 0.1)
7
7
  hashie (~> 5.0)
@@ -10,63 +10,69 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
- diff-lcs (1.5.0)
14
- faraday (2.7.4)
15
- faraday-net_http (>= 2.0, < 3.1)
16
- ruby2_keywords (>= 0.0.4)
13
+ diff-lcs (1.5.1)
14
+ faraday (2.9.0)
15
+ faraday-net_http (>= 2.0, < 3.2)
17
16
  faraday-mashify (0.1.1)
18
17
  faraday (~> 2.0)
19
18
  hashie
20
- faraday-net_http (3.0.2)
19
+ faraday-net_http (3.1.0)
20
+ net-http
21
21
  hashie (5.0.0)
22
- json (2.6.3)
23
- parallel (1.23.0)
24
- parser (3.2.2.1)
22
+ json (2.7.1)
23
+ language_server-protocol (3.17.0.3)
24
+ net-http (0.4.1)
25
+ uri
26
+ parallel (1.24.0)
27
+ parser (3.3.0.5)
25
28
  ast (~> 2.4.1)
29
+ racc
30
+ racc (1.7.3)
26
31
  rainbow (3.1.1)
27
- rake (13.0.6)
28
- regexp_parser (2.8.0)
29
- rexml (3.2.5)
30
- rspec (3.12.0)
31
- rspec-core (~> 3.12.0)
32
- rspec-expectations (~> 3.12.0)
33
- rspec-mocks (~> 3.12.0)
34
- rspec-core (3.12.2)
35
- rspec-support (~> 3.12.0)
36
- rspec-expectations (3.12.3)
32
+ rake (13.1.0)
33
+ regexp_parser (2.9.0)
34
+ rexml (3.2.6)
35
+ rspec (3.13.0)
36
+ rspec-core (~> 3.13.0)
37
+ rspec-expectations (~> 3.13.0)
38
+ rspec-mocks (~> 3.13.0)
39
+ rspec-core (3.13.0)
40
+ rspec-support (~> 3.13.0)
41
+ rspec-expectations (3.13.0)
37
42
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.12.0)
39
- rspec-mocks (3.12.5)
43
+ rspec-support (~> 3.13.0)
44
+ rspec-mocks (3.13.0)
40
45
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.12.0)
42
- rspec-support (3.12.0)
43
- rubocop (1.50.2)
46
+ rspec-support (~> 3.13.0)
47
+ rspec-support (3.13.1)
48
+ rubocop (1.61.0)
44
49
  json (~> 2.3)
50
+ language_server-protocol (>= 3.17.0)
45
51
  parallel (~> 1.10)
46
- parser (>= 3.2.0.0)
52
+ parser (>= 3.3.0.2)
47
53
  rainbow (>= 2.2.2, < 4.0)
48
54
  regexp_parser (>= 1.8, < 3.0)
49
55
  rexml (>= 3.2.5, < 4.0)
50
- rubocop-ast (>= 1.28.0, < 2.0)
56
+ rubocop-ast (>= 1.30.0, < 2.0)
51
57
  ruby-progressbar (~> 1.7)
52
58
  unicode-display_width (>= 2.4.0, < 3.0)
53
- rubocop-ast (1.28.1)
54
- parser (>= 3.2.1.0)
59
+ rubocop-ast (1.31.1)
60
+ parser (>= 3.3.0.4)
55
61
  ruby-progressbar (1.13.0)
56
- ruby2_keywords (0.0.5)
57
- unicode-display_width (2.4.2)
58
- vcr (6.1.0)
62
+ unicode-display_width (2.5.0)
63
+ uri (0.13.0)
64
+ vcr (6.2.0)
59
65
 
60
66
  PLATFORMS
61
67
  arm64-darwin-21
62
68
  x86_64-linux
63
69
 
64
70
  DEPENDENCIES
65
- rake (~> 13.0)
71
+ rake (~> 13.1)
66
72
  relic_link!
67
- rspec (~> 3.0)
68
- rubocop (~> 1.21)
69
- vcr (~> 6.1)
73
+ rspec (~> 3.13)
74
+ rubocop (~> 1.61)
75
+ vcr (~> 6.2)
70
76
 
71
77
  BUNDLED WITH
72
78
  2.4.7
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/v0.1.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)
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/v0.1.2) 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.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!
33
33
 
34
34
  ## Contributing
35
35
 
@@ -10,6 +10,9 @@ module RelicLink
10
10
  # Endpoint definitions for the CoH3 leaderboards API.
11
11
  module Leaderboards
12
12
  # List available leaderboards and associated metadata.
13
+ #
14
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
15
+ # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
13
16
  def available_leaderboards
14
17
  get('getAvailableLeaderboards')
15
18
  end
@@ -31,13 +34,18 @@ module RelicLink
31
34
  # Field to sort the leaderboard entries by.
32
35
  #
33
36
  # @raise [ArgumentError] if the required parameters aren't provided.
37
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
38
+ # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
39
+ # @raise [Errors::NotFound] if +leaderboard_id+ does not correspond to a leaderboard.
40
+ # @raise [RelicLink::Errors::BadRequestError] if +start+, +count+, or +sort_by+ are outside the
41
+ # limits enumerated above.
34
42
  def leaderboard(options = {})
35
43
  raise ArgumentError, 'Required argument :leaderboard_id missing' if options[:leaderboard_id].nil?
36
44
 
37
45
  get('getLeaderboard2', format_sort_key(options))
38
46
  end
39
47
 
40
- private
48
+ private
41
49
 
42
50
  def format_sort_key(options)
43
51
  options.transform_keys do |key|
@@ -22,6 +22,12 @@ module RelicLink
22
22
  # be in the format +/steam/<ID>+ (one of required).
23
23
  #
24
24
  # @raise [ArgumentError] if none of the required parameters are provided.
25
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
26
+ # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
27
+ # @raise [Errors::UnknownProfileIds] if no values in +profile_ids+ match known profile IDs.
28
+ # @raise [Errors::UnknownAliases] if no values in +aliases+ match known aliases.
29
+ # @raise [Errors::UnregisteredProfileName] if no values in +profile_names+ match known profile names.
30
+ # @raise [RelicLink::Errors::BadRequestError] if inputs violate type constraints.
25
31
  def recent_match_history(options = {})
26
32
  unless options.keys.intersect?(%i[profile_ids aliases profile_names])
27
33
  raise ArgumentError, 'Missing one of required arguments :profile_ids, :aliases, or :profile_names'
@@ -39,6 +45,9 @@ module RelicLink
39
45
  # @param profile_id [Integer] Internal Relic ID of player whose stats you wish to retrieve (required).
40
46
  #
41
47
  # @raise [ArgumentError] if no +profile_id+ provided.
48
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
49
+ # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
50
+ # @raise [RelicLink::Errors::BadRequestError] if input violates type constraints.
42
51
  def recent_match_history_by_profile_id(profile_id)
43
52
  raise ArgumentError, 'Required argument :profile_id missing' if profile_id.nil?
44
53
 
@@ -22,6 +22,12 @@ module RelicLink
22
22
  # be in the format +/steam/<ID>+ (one of required).
23
23
  #
24
24
  # @raise [ArgumentError] if none of the required parameters are provided.
25
+ # @raise [RelicLink::Errors::ServerError] if Relic's API is down.
26
+ # @raise [RelicLink::Errors::RateLimitError] if you're rate-limited.
27
+ # @raise [Errors::UnknownProfileIds] if no values in +profile_ids+ match known profile IDs.
28
+ # @raise [Errors::UnknownAliases] if no values in +aliases+ match known aliases.
29
+ # @raise [Errors::UnregisteredProfileName] if no values in +profile_names+ match known profile names.
30
+ # @raise [RelicLink::Errors::BadRequestError] if inputs violate type constraints.
25
31
  def personal_stats(options = {})
26
32
  unless options.keys.intersect?(%i[profile_ids aliases profile_names])
27
33
  raise ArgumentError, 'Missing one of required params :profile_ids, :aliases, or :profile_names'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Api
6
+ Error = Errors::RelicError
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Api
6
+ module Errors
7
+ # Base wrapper for Relic CoH3 API errors.
8
+ class RelicError < ::Faraday::Error
9
+ attr_reader :response
10
+
11
+ def initialize(message, response = nil)
12
+ super(message)
13
+ @response = response
14
+ end
15
+
16
+ def error
17
+ response.body.error
18
+ end
19
+
20
+ def errors
21
+ response.body.errors
22
+ end
23
+
24
+ def response_metadata
25
+ response.body.response_metadata
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Coh3
5
+ module Api
6
+ # Errors specific to the Relic CoH3 API.
7
+ module Errors
8
+ # Raised when querying for a leaderboard that doesn't exist.
9
+ class NotFound < RelicError; end
10
+ # Raised when querying for aliases that don't exist.
11
+ class UnknownAliases < RelicError; end
12
+ # Raised when querying for profile IDs that don't exist.
13
+ class UnknownProfileIds < RelicError; end
14
+ # Raised when querying for profile names (such as Steam IDs) that don't exist.
15
+ class UnregisteredProfileName < RelicError; end
16
+
17
+ # Mapping of Relic error messages to error classes.
18
+ ERROR_CLASSES = {
19
+ 'NOT_FOUND' => NotFound,
20
+ 'UNKNOWN_ALIASES' => UnknownAliases,
21
+ 'UNKNOWN_PROFILE_IDS' => UnknownProfileIds,
22
+ 'UNREGISTERED_PROFILE_NAME' => UnregisteredProfileName
23
+ }.freeze
24
+ end
25
+ end
26
+ end
27
+ end
@@ -8,7 +8,7 @@ module RelicLink
8
8
  # Faraday connection implementation for API requests. You shouldn't
9
9
  # ever have to use this directly.
10
10
  module Connection
11
- private
11
+ private
12
12
 
13
13
  def connection
14
14
  @connection ||= ::Faraday.new(
@@ -16,9 +16,11 @@ module RelicLink
16
16
  ) do |f|
17
17
  f.params[:title] = 'coh3'
18
18
 
19
- f.response :logger, logger if logger
19
+ f.use ::RelicLink::Coh3::Faraday::Response::RaiseError
20
20
  f.response :mashify
21
21
  f.response :json
22
+ f.use ::RelicLink::Faraday::Response::WrapError
23
+ f.response :logger, logger if logger
22
24
  end
23
25
  end
24
26
  end
@@ -0,0 +1,35 @@
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 RaiseError < ::Faraday::Middleware
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
+ return unless env.success?
14
+
15
+ body = env.body
16
+ return unless body
17
+
18
+ return if body['result']['code'].zero?
19
+
20
+ raise_relic_error!(body, env)
21
+ end
22
+
23
+ private
24
+
25
+ def raise_relic_error!(body, env)
26
+ error_message = body['result']['message']
27
+ error_class = RelicLink::Coh3::Api::Errors::ERROR_CLASSES[error_message]
28
+ error_class ||= RelicLink::Coh3::Api::Errors::RelicError
29
+ raise error_class.new(error_message, env.response)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Errors
5
+ # Base wrapper for API server errors.
6
+ class ServerError < ::Faraday::Error
7
+ attr_reader :response
8
+
9
+ def initialize(message, response)
10
+ @response = response
11
+ super(message)
12
+ end
13
+ end
14
+
15
+ # Raised when an API response cannot be parsed.
16
+ class ParsingError < ServerError
17
+ def initialize(response)
18
+ super('parsing_error', response)
19
+ end
20
+ end
21
+
22
+ # Base wrapper for API HTTP request errors.
23
+ class HttpRequestError < ServerError; end
24
+
25
+ # Raised when a 400 is returned in an API response.
26
+ class BadRequestError < HttpRequestError
27
+ def initialize(response)
28
+ super('bad_request', response)
29
+ end
30
+ end
31
+
32
+ # Raised when a 429 is returned in an API response.
33
+ class RateLimitError < HttpRequestError
34
+ def initialize(response)
35
+ super('rate_limited', response)
36
+ end
37
+ end
38
+
39
+ # Raised when an API request times out.
40
+ class TimeoutError < HttpRequestError
41
+ def initialize(response)
42
+ super('timeout_error', response)
43
+ end
44
+ end
45
+
46
+ # Raised when a 5xx is returned in an API response.
47
+ class UnavailableError < HttpRequestError
48
+ def initialize(response)
49
+ super('unavailable_error', response)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -9,6 +9,8 @@ module RelicLink
9
9
  connection.get(path) do |req|
10
10
  req.params = req.params.merge(options)
11
11
  end.body
12
+ rescue ::Faraday::ParsingError => e
13
+ raise RelicLink::Errors::ParsingError, e.response
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelicLink
4
+ module Faraday
5
+ module Response
6
+ # Middleware to wrap generic API errors and raise them as exceptions.
7
+ class WrapError < ::Faraday::Middleware
8
+ UNAVAILABLE_ERROR_STATUSES = (500..599)
9
+
10
+ def on_complete(env)
11
+ return unless UNAVAILABLE_ERROR_STATUSES.cover?(env.status)
12
+
13
+ raise RelicLink::Errors::UnavailableError, env.response
14
+ end
15
+
16
+ def call(env)
17
+ super
18
+ rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed
19
+ raise RelicLink::Errors::TimeoutError, env.response
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelicLink
4
- VERSION = '0.1.2'
4
+ VERSION = '1.1.0'
5
5
  end
data/lib/relic_link.rb CHANGED
@@ -7,6 +7,13 @@ require 'json'
7
7
  require_relative 'relic_link/logger'
8
8
  require_relative 'relic_link/coh3/config'
9
9
 
10
+ require_relative 'relic_link/errors/server_error'
11
+ require_relative 'relic_link/coh3/api/errors/relic_error'
12
+ require_relative 'relic_link/coh3/api/error'
13
+ require_relative 'relic_link/coh3/api/errors'
14
+ require_relative 'relic_link/coh3/faraday/response/raise_error'
15
+ require_relative 'relic_link/faraday/response/wrap_error'
16
+
10
17
  require_relative 'relic_link/coh3/util'
11
18
  require_relative 'relic_link/coh3/api/endpoints'
12
19
  require_relative 'relic_link/faraday/request'
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: 0.1.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryantaylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -76,11 +76,17 @@ files:
76
76
  - lib/relic_link/coh3/api/endpoints/leaderboards/sort.rb
77
77
  - lib/relic_link/coh3/api/endpoints/matches.rb
78
78
  - lib/relic_link/coh3/api/endpoints/stats.rb
79
+ - lib/relic_link/coh3/api/error.rb
80
+ - lib/relic_link/coh3/api/errors.rb
81
+ - lib/relic_link/coh3/api/errors/relic_error.rb
79
82
  - lib/relic_link/coh3/client.rb
80
83
  - lib/relic_link/coh3/config.rb
81
84
  - lib/relic_link/coh3/faraday/connection.rb
85
+ - lib/relic_link/coh3/faraday/response/raise_error.rb
82
86
  - lib/relic_link/coh3/util.rb
87
+ - lib/relic_link/errors/server_error.rb
83
88
  - lib/relic_link/faraday/request.rb
89
+ - lib/relic_link/faraday/response/wrap_error.rb
84
90
  - lib/relic_link/logger.rb
85
91
  - lib/relic_link/version.rb
86
92
  - relic_link.gemspec