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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72074a3a5bc6699bf1a5d17aa79b7653fb1b5bc7
4
- data.tar.gz: 46aab387557d19fa6db6a0b7d5b588640afb01f0
3
+ metadata.gz: ee56e3e11c13b620ee6b5a04c3eab742c6064297
4
+ data.tar.gz: 39bf3533177283eadb4c021bee58a38d889cbf4b
5
5
  SHA512:
6
- metadata.gz: 4643efa421e81d2f548c6982e19d54b3234ae45c7b4fc1540be1200d10c533788cc58d0e3c871b6354d93586a0e8e51d9706b84a1698b2fdbf9b09db8af2a400
7
- data.tar.gz: 11005b933a45e374f66481311aa15df949fbab2b006c4576304c9f5598ebad5c27dc22a496aec3ba3eb49e92f5b629358da8828e30096c81ac47575ab87d7564
6
+ metadata.gz: 236a3df567693a41cdcf45c761d0339748748581c048763850122e93efcf56b58633d951b20c9c2ce2f034ab1728c269d784378adae250059bf04b1dbbad5729
7
+ data.tar.gz: 5dacf1bcec13579a7161f9467d520174960a1544a03dc2f99cc2a6fdca959901db6ce7800c0dfed10bc235c6353a6e457398e410a59dc175e0c277b9abe1e525
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.7.2'
25
+ gem 'intercom', '~> 3.7.3'
26
26
 
27
27
  ## Basic Usage
28
28
 
data/changes.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 3.7.3
2
+ Added error handling for when an admin cannot be found.
3
+
1
4
  3.7.2
2
5
  Added error handling for when an app's custom attribute limits have been reached.
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, :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
@@ -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
  #
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.7.3"
2
+ VERSION = "3.7.4"
3
3
  end
@@ -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.3
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 00:00:00.000000000 Z
18
+ date: 2019-03-01 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest