relic_link 0.1.1 → 1.0.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 +4 -4
- data/.rubocop.yml +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +9 -6
- data/README.md +2 -2
- data/lib/relic_link/coh3/api/error.rb +9 -0
- data/lib/relic_link/coh3/api/errors/relic_error.rb +31 -0
- data/lib/relic_link/coh3/api/errors.rb +27 -0
- data/lib/relic_link/coh3/client.rb +28 -0
- data/lib/relic_link/coh3/config.rb +40 -0
- data/lib/relic_link/coh3/faraday/connection.rb +3 -1
- data/lib/relic_link/coh3/faraday/response/raise_error.rb +28 -0
- data/lib/relic_link/errors/server_error.rb +46 -0
- data/lib/relic_link/faraday/request.rb +2 -0
- data/lib/relic_link/faraday/response/wrap_error.rb +24 -0
- data/lib/relic_link/logger.rb +20 -0
- data/lib/relic_link/version.rb +1 -1
- data/lib/relic_link.rb +11 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91f52523becf51e404509246fefdcdbd84a86113924a1e8d0c9d82a1c29b0930
|
4
|
+
data.tar.gz: 914a001a68c62e4ddea565bc2591c09ffe3ce71de99461f079a56c91e6891dae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb580a08a348b9332adfd000c3621f7c91553f066618e0ae0f6e2ddafec2d9be22dfd61e2cbac35a4464891bd5cf92ea2df5f0194413c1065b5623e6cf6bf1a
|
7
|
+
data.tar.gz: 6641c8b30587fb37118a3201a8e3dca50ebd112f96280774f74ad9749ec2e350e6cd4ffc342be75608c025a2fa5ee87f8a76aafec9f88973052361ff68ce54c8
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relic_link (0.1.
|
4
|
+
relic_link (0.1.2)
|
5
5
|
faraday (~> 2.7)
|
6
6
|
faraday-mashify (~> 0.1)
|
7
7
|
hashie (~> 5.0)
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
ast (2.4.2)
|
13
13
|
diff-lcs (1.5.0)
|
14
|
-
faraday (2.7.
|
14
|
+
faraday (2.7.6)
|
15
15
|
faraday-net_http (>= 2.0, < 3.1)
|
16
16
|
ruby2_keywords (>= 0.0.4)
|
17
17
|
faraday-mashify (0.1.1)
|
@@ -21,8 +21,10 @@ GEM
|
|
21
21
|
hashie (5.0.0)
|
22
22
|
json (2.6.3)
|
23
23
|
parallel (1.23.0)
|
24
|
-
parser (3.2.2.
|
24
|
+
parser (3.2.2.3)
|
25
25
|
ast (~> 2.4.1)
|
26
|
+
racc
|
27
|
+
racc (1.7.0)
|
26
28
|
rainbow (3.1.1)
|
27
29
|
rake (13.0.6)
|
28
30
|
regexp_parser (2.8.0)
|
@@ -40,7 +42,7 @@ GEM
|
|
40
42
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
43
|
rspec-support (~> 3.12.0)
|
42
44
|
rspec-support (3.12.0)
|
43
|
-
rubocop (1.
|
45
|
+
rubocop (1.52.0)
|
44
46
|
json (~> 2.3)
|
45
47
|
parallel (~> 1.10)
|
46
48
|
parser (>= 3.2.0.0)
|
@@ -50,7 +52,7 @@ GEM
|
|
50
52
|
rubocop-ast (>= 1.28.0, < 2.0)
|
51
53
|
ruby-progressbar (~> 1.7)
|
52
54
|
unicode-display_width (>= 2.4.0, < 3.0)
|
53
|
-
rubocop-ast (1.
|
55
|
+
rubocop-ast (1.29.0)
|
54
56
|
parser (>= 3.2.1.0)
|
55
57
|
ruby-progressbar (1.13.0)
|
56
58
|
ruby2_keywords (0.0.5)
|
@@ -59,12 +61,13 @@ GEM
|
|
59
61
|
|
60
62
|
PLATFORMS
|
61
63
|
arm64-darwin-21
|
64
|
+
x86_64-linux
|
62
65
|
|
63
66
|
DEPENDENCIES
|
64
67
|
rake (~> 13.0)
|
65
68
|
relic_link!
|
66
69
|
rspec (~> 3.0)
|
67
|
-
rubocop (~> 1.
|
70
|
+
rubocop (~> 1.52)
|
68
71
|
vcr (~> 6.1)
|
69
72
|
|
70
73
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RelicLink
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/relic_link) [](https://rubydoc.info/github/ryantaylor/relic_link/
|
3
|
+
[](https://badge.fury.io/rb/relic_link) [](https://rubydoc.info/github/ryantaylor/relic_link/v1.0.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/
|
32
|
+
Consult the [documentation](https://rubydoc.info/github/ryantaylor/relic_link/v1.0.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
|
|
@@ -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
|
@@ -13,6 +13,34 @@ module RelicLink
|
|
13
13
|
include Faraday::Connection
|
14
14
|
include Api::Endpoints
|
15
15
|
include Util
|
16
|
+
|
17
|
+
attr_accessor(*RelicLink::Coh3::Config::ATTRIBUTES)
|
18
|
+
|
19
|
+
# Initializes a new client.
|
20
|
+
#
|
21
|
+
# @option options [Logger] :logger
|
22
|
+
# Instance of a logging class. If not provided, defaults to +STDOUT+ at +Logging::WARN+.
|
23
|
+
#
|
24
|
+
# @return [Client]
|
25
|
+
def initialize(options = {})
|
26
|
+
RelicLink::Coh3::Config::ATTRIBUTES.each do |key|
|
27
|
+
send("#{key}=", options.fetch(key, RelicLink::Coh3.config.send(key)))
|
28
|
+
end
|
29
|
+
@logger ||= RelicLink::Coh3::Config.logger || RelicLink::Logger.default
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
# Set configuration options. Can be set on the returned object
|
34
|
+
# directly or in a block.
|
35
|
+
def configure
|
36
|
+
block_given? ? yield(RelicLink::Coh3::Config) : RelicLink::Coh3::Config
|
37
|
+
end
|
38
|
+
|
39
|
+
# Current config module.
|
40
|
+
def config
|
41
|
+
RelicLink::Coh3::Config
|
42
|
+
end
|
43
|
+
end
|
16
44
|
end
|
17
45
|
end
|
18
46
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RelicLink
|
4
|
+
# Company of Heroes 3 API wrapper.
|
5
|
+
module Coh3
|
6
|
+
# Configuration options for the CoH3 API client.
|
7
|
+
module Config
|
8
|
+
extend self
|
9
|
+
|
10
|
+
# Configurable attributes
|
11
|
+
ATTRIBUTES = %i[
|
12
|
+
logger
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
attr_accessor(*ATTRIBUTES)
|
16
|
+
|
17
|
+
# Set all config options back to defaults.
|
18
|
+
def reset
|
19
|
+
self.logger = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
module_function :reset
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
# Set configuration options. Can be set on the returned object
|
27
|
+
# directly or in a block.
|
28
|
+
def configure
|
29
|
+
block_given? ? yield(Config) : Config
|
30
|
+
end
|
31
|
+
|
32
|
+
# Current config module.
|
33
|
+
def config
|
34
|
+
Config
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
RelicLink::Coh3::Config.reset
|
@@ -16,9 +16,11 @@ module RelicLink
|
|
16
16
|
) do |f|
|
17
17
|
f.params[:title] = 'coh3'
|
18
18
|
|
19
|
-
f.
|
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,28 @@
|
|
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
|
+
|
12
|
+
return unless env.success?
|
13
|
+
|
14
|
+
body = env.body
|
15
|
+
return unless body
|
16
|
+
|
17
|
+
return if body['result']['code'].zero?
|
18
|
+
|
19
|
+
error_message = body['result']['message']
|
20
|
+
error_class = RelicLink::Coh3::Api::Errors::ERROR_CLASSES[error_message]
|
21
|
+
error_class ||= RelicLink::Coh3::Api::Errors::RelicError
|
22
|
+
raise error_class.new(error_message, env.response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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 an API request times out.
|
33
|
+
class TimeoutError < HttpRequestError
|
34
|
+
def initialize(response)
|
35
|
+
super('timeout_error', response)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Raised when a 5xx is returned in an API response.
|
40
|
+
class UnavailableError < HttpRequestError
|
41
|
+
def initialize(response)
|
42
|
+
super('unavailable_error', response)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module RelicLink
|
6
|
+
# Default logging class.
|
7
|
+
class Logger < ::Logger
|
8
|
+
# Default logger, used when a logger is not provided in config.
|
9
|
+
# Default log output is +STDOUT+ and log level is +Logger::WARN+.
|
10
|
+
#
|
11
|
+
# @return [::Logger]
|
12
|
+
def self.default
|
13
|
+
return @default if @default
|
14
|
+
|
15
|
+
logger = new STDOUT
|
16
|
+
logger.level = Logger::WARN
|
17
|
+
@default = logger
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/relic_link/version.rb
CHANGED
data/lib/relic_link.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'faraday'
|
4
|
+
require 'hashie'
|
4
5
|
require 'json'
|
5
6
|
|
7
|
+
require_relative 'relic_link/logger'
|
8
|
+
require_relative 'relic_link/coh3/config'
|
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
|
+
|
6
17
|
require_relative 'relic_link/coh3/util'
|
7
18
|
require_relative 'relic_link/coh3/api/endpoints'
|
8
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.
|
4
|
+
version: 1.0.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-
|
11
|
+
date: 2023-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -76,10 +76,18 @@ 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
|
83
|
+
- lib/relic_link/coh3/config.rb
|
80
84
|
- lib/relic_link/coh3/faraday/connection.rb
|
85
|
+
- lib/relic_link/coh3/faraday/response/raise_error.rb
|
81
86
|
- lib/relic_link/coh3/util.rb
|
87
|
+
- lib/relic_link/errors/server_error.rb
|
82
88
|
- lib/relic_link/faraday/request.rb
|
89
|
+
- lib/relic_link/faraday/response/wrap_error.rb
|
90
|
+
- lib/relic_link/logger.rb
|
83
91
|
- lib/relic_link/version.rb
|
84
92
|
- relic_link.gemspec
|
85
93
|
- sig/relic_link.rbs
|