intercom 2.2.4 → 2.3.0

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: 7fa96a0842530f56baae6d4a78782fc99dbdfb5d
4
- data.tar.gz: aab9881adb19557ed2e03d2edf4e8007aa5e7c18
3
+ metadata.gz: 513076550f366c50ddd55f25cf420c9e28ed4a67
4
+ data.tar.gz: fe6b1eb608e712aa9094035dc14b73e3c7005315
5
5
  SHA512:
6
- metadata.gz: 46ff0d47d1be82494ab2b76b2ed90a73798f7e9465634e19e305495b7b27fd9c8887364906a0ecca0bc63267b2fb8ac2b7c4610ab0e302fd4b3a90b2729ea263
7
- data.tar.gz: 4e47ecae6dea2a440d4580b7597ce91ec471d01f51f2f426ba043267a95a236964f0723735884b9b5c96b7c1517f5e932c464dad4de565941285f693020eaceb
6
+ metadata.gz: 0a3d1a25d2f82c0e88b51c84172b966eeb35d3866a3ba66e5f197522c6e79710baf155166813514f17df91a14fda47e34f479d4632b94191d01b083684343a70
7
+ data.tar.gz: d90da12671da821d98af3c53009a64adb3425af83a407a428983bb926610c85b64f25171c620682b37271666d81e23562d234db518dcaa29c4bd8608db0705a2
data/README.md CHANGED
@@ -19,7 +19,7 @@ Additionally, the new version uses Ruby 2.
19
19
 
20
20
  Using bundler:
21
21
 
22
- gem 'intercom', "~> 2.2.4"
22
+ gem 'intercom', "~> 2.3.0"
23
23
 
24
24
  ## Basic Usage
25
25
 
@@ -328,7 +328,7 @@ user = payload.model
328
328
  Note that models generated from webhook notifications might differ slightly from models directly acquired via the API. If this presents a problem, calling `payload.load` will load the model from the API using the `id` field.
329
329
 
330
330
  ### Errors
331
- You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of Intercom:Error will be raised. If desired, you can get at the http_code of an Intercom::Error via it's `http_code` method.
331
+ You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of Intercom:Error will be raised. If desired, you can get at the http_code of an Intercom::Error via its `http_code` method.
332
332
 
333
333
  The list of different error subclasses are listed below. As they all inherit off Intercom::Error you can choose to rescue Intercom::Error or
334
334
  else rescue the more specific error subclass.
@@ -343,6 +343,7 @@ Intercom::BadRequestError
343
343
  Intercom::RateLimitExceeded
344
344
  Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
345
345
  Intercom::MultipleMatchingUsersError
