intercom 3.5.17 → 3.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +1 -0
- data/README.md +14 -1
- data/changes.txt +3 -0
- data/lib/intercom/client.rb +4 -2
- data/lib/intercom/request.rb +10 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/intercom/request_spec.rb +44 -1
- metadata +4 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d73b6f0f89970d9ccc8e82cfb969549e5f9720a
|
4
|
+
data.tar.gz: eecb568c0c6116afbef3cec73ee93a459af3bb23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1c7a6abeaa8ad78409defd2435908245d152f222dbd68a01ef4ef8dbea14a49044f4a6339b9bfecb3db511e8e9fd0cb027ddcd9359d0b0a1c83cb4dec2417f6
|
7
|
+
data.tar.gz: 369edfbdd536899f05923d299c61e53b57b57e975370ad7bb16d6090d03786228e86a14b69ea018d8836ef0e688d0adce3d4978339cf4dfbd93be0a4f5a85560
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
|
|
22
22
|
|
23
23
|
Using bundler:
|
24
24
|
|
25
|
-
gem 'intercom', '~> 3.5.
|
25
|
+
gem 'intercom', '~> 3.5.18'
|
26
26
|
|
27
27
|
## Basic Usage
|
28
28
|
|
@@ -134,6 +134,9 @@ intercom.companies.all.each {|company| puts %Q(#{company.name} - #{company.custo
|
|
134
134
|
intercom.companies.all.map {|company| company.name }
|
135
135
|
# Get a list of users in a company
|
136
136
|
intercom.companies.users(company.id)
|
137
|
+
# Get a large list of companies using scroll
|
138
|
+
intercom.companies.scroll.each { |comp| puts comp.name}
|
139
|
+
# Please see users scroll for more details of how to use scroll
|
137
140
|
```
|
138
141
|
|
139
142
|
#### Tags
|
@@ -371,6 +374,10 @@ intercom.contacts.convert(contact, user)
|
|
371
374
|
|
372
375
|
# Delete a contact
|
373
376
|
intercom.contacts.delete(contact)
|
377
|
+
|
378
|
+
# Get a large list of contacts using scroll
|
379
|
+
intercom.contacts.scroll.each { |lead| puts lead.id}
|
380
|
+
# Please see users scroll for more details of how to use scroll
|
374
381
|
```
|
375
382
|
|
376
383
|
### Counts
|
@@ -433,6 +440,12 @@ intercom.rate_limit_details
|
|
433
440
|
#=> {:limit=>180, :remaining=>179, :reset_at=>2014-10-07 14:58:00 +0100}
|
434
441
|
```
|
435
442
|
|
443
|
+
You can handle the rate limits yourself but a simple option is to use the handle_rate_limit flag.
|
444
|
+
This will automatically catch the 429 rate limit exceeded error and wait until the reset time to retry.
|
445
|
+
|
446
|
+
```
|
447
|
+
intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
|
448
|
+
```
|
436
449
|
|
437
450
|
### Pull Requests
|
438
451
|
|
data/changes.txt
CHANGED
data/lib/intercom/client.rb
CHANGED
@@ -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
|
5
|
+
attr_reader :base_url, :rate_limit_details, :username_part, :password_part, :handle_rate_limit
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def set_base_url(base_url)
|
@@ -14,7 +14,7 @@ module Intercom
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize(app_id: 'my_app_id', api_key: 'my_api_key', token: nil, base_url:'https://api.intercom.io')
|
17
|
+
def initialize(app_id: 'my_app_id', api_key: 'my_api_key', token: nil, base_url:'https://api.intercom.io', handle_rate_limit: false)
|
18
18
|
if token
|
19
19
|
@username_part = token
|
20
20
|
@password_part = ""
|
@@ -26,6 +26,7 @@ module Intercom
|
|
26
26
|
|
27
27
|
@base_url = base_url
|
28
28
|
@rate_limit_details = {}
|
29
|
+
@handle_rate_limit = handle_rate_limit
|
29
30
|
end
|
30
31
|
|
31
32
|
def admins
|
@@ -108,6 +109,7 @@ module Intercom
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def execute_request(request)
|
112
|
+
request.handle_rate_limit = handle_rate_limit
|
111
113
|
request.execute(@base_url, username: @username_part, secret: @password_part)
|
112
114
|
ensure
|
113
115
|
@rate_limit_details = request.rate_limit_details
|
data/lib/intercom/request.rb
CHANGED
@@ -3,11 +3,12 @@ require 'net/https'
|
|
3
3
|
|
4
4
|
module Intercom
|
5
5
|
class Request
|
6
|
-
attr_accessor :path, :net_http_method, :rate_limit_details
|
6
|
+
attr_accessor :path, :net_http_method, :rate_limit_details, :handle_rate_limit
|
7
7
|
|
8
8
|
def initialize(path, net_http_method)
|
9
9
|
self.path = path
|
10
10
|
self.net_http_method = net_http_method
|
11
|
+
self.handle_rate_limit = false
|
11
12
|
end
|
12
13
|
|
13
14
|
def set_common_headers(method, base_uri)
|
@@ -58,6 +59,7 @@ module Intercom
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def execute(target_base_url=nil, username:, secret: nil)
|
62
|
+
retries = 3
|
61
63
|
base_uri = URI.parse(target_base_url)
|
62
64
|
set_common_headers(net_http_method, base_uri)
|
63
65
|
set_basic_auth(net_http_method, username, secret)
|
@@ -70,6 +72,13 @@ module Intercom
|
|
70
72
|
parsed_body = parse_body(decoded_body, response)
|
71
73
|
raise_errors_on_failure(response)
|
72
74
|
parsed_body
|
75
|
+
rescue Intercom::RateLimitExceeded => e
|
76
|
+
if @handle_rate_limit
|
77
|
+
sleep (@rate_limit_details[:reset_at] - Time.now.utc).ceil
|
78
|
+
retry unless (retries -=1).zero?
|
79
|
+
else
|
80
|
+
raise e
|
81
|
+
end
|
73
82
|
rescue Timeout::Error
|
74
83
|
raise Intercom::ServiceUnavailableError.new('Service Unavailable [request timed out]')
|
75
84
|
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
+
WebMock.enable!
|
5
|
+
|
4
6
|
describe 'Intercom::Request' do
|
5
7
|
it 'raises an error when a html error page rendered' do
|
6
8
|
response = OpenStruct.new(:code => 500)
|
@@ -14,9 +16,50 @@ describe 'Intercom::Request' do
|
|
14
16
|
proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::RateLimitExceeded)
|
15
17
|
end
|
16
18
|
|
19
|
+
describe 'Intercom::Client' do
|
20
|
+
let (:client) { Intercom::Client.new(token: 'foo', handle_rate_limit: true) }
|
21
|
+
let (:uri) {"https://api.intercom.io/users"}
|
22
|
+
|
23
|
+
it 'should have handle_rate_limit set' do
|
24
|
+
client.handle_rate_limit.must_equal(true)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should call sleep for rate limit error three times' do
|
28
|
+
# Use webmock to mock the HTTP request
|
29
|
+
stub_request(:any, uri).\
|
30
|
+
to_return(status: [429, "Too Many Requests"], headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 })
|
31
|
+
req = Intercom::Request.get(uri, "")
|
32
|
+
req.handle_rate_limit=true
|
33
|
+
req.expects(:sleep).times(3).with(any_parameters)
|
34
|
+
req.execute(target_base_url=uri, username: "ted", secret: "")
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not call sleep for rate limit error' do
|
38
|
+
# Use webmock to mock the HTTP request
|
39
|
+
stub_request(:any, uri).\
|
40
|
+
to_return(status: [200, "OK"], headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 })
|
41
|
+
req = Intercom::Request.get(uri, "")
|
42
|
+
req.handle_rate_limit=true
|
43
|
+
req.expects(:sleep).never.with(any_parameters)
|
44
|
+
req.execute(target_base_url=uri, username: "ted", secret: "")
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should call sleep for rate limit error just once' do
|
48
|
+
# Use webmock to mock the HTTP request
|
49
|
+
stub_request(:any, uri).\
|
50
|
+
to_return(status: [429, "Too Many Requests"], headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 }).\
|
51
|
+
then.to_return(status: [200, "OK"])
|
52
|
+
req = Intercom::Request.get(uri, "")
|
53
|
+
req.handle_rate_limit=true
|
54
|
+
req.expects(:sleep).with(any_parameters)
|
55
|
+
req.execute(target_base_url=uri, username: "ted", secret: "")
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
17
60
|
it 'parse_body returns nil if decoded_body is nil' do
|
18
61
|
response = OpenStruct.new(:code => 500)
|
19
62
|
req = Intercom::Request.new('path/', 'GET')
|
20
|
-
req.parse_body(nil, response)
|
63
|
+
assert_nil(req.parse_body(nil, response))
|
21
64
|
end
|
22
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2017-
|
18
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -243,31 +243,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
243
|
version: '0'
|
244
244
|
requirements: []
|
245
245
|
rubyforge_project: intercom
|
246
|
-
rubygems_version: 2.
|
246
|
+
rubygems_version: 2.5.1
|
247
247
|
signing_key:
|
248
248
|
specification_version: 4
|
249
249
|
summary: Ruby bindings for the Intercom API
|
250
|
-
test_files:
|
251
|
-
- spec/spec_helper.rb
|
252
|
-
- spec/unit/intercom/admin_spec.rb
|
253
|
-
- spec/unit/intercom/client_collection_proxy_spec.rb
|
254
|
-
- spec/unit/intercom/client_spec.rb
|
255
|
-
- spec/unit/intercom/company_spec.rb
|
256
|
-
- spec/unit/intercom/contact_spec.rb
|
257
|
-
- spec/unit/intercom/conversation_spec.rb
|
258
|
-
- spec/unit/intercom/count_spec.rb
|
259
|
-
- spec/unit/intercom/event_spec.rb
|
260
|
-
- spec/unit/intercom/job_spec.rb
|
261
|
-
- spec/unit/intercom/lib/flat_store_spec.rb
|
262
|
-
- spec/unit/intercom/message_spec.rb
|
263
|
-
- spec/unit/intercom/note_spec.rb
|
264
|
-
- spec/unit/intercom/request_spec.rb
|
265
|
-
- spec/unit/intercom/scroll_collection_proxy_spec.rb
|
266
|
-
- spec/unit/intercom/segment_spec.rb
|
267
|
-
- spec/unit/intercom/subscription_spec.rb
|
268
|
-
- spec/unit/intercom/tag_spec.rb
|
269
|
-
- spec/unit/intercom/traits/api_resource_spec.rb
|
270
|
-
- spec/unit/intercom/user_spec.rb
|
271
|
-
- spec/unit/intercom/visitors_spec.rb
|
272
|
-
- spec/unit/intercom_spec.rb
|
273
|
-
has_rdoc:
|
250
|
+
test_files: []
|