Permalink
Browse files

Upgraded version number.

Refactored code to extract the rate limit information from the header.
  • Loading branch information...
1 parent 601e511 commit 84645e9000c50a0cc05bf782d0d752ddeb920a55 etagwerker committed Apr 15, 2011
Showing with 9 additions and 4 deletions.
  1. +8 −3 lib/topsy/client.rb
  2. +1 −1 lib/topsy/version.rb
View
@@ -204,10 +204,15 @@ def mashup(response)
Hashie::Mash.new(response).response
end
+ # extracts the header key
+ def extract_header_value(response, key)
+ response.headers[key].class == Array ? response.headers[key].first.to_i : response.headers[key].to_i
+ end
+
def get_rate_limit_status(response)
- limit = response.headers['x-ratelimit-limit'].respond_to?(:each) ? response.headers['x-ratelimit-limit'].first.to_i : response.headers['x-ratelimit-limit'].to_i
- remaining = response.headers['x-rateremaining-remaining'].respond_to?(:each) ? response.headers['x-rateremaining-remaining'].first.to_i : response.headers['x-rateremaining-remaining'].to_i
- reset = response.headers['x-ratereset-reset'].respond_to?(:each) ? response.headers['x-ratereset-reset'].first.to_i : response.headers['x-ratereset-reset'].to_i
+ limit = extract_header_value(response,'x-ratelimit-limit')
+ remaining = extract_header_value(response,'x-ratelimit-remaining')
+ reset = extract_header_value(response,'x-ratelimit-reset')
headers = {
'limit' => limit,
'remaining' => remaining,
View
@@ -1,3 +1,3 @@
module Topsy
- VERSION = '0.3.4'
+ VERSION = '0.3.5'
end

0 comments on commit 84645e9

Please sign in to comment.