intercom 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -9
- data/changes.txt +6 -0
- data/lib/intercom/errors.rb +4 -1
- data/lib/intercom/request.rb +16 -10
- data/lib/intercom/traits/api_resource.rb +9 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/unit/intercom/message_spec.rb +21 -0
- data/spec/unit/intercom/notification_spec.rb +3 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1105afd003920f148d703151927542f8174aae57
|
4
|
+
data.tar.gz: 13cd1a35776e6b353ed85884157992b9f7750a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37bf3114fcb13dda58f34ce37623ab33adee640ded7d45c1aeb4e452ee4ebe7492fcc3f76ce48d53bfddd559795e1dc83e76e6e0a48eef696b3590a866729769
|
7
|
+
data.tar.gz: 8bc6eb1b8e44ca74e095ea3f74ea848bba15cafadf1421802921b3f43f599d31154d2f5fc124824eb72a703ff8a70a239a0e31377be7f0d310c7d2bcfa952235
|
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.
|
22
|
+
gem 'intercom', "~> 2.2.2"
|
23
23
|
|
24
24
|
## Basic Usage
|
25
25
|
|
@@ -44,7 +44,7 @@ Resources this API supports:
|
|
44
44
|
https://api.intercom.io/messages
|
45
45
|
https://api.intercom.io/counts
|
46
46
|
https://api.intercom.io/subscriptions
|
47
|
-
|
47
|
+
|
48
48
|
Additionally, the library can handle incoming webhooks from Intercom and convert to `Intercom::` models.
|
49
49
|
|
50
50
|
### Examples
|
@@ -113,7 +113,7 @@ Intercom::Tag.find_all_for_user(:user_id => '3')
|
|
113
113
|
# Tag companies
|
114
114
|
tag = Intercom::Tag.tag_companies('red', ["42ea2f1b93891f6a99000427"])
|
115
115
|
# Untag companies
|
116
|
-
Intercom::Tag.
|
116
|
+
Intercom::Tag.untag_companies('blue', ["42ea2f1b93891f6a99000427"])
|
117
117
|
# Iterate over all tags for company
|
118
118
|
Intercom::Tag.find_all_for_company(:id => '43357e2c3c77661e25000026')
|
119
119
|
Intercom::Tag.find_all_for_company(:company_id => '6')
|
@@ -205,9 +205,10 @@ Intercom::Segment.count
|
|
205
205
|
Intercom::Tag.count
|
206
206
|
```
|
207
207
|
|
208
|
-
#### Full loading of
|
208
|
+
#### Full loading of an embedded entity
|
209
209
|
```ruby
|
210
|
-
# Given a
|
210
|
+
# Given a conversation with a partial user, load the full user. This can be
|
211
|
+
# done for any entity
|
211
212
|
conversation.user.load
|
212
213
|
```
|
213
214
|
|
@@ -223,7 +224,7 @@ Intercom::Message.create({
|
|
223
224
|
:id => "1234"
|
224
225
|
},
|
225
226
|
:to => {
|
226
|
-
:type =>
|
227
|
+
:type => "user",
|
227
228
|
:id => "5678"
|
228
229
|
}
|
229
230
|
})
|
@@ -271,16 +272,16 @@ Metadata Objects support a few simple types that Intercom can present on your be
|
|
271
272
|
|
272
273
|
```ruby
|
273
274
|
Intercom::Event.create(:event_name => "placed-order", :email => current_user.email,
|
274
|
-
:created_at => 1403001013
|
275
|
+
:created_at => 1403001013,
|
275
276
|
:metadata => {
|
276
|
-
:order_date => Time.now.to_i,
|
277
|
+
:order_date => Time.now.to_i,
|
277
278
|
:stripe_invoice => 'inv_3434343434',
|
278
279
|
:order_number => {
|
279
280
|
:value => '3434-3434',
|
280
281
|
:url => 'https://example.org/orders/3434-3434'
|
281
282
|
},
|
282
283
|
price: {
|
283
|
-
:currency => 'usd',
|
284
|
+
:currency => 'usd',
|
284
285
|
:amount => 2999
|
285
286
|
}
|
286
287
|
}
|
@@ -336,6 +337,7 @@ else rescue the more specific error subclass.
|
|
336
337
|
Intercom::AuthenticationError
|
337
338
|
Intercom::ServerError
|
338
339
|
Intercom::ServiceUnavailableError
|
340
|
+
Intercom::ServiceConnectionError
|
339
341
|
Intercom::ResourceNotFound
|
340
342
|
Intercom::BadRequestError
|
341
343
|
Intercom::RateLimitExceeded
|
data/changes.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2.2.2
|
2
|
+
- Improve spec strings (thanks to @jkeyes)
|
3
|
+
- Improve README readability (thanks to @jkeyes)
|
4
|
+
- Raise Intercom::ServiceConnectionError on connection failure
|
5
|
+
- Fix creation of Intercom::Message with stringy keys in to/from fields
|
6
|
+
|
1
7
|
2.2.1
|
2
8
|
- Webhook Notification support
|
3
9
|
- Webhook Subscription support
|
data/lib/intercom/errors.rb
CHANGED
@@ -20,9 +20,12 @@ module Intercom
|
|
20
20
|
# Raised when we have bad gateway errors.
|
21
21
|
class BadGatewayError < IntercomError; end
|
22
22
|
|
23
|
-
# Raised when we
|
23
|
+
# Raised when we experience a socket read timeout
|
24
24
|
class ServiceUnavailableError < IntercomError; end
|
25
25
|
|
26
|
+
# Raised when we experience socket connect timeout
|
27
|
+
class ServiceConnectionError < IntercomError; end
|
28
|
+
|
26
29
|
# Raised when requesting resources on behalf of a user that doesn't exist in your application on Intercom.
|
27
30
|
class ResourceNotFound < IntercomError; end
|
28
31
|
|
data/lib/intercom/request.rb
CHANGED
@@ -57,18 +57,24 @@ module Intercom
|
|
57
57
|
def execute(target_base_url=nil)
|
58
58
|
base_uri = URI.parse(target_base_url)
|
59
59
|
set_common_headers(net_http_method, base_uri)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
begin
|
61
|
+
client(base_uri).start do |http|
|
62
|
+
begin
|
63
|
+
response = http.request(net_http_method)
|
64
|
+
decoded = decode(response['content-encoding'], response.body)
|
65
|
+
unless decoded.strip.empty?
|
66
|
+
parsed_body = JSON.parse(decoded)
|
67
|
+
raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
|
68
|
+
end
|
69
|
+
raise_errors_on_failure(response)
|
70
|
+
parsed_body
|
71
|
+
rescue Timeout::Error
|
72
|
+
raise Intercom::ServiceUnavailableError.new('Service Unavailable [request timed out]')
|
73
|
+
end
|
66
74
|
end
|
67
|
-
|
68
|
-
|
75
|
+
rescue Timeout::Error
|
76
|
+
raise Intercom::ServiceConnectionError.new('Failed to connect to service [connection attempt timed out]')
|
69
77
|
end
|
70
|
-
rescue Timeout::Error
|
71
|
-
raise Intercom::ServiceUnavailableError.new('Service Unavailable')
|
72
78
|
end
|
73
79
|
|
74
80
|
def decode(content_encoding, body)
|
@@ -67,7 +67,7 @@ module Intercom
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def set_property(attribute, value)
|
70
|
-
if typed_value?(value) && !custom_attribute_field?(attribute)
|
70
|
+
if typed_value?(value) && !custom_attribute_field?(attribute) && !message_from_field?(attribute, value) && !message_to_field?(attribute, value)
|
71
71
|
value_to_set = Intercom::Lib::TypedJsonDeserializer.new(value).deserialize
|
72
72
|
elsif flat_store_attribute?(attribute)
|
73
73
|
value_to_set = Intercom::Lib::FlatStore.new(value)
|
@@ -80,6 +80,14 @@ module Intercom
|
|
80
80
|
def custom_attribute_field?(attribute)
|
81
81
|
attribute == 'custom_attributes'
|
82
82
|
end
|
83
|
+
|
84
|
+
def message_from_field?(attribute, value)
|
85
|
+
attribute.to_s == 'from' && value.is_a?(Hash) && value['type']
|
86
|
+
end
|
87
|
+
|
88
|
+
def message_to_field?(attribute, value)
|
89
|
+
attribute.to_s == 'to' && value.is_a?(Hash) && value['type']
|
90
|
+
end
|
83
91
|
|
84
92
|
def typed_value?(value)
|
85
93
|
value.is_a? Hash and !!value['type']
|
data/lib/intercom/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Intercom::Message" do
|
4
|
+
|
5
|
+
let (:user) {Intercom::User.new("email" => "jim@example.com", :user_id => "12345", :created_at => Time.now, :name => "Jim Bob")}
|
6
|
+
|
7
|
+
it 'creates an user message with symbol keys' do
|
8
|
+
Intercom.expects(:post).with('/messages', {'from' => { :type => 'user', :email => 'jim@example.com'}, 'body' => 'halp'}).returns(:status => 200)
|
9
|
+
Intercom::Message.create(:from => { :type => "user", :email => "jim@example.com" }, :body => "halp")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "creates an user message with string keys" do
|
13
|
+
Intercom.expects(:post).with('/messages', {'from' => { 'type' => 'user', 'email' => 'jim@example.com'}, 'body' => 'halp'}).returns(:status => 200)
|
14
|
+
Intercom::Message.create('from' => { 'type' => "user", 'email' => "jim@example.com" }, 'body' => "halp")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a admin message" do
|
18
|
+
Intercom.expects(:post).with('/messages', {'from' => { 'type' => "admin", 'id' => "1234" }, 'to' => { 'type' => 'user', 'id' => '5678' }, 'body' => 'halp', 'message_type' => 'inapp'}).returns(:status => 200)
|
19
|
+
Intercom::Message.create('from' => { 'type' => "admin", 'id' => "1234" }, :to => { 'type' => 'user', 'id' => '5678' }, 'body' => "halp", 'message_type' => 'inapp')
|
20
|
+
end
|
21
|
+
end
|
@@ -12,7 +12,7 @@ describe "Intercom::Notification" do
|
|
12
12
|
payload.model_type.must_equal Intercom::User
|
13
13
|
end
|
14
14
|
|
15
|
-
it "returns correct notification topic" do
|
15
|
+
it "returns correct User notification topic" do
|
16
16
|
payload = Intercom::Notification.new(test_user_notification)
|
17
17
|
payload.topic.must_equal "user.created"
|
18
18
|
end
|
@@ -27,12 +27,12 @@ describe "Intercom::Notification" do
|
|
27
27
|
payload.model.must_be_instance_of Intercom::Conversation
|
28
28
|
end
|
29
29
|
|
30
|
-
it "returns correct model type for
|
30
|
+
it "returns correct model type for Conversation" do
|
31
31
|
payload = Intercom::Notification.new(test_conversation_notification)
|
32
32
|
payload.model_type.must_equal Intercom::Conversation
|
33
33
|
end
|
34
34
|
|
35
|
-
it "returns correct notification topic" do
|
35
|
+
it "returns correct Conversation notification topic" do
|
36
36
|
payload = Intercom::Notification.new(test_conversation_notification)
|
37
37
|
payload.topic.must_equal "conversation.user.created"
|
38
38
|
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
|
+
version: 2.2.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: 2014-
|
18
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- spec/unit/intercom/collection_proxy_spec.rb
|
159
159
|
- spec/unit/intercom/event_spec.rb
|
160
160
|
- spec/unit/intercom/lib/flat_store_spec.rb
|
161
|
+
- spec/unit/intercom/message_spec.rb
|
161
162
|
- spec/unit/intercom/note_spec.rb
|
162
163
|
- spec/unit/intercom/notification_spec.rb
|
163
164
|
- spec/unit/intercom/subscription_spec.rb
|
@@ -195,6 +196,7 @@ test_files:
|
|
195
196
|
- spec/unit/intercom/collection_proxy_spec.rb
|
196
197
|
- spec/unit/intercom/event_spec.rb
|
197
198
|
- spec/unit/intercom/lib/flat_store_spec.rb
|
199
|
+
- spec/unit/intercom/message_spec.rb
|
198
200
|
- spec/unit/intercom/note_spec.rb
|
199
201
|
- spec/unit/intercom/notification_spec.rb
|
200
202
|
- spec/unit/intercom/subscription_spec.rb
|