intercom 3.5.23 → 3.5.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +12 -0
- data/Gemfile +0 -3
- data/README.md +2 -2
- data/lib/intercom/errors.rb +9 -0
- data/lib/intercom/request.rb +9 -2
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/intercom/client_collection_proxy_spec.rb +5 -5
- data/spec/unit/intercom/request_spec.rb +11 -0
- data/spec/unit/intercom/user_spec.rb +1 -1
- metadata +3 -3
- data/circle.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec8a7ce6c9363737310afd46f571c394f4e324ec
|
4
|
+
data.tar.gz: aa4056bdf51ad0423f38b89694c333548450aacb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a05546c944b5c41dc6725244c7c7fd8c7502218c7ac320b70782d47b65d075bc1671547ce610c8eeb972f0bbe8ec30e41fcc0c7c77368e0ec45e24bf13327c9
|
7
|
+
data.tar.gz: 106162c9952d8d1bb7f752bae45d53036788d792bffcd7d01248bc724bfa68f94ba48c187c7f357011bfbee60a29bce86890e1466531eab3ee59c7e5e1ae7df2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,13 +22,13 @@ 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.24'
|
26
26
|
|
27
27
|
## Basic Usage
|
28
28
|
|
29
29
|
### Configure your client
|
30
30
|
|
31
|
-
> If you already have a personal access token you can find it [here](https://app.intercom.io/
|
31
|
+
> If you already have a personal access token you can find it [here](https://app.intercom.io/developers/_/access-token). If you want to create or learn more about personal access tokens then you can find more info [here](https://developers.intercom.io/docs/personal-access-tokens).
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
# With an OAuth or Personal Access token:
|
data/lib/intercom/errors.rb
CHANGED
@@ -27,6 +27,15 @@ module Intercom
|
|
27
27
|
# Check that you have set Intercom.token correctly.
|
28
28
|
class AuthenticationError < IntercomError; end
|
29
29
|
|
30
|
+
# Raised when the token provided is linked to a deleted application.
|
31
|
+
class AppSuspendedError < AuthenticationError; end
|
32
|
+
|
33
|
+
# Raised when the token provided has been revoked.
|
34
|
+
class TokenRevokedError < AuthenticationError; end
|
35
|
+
|
36
|
+
# Raised when the token provided can't be decoded, and is most likely invalid.
|
37
|
+
class TokenUnauthorizedError < AuthenticationError; end
|
38
|
+
|
30
39
|
# Raised when something goes wrong on within the Intercom API service.
|
31
40
|
class ServerError < IntercomError; end
|
32
41
|
|
data/lib/intercom/request.rb
CHANGED
@@ -74,7 +74,8 @@ module Intercom
|
|
74
74
|
parsed_body
|
75
75
|
rescue Intercom::RateLimitExceeded => e
|
76
76
|
if @handle_rate_limit
|
77
|
-
|
77
|
+
seconds_to_retry = (@rate_limit_details[:reset_at] - Time.now.utc).ceil
|
78
|
+
sleep seconds_to_retry unless seconds_to_retry < 0
|
78
79
|
retry unless (retries -=1).zero?
|
79
80
|
else
|
80
81
|
raise e
|
@@ -109,7 +110,7 @@ module Intercom
|
|
109
110
|
rate_limit_details = {}
|
110
111
|
rate_limit_details[:limit] = response['X-RateLimit-Limit'].to_i if response['X-RateLimit-Limit']
|
111
112
|
rate_limit_details[:remaining] = response['X-RateLimit-Remaining'].to_i if response['X-RateLimit-Remaining']
|
112
|
-
rate_limit_details[:reset_at] = Time.
|
113
|
+
rate_limit_details[:reset_at] = Time.parse(response['X-RateLimit-Reset']) if response['X-RateLimit-Reset']
|
113
114
|
@rate_limit_details = rate_limit_details
|
114
115
|
end
|
115
116
|
|
@@ -151,6 +152,12 @@ module Intercom
|
|
151
152
|
case error_code
|
152
153
|
when 'unauthorized', 'forbidden', 'token_not_found'
|
153
154
|
raise Intercom::AuthenticationError.new(error_details['message'], error_context)
|
155
|
+
when 'token_suspended'
|
156
|
+
raise Intercom::AppSuspendedError.new(error_details['message'], error_context)
|
157
|
+
when 'token_revoked'
|
158
|
+
raise Intercom::TokenRevokedError.new(error_details['message'], error_context)
|
159
|
+
when 'token_unauthorized'
|
160
|
+
raise Intercom::TokenUnauthorizedError.new(error_details['message'], error_context)
|
154
161
|
when "bad_request", "missing_parameter", 'parameter_invalid', 'parameter_not_found'
|
155
162
|
raise Intercom::BadRequestError.new(error_details['message'], error_context)
|
156
163
|
when "not_restorable"
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -235,7 +235,7 @@ def users_scroll(include_users= false)
|
|
235
235
|
}
|
236
236
|
end
|
237
237
|
|
238
|
-
def users_pagination(include_next_link
|
238
|
+
def users_pagination(include_next_link:, per_page:, page:, total_pages:, total_count:, user_list:)
|
239
239
|
{
|
240
240
|
"type"=>"user.list",
|
241
241
|
"pages"=>
|
@@ -38,21 +38,21 @@ describe Intercom::ClientCollectionProxy do
|
|
38
38
|
test_user("user4@example.com"), test_user("user5@example.com"), test_user("user6@example.com"),
|
39
39
|
test_user("user7@example.com"), test_user("user8@example.com"), test_user("user9@example.com"),
|
40
40
|
test_user("user10@example.com")]
|
41
|
-
client.expects(:get).with("/users", {:type=>'users', :per_page => 10, :page => 1}).returns(users_pagination(false, per_page
|
41
|
+
client.expects(:get).with("/users", {:type=>'users', :per_page => 10, :page => 1}).returns(users_pagination(include_next_link: false, per_page: 10, page: 1, total_pages: 1, total_count: 10, user_list: users))
|
42
42
|
result = client.users.find_all(:type=>'users', :per_page => 10, :page => 1).map {|user| user.email }
|
43
43
|
result.must_equal %W(user1@example.com user2@example.com user3@example.com user4@example.com user5@example.com user6@example.com user7@example.com user8@example.com user9@example.com user10@example.com)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "supports multi page pagination" do
|
47
47
|
users = [test_user("user3@example.com"), test_user("user4@example.com")]
|
48
|
-
client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 3}).returns(users_pagination(true, per_page
|
48
|
+
client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 3}).returns(users_pagination(include_next_link: true, per_page: 2, page: 3, total_pages: 5, total_count: 10, user_list: users))
|
49
49
|
result = client.users.find_all(:type=>'users', :per_page => 2, :page => 3).map {|user| user.email }
|
50
50
|
result.must_equal %W(user3@example.com user4@example.com)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "works with page out of range request" do
|
54
54
|
users = []
|
55
|
-
client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 30}).returns(users_pagination(true, per_page
|
55
|
+
client.expects(:get).with("/users", {:type=>'users', :per_page => 2, :page => 30}).returns(users_pagination(include_next_link: true, per_page: 2, page: 30, total_pages: 2, total_count: 3, user_list: users))
|
56
56
|
result = client.users.find_all(:type=>'users', :per_page => 2, :page => 30).map {|user| user.email }
|
57
57
|
result.must_equal %W()
|
58
58
|
end
|
@@ -62,7 +62,7 @@ describe Intercom::ClientCollectionProxy do
|
|
62
62
|
time_increment=1000
|
63
63
|
users = [test_user_dates(email="user1@example.com", created_at=test_date), test_user_dates(email="user2@example.com", created_at=test_date-time_increment),
|
64
64
|
test_user_dates(email="user3@example.com", created_at=test_date-2*time_increment), test_user_dates(email="user4@example.com", created_at=test_date-3*time_increment)]
|
65
|
-
client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at"}).returns(users_pagination(true, per_page
|
65
|
+
client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at"}).returns(users_pagination(include_next_link: true, per_page: 4, page: 5, total_pages: 6, total_count: 30, user_list: users))
|
66
66
|
result = client.users.find_all(:type=>'users', :per_page => 4, :page => 5, :order => "asc", :sort => "created_at").map(&:email)
|
67
67
|
result.must_equal %W(user1@example.com user2@example.com user3@example.com user4@example.com)
|
68
68
|
end
|
@@ -72,7 +72,7 @@ describe Intercom::ClientCollectionProxy do
|
|
72
72
|
time_increment=1000
|
73
73
|
users = [test_user_dates(email="user4@example.com", created_at=3*test_date), test_user_dates(email="user3@example.com", created_at=test_date-2*time_increment),
|
74
74
|
test_user_dates(email="user2@example.com", created_at=test_date-time_increment), test_user_dates(email="user1@example.com", created_at=test_date)]
|
75
|
-
client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at"}).returns(users_pagination(true, per_page
|
75
|
+
client.expects(:get).with("/users", {:type=>'users', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at"}).returns(users_pagination(include_next_link: true, per_page: 4, page: 5, total_pages: 6, total_count: 30, user_list: users))
|
76
76
|
result = client.users.find_all(:type=>'users', :per_page => 4, :page => 5, :order => "desc", :sort => "created_at").map {|user| user.email }
|
77
77
|
result.must_equal %W(user4@example.com user3@example.com user2@example.com user1@example.com)
|
78
78
|
end
|
@@ -61,6 +61,17 @@ describe 'Intercom::Request' do
|
|
61
61
|
req.execute(target_base_url=uri, username: "ted", secret: "")
|
62
62
|
end
|
63
63
|
|
64
|
+
it 'should not sleep if rate limit reset time has passed' do
|
65
|
+
# Use webmock to mock the HTTP request
|
66
|
+
stub_request(:any, uri).\
|
67
|
+
to_return(status: [429, "Too Many Requests"], headers: { 'X-RateLimit-Reset' => Time.parse("February 25 2010").utc }).\
|
68
|
+
then.to_return(status: [200, "OK"])
|
69
|
+
req = Intercom::Request.get(uri, "")
|
70
|
+
req.handle_rate_limit=true
|
71
|
+
req.expects(:sleep).never.with(any_parameters)
|
72
|
+
req.execute(target_base_url=uri, username: "ted", secret: "")
|
73
|
+
end
|
74
|
+
|
64
75
|
end
|
65
76
|
|
66
77
|
|
@@ -239,7 +239,7 @@ describe "Intercom::User" do
|
|
239
239
|
it "allows setting dates to nil without converting them to 0" do
|
240
240
|
client.expects(:post).with("/users", {"email" => "jo@example.com", 'custom_attributes' => {}, "remote_created_at" => nil}).returns({"email" => "jo@example.com"})
|
241
241
|
user = client.users.create("email" => "jo@example.com", "remote_created_at" => nil)
|
242
|
-
user.remote_created_at
|
242
|
+
assert_nil user.remote_created_at
|
243
243
|
end
|
244
244
|
|
245
245
|
it "sets/gets rw keys" do
|
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.24
|
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:
|
18
|
+
date: 2018-05-10 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -131,6 +131,7 @@ executables: []
|
|
131
131
|
extensions: []
|
132
132
|
extra_rdoc_files: []
|
133
133
|
files:
|
134
|
+
- ".circleci/config.yml"
|
134
135
|
- ".github/ISSUE_TEMPLATE.md"
|
135
136
|
- ".gitignore"
|
136
137
|
- ".travis.yml"
|
@@ -140,7 +141,6 @@ files:
|
|
140
141
|
- RELEASING.md
|
141
142
|
- Rakefile
|
142
143
|
- changes.txt
|
143
|
-
- circle.yml
|
144
144
|
- intercom.gemspec
|
145
145
|
- lib/data/cacert.pem
|
146
146
|
- lib/ext/sliceable_hash.rb
|