intercom 2.2.0 → 2.2.1
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 +37 -1
- data/changes.txt +4 -0
- data/lib/intercom.rb +2 -0
- data/lib/intercom/collection_proxy.rb +5 -1
- data/lib/intercom/notification.rb +20 -0
- data/lib/intercom/subscription.rb +15 -0
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +157 -0
- data/spec/unit/intercom/notification_spec.rb +45 -0
- data/spec/unit/intercom/subscription_spec.rb +18 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9111e19a82bb7d9ffba1c0677d77c629266ac7c
|
4
|
+
data.tar.gz: 02a3c89982a481e6b2b3410d4cbec80630556daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0695acd0c2f7227c16a2253f90e18b8be2398d2032175ac69c5067e6d6bbfe13d64a5ab85d0c0b1aa734f7aa0bf6acbadc202649c715370a07dd3c405a1d6f73
|
7
|
+
data.tar.gz: 0b6a49e6137e4794199175cdc9b8dca25b71be86b5413146c1cf379a3a324ce6a92a9ffdd1e1ea67e5384c1e13e326e54504dd055ccfe3da2dd0691c1d1b6022
|
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.1"
|
23
23
|
|
24
24
|
## Basic Usage
|
25
25
|
|
@@ -43,6 +43,9 @@ Resources this API supports:
|
|
43
43
|
https://api.intercom.io/conversations
|
44
44
|
https://api.intercom.io/messages
|
45
45
|
https://api.intercom.io/counts
|
46
|
+
https://api.intercom.io/subscriptions
|
47
|
+
|
48
|
+
Additionally, the library can handle incoming webhooks from Intercom and convert to `Intercom::` models.
|
46
49
|
|
47
50
|
### Examples
|
48
51
|
|
@@ -290,6 +293,39 @@ The metadata key values in the example are treated as follows-
|
|
290
293
|
- order_number: a Rich Link (value contains 'url' and 'value' keys)
|
291
294
|
- price: An Amount in US Dollars (value contains 'amount' and 'currency' keys)
|
292
295
|
|
296
|
+
### Subscriptions
|
297
|
+
|
298
|
+
Subscribe to events in Intercom to receive webhooks.
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
# create a subscription
|
302
|
+
Intercom::Subscription.create(:url => "http://example.com", :topics => ["user.created"])
|
303
|
+
|
304
|
+
# fetch a subscription
|
305
|
+
Intercom::Subscription.find(:id => "nsub_123456789")
|
306
|
+
|
307
|
+
# list subscriptions
|
308
|
+
Intercom::Subscription.all
|
309
|
+
```
|
310
|
+
|
311
|
+
### Webhooks
|
312
|
+
|
313
|
+
```ruby
|
314
|
+
# create a payload from the notification hash (from json).
|
315
|
+
payload = Intercom::Notification.new(notification_hash)
|
316
|
+
|
317
|
+
payload.type
|
318
|
+
# => 'user.created'
|
319
|
+
|
320
|
+
payload.model_type
|
321
|
+
# => Intercom::User
|
322
|
+
|
323
|
+
user = payload.model
|
324
|
+
# => Instance of Intercom::User
|
325
|
+
```
|
326
|
+
|
327
|
+
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.
|
328
|
+
|
293
329
|
### Errors
|
294
330
|
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.
|
295
331
|
|
data/changes.txt
CHANGED
data/lib/intercom.rb
CHANGED
@@ -47,7 +47,11 @@ module Intercom
|
|
47
47
|
|
48
48
|
def deserialize_response_hash(response_hash, block)
|
49
49
|
top_level_type = response_hash.delete('type')
|
50
|
-
|
50
|
+
if resource_name == 'subscriptions'
|
51
|
+
top_level_entity_key = 'items'
|
52
|
+
else
|
53
|
+
top_level_entity_key = Utils.entity_key_from_type(top_level_type)
|
54
|
+
end
|
51
55
|
response_hash[top_level_entity_key].each do |object_json|
|
52
56
|
block.call Lib::TypedJsonDeserializer.new(object_json).deserialize
|
53
57
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'intercom/api_operations/list'
|
2
|
+
require 'intercom/api_operations/find_all'
|
3
|
+
require 'intercom/api_operations/save'
|
4
|
+
require 'intercom/api_operations/delete'
|
5
|
+
require 'intercom/traits/api_resource'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
class Subscription
|
9
|
+
include ApiOperations::List
|
10
|
+
include ApiOperations::Find
|
11
|
+
include ApiOperations::Save
|
12
|
+
include ApiOperations::Delete
|
13
|
+
include Traits::ApiResource
|
14
|
+
end
|
15
|
+
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -132,6 +132,163 @@ def test_tag
|
|
132
132
|
}
|
133
133
|
end
|
134
134
|
|
135
|
+
def test_user_notification
|
136
|
+
{
|
137
|
+
"type" => "notification_event",
|
138
|
+
"id" => "notif_123456-56465-546546",
|
139
|
+
"topic" => "user.created",
|
140
|
+
"app_id" => "aaaaaa",
|
141
|
+
"data" =>
|
142
|
+
{
|
143
|
+
"type" => "notification_event_data",
|
144
|
+
"item" =>
|
145
|
+
{
|
146
|
+
"type" => "user",
|
147
|
+
"id" => "aaaaaaaaaaaaaaaaaaaaaaaa",
|
148
|
+
"user_id" => nil,
|
149
|
+
"email" => "joe@example.com",
|
150
|
+
"name" => "Joe Schmoe",
|
151
|
+
"avatar" =>
|
152
|
+
{
|
153
|
+
"type" => "avatar",
|
154
|
+
"image_url" => nil
|
155
|
+
},
|
156
|
+
"app_id" => "aaaaa",
|
157
|
+
"companies" =>
|
158
|
+
{
|
159
|
+
"type" => "company.list",
|
160
|
+
"companies" => [ ]
|
161
|
+
},
|
162
|
+
"location_data" =>
|
163
|
+
{
|
164
|
+
},
|
165
|
+
"last_request_at" => nil,
|
166
|
+
"created_at" => "1401970114",
|
167
|
+
"remote_created_at" => nil,
|
168
|
+
"updated_at" => "1401970114",
|
169
|
+
"session_count" => 0,
|
170
|
+
"social_profiles" =>
|
171
|
+
{
|
172
|
+
"type" => "social_profile.list",
|
173
|
+
"social_profiles" => [ ]
|
174
|
+
},
|
175
|
+
"unsubscribed_from_emails" => false,
|
176
|
+
"user_agent_data" => nil,
|
177
|
+
"tags" =>
|
178
|
+
{
|
179
|
+
"type" => "tag.list",
|
180
|
+
"tags" => [ ]
|
181
|
+
},
|
182
|
+
"segments" =>
|
183
|
+
{
|
184
|
+
"type" => "segment.list",
|
185
|
+
"segments" => [ ]
|
186
|
+
},
|
187
|
+
"custom_attributes" =>
|
188
|
+
{
|
189
|
+
}
|
190
|
+
}
|
191
|
+
},
|
192
|
+
"delivery_status" => nil,
|
193
|
+
"delivery_attempts" => 1,
|
194
|
+
"delivered_at" => 0,
|
195
|
+
"first_sent_at" => 1410188629,
|
196
|
+
"created_at" => 1410188628,
|
197
|
+
"links" => { },
|
198
|
+
"self" => nil
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_conversation_notification
|
203
|
+
{
|
204
|
+
"type"=>"notification_event",
|
205
|
+
"id"=>"notif_123456-56465-546546",
|
206
|
+
"topic"=>"conversation.user.created",
|
207
|
+
"app_id"=>"aaaaa",
|
208
|
+
"data"=>
|
209
|
+
{
|
210
|
+
"type"=>"notification_event_data",
|
211
|
+
"item"=>
|
212
|
+
{
|
213
|
+
"type"=>"conversation",
|
214
|
+
"id"=>"123456789",
|
215
|
+
"created_at"=>"1410335293",
|
216
|
+
"updated_at"=>"1410335293",
|
217
|
+
"user"=>
|
218
|
+
{
|
219
|
+
"type"=>"user",
|
220
|
+
"id"=>"540f1de7112d3d1d51001637",
|
221
|
+
"name"=>"Kill Bill",
|
222
|
+
"email"=>"bill@bill.bill"},
|
223
|
+
"assignee"=>
|
224
|
+
{
|
225
|
+
"type"=>"nobody_admin",
|
226
|
+
"id"=>nil
|
227
|
+
},
|
228
|
+
"conversation_message"=>
|
229
|
+
{
|
230
|
+
"type"=>"conversation_message",
|
231
|
+
"id"=>"321546",
|
232
|
+
"subject"=>"",
|
233
|
+
"body"=>"<p>An important message</p>",
|
234
|
+
"author"=>
|
235
|
+
{
|
236
|
+
"type"=>"user",
|
237
|
+
"id"=>"aaaaaaaaaaaaaaaaaaaaaa",
|
238
|
+
"name"=>"Kill Bill",
|
239
|
+
"email"=>"bill@bill.bill"},
|
240
|
+
"attachments"=>[]
|
241
|
+
},
|
242
|
+
"conversation_parts"=>
|
243
|
+
{
|
244
|
+
"type"=>"conversation_part.list",
|
245
|
+
"conversation_parts"=>[]
|
246
|
+
},
|
247
|
+
"open"=>nil,
|
248
|
+
"read"=>true,
|
249
|
+
"links"=>
|
250
|
+
{
|
251
|
+
"conversation_web"=>
|
252
|
+
"https://app.intercom.io/a/apps/aaaaaa/inbox/all/conversations/123456789"}
|
253
|
+
}
|
254
|
+
},
|
255
|
+
"delivery_status"=>nil,
|
256
|
+
"delivery_attempts"=>1,
|
257
|
+
"delivered_at"=>0,
|
258
|
+
"first_sent_at"=>1410335293,
|
259
|
+
"created_at"=>1410335293,
|
260
|
+
"links"=>{},
|
261
|
+
"self"=>nil
|
262
|
+
}
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_subscription
|
266
|
+
{"request"=>
|
267
|
+
{"type"=>"notification_subscription",
|
268
|
+
"id"=>"nsub_123456789",
|
269
|
+
"created_at"=>1410368642,
|
270
|
+
"updated_at"=>1410368642,
|
271
|
+
"service_type"=>"web",
|
272
|
+
"app_id"=>"3qmk5gyg",
|
273
|
+
"url"=>
|
274
|
+
"http://example.com",
|
275
|
+
"self"=>
|
276
|
+
"https://api.intercom.io/subscriptions/nsub_123456789",
|
277
|
+
"topics"=>["user.created", "conversation.user.replied", "conversation.admin.replied"],
|
278
|
+
"active"=>true,
|
279
|
+
"metadata"=>{},
|
280
|
+
"hub_secret"=>nil,
|
281
|
+
"mode"=>"point",
|
282
|
+
"links"=>
|
283
|
+
{"sent"=>
|
284
|
+
"https://api.intercom.io/subscriptions/nsub_123456789/sent",
|
285
|
+
"retry"=>
|
286
|
+
"https://api.intercom.io/subscriptions/nsub_123456789/retry",
|
287
|
+
"errors"=>
|
288
|
+
"https://api.intercom.io/subscriptions/nsub_123456789/errors"},
|
289
|
+
"notes"=>[]}}
|
290
|
+
end
|
291
|
+
|
135
292
|
def error_on_modify_frozen
|
136
293
|
RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
|
137
294
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Intercom::Notification" do
|
4
|
+
|
5
|
+
it "converts notification hash to object" do
|
6
|
+
payload = Intercom::Notification.new(test_user_notification)
|
7
|
+
payload.must_be_instance_of Intercom::Notification
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns correct model type for User" do
|
11
|
+
payload = Intercom::Notification.new(test_user_notification)
|
12
|
+
payload.model_type.must_equal Intercom::User
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns correct notification topic" do
|
16
|
+
payload = Intercom::Notification.new(test_user_notification)
|
17
|
+
payload.topic.must_equal "user.created"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns instance of User" do
|
21
|
+
payload = Intercom::Notification.new(test_user_notification)
|
22
|
+
payload.model.must_be_instance_of Intercom::User
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns instance of Conversation" do
|
26
|
+
payload = Intercom::Notification.new(test_conversation_notification)
|
27
|
+
payload.model.must_be_instance_of Intercom::Conversation
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns correct model type for User" do
|
31
|
+
payload = Intercom::Notification.new(test_conversation_notification)
|
32
|
+
payload.model_type.must_equal Intercom::Conversation
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns correct notification topic" do
|
36
|
+
payload = Intercom::Notification.new(test_conversation_notification)
|
37
|
+
payload.topic.must_equal "conversation.user.created"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns inner User object for Conversation" do
|
41
|
+
payload = Intercom::Notification.new(test_conversation_notification)
|
42
|
+
payload.model.user.must_be_instance_of Intercom::User
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Intercom::Subscription" do
|
4
|
+
it "gets a subscription" do
|
5
|
+
Intercom.expects(:get).with("/subscriptions/nsub_123456789", {}).returns(test_subscription)
|
6
|
+
subscription = Intercom::Subscription.find(:id => "nsub_123456789")
|
7
|
+
subscription.request.topics[0].must_equal "user.created"
|
8
|
+
subscription.request.topics[1].must_equal "conversation.user.replied"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "creates a subscription" do
|
12
|
+
Intercom.expects(:post).with("/subscriptions", {'url' => "http://example.com", 'topics' => ["user.created"]}).returns(test_subscription)
|
13
|
+
subscription = Intercom::Subscription.create(:url => "http://example.com", :topics => ["user.created"])
|
14
|
+
subscription.request.topics[0].must_equal "user.created"
|
15
|
+
subscription.request.url.must_equal "http://example.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
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.1
|
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-09-
|
18
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -141,8 +141,10 @@ files:
|
|
141
141
|
- lib/intercom/lib/typed_json_deserializer.rb
|
142
142
|
- lib/intercom/message.rb
|
143
143
|
- lib/intercom/note.rb
|
144
|
+
- lib/intercom/notification.rb
|
144
145
|
- lib/intercom/request.rb
|
145
146
|
- lib/intercom/segment.rb
|
147
|
+
- lib/intercom/subscription.rb
|
146
148
|
- lib/intercom/tag.rb
|
147
149
|
- lib/intercom/traits/api_resource.rb
|
148
150
|
- lib/intercom/traits/dirty_tracking.rb
|
@@ -157,6 +159,8 @@ files:
|
|
157
159
|
- spec/unit/intercom/event_spec.rb
|
158
160
|
- spec/unit/intercom/lib/flat_store_spec.rb
|
159
161
|
- spec/unit/intercom/note_spec.rb
|
162
|
+
- spec/unit/intercom/notification_spec.rb
|
163
|
+
- spec/unit/intercom/subscription_spec.rb
|
160
164
|
- spec/unit/intercom/tag_spec.rb
|
161
165
|
- spec/unit/intercom/traits/api_resource_spec.rb
|
162
166
|
- spec/unit/intercom/user_spec.rb
|
@@ -192,6 +196,8 @@ test_files:
|
|
192
196
|
- spec/unit/intercom/event_spec.rb
|
193
197
|
- spec/unit/intercom/lib/flat_store_spec.rb
|
194
198
|
- spec/unit/intercom/note_spec.rb
|
199
|
+
- spec/unit/intercom/notification_spec.rb
|
200
|
+
- spec/unit/intercom/subscription_spec.rb
|
195
201
|
- spec/unit/intercom/tag_spec.rb
|
196
202
|
- spec/unit/intercom/traits/api_resource_spec.rb
|
197
203
|
- spec/unit/intercom/user_spec.rb
|