relic_link 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -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/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/version.rb +1 -1
- data/lib/relic_link.rb +7 -0
- metadata +8 -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/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)
|
@@ -65,7 +67,7 @@ DEPENDENCIES
|
|
65
67
|
rake (~> 13.0)
|
66
68
|
relic_link!
|
67
69
|
rspec (~> 3.0)
|
68
|
-
rubocop (~> 1.
|
70
|
+
rubocop (~> 1.52)
|
69
71
|
vcr (~> 6.1)
|
70
72
|
|
71
73
|
BUNDLED WITH
|
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/
|
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.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
|
@@ -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
|
data/lib/relic_link/version.rb
CHANGED
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.
|
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,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
|