intercom 3.9.0 → 3.9.2
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 +27 -4
- data/README.md +26 -1
- data/changes.txt +3 -0
- data/intercom.gemspec +1 -0
- data/lib/intercom/errors.rb +3 -0
- data/lib/intercom/request.rb +104 -84
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/intercom/client_spec.rb +11 -1
- data/spec/unit/intercom/request_spec.rb +115 -76
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b05fef934a0732652abcfa3f996dedcd0fe373e2d445313d91fd317e964d8972
|
4
|
+
data.tar.gz: 2cb22c404e5bdead26355feadae48df299124157850d0366eb4a57f7523ef1be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64f7face5cb2170fbe3e5f96a26ced8d869f9c0d529e2b061962d21ef0932276750903889af53f209e740a696c6847429bc7cd04a176266d78ad9be97de19d79
|
7
|
+
data.tar.gz: c4d837db173d1c67e99aee611248ff9e62965c1b3f5d01f94ef7e131bccfc137174df75316e4caf41be4d25a92fd4b7a32c08272a4d04a0dd020405968f1ccd7
|
data/.circleci/config.yml
CHANGED
@@ -1,12 +1,35 @@
|
|
1
1
|
version: 2
|
2
2
|
jobs:
|
3
|
-
|
3
|
+
"Test against Ruby 2.4":
|
4
4
|
docker:
|
5
|
-
- image: circleci/ruby:2.4.
|
6
|
-
|
5
|
+
- image: circleci/ruby:2.4.9
|
6
|
+
working_directory: ~/intercom-ruby
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- run: bundle install
|
10
|
+
- run: bundle exec rake
|
11
|
+
"Test against Ruby 2.5":
|
12
|
+
docker:
|
13
|
+
- image: circleci/ruby:2.5.7
|
7
14
|
working_directory: ~/intercom-ruby
|
8
|
-
|
9
15
|
steps:
|
10
16
|
- checkout
|
11
17
|
- run: bundle install
|
12
18
|
- run: bundle exec rake
|
19
|
+
"Test against Ruby 2.6":
|
20
|
+
docker:
|
21
|
+
- image: circleci/ruby:2.6.5
|
22
|
+
working_directory: ~/intercom-ruby
|
23
|
+
steps:
|
24
|
+
- checkout
|
25
|
+
- run: bundle install
|
26
|
+
- run: bundle exec rake
|
27
|
+
|
28
|
+
workflows:
|
29
|
+
version: 2
|
30
|
+
build_and_test:
|
31
|
+
jobs:
|
32
|
+
- "Test against Ruby 2.4"
|
33
|
+
- "Test against Ruby 2.5"
|
34
|
+
- "Test against Ruby 2.6"
|
35
|
+
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
|
|
23
23
|
|
24
24
|
Using bundler:
|
25
25
|
|
26
|
-
gem 'intercom', '~> 3.
|
26
|
+
gem 'intercom', '~> 3.9.0'
|
27
27
|
|
28
28
|
## Basic Usage
|
29
29
|
|
@@ -470,9 +470,13 @@ intercom.contacts.scroll.each { |lead| puts lead.id}
|
|
470
470
|
|
471
471
|
#### Customers
|
472
472
|
|
473
|
+
Our Customer API is a central place for all the information on your customers, whether they're users or leads. More detail in our API documentation on [Customers](https://developers.intercom.com/intercom-api-reference/v0/reference#customers).
|
474
|
+
|
475
|
+
```ruby
|
473
476
|
# Search for customers
|
474
477
|
customers = intercom.customers.search(query: { "field": "name", "operator": "=", "value": "Alice"}, per_page: 50, sort_field: "name", sort_order: "ascending")
|
475
478
|
customers.each { |customer| p customer.name }
|
479
|
+
```
|
476
480
|
|
477
481
|
#### Counts
|
478
482
|
|
@@ -556,3 +560,24 @@ intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
|
|
556
560
|
- **Send coherent history**. Make sure each individual commit in your pull
|
557
561
|
request is meaningful. If you had to make multiple intermediate commits while
|
558
562
|
developing, please squash them before sending them to us.
|
563
|
+
|
564
|
+
### Development
|
565
|
+
|
566
|
+
#### Running tests
|
567
|
+
|
568
|
+
```bash
|
569
|
+
# all tests
|
570
|
+
bundle exec spec
|
571
|
+
|
572
|
+
# unit tests
|
573
|
+
bundle exec spec:unit
|
574
|
+
|
575
|
+
# integration tests
|
576
|
+
bundle exec spec:integration
|
577
|
+
|
578
|
+
# single test file
|
579
|
+
bundle exec m spec/unit/intercom/job_spec.rb
|
580
|
+
|
581
|
+
# single test
|
582
|
+
bundle exec m spec/unit/intercom/job_spec.rb:49
|
583
|
+
```
|
data/changes.txt
CHANGED
data/intercom.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency 'minitest', '~> 5.4'
|
22
|
+
spec.add_development_dependency "m", "~> 1.5.0"
|
22
23
|
spec.add_development_dependency 'rake', '~> 10.3'
|
23
24
|
spec.add_development_dependency 'mocha', '~> 1.0'
|
24
25
|
spec.add_development_dependency "fakeweb", ["~> 1.3"]
|
data/lib/intercom/errors.rb
CHANGED
@@ -63,6 +63,9 @@ module Intercom
|
|
63
63
|
# Raised when you have exceeded the API rate limit
|
64
64
|
class RateLimitExceeded < IntercomError; end
|
65
65
|
|
66
|
+
# Raised when some attribute of the response cannot be handled
|
67
|
+
class UnexpectedResponseError < IntercomError; end
|
68
|
+
|
66
69
|
# Raised when the request throws an error not accounted for
|
67
70
|
class UnexpectedError < IntercomError; end
|
68
71
|
|
data/lib/intercom/request.rb
CHANGED
@@ -3,64 +3,48 @@ require 'net/https'
|
|
3
3
|
|
4
4
|
module Intercom
|
5
5
|
class Request
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
self.net_http_method = net_http_method
|
11
|
-
self.handle_rate_limit = false
|
12
|
-
end
|
13
|
-
|
14
|
-
def set_common_headers(method, base_uri)
|
15
|
-
method.add_field('AcceptEncoding', 'gzip, deflate')
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_basic_auth(method, username, secret)
|
19
|
-
method.basic_auth(CGI.unescape(username), CGI.unescape(secret))
|
20
|
-
end
|
6
|
+
class << self
|
7
|
+
def get(path, params)
|
8
|
+
new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers))
|
9
|
+
end
|
21
10
|
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
def post(path, form_data)
|
12
|
+
new(path, method_with_body(Net::HTTP::Post, path, form_data))
|
13
|
+
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
def delete(path, params)
|
16
|
+
new(path, method_with_body(Net::HTTP::Delete, path, params))
|
17
|
+
end
|
29
18
|
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
def put(path, form_data)
|
20
|
+
new(path, method_with_body(Net::HTTP::Put, path, form_data))
|
21
|
+
end
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
private def method_with_body(http_method, path, params)
|
24
|
+
request = http_method.send(:new, path, default_headers)
|
25
|
+
request.body = params.to_json
|
26
|
+
request["Content-Type"] = "application/json"
|
27
|
+
request
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
private def default_headers
|
31
|
+
{'Accept-Encoding' => 'gzip, deflate', 'Accept' => 'application/vnd.intercom.3+json', 'User-Agent' => "Intercom-Ruby/#{Intercom::VERSION}"}
|
32
|
+
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
private def append_query_string_to_url(url, params)
|
35
|
+
return url if params.empty?
|
36
|
+
query_string = params.map { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
37
|
+
url + "?#{query_string}"
|
38
|
+
end
|
47
39
|
end
|
48
40
|
|
49
|
-
def
|
50
|
-
|
41
|
+
def initialize(path, net_http_method)
|
42
|
+
self.path = path
|
43
|
+
self.net_http_method = net_http_method
|
44
|
+
self.handle_rate_limit = false
|
51
45
|
end
|
52
46
|
|
53
|
-
|
54
|
-
net = Net::HTTP.new(uri.host, uri.port)
|
55
|
-
if uri.is_a?(URI::HTTPS)
|
56
|
-
net.use_ssl = true
|
57
|
-
net.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
58
|
-
net.ca_file = File.join(File.dirname(__FILE__), '../data/cacert.pem')
|
59
|
-
end
|
60
|
-
net.read_timeout = read_timeout
|
61
|
-
net.open_timeout = open_timeout
|
62
|
-
net
|
63
|
-
end
|
47
|
+
attr_accessor :handle_rate_limit
|
64
48
|
|
65
49
|
def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_timeout: 30, api_version: nil)
|
66
50
|
retries = 3
|
@@ -72,10 +56,16 @@ module Intercom
|
|
72
56
|
client(base_uri, read_timeout: read_timeout, open_timeout: open_timeout).start do |http|
|
73
57
|
begin
|
74
58
|
response = http.request(net_http_method)
|
59
|
+
|
75
60
|
set_rate_limit_details(response)
|
76
|
-
decoded_body = decode_body(response)
|
77
|
-
parsed_body = parse_body(decoded_body, response)
|
78
61
|
raise_errors_on_failure(response)
|
62
|
+
|
63
|
+
parsed_body = extract_response_body(response)
|
64
|
+
|
65
|
+
return nil if parsed_body.nil?
|
66
|
+
|
67
|
+
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
|
68
|
+
|
79
69
|
parsed_body
|
80
70
|
rescue Intercom::RateLimitExceeded => e
|
81
71
|
if @handle_rate_limit
|
@@ -98,24 +88,51 @@ module Intercom
|
|
98
88
|
end
|
99
89
|
end
|
100
90
|
|
101
|
-
|
102
|
-
|
103
|
-
|
91
|
+
attr_accessor :path,
|
92
|
+
:net_http_method,
|
93
|
+
:rate_limit_details
|
104
94
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
95
|
+
private :path,
|
96
|
+
:net_http_method,
|
97
|
+
:rate_limit_details
|
98
|
+
|
99
|
+
private def client(uri, read_timeout:, open_timeout:)
|
100
|
+
net = Net::HTTP.new(uri.host, uri.port)
|
101
|
+
if uri.is_a?(URI::HTTPS)
|
102
|
+
net.use_ssl = true
|
103
|
+
net.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
104
|
+
net.ca_file = File.join(File.dirname(__FILE__), '../data/cacert.pem')
|
112
105
|
end
|
113
|
-
|
114
|
-
|
115
|
-
|
106
|
+
net.read_timeout = read_timeout
|
107
|
+
net.open_timeout = open_timeout
|
108
|
+
net
|
116
109
|
end
|
117
110
|
|
118
|
-
def
|
111
|
+
private def extract_response_body(response)
|
112
|
+
decoded_body = decode(response['content-encoding'], response.body)
|
113
|
+
|
114
|
+
json_parse_response(decoded_body, response.code)
|
115
|
+
end
|
116
|
+
|
117
|
+
private def decode(content_encoding, body)
|
118
|
+
return body if (!body) || body.empty? || content_encoding != 'gzip'
|
119
|
+
Zlib::GzipReader.new(StringIO.new(body)).read.force_encoding("utf-8")
|
120
|
+
end
|
121
|
+
|
122
|
+
private def json_parse_response(str, code)
|
123
|
+
return nil if str.to_s.empty?
|
124
|
+
|
125
|
+
JSON.parse(str)
|
126
|
+
rescue JSON::ParserError
|
127
|
+
msg = <<~MSG.gsub(/[[:space:]]+/, " ").strip # #squish from ActiveSuppor
|
128
|
+
Expected a JSON response body. Instead got '#{str}'
|
129
|
+
with status code '#{code}'.
|
130
|
+
MSG
|
131
|
+
|
132
|
+
raise UnexpectedResponseError, msg
|
133
|
+
end
|
134
|
+
|
135
|
+
private def set_rate_limit_details(response)
|
119
136
|
rate_limit_details = {}
|
120
137
|
rate_limit_details[:limit] = response['X-RateLimit-Limit'].to_i if response['X-RateLimit-Limit']
|
121
138
|
rate_limit_details[:remaining] = response['X-RateLimit-Remaining'].to_i if response['X-RateLimit-Remaining']
|
@@ -123,30 +140,39 @@ module Intercom
|
|
123
140
|
@rate_limit_details = rate_limit_details
|
124
141
|
end
|
125
142
|
|
126
|
-
def
|
127
|
-
|
128
|
-
Zlib::GzipReader.new(StringIO.new(body)).read.force_encoding("utf-8")
|
143
|
+
private def set_common_headers(method, base_uri)
|
144
|
+
method.add_field('AcceptEncoding', 'gzip, deflate')
|
129
145
|
end
|
130
146
|
|
131
|
-
def
|
132
|
-
|
147
|
+
private def set_basic_auth(method, username, secret)
|
148
|
+
method.basic_auth(CGI.unescape(username), CGI.unescape(secret))
|
149
|
+
end
|
150
|
+
|
151
|
+
private def set_api_version(method, api_version)
|
152
|
+
method.add_field('Intercom-Version', api_version)
|
153
|
+
end
|
154
|
+
|
155
|
+
private def raise_errors_on_failure(res)
|
156
|
+
code = res.code.to_i
|
157
|
+
|
158
|
+
if code == 404
|
133
159
|
raise Intercom::ResourceNotFound.new('Resource Not Found')
|
134
|
-
elsif
|
160
|
+
elsif code == 401
|
135
161
|
raise Intercom::AuthenticationError.new('Unauthorized')
|
136
|
-
elsif
|
162
|
+
elsif code == 403
|
137
163
|
raise Intercom::AuthenticationError.new('Forbidden')
|
138
|
-
elsif
|
164
|
+
elsif code == 429
|
139
165
|
raise Intercom::RateLimitExceeded.new('Rate Limit Exceeded')
|
140
|
-
elsif
|
166
|
+
elsif code == 500
|
141
167
|
raise Intercom::ServerError.new('Server Error')
|
142
|
-
elsif
|
168
|
+
elsif code == 502
|
143
169
|
raise Intercom::BadGatewayError.new('Bad Gateway Error')
|
144
|
-
elsif
|
170
|
+
elsif code == 503
|
145
171
|
raise Intercom::ServiceUnavailableError.new('Service Unavailable')
|
146
172
|
end
|
147
173
|
end
|
148
174
|
|
149
|
-
def raise_application_errors_on_failure(error_list_details, http_code)
|
175
|
+
private def raise_application_errors_on_failure(error_list_details, http_code)
|
150
176
|
# Currently, we don't support multiple errors
|
151
177
|
error_details = error_list_details['errors'].first
|
152
178
|
error_code = error_details['type'] || error_details['code']
|
@@ -198,18 +224,12 @@ module Intercom
|
|
198
224
|
end
|
199
225
|
end
|
200
226
|
|
201
|
-
def message_for_unexpected_error_with_type(error_details, parsed_http_code)
|
227
|
+
private def message_for_unexpected_error_with_type(error_details, parsed_http_code)
|
202
228
|
"The error of type '#{error_details['type']}' is not recognized. It occurred with the message: #{error_details['message']} and http_code: '#{parsed_http_code}'. Please contact Intercom with these details."
|
203
229
|
end
|
204
230
|
|
205
|
-
def message_for_unexpected_error_without_type(error_details, parsed_http_code)
|
231
|
+
private def message_for_unexpected_error_without_type(error_details, parsed_http_code)
|
206
232
|
"An unexpected error occured. It occurred with the message: #{error_details['message']} and http_code: '#{parsed_http_code}'. Please contact Intercom with these details."
|
207
233
|
end
|
208
|
-
|
209
|
-
def self.append_query_string_to_url(url, params)
|
210
|
-
return url if params.empty?
|
211
|
-
query_string = params.map { |k, v| "#{k.to_s}=#{CGI::escape(v.to_s)}" }.join('&')
|
212
|
-
url + "?#{query_string}"
|
213
|
-
end
|
214
234
|
end
|
215
235
|
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,12 +4,22 @@ module Intercom
|
|
4
4
|
describe Client do
|
5
5
|
let(:app_id) { 'myappid' }
|
6
6
|
let(:api_key) { 'myapikey' }
|
7
|
-
let(:client)
|
7
|
+
let(:client) do
|
8
|
+
Client.new(
|
9
|
+
app_id: app_id,
|
10
|
+
api_key: api_key,
|
11
|
+
handle_rate_limit: true
|
12
|
+
)
|
13
|
+
end
|
8
14
|
|
9
15
|
it 'should set the base url' do
|
10
16
|
client.base_url.must_equal('https://api.intercom.io')
|
11
17
|
end
|
12
18
|
|
19
|
+
it 'should have handle_rate_limit set' do
|
20
|
+
_(client.handle_rate_limit).must_equal(true)
|
21
|
+
end
|
22
|
+
|
13
23
|
it 'should be able to change the base url' do
|
14
24
|
prev = client.options(Intercom::Client.set_base_url('https://mymockintercom.io'))
|
15
25
|
client.base_url.must_equal('https://mymockintercom.io')
|
@@ -3,107 +3,146 @@ require 'ostruct'
|
|
3
3
|
|
4
4
|
WebMock.enable!
|
5
5
|
|
6
|
-
describe 'Intercom::Request' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
describe 'Intercom::Request', '#execute' do
|
7
|
+
let(:uri) {"https://api.intercom.io/users"}
|
8
|
+
let(:req) { Intercom::Request.get(uri, {}) }
|
9
|
+
let(:default_body) { { data: "test" }.to_json }
|
10
|
+
|
11
|
+
def execute!
|
12
|
+
req.execute(uri, username: 'ted', secret: '')
|
11
13
|
end
|
12
14
|
|
13
|
-
it '
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
it 'should call sleep for rate limit error three times and raise a rate limit error otherwise' do
|
16
|
+
stub_request(:any, uri).to_return(
|
17
|
+
status: [429, "Too Many Requests"],
|
18
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
19
|
+
body: default_body
|
20
|
+
)
|
21
|
+
|
22
|
+
req.handle_rate_limit=true
|
23
|
+
|
24
|
+
req.expects(:sleep).times(3).with(any_parameters)
|
25
|
+
|
26
|
+
expect { execute! }.must_raise(Intercom::RateLimitExceeded)
|
17
27
|
end
|
18
28
|
|
19
|
-
it '
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
it 'should not call sleep for rate limit error' do
|
30
|
+
stub_request(:any, uri).to_return(
|
31
|
+
status: [200, "OK"],
|
32
|
+
headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 },
|
33
|
+
body: default_body
|
34
|
+
)
|
35
|
+
|
36
|
+
req.handle_rate_limit=true
|
37
|
+
req.expects(:sleep).never.with(any_parameters)
|
38
|
+
|
39
|
+
execute!
|
23
40
|
end
|
24
41
|
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
it 'should call sleep for rate limit error just once' do
|
43
|
+
stub_request(:any, uri).to_return(
|
44
|
+
status: [429, "Too Many Requests"],
|
45
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
46
|
+
).then.to_return(status: [200, "OK"], body: default_body)
|
28
47
|
|
29
|
-
|
30
|
-
|
31
|
-
|
48
|
+
req.handle_rate_limit=true
|
49
|
+
req.expects(:sleep).with(any_parameters)
|
50
|
+
|
51
|
+
execute!
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should not sleep if rate limit reset time has passed' do
|
55
|
+
stub_request(:any, uri).to_return(
|
56
|
+
status: [429, "Too Many Requests"],
|
57
|
+
headers: { 'X-RateLimit-Reset' => Time.parse("February 25 2010").utc.to_i.to_s },
|
58
|
+
body: default_body
|
59
|
+
).then.to_return(status: [200, "OK"], body: default_body)
|
60
|
+
|
61
|
+
req.handle_rate_limit=true
|
62
|
+
req.expects(:sleep).never.with(any_parameters)
|
63
|
+
|
64
|
+
execute!
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'handles an empty body gracefully' do
|
68
|
+
stub_request(:any, uri).to_return(
|
69
|
+
status: 200,
|
70
|
+
body: nil
|
71
|
+
)
|
32
72
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
73
|
+
assert_nil(execute!)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'HTTP error handling' do
|
77
|
+
it 'raises an error when the response is successful but the body is not JSON' do
|
78
|
+
stub_request(:any, uri).to_return(
|
79
|
+
status: 200,
|
80
|
+
body: '<html>something</html>'
|
81
|
+
)
|
82
|
+
|
83
|
+
expect { execute! }.must_raise(Intercom::UnexpectedResponseError)
|
42
84
|
end
|
43
85
|
|
44
|
-
it '
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
req.execute(uri, username: "ted", secret: "")
|
86
|
+
it 'raises an error when an html error page rendered' do
|
87
|
+
stub_request(:any, uri).to_return(
|
88
|
+
status: 500,
|
89
|
+
body: '<html>something</html>'
|
90
|
+
)
|
91
|
+
|
92
|
+
expect { execute! }.must_raise(Intercom::ServerError)
|
52
93
|
end
|
53
94
|
|
54
|
-
it '
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
req.expects(:sleep).with(any_parameters)
|
62
|
-
req.execute(uri, username: "ted", secret: "")
|
95
|
+
it 'raises an error if the decoded_body is "null"' do
|
96
|
+
stub_request(:any, uri).to_return(
|
97
|
+
status: 500,
|
98
|
+
body: 'null'
|
99
|
+
)
|
100
|
+
|
101
|
+
expect { execute! }.must_raise(Intercom::ServerError)
|
63
102
|
end
|
64
103
|
|
65
|
-
it '
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
req.expects(:sleep).never.with(any_parameters)
|
73
|
-
req.execute(uri, username: "ted", secret: "")
|
104
|
+
it 'raises a RateLimitExceeded error when the response code is 429' do
|
105
|
+
stub_request(:any, uri).to_return(
|
106
|
+
status: 429,
|
107
|
+
body: 'null'
|
108
|
+
)
|
109
|
+
|
110
|
+
expect { execute! }.must_raise(Intercom::RateLimitExceeded)
|
74
111
|
end
|
75
112
|
end
|
76
113
|
|
77
|
-
|
78
|
-
describe "Application errors on failure" do
|
114
|
+
describe "application error handling" do
|
79
115
|
let(:uri) {"https://api.intercom.io/conversations/reply"}
|
116
|
+
let(:req) { Intercom::Request.put(uri, {}) }
|
117
|
+
|
80
118
|
it 'should raise ResourceNotUniqueError error on resource_conflict code' do
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
119
|
+
stub_request(:put, uri).to_return(
|
120
|
+
status: [409, "Resource Already Exists"],
|
121
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
122
|
+
body: { type: "error.list", errors: [ code: "resource_conflict" ] }.to_json
|
123
|
+
)
|
124
|
+
|
125
|
+
expect { execute! }.must_raise(Intercom::ResourceNotUniqueError)
|
86
126
|
end
|
87
127
|
|
88
128
|
it 'should raise ApiVersionInvalid error on intercom_version_invalid code' do
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
129
|
+
stub_request(:put, uri).to_return(
|
130
|
+
status: [400, "Bad Request"],
|
131
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
132
|
+
body: { type: "error.list", errors: [ code: "intercom_version_invalid" ] }.to_json
|
133
|
+
)
|
134
|
+
|
135
|
+
expect { execute! }.must_raise(Intercom::ApiVersionInvalid)
|
94
136
|
end
|
95
137
|
|
96
138
|
it 'should raise ResourceNotFound error on company_not_found code' do
|
97
|
-
stub_request(:put, uri)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
139
|
+
stub_request(:put, uri).to_return(
|
140
|
+
status: [404, "Not Found"],
|
141
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
142
|
+
body: { type: "error.list", errors: [ code: "company_not_found" ] }.to_json
|
143
|
+
)
|
103
144
|
|
104
|
-
|
105
|
-
|
106
|
-
req = Intercom::Request.new('path/', 'GET')
|
107
|
-
assert_nil(req.parse_body(nil, response))
|
145
|
+
expect { execute! }.must_raise(Intercom::ResourceNotFound)
|
146
|
+
end
|
108
147
|
end
|
109
148
|
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.9.
|
4
|
+
version: 3.9.2
|
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: 2019-
|
18
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -31,6 +31,20 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '5.4'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: m
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.0
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.5.0
|
34
48
|
- !ruby/object:Gem::Dependency
|
35
49
|
name: rake
|
36
50
|
requirement: !ruby/object:Gem::Requirement
|