346
+ Intercom::HttpError # Raised when response object is unexpectedly nil
346
347
  ```
347
348
 
348
349
  ### Rate Limiting
data/changes.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 2.3.0
2
+ - Add Intercom::HttpError to be raised when empty response entity received unexpectedly
3
+ - Raise Intercom errors more gracefully when HTML returned
4
+ - Fixed README typo (thanks to @marckohlbrugge)
5
+
1
6
  2.2.4
2
7
  - Add Intercom::MultipleMatchingUsersError
3
8
 
@@ -10,6 +10,7 @@ module Intercom
10
10
  else
11
11
  response = Intercom.get("/#{collection_name}", params)
12
12
  end
13
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
13
14
  from_api(response)
14
15
  end
15
16
  end
@@ -8,6 +8,7 @@ module Intercom
8
8
  else
9
9
  raise "Cannot load #{self.class} as it does not have a valid id."
10
10
  end
11
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
11
12
  from_response(response)
12
13
  end
13
14
  end
@@ -21,6 +21,7 @@ module Intercom
21
21
  else
22
22
  response_hash = Intercom.get(@finder_url, @finder_params)
23
23
  end
24
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
24
25
  deserialize_response_hash(response_hash, block)
25
26
  next_page = extract_next_link(response_hash)
26
27
  break if next_page.nil?
@@ -43,6 +43,9 @@ module Intercom
43
43
 
44
44
  # Raised when you try to call a non-setter method that does not exist on an object
45
45
  class Intercom::AttributeNotSetError < IntercomError ; end
46
+
47
+ # Raised when unexpected nil returned from server
48
+ class Intercom::HttpError < IntercomError ; end
46
49
 
47
50
  #
48
51
  # Non-public errors (internal to the gem)
@@ -62,11 +62,8 @@ module Intercom
62
62
  begin
63
63
  response = http.request(net_http_method)
64
64
  set_rate_limit_details(response)
65
- decoded = decode(response['content-encoding'], response.body)
66
- unless decoded.strip.empty?
67
- parsed_body = JSON.parse(decoded)
68
- raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
69
- end
65
+ decoded_body = decode_body(response)
66
+ parsed_body = parse_body(decoded_body, response)
70
67
  raise_errors_on_failure(response)
71
68
  parsed_body
72
69
  rescue Timeout::Error
@@ -77,6 +74,23 @@ module Intercom
77
74
  raise Intercom::ServiceConnectionError.new('Failed to connect to service [connection attempt timed out]')
78
75
  end
79
76
  end
77
+
78
+ def decode_body(response)
79
+ decode(response['content-encoding'], response.body)
80
+ end
81
+
82
+ def parse_body(decoded_body, response)
83
+ parsed_body = nil
84
+ unless decoded_body.strip.empty?
85
+ begin
86
+ parsed_body = JSON.parse(decoded_body)
87
+ rescue JSON::ParserError => e
88
+ raise_errors_on_failure(response)
89
+ end
90
+ raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
91
+ end
92
+ parsed_body
93
+ end
80
94
 
81
95
  def set_rate_limit_details(response)
82
96
  rate_limit_details = {}
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "2.2.4"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intercom::Company do
4
+
5
+ describe 'when no response raises error' do
6
+ it 'on find' do
7
+ Intercom.expects(:get).with("/companies", {:company_id => '4'}).returns(nil)
8
+ proc {company = Intercom::Company.find(:company_id => '4')}.must_raise Intercom::HttpError
9
+ end
10
+
11
+ it 'on find_all' do
12
+ Intercom.expects(:get).with("/companies", {}).returns(nil)
13
+ proc {Intercom::Company.all.each {|company| }}.must_raise Intercom::HttpError
14
+ end
15
+
16
+ it 'on load' do
17
+ Intercom.expects(:get).with("/companies", {:company_id => '4'}).returns({'type' =>'user', 'id' =>'aaaaaaaaaaaaaaaaaaaaaaaa', 'company_id' => '4', 'name' => 'MyCo'})
18
+ company = Intercom::Company.find(:company_id => '4')
19
+ Intercom.expects(:get).with('/companies/aaaaaaaaaaaaaaaaaaaaaaaa', {}).returns(nil)
20
+ proc {company.load}.must_raise Intercom::HttpError
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'ostruct'
3
+
4
+ describe 'Intercom::Request' do
5
+ it 'raises an error when a html error page rendered' do
6
+ response = OpenStruct.new(:code => 500)
7
+ req = Intercom::Request.new('path/', 'GET')
8
+ proc {req.parse_body('<html>somethjing</html>', response)}.must_raise(Intercom::ServerError)
9
+ end
10
+ end
@@ -219,32 +219,5 @@ describe "Intercom::User" do
219
219
  it "returns the total number of users" do
220
220
  Intercom::Count.expects(:user_count).returns('count_info')
221
221
  Intercom::User.count
222
- end
223
-
224
- ##TODO: Investigate
225
- #it "converts company created_at values to unix timestamps" do
226
- # time = Time.now
227
-
228
- # user = Intercom::User.new("companies" => [
229
- # { "created_at" => time },
230
- # { "created_at" => time.to_i }
231
- # ])
232
-
233
- # as_hash = user.to_hash
234
- # require 'ruby-debug' ; debugger
235
- # first_company_as_hash = as_hash["companies"][0]
236
- # second_company_as_hash = as_hash["companies"][1]
237
-
238
- # first_company_as_hash["created_at"].must_equal time.to_i
239
- # second_company_as_hash["created_at"].must_equal time.to_i
240
- #end
241
-
242
- # it "tracks events" do
243
- # user = Intercom::User.new("email" => "jim@example.com", :user_id => "12345", :created_at => Time.now, :name => "Jim Bob")
244
- # Intercom::Event.expects(:create).with(:event_name => 'registration', :user => user)
245
- # event = user.track_event('registration')
246
-
247
- # Intercom::Event.expects(:create).with(:event_name => 'another', :user => user, :created_at => 1391691571)
248
- # event = user.track_event("another", {:created_at => 1391691571})
249
- # end
222
+ end
250
223
  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: 2.2.4
4
+ version: 2.3.0
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: 2014-10-10 00:00:00.000000000 Z
18
+ date: 2014-10-21 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -156,11 +156,13 @@ files:
156
156
  - spec/spec_helper.rb
157
157
  - spec/unit/intercom/admin_spec.rb
158
158
  - spec/unit/intercom/collection_proxy_spec.rb
159
+ - spec/unit/intercom/company_spec.rb
159
160
  - spec/unit/intercom/event_spec.rb
160
161
  - spec/unit/intercom/lib/flat_store_spec.rb
161
162
  - spec/unit/intercom/message_spec.rb
162
163
  - spec/unit/intercom/note_spec.rb
163
164
  - spec/unit/intercom/notification_spec.rb
165
+ - spec/unit/intercom/request_spec.rb
164
166
  - spec/unit/intercom/subscription_spec.rb
165
167
  - spec/unit/intercom/tag_spec.rb
166
168
  - spec/unit/intercom/traits/api_resource_spec.rb
@@ -194,11 +196,13 @@ test_files:
194
196
  - spec/spec_helper.rb
195
197
  - spec/unit/intercom/admin_spec.rb
196
198
  - spec/unit/intercom/collection_proxy_spec.rb
199
+ - spec/unit/intercom/company_spec.rb
197
200
  - spec/unit/intercom/event_spec.rb
198
201
  - spec/unit/intercom/lib/flat_store_spec.rb
199
202
  - spec/unit/intercom/message_spec.rb
200
203
  - spec/unit/intercom/note_spec.rb
201
204
  - spec/unit/intercom/notification_spec.rb
205
+ - spec/unit/intercom/request_spec.rb
202
206
  - spec/unit/intercom/subscription_spec.rb
203
207
  - spec/unit/intercom/tag_spec.rb
204
208
  - spec/unit/intercom/traits/api_resource_spec.rb