intercom 3.5.17 → 3.5.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c01c8eb70ddcf8ebfbf6a2cfe271caaf610edf6
4
- data.tar.gz: 56b74c46c5214b4bab506f81668ecfdea9deb889
3
+ metadata.gz: 0d73b6f0f89970d9ccc8e82cfb969549e5f9720a
4
+ data.tar.gz: eecb568c0c6116afbef3cec73ee93a459af3bb23
5
5
  SHA512:
6
- metadata.gz: a0118ea62d5810289c2a3858212ad1e3bbfdc80c1c230287a5912bb14ae11476353eda8822fc9aa10932bc104f94164965f91e217e119a6e5259480ccdc934f6
7
- data.tar.gz: edfad895f3e8a9ef70acbbe60b837577c56cc743181827a20c98ff968851ca8ce7559adb8c459d50d34c48b1950b8fe26cea16f6a135313f56e6aa74df9a785a
6
+ metadata.gz: c1c7a6abeaa8ad78409defd2435908245d152f222dbd68a01ef4ef8dbea14a49044f4a6339b9bfecb3db511e8e9fd0cb027ddcd9359d0b0a1c83cb4dec2417f6
7
+ data.tar.gz: 369edfbdd536899f05923d299c61e53b57b57e975370ad7bb16d6090d03786228e86a14b69ea018d8836ef0e688d0adce3d4978339cf4dfbd93be0a4f5a85560
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ before_install:
4
+ - gem install bundler
5
+ - gem update --system
6
+ - gem --version
3
7
  rvm:
4
8
  - 2.1.0
5
9
  - 2.2.0
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem 'webmock'
3
4
  gemspec
4
5
 
5
6
  group :development, :test do
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.10'
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
 
@@ -1,3 +1,6 @@
1
+ 3.5.17
2
+ - Fix BlockedUserError typo
3
+
1
4
  3.5.16
2
5
  - Standardize comparison of attribute as string when input is Hash or JSON
3
6
 
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.5.17"
2
+ VERSION = "3.5.19"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require 'intercom'
2
2
  require 'minitest/autorun'
3
3
  require 'mocha/setup'
4
+ require 'webmock'
5
+ include WebMock::API
4
6
 
5
7
  def test_user(email="bob@example.com")
6
8
  {
@@ -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).must_equal(nil)
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.17
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-07-11 00:00:00.000000000 Z
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.4.8
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: []