thegamesdb 2.1.0 → 2.1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -1
- data/lib/thegamesdb/version.rb +1 -1
- data/lib/thegamesdb.rb +15 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ded70fb01850d93f701c54ad8c22a3bb7499b0f5898e2dca9fd57bd61a74530
|
4
|
+
data.tar.gz: 315ddaeb3dcdbb9fa908322851fab3592e093249697f1825693b20d99f9df733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5eadd3bc0189b5e2f70a308f01f34985684234c25d358a1401622410509f0a87e050545553d95b5abff0674f9e107a11a857a1f069020bf170b59e6706379ca
|
7
|
+
data.tar.gz: 8f6e27ba722964459af0c382c6d7fdaaf42f2e8f61b49c040b1a99382987e30a67f87a57e83a95b8d9c871278ece70ff66c911c2fa3d7978ab388fce3889e669
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ A Ruby gem to interact with [TheGamesDB](http://thegamesdb.net) API.
|
|
3
3
|
|
4
4
|
The Legacy API has been shutdown. The gem is now using the new API and you need to [request an API key](https://forums.thegamesdb.net/viewforum.php?f=10) to use it.
|
5
5
|
|
6
|
-
](https://github.com/picandocodigo/gamesdb/actions/workflows/main.yml)
|
7
7
|
[](https://badge.fury.io/rb/thegamesdb)
|
8
8
|
[](https://codeclimate.com/github/picandocodigo/gamesdb/maintainability)
|
9
9
|
|
@@ -23,6 +23,7 @@ The Legacy API has been shutdown. The gem is now using the new API and you need
|
|
23
23
|
* [Genres](#genres)
|
24
24
|
* [Developers](#developers)
|
25
25
|
* [Publishers](#publishers)
|
26
|
+
* [Error Handling](#error-handling)
|
26
27
|
* [RubyDoc](https://www.rubydoc.info/gems/thegamesdb)
|
27
28
|
* [Development](#development)
|
28
29
|
* [Contributing](#contributing)
|
@@ -384,6 +385,10 @@ Usage:
|
|
384
385
|
]
|
385
386
|
```
|
386
387
|
|
388
|
+
### Error Handling
|
389
|
+
|
390
|
+
If there's an error from the API (e.g. 401) or `Net::HTTP` (e.g. 503 - Service Unavailable), the client will raise a `Gamesdb::Error` with the status code and message.
|
391
|
+
|
387
392
|
## Development
|
388
393
|
|
389
394
|
Run all tests:
|
data/lib/thegamesdb/version.rb
CHANGED
data/lib/thegamesdb.rb
CHANGED
@@ -40,20 +40,25 @@ module Gamesdb
|
|
40
40
|
def perform_request(url, params = {})
|
41
41
|
raise ArgumentError, 'You need to set the API KEY to use the GamesDB API' unless @api_key
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
refresh_allowances(response)
|
50
|
-
response
|
43
|
+
uri = prepare_uri(params, url)
|
44
|
+
response = Net::HTTP.get_response(uri)
|
45
|
+
check_http_errors(response)
|
46
|
+
json_response = JSON.parse(response.body)
|
47
|
+
refresh_allowances(json_response)
|
48
|
+
json_response
|
51
49
|
rescue StandardError => e
|
52
50
|
raise e
|
53
51
|
end
|
54
52
|
|
55
53
|
private
|
56
54
|
|
55
|
+
def prepare_uri(params, url)
|
56
|
+
params = params.merge({ apikey: @api_key })
|
57
|
+
uri = URI(BASE_URL + url)
|
58
|
+
uri.query = URI.encode_www_form(params)
|
59
|
+
uri
|
60
|
+
end
|
61
|
+
|
57
62
|
def refresh_allowances(response)
|
58
63
|
@remaining_monthly_allowance = response['remaining_monthly_allowance']
|
59
64
|
@extra_allowance = response['extra_allowance']
|
@@ -61,8 +66,8 @@ module Gamesdb
|
|
61
66
|
end
|
62
67
|
|
63
68
|
# TODO: More granular errors
|
64
|
-
def
|
65
|
-
raise Gamesdb::Error.new(response
|
69
|
+
def check_http_errors(response)
|
70
|
+
raise Gamesdb::Error.new(response.code, response.message) if response.code.to_i >= 300
|
66
71
|
end
|
67
72
|
|
68
73
|
# Process games for platform_games
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thegamesdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Briano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|