File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ module Intercom
3636 @current_endpoint = nil
3737 @app_id = nil
3838 @app_api_key = nil
39+ @rate_limit_details = { }
3940
4041 def self . app_id = ( app_id )
4142 @app_id = app_id
@@ -48,10 +49,19 @@ def self.app_id
4849 def self . app_api_key = ( app_api_key )
4950 @app_api_key = app_api_key
5051 end
52+
5153 def self . app_api_key
5254 @app_api_key
5355 end
5456
57+ def self . rate_limit_details = ( rate_limit_details )
58+ @rate_limit_details = rate_limit_details
59+ end
60+
61+ def self . rate_limit_details
62+ @rate_limit_details
63+ end
64+
5565 # This method is obsolete and used to warn of backwards incompatible changes on upgrading
5666 def self . api_key = ( val )
5767 raise ArgumentError , "#{ compatibility_warning_text } #{ compatibility_workaround_text } #{ related_docs_text } "
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ def execute(target_base_url=nil)
6161 client ( base_uri ) . start do |http |
6262 begin
6363 response = http . request ( net_http_method )
64+ set_rate_limit_details ( response )
6465 decoded = decode ( response [ 'content-encoding' ] , response . body )
6566 unless decoded . strip . empty?
6667 parsed_body = JSON . parse ( decoded )
@@ -77,6 +78,14 @@ def execute(target_base_url=nil)
7778 end
7879 end
7980
81+ def set_rate_limit_details ( response )
82+ rate_limit_details = { }
83+ rate_limit_details [ :limit ] = response [ 'X-RateLimit-Limit' ] . to_i if response [ 'X-RateLimit-Limit' ]
84+ rate_limit_details [ :remaining ] = response [ 'X-RateLimit-Remaining' ] . to_i if response [ 'X-RateLimit-Remaining' ]
85+ rate_limit_details [ :reset_at ] = Time . at ( response [ 'X-RateLimit-Reset' ] . to_i ) if response [ 'X-RateLimit-Reset' ]
86+ Intercom . rate_limit_details = rate_limit_details
87+ end
88+
8089 def decode ( content_encoding , body )
8190 return body if ( !body ) || body . empty? || content_encoding != 'gzip'
8291 Zlib ::GzipReader . new ( StringIO . new ( body ) ) . read
You can’t perform that action at this time.
0 commit comments