giant_bomb_api 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/giant_bomb_api.gemspec +1 -1
- data/lib/giant_bomb_api/client.rb +2 -2
- data/lib/giant_bomb_api/collection_resource.rb +6 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c32f84cbf52676ea0e0d81a3b271cb5be3c46d8
|
4
|
+
data.tar.gz: 199c89944d3b30b14dfbc7a38378e445d308eade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05fc6f28698fb6e4edd5a71994d68a0ec4e0936328e3fe152065b2c7b9ec6f416702abb73d5b730d425f284168a4a64e56dbb49d5016ae7ec1486cf2dd654804
|
7
|
+
data.tar.gz: 98da2ac95e7c83ecd3a5608f7045c023a65dbf7baf4556ba510f495b071c5cdbd1be6c2d4ed4a79c7dc1089acdfba9b2df38d0eb084b8a713bc5f9091df9dbe8
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Giant Bomb API
|
2
2
|
|
3
|
-
An unofficial ruby wrapper for the [Giantbomb API](
|
3
|
+
An unofficial ruby wrapper for the [Giantbomb API](https://www.giantbomb.com/api/). An API that provides structured data about videogames. You should inform yourself about the endpoints at http://www.giantbomb.com/api/documentation .
|
4
4
|
|
5
5
|
This gem aims to provide access to most endpoints on the API. You'll be able to **search**, **filter** and page throught most of them. See further below on what is supported.
|
6
6
|
|
@@ -133,6 +133,7 @@ end
|
|
133
133
|
- `limit`: the number of results to return per page. Defaults to 100 (the max allowed through the Giant Bomb API)
|
134
134
|
- `offset`: defaults to 0
|
135
135
|
- `should_rate_limit`: pass this in as true if you want to ensure that you are rate limiting your requests to under the required 200 per resource per hour (which is important if you're trying to iterate through every page of a resource)
|
136
|
+
- `rate_per_hour`: defaults to 200 (the standard Giant Bomb hourly request limit). Override this value if you want to send more requests per hour (not recommended) or less.
|
136
137
|
|
137
138
|
Example using the optional arguments:
|
138
139
|
|
data/giant_bomb_api.gemspec
CHANGED
@@ -8,7 +8,7 @@ module GiantBombApi
|
|
8
8
|
class Client
|
9
9
|
attr_accessor :api_key
|
10
10
|
|
11
|
-
API_URL = '
|
11
|
+
API_URL = 'https://www.giantbomb.com/api/'.freeze
|
12
12
|
|
13
13
|
def initialize(api_key: nil, options: {})
|
14
14
|
@api_key = api_key
|
@@ -51,4 +51,4 @@ module GiantBombApi
|
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
|
-
end
|
54
|
+
end
|
@@ -12,8 +12,8 @@ module GiantBombApi
|
|
12
12
|
self.instance_variable_get("@collection_resource_name") || self.resource_name.pluralize
|
13
13
|
end
|
14
14
|
|
15
|
-
def each_page(sort: {}, limit: 100, offset: 0, should_rate_limit: false)
|
16
|
-
rate_limit(should_rate_limit) do
|
15
|
+
def each_page(sort: {}, limit: 100, offset: 0, should_rate_limit: false, rate_per_hour: 200)
|
16
|
+
rate_limit(should_rate_limit, rate_per_hour) do
|
17
17
|
response = where(sort: sort, limit: limit, offset: offset, tries: 5)
|
18
18
|
yield response
|
19
19
|
offset += limit
|
@@ -34,7 +34,7 @@ module GiantBombApi
|
|
34
34
|
tries ||= (params[:tries] || 0)
|
35
35
|
|
36
36
|
args = {}
|
37
|
-
args[:filter] = params.reject {|key,value| %i(sort limit offset).include?(key) }
|
37
|
+
args[:filter] = params.reject {|key,value| %i(sort limit offset tries).include?(key) }
|
38
38
|
args[:sort] = sort if sort.present?
|
39
39
|
args[:limit] = limit if limit.present?
|
40
40
|
args[:offset] = offset if offset.present?
|
@@ -51,7 +51,7 @@ module GiantBombApi
|
|
51
51
|
|
52
52
|
private
|
53
53
|
|
54
|
-
def rate_limit(should_rate_limit, &block)
|
54
|
+
def rate_limit(should_rate_limit, rate_per_hour, &block)
|
55
55
|
started_at = Time.now
|
56
56
|
num_of_requests = 0
|
57
57
|
|
@@ -69,9 +69,8 @@ module GiantBombApi
|
|
69
69
|
|
70
70
|
request_time = t2 - t1
|
71
71
|
time_to_one_hour = (started_at + 1.hour) - t2
|
72
|
-
remaining_requests =
|
73
|
-
min_time_per_request = time_to_one_hour / remaining_requests
|
74
|
-
|
72
|
+
remaining_requests = rate_per_hour - num_of_requests
|
73
|
+
min_time_per_request = remaining_requests.zero? ? time_to_one_hour : time_to_one_hour / remaining_requests
|
75
74
|
sleep(min_time_per_request - request_time) if request_time < min_time_per_request
|
76
75
|
end
|
77
76
|
end
|