intercom 3.7.3 → 3.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/changes.txt +3 -0
- data/lib/intercom/client.rb +11 -3
- data/lib/intercom/errors.rb +3 -0
- data/lib/intercom/request.rb +8 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/unit/intercom/client_spec.rb +23 -0
- data/spec/unit/intercom/request_spec.rb +8 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee56e3e11c13b620ee6b5a04c3eab742c6064297
|
4
|
+
data.tar.gz: 39bf3533177283eadb4c021bee58a38d889cbf4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236a3df567693a41cdcf45c761d0339748748581c048763850122e93efcf56b58633d951b20c9c2ce2f034ab1728c269d784378adae250059bf04b1dbbad5729
|
7
|
+
data.tar.gz: 5dacf1bcec13579a7161f9467d520174960a1544a03dc2f99cc2a6fdca959901db6ce7800c0dfed10bc235c6353a6e457398e410a59dc175e0c277b9abe1e525
|
data/README.md
CHANGED
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, :handle_rate_limit, :timeouts
|
5
|
+
attr_reader :base_url, :rate_limit_details, :username_part, :password_part, :handle_rate_limit, :timeouts, :api_version
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def set_base_url(base_url)
|
@@ -25,7 +25,7 @@ module Intercom
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
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)
|
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, api_version: nil)
|
29
29
|
if token
|
30
30
|
@username_part = token
|
31
31
|
@password_part = ""
|
@@ -35,6 +35,9 @@ module Intercom
|
|
35
35
|
end
|
36
36
|
validate_credentials!
|
37
37
|
|
38
|
+
@api_version = api_version
|
39
|
+
validate_api_version!
|
40
|
+
|
38
41
|
@base_url = base_url
|
39
42
|
@rate_limit_details = {}
|
40
43
|
@handle_rate_limit = handle_rate_limit
|
@@ -123,9 +126,14 @@ module Intercom
|
|
123
126
|
fail error if @username_part.nil?
|
124
127
|
end
|
125
128
|
|
129
|
+
def validate_api_version!
|
130
|
+
error = MisconfiguredClientError.new("api_version must be either nil or a valid API version")
|
131
|
+
fail error if (@api_version && Gem::Version.new(@api_version) < Gem::Version.new('1.0'))
|
132
|
+
end
|
133
|
+
|
126
134
|
def execute_request(request)
|
127
135
|
request.handle_rate_limit = handle_rate_limit
|
128
|
-
request.execute(@base_url, username: @username_part, secret: @password_part, **timeouts)
|
136
|
+
request.execute(@base_url, username: @username_part, secret: @password_part, api_version: @api_version, **timeouts)
|
129
137
|
ensure
|
130
138
|
@rate_limit_details = request.rate_limit_details
|
131
139
|
end
|
data/lib/intercom/errors.rb
CHANGED
@@ -81,6 +81,9 @@ module Intercom
|
|
81
81
|
# Raised when unexpected nil returned from server
|
82
82
|
class Intercom::HttpError < IntercomError; end
|
83
83
|
|
84
|
+
# Raised when an invalid api version is used
|
85
|
+
class ApiVersionInvalid < IntercomError; end
|
86
|
+
|
84
87
|
#
|
85
88
|
# Non-public errors (internal to the gem)
|
86
89
|
#
|
data/lib/intercom/request.rb
CHANGED
@@ -19,6 +19,10 @@ module Intercom
|
|
19
19
|
method.basic_auth(CGI.unescape(username), CGI.unescape(secret))
|
20
20
|
end
|
21
21
|
|
22
|
+
def set_api_version(method, api_version)
|
23
|
+
method.add_field('Intercom-Version', api_version)
|
24
|
+
end
|
25
|
+
|
22
26
|
def self.get(path, params)
|
23
27
|
new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers))
|
24
28
|
end
|
@@ -58,11 +62,12 @@ module Intercom
|
|
58
62
|
net
|
59
63
|
end
|
60
64
|
|
61
|
-
def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_timeout: 30)
|
65
|
+
def execute(target_base_url=nil, username:, secret: nil, read_timeout: 90, open_timeout: 30, api_version: nil)
|
62
66
|
retries = 3
|
63
67
|
base_uri = URI.parse(target_base_url)
|
64
68
|
set_common_headers(net_http_method, base_uri)
|
65
69
|
set_basic_auth(net_http_method, username, secret)
|
70
|
+
set_api_version(net_http_method, api_version) if api_version
|
66
71
|
begin
|
67
72
|
client(base_uri, read_timeout: read_timeout, open_timeout: open_timeout).start do |http|
|
68
73
|
begin
|
@@ -180,6 +185,8 @@ module Intercom
|
|
180
185
|
raise Intercom::MultipleMatchingUsersError.new(error_details['message'], error_context)
|
181
186
|
when 'resource_conflict'
|
182
187
|
raise Intercom::ResourceNotUniqueError.new(error_details['message'], error_context)
|
188
|
+
when 'intercom_version_invalid'
|
189
|
+
raise Intercom::ApiVersionInvalid.new(error_details['message'], error_context)
|
183
190
|
when nil, ''
|
184
191
|
raise Intercom::UnexpectedError.new(message_for_unexpected_error_without_type(error_details, parsed_http_code), error_context)
|
185
192
|
else
|
data/lib/intercom/version.rb
CHANGED
@@ -42,6 +42,29 @@ module Intercom
|
|
42
42
|
proc { Client.new(app_id: nil, api_key: nil) }.must_raise MisconfiguredClientError
|
43
43
|
end
|
44
44
|
|
45
|
+
describe 'API version' do
|
46
|
+
it 'does not set the api version by default' do
|
47
|
+
assert_nil(client.api_version)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'allows api version to be provided' do
|
51
|
+
Client.new(app_id: app_id, api_key: api_key, api_version: '1.0').api_version.must_equal('1.0')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'allows api version to be nil' do
|
55
|
+
# matches default behavior, and will honor version set in the Developer Hub
|
56
|
+
assert_nil(Client.new(app_id: app_id, api_key: api_key, api_version: nil).api_version)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'raises on invalid api version' do
|
60
|
+
proc { Client.new(app_id: app_id, api_key: api_key, api_version: '0.2') }.must_raise MisconfiguredClientError
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'raises on empty api version' do
|
64
|
+
proc { Client.new(app_id: app_id, api_key: api_key, api_version: '') }.must_raise MisconfiguredClientError
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
45
68
|
describe 'OAuth clients' do
|
46
69
|
it 'supports "token"' do
|
47
70
|
client = Client.new(token: 'foo')
|
@@ -72,7 +72,6 @@ describe 'Intercom::Request' do
|
|
72
72
|
req.expects(:sleep).never.with(any_parameters)
|
73
73
|
req.execute(target_base_url=uri, username: "ted", secret: "")
|
74
74
|
end
|
75
|
-
|
76
75
|
end
|
77
76
|
|
78
77
|
|
@@ -85,6 +84,14 @@ describe 'Intercom::Request' do
|
|
85
84
|
req = Intercom::Request.put(uri, "")
|
86
85
|
expect { req.execute(target_base_url=uri, username: "ted", secret: "") }.must_raise(Intercom::ResourceNotUniqueError)
|
87
86
|
end
|
87
|
+
|
88
|
+
it 'should raise ApiVersionInvalid error on intercom_version_invalid code' do
|
89
|
+
# Use webmock to mock the HTTP request
|
90
|
+
stub_request(:put, uri).\
|
91
|
+
to_return(status: [400, "Bad Request"], headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s }, body: {type: "error.list", errors: [ code: "intercom_version_invalid" ]}.to_json)
|
92
|
+
req = Intercom::Request.put(uri, "")
|
93
|
+
expect { req.execute(uri, username: "ted", secret: "") }.must_raise(Intercom::ApiVersionInvalid)
|
94
|
+
end
|
88
95
|
end
|
89
96
|
|
90
97
|
it 'parse_body returns nil if decoded_body is nil' 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.7.
|
4
|
+
version: 3.7.4
|
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-01
|
18
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|