intercom 4.1.2 → 4.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +68 -31
- data/changes.txt +7 -0
- data/lib/intercom/base_collection_proxy.rb +1 -0
- data/lib/intercom/lib/dynamic_accessors.rb +9 -10
- data/lib/intercom/version.rb +1 -1
- data/spec/unit/intercom/base_collection_proxy_spec.rb +18 -1
- data/spec/unit/intercom/contact_spec.rb +22 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02dd1486f502ecd7d6cd6c5ac0eda0dd7aa0efa2f127caee9eb4d5c2f87d131d
|
4
|
+
data.tar.gz: 618094ddfd695421006362dc450cf42d9e09f8fd70238dd9a783c1e98821112e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d551de01dc64b86f6e414234e0b0bdb8f207f2387cab6f15254ff5aa9f8561232fa1b6412ad067eaef768d9a6fffcbf0677330f8aee8667a0fd597bae5d7c7a7
|
7
|
+
data.tar.gz: 843174258835ec50702e28c10b16592d954e67a95318314f1c3eb544ee48705b2115ff82924c67eee32a280670c91c0885bbd04bb816d8ce59bb4db10258d1ca
|
data/README.md
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
# intercom-ruby
|
2
2
|
|
3
|
-
|
3
|
+
[![Circle CI](https://circleci.com/gh/intercom/intercom-ruby.png?style=shield)](https://circleci.com/gh/intercom/intercom-ruby)
|
4
|
+
[![gem](https://img.shields.io/gem/v/intercom)](https://rubygems.org/gems/intercom)
|
5
|
+
![Intercom API Version](https://img.shields.io/badge/Intercom%20API%20Version-2.2-blue)
|
6
|
+
|
7
|
+
> Ruby bindings for the [Intercom API](https://developers.intercom.io/reference).
|
8
|
+
|
9
|
+
## Project Updates
|
10
|
+
|
11
|
+
### Maintenance
|
12
|
+
|
13
|
+
We're currently building a new team to provide in-depth and dedicated SDK support.
|
14
|
+
|
15
|
+
In the meantime, we'll be operating on limited capacity, meaning all pull requests will be evaluated on a best effort basis and will be limited to critical issues.
|
16
|
+
|
17
|
+
We'll communicate all relevant updates as we build this new team and support strategy in the coming months.
|
4
18
|
|
5
19
|
[API Documentation](https://developers.intercom.io/docs)
|
6
20
|
|
7
21
|
[Gem Documentation](http://rubydoc.info/github/intercom/intercom-ruby/master/frames)
|
8
22
|
|
9
|
-
For generating Intercom JavaScript script tags for Rails, please see https://github.com/intercom/intercom-rails
|
23
|
+
For generating Intercom JavaScript script tags for Rails, please see [intercom/intercom-rails](https://github.com/intercom/intercom-rails)
|
10
24
|
|
11
25
|
## Upgrading information
|
12
26
|
|
@@ -16,12 +30,15 @@ This version of the gem is compatible with `Ruby 2.1` and above.
|
|
16
30
|
|
17
31
|
## Installation
|
18
32
|
|
19
|
-
|
20
|
-
|
33
|
+
```bash
|
34
|
+
gem install intercom
|
35
|
+
```
|
21
36
|
|
22
37
|
Using bundler:
|
23
38
|
|
24
|
-
|
39
|
+
```bundler
|
40
|
+
gem 'intercom', '~> 4.1'
|
41
|
+
```
|
25
42
|
|
26
43
|
## Basic Usage
|
27
44
|
|
@@ -36,7 +53,7 @@ intercom = Intercom::Client.new(token: 'my_token')
|
|
36
53
|
|
37
54
|
```ruby
|
38
55
|
# With a versioned app:
|
39
|
-
intercom = Intercom::Client.new(token: 'my_token', api_version: '2.
|
56
|
+
intercom = Intercom::Client.new(token: 'my_token', api_version: '2.2')
|
40
57
|
```
|
41
58
|
|
42
59
|
If you are building a third party application you can get your access_tokens by [setting-up-oauth](https://developers.intercom.io/page/setting-up-oauth) for Intercom.
|
@@ -46,29 +63,31 @@ You can also use the [omniauth-intercom lib](https://github.com/intercom/omniaut
|
|
46
63
|
|
47
64
|
Resources this API supports:
|
48
65
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
```text
|
67
|
+
https://api.intercom.io/contacts
|
68
|
+
https://api.intercom.io/visitors
|
69
|
+
https://api.intercom.io/companies
|
70
|
+
https://api.intercom.io/data_attributes
|
71
|
+
https://api.intercom.io/events
|
72
|
+
https://api.intercom.io/tags
|
73
|
+
https://api.intercom.io/notes
|
74
|
+
https://api.intercom.io/segments
|
75
|
+
https://api.intercom.io/conversations
|
76
|
+
https://api.intercom.io/messages
|
77
|
+
https://api.intercom.io/admins
|
78
|
+
https://api.intercom.io/teams
|
79
|
+
https://api.intercom.io/counts
|
80
|
+
https://api.intercom.io/subscriptions
|
81
|
+
https://api.intercom.io/jobs
|
82
|
+
https://api.intercom.io/articles
|
83
|
+
https://api.intercom.io/help_center/collections
|
84
|
+
https://api.intercom.io/help_center/sections
|
85
|
+
```
|
68
86
|
|
69
87
|
### Examples
|
70
88
|
|
71
89
|
#### Contacts
|
90
|
+
|
72
91
|
Note that this is a new resource compatible only with the new [Contacts API](https://developers.intercom.com/intercom-api-reference/reference#contacts-model) released in API v2.0.
|
73
92
|
|
74
93
|
```ruby
|
@@ -146,6 +165,7 @@ contact.companies.each {|c| p c.name}
|
|
146
165
|
```
|
147
166
|
|
148
167
|
#### Visitors
|
168
|
+
|
149
169
|
```ruby
|
150
170
|
# Get and update a visitor
|
151
171
|
visitor = intercom.visitors.find(id: "5dd570e7b1b922452676af23")
|
@@ -161,6 +181,7 @@ intercom.visitors.convert(visitor, user)
|
|
161
181
|
```
|
162
182
|
|
163
183
|
#### Companies
|
184
|
+
|
164
185
|
```ruby
|
165
186
|
# Find a company by company_id
|
166
187
|
company = intercom.companies.find(company_id: "44")
|
@@ -188,7 +209,9 @@ intercom.companies.scroll.each { |comp| puts comp.name}
|
|
188
209
|
```
|
189
210
|
|
190
211
|
#### Data Attributes
|
212
|
+
|
191
213
|
Data Attributes are a type of metadata used to describe your customer and company models. These include standard and custom attributes.
|
214
|
+
|
192
215
|
```ruby
|
193
216
|
# Create a new custom data attribute
|
194
217
|
intercom.data_attributes.create({ name: "test_attribute", model: "contact", data_type: "string" })
|
@@ -208,10 +231,11 @@ intercom.data_attributes.save(attribute)
|
|
208
231
|
|
209
232
|
# Find all customer attributes including archived
|
210
233
|
customer_attributes_incl_archived = intercom.data_attributes.find_all({"model": "contact", "include_archived": true})
|
211
|
-
customer_attributes_incl_archived.each { |attr| p
|
234
|
+
customer_attributes_incl_archived.each { |attr| p attr.name }
|
212
235
|
```
|
213
236
|
|
214
237
|
#### Events
|
238
|
+
|
215
239
|
```ruby
|
216
240
|
intercom.events.create(
|
217
241
|
event_name: "invited-friend",
|
@@ -257,7 +281,8 @@ intercom.events.create(
|
|
257
281
|
)
|
258
282
|
```
|
259
283
|
|
260
|
-
The metadata key values in the example are treated as follows
|
284
|
+
The metadata key values in the example are treated as follows:
|
285
|
+
|
261
286
|
- order_date: a Date (key ends with '_date')
|
262
287
|
- stripe_invoice: The identifier of the Stripe invoice (has a 'stripe_invoice' key)
|
263
288
|
- order_number: a Rich Link (value contains 'url' and 'value' keys)
|
@@ -266,6 +291,7 @@ The metadata key values in the example are treated as follows-
|
|
266
291
|
*NB:* This version of the gem reserves the field name `type` in Event data.
|
267
292
|
|
268
293
|
#### Tags
|
294
|
+
|
269
295
|
```ruby
|
270
296
|
# Iterate over all tags
|
271
297
|
intercom.tags.all.each {|tag| "#{tag.id} - #{tag.name}" }
|
@@ -279,12 +305,14 @@ tag = intercom.tags.untag(name: 'blue', companies: [{ company_id: "42ea2f1b93891
|
|
279
305
|
```
|
280
306
|
|
281
307
|
#### Notes
|
308
|
+
|
282
309
|
```ruby
|
283
310
|
# Find a note by id
|
284
311
|
note = intercom.notes.find(id: "123")
|
285
312
|
```
|
286
313
|
|
287
314
|
#### Segments
|
315
|
+
|
288
316
|
```ruby
|
289
317
|
# Find a segment
|
290
318
|
segment = intercom.segments.find(id: segment_id)
|
@@ -294,6 +322,7 @@ intercom.segments.all.each {|segment| puts "id: #{segment.id} name: #{segment.na
|
|
294
322
|
```
|
295
323
|
|
296
324
|
#### Conversations
|
325
|
+
|
297
326
|
```ruby
|
298
327
|
# Iterate over all conversations for your app
|
299
328
|
intercom.conversations.all.each { |convo| ... }
|
@@ -424,6 +453,7 @@ conversation.remove_contact(id: contact.id, admin_id: admin.id)
|
|
424
453
|
```
|
425
454
|
|
426
455
|
#### Full loading of an embedded entity
|
456
|
+
|
427
457
|
```ruby
|
428
458
|
# Given a conversation with a partial contact, load the full contact. This can be
|
429
459
|
# done for any entity
|
@@ -431,6 +461,7 @@ intercom.contacts.load(conversation.contacts.first)
|
|
431
461
|
```
|
432
462
|
|
433
463
|
#### Sending messages
|
464
|
+
|
434
465
|
```ruby
|
435
466
|
|
436
467
|
# InApp message from admin to user
|
@@ -497,6 +528,7 @@ intercom.messages.create({
|
|
497
528
|
```
|
498
529
|
|
499
530
|
#### Admins
|
531
|
+
|
500
532
|
```ruby
|
501
533
|
# Find access token owner (only with Personal Access Token and OAuth)
|
502
534
|
intercom.admins.me
|
@@ -507,6 +539,7 @@ intercom.admins.all.each {|admin| puts admin.email }
|
|
507
539
|
```
|
508
540
|
|
509
541
|
#### Teams
|
542
|
+
|
510
543
|
```ruby
|
511
544
|
# Find a team by id
|
512
545
|
intercom.teams.find(id: team_id)
|
@@ -544,6 +577,7 @@ intercom.subscriptions.all
|
|
544
577
|
```
|
545
578
|
|
546
579
|
#### Articles
|
580
|
+
|
547
581
|
```ruby
|
548
582
|
# Create an article
|
549
583
|
article = intercom.articles.create(title: "New Article", author_id: "123456")
|
@@ -577,6 +611,7 @@ intercom.articles.delete(article)
|
|
577
611
|
```
|
578
612
|
|
579
613
|
#### Collections
|
614
|
+
|
580
615
|
```ruby
|
581
616
|
# Create a collection
|
582
617
|
collection = intercom.collections.create(name: "New Collection")
|
@@ -609,6 +644,7 @@ intercom.collections.delete(collection)
|
|
609
644
|
```
|
610
645
|
|
611
646
|
#### Sections
|
647
|
+
|
612
648
|
```ruby
|
613
649
|
# Create a section
|
614
650
|
section = intercom.sections.create(name: "New Section", parent_id: "123456")
|
@@ -660,6 +696,7 @@ Intercom::RateLimitExceeded
|
|
660
696
|
Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
|
661
697
|
Intercom::MultipleMatchingUsersError
|
662
698
|
Intercom::HttpError # Raised when response object is unexpectedly nil
|
699
|
+
Intercom::GatewayTimeoutError
|
663
700
|
```
|
664
701
|
|
665
702
|
### Rate Limiting
|
@@ -674,7 +711,7 @@ intercom.rate_limit_details
|
|
674
711
|
You can handle the rate limits yourself but a simple option is to use the handle_rate_limit flag.
|
675
712
|
This will automatically catch the 429 rate limit exceeded error and wait until the reset time to retry. After three retries a rate limit exception will be raised. Encountering this error frequently may require a revisiting of your usage of the API.
|
676
713
|
|
677
|
-
```
|
714
|
+
```ruby
|
678
715
|
intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
|
679
716
|
```
|
680
717
|
|
@@ -700,13 +737,13 @@ intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
|
|
700
737
|
|
701
738
|
```bash
|
702
739
|
# all tests
|
703
|
-
bundle exec spec
|
740
|
+
bundle exec rake spec
|
704
741
|
|
705
742
|
# unit tests
|
706
|
-
bundle exec spec:unit
|
743
|
+
bundle exec rake spec:unit
|
707
744
|
|
708
745
|
# integration tests
|
709
|
-
bundle exec spec:integration
|
746
|
+
bundle exec rake spec:integration
|
710
747
|
|
711
748
|
# single test file
|
712
749
|
bundle exec m spec/unit/intercom/job_spec.rb
|
data/changes.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
4.1.2
|
2
|
+
- Adding support for company delete.
|
3
|
+
- Adding support for archiving/unarchiving contacts.
|
4
|
+
- Adding support for listing contact segments.
|
5
|
+
- Fixed issue with scroll collection proxy.
|
6
|
+
- Fixed issue with running assignment rules on a conversation.
|
7
|
+
|
1
8
|
4.1.1
|
2
9
|
- Fixed bug with deprecated lead resource.
|
3
10
|
|
@@ -5,20 +5,19 @@ module Intercom
|
|
5
5
|
class << self
|
6
6
|
|
7
7
|
def define_accessors(attribute, value, object)
|
8
|
-
klass = object.class
|
9
8
|
if attribute.to_s.end_with?('_at') && attribute.to_s != 'update_last_request_at'
|
10
|
-
define_date_based_accessors(attribute, value,
|
9
|
+
define_date_based_accessors(attribute, value, object)
|
11
10
|
elsif object.flat_store_attribute?(attribute)
|
12
|
-
define_flat_store_based_accessors(attribute, value,
|
11
|
+
define_flat_store_based_accessors(attribute, value, object)
|
13
12
|
else
|
14
|
-
define_standard_accessors(attribute, value,
|
13
|
+
define_standard_accessors(attribute, value, object)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
private
|
19
18
|
|
20
|
-
def define_flat_store_based_accessors(attribute, value,
|
21
|
-
|
19
|
+
def define_flat_store_based_accessors(attribute, value, object)
|
20
|
+
object.instance_eval %Q"
|
22
21
|
def #{attribute}=(value)
|
23
22
|
mark_field_as_changed!(:#{attribute})
|
24
23
|
@#{attribute} = Intercom::Lib::FlatStore.new(value)
|
@@ -29,8 +28,8 @@ module Intercom
|
|
29
28
|
"
|
30
29
|
end
|
31
30
|
|
32
|
-
def define_date_based_accessors(attribute, value,
|
33
|
-
|
31
|
+
def define_date_based_accessors(attribute, value, object)
|
32
|
+
object.instance_eval %Q"
|
34
33
|
def #{attribute}=(value)
|
35
34
|
mark_field_as_changed!(:#{attribute})
|
36
35
|
@#{attribute} = value.nil? ? nil : value.to_i
|
@@ -41,8 +40,8 @@ module Intercom
|
|
41
40
|
"
|
42
41
|
end
|
43
42
|
|
44
|
-
def define_standard_accessors(attribute, value,
|
45
|
-
|
43
|
+
def define_standard_accessors(attribute, value, object)
|
44
|
+
object.instance_eval %Q"
|
46
45
|
def #{attribute}=(value)
|
47
46
|
mark_field_as_changed!(:#{attribute})
|
48
47
|
@#{attribute} = value
|
data/lib/intercom/version.rb
CHANGED
@@ -4,7 +4,7 @@ describe Intercom::BaseCollectionProxy do
|
|
4
4
|
let(:client) { Intercom::Client.new(token: 'token') }
|
5
5
|
|
6
6
|
it "stops iterating if no starting after value" do
|
7
|
-
client.expects(:get).with("/contacts", {}).
|
7
|
+
client.expects(:get).with("/contacts", {}).returns(page_of_contacts(false))
|
8
8
|
emails = []
|
9
9
|
client.contacts.all.each { |contact| emails << contact.email }
|
10
10
|
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
|
@@ -15,6 +15,7 @@ describe Intercom::BaseCollectionProxy do
|
|
15
15
|
client.expects(:get).with('/contacts', { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false))
|
16
16
|
emails = []
|
17
17
|
client.contacts.all.each { |contact| emails << contact.email }
|
18
|
+
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com test1@example.com test2@example.com test3@example.com]
|
18
19
|
end
|
19
20
|
|
20
21
|
it "supports indexed array access" do
|
@@ -27,4 +28,20 @@ describe Intercom::BaseCollectionProxy do
|
|
27
28
|
emails = client.contacts.all.map { |contact| contact.email }
|
28
29
|
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
|
29
30
|
end
|
31
|
+
|
32
|
+
it "keeps entire collection iterable after first iteration" do
|
33
|
+
contacts = client.contacts.all
|
34
|
+
emails_iter1 = []
|
35
|
+
emails_iter2 = []
|
36
|
+
expects_pagination = proc do
|
37
|
+
client.expects(:get).with("/contacts", {}).returns(page_of_contacts(true))
|
38
|
+
client.expects(:get).with("/contacts", { starting_after: "EnCrYpTeDsTrInG" }).returns(page_of_contacts(false))
|
39
|
+
end
|
40
|
+
|
41
|
+
expects_pagination.call
|
42
|
+
contacts.each { |contact| emails_iter1 << contact.email }
|
43
|
+
expects_pagination.call
|
44
|
+
contacts.each { |contact| emails_iter2 << contact.email }
|
45
|
+
_(emails_iter1).must_equal emails_iter2
|
46
|
+
end
|
30
47
|
end
|
@@ -274,6 +274,7 @@ describe Intercom::Contact do
|
|
274
274
|
|
275
275
|
describe 'nested resources' do
|
276
276
|
let(:contact) { Intercom::Contact.new(id: '1', client: client) }
|
277
|
+
let(:contact_no_tags) { Intercom::Contact.new(id: '2', client: client, tags: []) }
|
277
278
|
let(:company) { Intercom::Company.new(id: '1') }
|
278
279
|
let(:tag) { Intercom::Tag.new(id: '1') }
|
279
280
|
let(:note) { Intercom::Note.new(body: "<p>Text for the note</p>") }
|
@@ -299,6 +300,27 @@ describe Intercom::Contact do
|
|
299
300
|
_(proxy.resource_class).must_equal Intercom::Tag
|
300
301
|
end
|
301
302
|
|
303
|
+
it 'returns correct tags from differring contacts' do
|
304
|
+
client.expects(:get).with('/contacts/1/tags', {}).returns({
|
305
|
+
'type' => 'tag.list',
|
306
|
+
'tags' => [
|
307
|
+
{
|
308
|
+
'type' => 'tag',
|
309
|
+
'id' => '1',
|
310
|
+
'name' => 'VIP Customer'
|
311
|
+
},
|
312
|
+
{
|
313
|
+
'type' => 'tag',
|
314
|
+
'id' => '2',
|
315
|
+
'name' => 'Test tag'
|
316
|
+
}
|
317
|
+
]
|
318
|
+
})
|
319
|
+
|
320
|
+
_(contact_no_tags.tags.map{ |t| t.id }).must_equal []
|
321
|
+
_(contact.tags.map{ |t| t.id }).must_equal ['1', '2']
|
322
|
+
end
|
323
|
+
|
302
324
|
it 'returns a collection proxy for listing companies' do
|
303
325
|
proxy = contact.companies
|
304
326
|
_(proxy.resource_name).must_equal 'companies'
|
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: 4.1.
|
4
|
+
version: 4.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -12,10 +12,10 @@ authors:
|
|
12
12
|
- Declan McGrath
|
13
13
|
- Jamie Osler
|
14
14
|
- Bob Long
|
15
|
-
autorequire:
|
15
|
+
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date:
|
18
|
+
date: 2022-03-01 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -256,7 +256,7 @@ homepage: https://www.intercom.io
|
|
256
256
|
licenses:
|
257
257
|
- MIT
|
258
258
|
metadata: {}
|
259
|
-
post_install_message:
|
259
|
+
post_install_message:
|
260
260
|
rdoc_options: []
|
261
261
|
require_paths:
|
262
262
|
- lib
|
@@ -271,8 +271,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
271
271
|
- !ruby/object:Gem::Version
|
272
272
|
version: '0'
|
273
273
|
requirements: []
|
274
|
-
rubygems_version: 3.
|
275
|
-
signing_key:
|
274
|
+
rubygems_version: 3.2.16
|
275
|
+
signing_key:
|
276
276
|
specification_version: 4
|
277
277
|
summary: Ruby bindings for the Intercom API
|
278
278
|
test_files:
|