@@ -2,7 +2,7 @@ module Intercom
22 class MisconfiguredClientError < StandardError ; end
33 class Client
44 include Options
5- attr_reader :base_url , :rate_limit_details , :username_part , :password_part , :handle_rate_limit
5+ attr_reader :base_url , :rate_limit_details , :username_part , :password_part , :handle_rate_limit , :timeouts
66
77 class << self
88 def set_base_url ( base_url )
@@ -12,6 +12,17 @@ def set_base_url(base_url)
1212 Proc . new { |obj | set_base_url ( old_url ) . call ( o ) }
1313 end
1414 end
15+
16+ def set_timeouts ( open_timeout : nil , read_timeout : nil )
17+ return Proc . new do |o |
18+ old_timeouts = o . timeouts
19+ timeouts = { }
20+ timeouts [ :open_timeout ] = open_timeout if open_timeout
21+ timeouts [ :read_timeout ] = read_timeout if read_timeout
22+ o . send ( :timeouts= , timeouts )
23+ Proc . new { |obj | set_timeouts ( old_timeouts ) . call ( o ) }
24+ end
25+ end
1526 end
1627
1728 def initialize ( app_id : 'my_app_id' , api_key : 'my_api_key' , token : nil , base_url :'https://api.intercom.io' , handle_rate_limit : false )
@@ -27,6 +38,10 @@ def initialize(app_id: 'my_app_id', api_key: 'my_api_key', token: nil, base_url:
2738 @base_url = base_url
2839 @rate_limit_details = { }
2940 @handle_rate_limit = handle_rate_limit
41+ @timeouts = {
42+ open_timeout : 30 ,
43+ read_timeout : 90
44+ }
3045 end
3146
3247 def admins
@@ -110,13 +125,17 @@ def validate_credentials!
110125
111126 def execute_request ( request )
112127 request . handle_rate_limit = handle_rate_limit
113- request . execute ( @base_url , username : @username_part , secret : @password_part )
128+ request . execute ( @base_url , username : @username_part , secret : @password_part , ** timeouts )
114129 ensure
115130 @rate_limit_details = request . rate_limit_details
116131 end
117132
118133 def base_url = ( new_url )
119134 @base_url = new_url
120135 end
136+
137+ def timeouts = ( timeouts )
138+ @timeouts = @timeouts . merge ( timeouts )
139+ end
121140 end
122141end
0 commit comments