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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96c196f26a23e4fc41d2dd883f939c8c83e062c7
4
- data.tar.gz: 6b6739d5ce1ffb80772ad6c4a42643c9e8ae98ba
3
+ metadata.gz: 1c32f84cbf52676ea0e0d81a3b271cb5be3c46d8
4
+ data.tar.gz: 199c89944d3b30b14dfbc7a38378e445d308eade
5
5
  SHA512:
6
- metadata.gz: 434798f04cdb4329fbee5ac8dd25de961865488a5d9a875973c009169255c56be6d69dfbc9f50abde08d7f0123bc530db6a2ade93e0bb6b3f706b022dcd9c58a
7
- data.tar.gz: 53ed38aebfd37671baa86fd6791c1c1a0809e9a31df3ddb035d6c0d4d72f17d2b67da0901122cf3fb409148faf5ab82da2624084a5b44aa190fe94dc9d1757c5
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](http://api.giantbomb.com). An API that provides structured data about videogames. You should inform yourself about the endpoints at http://www.giantbomb.com/api/documentation .
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "giant_bomb_api"
3
- s.version = "0.5.2"
3
+ s.version = "0.5.3"
4
4
  s.default_executable = "giantbomb"
5
5
 
6
6
  s.authors = ["Tim Adler"]
@@ -8,7 +8,7 @@ module GiantBombApi
8
8
  class Client
9
9
  attr_accessor :api_key
10
10
 
11
- API_URL = 'http://api.giantbomb.com'
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 = 200 - num_of_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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giant_bomb_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Adler