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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dff06dfb7c9c5737a8f737a1dcf365cdd3c13ac9f7af2efef21d52548d91f2b
4
- data.tar.gz: a6aa0de586fddb22974910bd6937a18e228209adc9555ee795e254e3bcbc6f84
3
+ metadata.gz: 4ded70fb01850d93f701c54ad8c22a3bb7499b0f5898e2dca9fd57bd61a74530
4
+ data.tar.gz: 315ddaeb3dcdbb9fa908322851fab3592e093249697f1825693b20d99f9df733
5
5
  SHA512:
6
- metadata.gz: d37e33b44631f031287f6047b79f15fa7d0c112ee1d021724693020e796e9936c2d5b95b2cf0933b4fe0092467bf4c19ca85ca10bf3196382213d6f2f7d21475
7
- data.tar.gz: 154aebc525bdec5ae98b1209d42ad1edc1101f354c7a47607405870888d37fd18bc0303da4cb9053cc0ecd8aa02025b5102509d609e8c298859d5669a64f62e0
6
+ metadata.gz: c5eadd3bc0189b5e2f70a308f01f34985684234c25d358a1401622410509f0a87e050545553d95b5abff0674f9e107a11a857a1f069020bf170b59e6706379ca
7
+ data.tar.gz: 8f6e27ba722964459af0c382c6d7fdaaf42f2e8f61b49c040b1a99382987e30a67f87a57e83a95b8d9c871278ece70ff66c911c2fa3d7978ab388fce3889e669
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.1
4
+
5
+ - Small update to error handling. Catches `Net::HTTP` errors such as 503 Service Unavailable and raises `Gamesdb::Error`.
6
+
3
7
  ## 2.1.0
4
8
 
5
9
  Now testing Ruby versions 3.0, 3.1, 3.2, JRuby and TruffleRuby.
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
- ![Build Status](https://github.com/picandocodigo/gamesdb/workflows/Tests/badge.svg?branch=master)
6
+ [![Tests](https://github.com/picandocodigo/gamesdb/actions/workflows/main.yml/badge.svg)](https://github.com/picandocodigo/gamesdb/actions/workflows/main.yml)
7
7
  [![Gem Version](https://badge.fury.io/rb/thegamesdb.svg)](https://badge.fury.io/rb/thegamesdb)
8
8
  [![Maintainability](https://api.codeclimate.com/v1/badges/2dcf3cdcbe37adcea569/maintainability)](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:
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Gem version
4
4
  module Gamesdb
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.1'
6
6
  end
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
- params = params.merge({ apikey: @api_key })
44
- uri = URI(BASE_URL + url)
45
- uri.query = URI.encode_www_form(params)
46
- response = JSON.parse(Net::HTTP.get_response(uri).body)
47
- http_error(response) if response['code'] >= 300
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 http_error(response)
65
- raise Gamesdb::Error.new(response['code'], response['status'])
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler