Skip to content

Commit ef65185

Browse files
committed
Tweaks
* Add custom exception for rate limited response * Rate limit is exceptionally hard to trigger, even without an API key, so not going to add internal rate limiting at the moment * Add extra per_page argument for users manually calling paginator * Remove extra calculation for limit parameter * Add columns and minify params to Content endpoint
1 parent d91334d commit ef65185

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

lib/xivapi/exceptions.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ def initialize(response)
44
if response.headers[:content_type] == 'application/problem+json'
55
message = JSON.parse(response)['Message']
66
else
7-
message = 'Error contacting the API'
7+
message = 'Error contacting the API.'
88
end
99

1010
super(message)
1111
end
1212
end
1313

14+
class RateLimitError < StandardError
15+
def initialize
16+
super('Too many requests.')
17+
end
18+
end
19+
1420
class ContentNotAvailable < StandardError
1521
def initialize
16-
super('Content is not currently available on XIVAPI')
22+
super('Content is not currently available on XIVAPI.')
1723
end
1824
end
1925

lib/xivapi/http.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def request(client, endpoint, params = {})
1212
body = JSON.parse(response.body)
1313
objectify(body)
1414
rescue RestClient::ExceptionWithResponse => e
15-
raise XIVAPI::RequestError.new(e.response)
15+
if e.http_code == 429
16+
raise XIVAPI::RateLimitError.new
17+
else
18+
raise XIVAPI::RequestError.new(e.response)
19+
end
1620
rescue RestClient::Exception => e
1721
raise e
1822
end

lib/xivapi/paginator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ class Paginator
33
include Enumerable
44
include XIVAPI::HTTP
55

6-
def initialize(client, params, endpoint, limit)
6+
def initialize(client, params, endpoint, limit, per_page = nil)
77
@client = client
8-
@params = params.merge(limit: [limit, 100].min)
8+
@params = params.merge(limit: per_page || limit)
99
@endpoint = endpoint
1010
@limit = limit
1111
end

lib/xivapi/request.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def search(indexes: [], string: '', string_column: 'Name_en', string_algo: 'wild
1313
end
1414

1515
# Content
16-
def content(name: nil, ids: [], limit: 100, columns: [])
16+
def content(name: nil, ids: [], minify: false, limit: 100, columns: [])
1717
if name.nil?
1818
request(self, 'content')
1919
elsif [*ids].size == 1
20-
request("#{name.capitalize}/#{[*ids].first}")
20+
params = { minify: minify ? 1 : 0, columns: [*columns].join(',') }
21+
request(self, "#{name.capitalize}/#{[*ids].first}", params)
2122
else
2223
params = { ids: [*ids].join(','), columns: [*columns].join(',') }
2324
XIVAPI::Paginator.new(self, params, name.capitalize, limit)

0 commit comments

Comments
 (0)