@@ -2,7 +2,7 @@ module Intercom
2
2
class MisconfiguredClientError < StandardError ; end
3
3
class Client
4
4
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
6
6
7
7
class << self
8
8
def set_base_url ( base_url )
@@ -12,6 +12,17 @@ def set_base_url(base_url)
12
12
Proc . new { |obj | set_base_url ( old_url ) . call ( o ) }
13
13
end
14
14
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
15
26
end
16
27
17
28
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:
27
38
@base_url = base_url
28
39
@rate_limit_details = { }
29
40
@handle_rate_limit = handle_rate_limit
41
+ @timeouts = {
42
+ open_timeout : 30 ,
43
+ read_timeout : 90
44
+ }
30
45
end
31
46
32
47
def admins
@@ -110,13 +125,17 @@ def validate_credentials!
110
125
111
126
def execute_request ( request )
112
127
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 )
114
129
ensure
115
130
@rate_limit_details = request . rate_limit_details
116
131
end
117
132
118
133
def base_url = ( new_url )
119
134
@base_url = new_url
120
135
end
136
+
137
+ def timeouts = ( timeouts )
138
+ @timeouts = @timeouts . merge ( timeouts )
139
+ end
121
140
end
122
141
end
0 commit comments