Skip to content

Commit

Permalink
feat(RateLimit): parse new headers (#6)
Browse files Browse the repository at this point in the history
* feat(RateLimit): parse new headers

* fix rate_limit_limit

Co-authored-by: vvillait88 <[email protected]>
  • Loading branch information
jamesbaez and vvillait88 authored Jul 22, 2022
1 parent 98c795a commit 4911cdd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/peopledatalabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


# gem build peopledatalabs.gemspec
# gem install ./peopledatalabs-1.0.2.gem
# gem install ./peopledatalabs-1.0.4.gem
# irb
# require 'peopledatalabs'
# rake spec PDL_API_KEY=API_KEY
Expand Down
28 changes: 20 additions & 8 deletions lib/peopledatalabs/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,27 @@ def self.handle_response(response)
# 'data' => response.parse
# }

rate_limit_remaining = response.headers['X-RateLimit-Remaining'] ? JSON.parse(response.headers['X-RateLimit-Remaining'].gsub("'",'"')) : {}
rate_limit_limit = response.headers['X-RateLimit-Limit'] ? JSON.parse(response.headers['X-RateLimit-Limit'].gsub("'",'"')) : {}

rate_limit = {
'retry_after' => to_number(response.headers['Retry-After']),
'rate_limit' => to_number(response.headers['X-RateLimit-Limit']),
'rateLimit_reset' => to_number(response.headers['X-RateLimit-Reset']),
'total_limit' => to_number(response.headers['X-TotalLimit-Limit']),
'total_limit_remaining' => to_number(response.headers['X-RateLimit-Remaining']),
'search_limit_remaining' => to_number(response.headers['X-SearchLimit-Remaining']),
'enrich_company_limit_remaining' => to_number(response.headers['X-EnrichCompanyLimit-Remaining']),
'person_identify_limit_remaining' => to_number(response.headers['X-PersonIdentifyLimit-Remaining'])
'call_credits_spent' => to_number(response.headers['X-Call-Credits-Spent']),
'call_credits_type' => response.headers['X-Call-Credits-Type'],
'rate_limit_reset' => response.headers['X-RateLimit-Reset'],
'rate_limit_remaining' => {
'minute' => to_number(rate_limit_remaining['minute']),
'day' => to_number(rate_limit_remaining['day']),
'month' => to_number(rate_limit_remaining['month'])
},
'rate_limit_limit' => {
'minute' => to_number(rate_limit_limit['minute']),
'day' => to_number(rate_limit_limit['day']),
'month' => to_number(rate_limit_limit['month'])
},
'lifetime_used' => to_number(response.headers['X-Lifetime-Used']),
'total_limit_remaining' => to_number(response.headers['X-TotalLimit-Remaining']),
'total_limit_purchased_remaining' => to_number(response.headers['X-TotalLimit-Purchased-Remaining']),
'total_limit_overages_remaining' => to_number(response.headers['X-TotalLimit-Overages-Remaining'])
}

parsed_response = response.parse
Expand Down
2 changes: 1 addition & 1 deletion lib/peopledatalabs/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Peopledatalabs
VERSION = "1.0.3"
VERSION = "1.0.4"
end

0 comments on commit 4911cdd

Please sign in to comment.