intercom 4.1.0 → 4.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0243df2d2e2715b541588cb09ed335e70bd1962767f06f475fd9b968ee4dace5
4
- data.tar.gz: 9695060c87906c18d77c049eff37e742fadca1bdc21355d4471d4fcbe6447042
3
+ metadata.gz: 02dd1486f502ecd7d6cd6c5ac0eda0dd7aa0efa2f127caee9eb4d5c2f87d131d
4
+ data.tar.gz: 618094ddfd695421006362dc450cf42d9e09f8fd70238dd9a783c1e98821112e
5
5
  SHA512:
6
- metadata.gz: 3ffece71e912927db02751a1d6ee8e84cf535c16491a75e6fd6a2ea1c4564b17eed584d4ea480b215bb93bb215a540b0f683c257211c672151d0c08cc4c9ea3d
7
- data.tar.gz: a60b0b793bab1f96d98fae70c75b7ceb3d609bd1b6239d115869c35acd8406119f9ceb8fcf0b7ad374f6d95eb510938098ef9cd9f6c29a46fb28760ede661665
6
+ metadata.gz: d551de01dc64b86f6e414234e0b0bdb8f207f2387cab6f15254ff5aa9f8561232fa1b6412ad067eaef768d9a6fffcbf0677330f8aee8667a0fd597bae5d7c7a7
7
+ data.tar.gz: 843174258835ec50702e28c10b16592d954e67a95318314f1c3eb544ee48705b2115ff82924c67eee32a280670c91c0885bbd04bb816d8ce59bb4db10258d1ca
data/README.md CHANGED
@@ -1,12 +1,26 @@
1
1
  # intercom-ruby
2
2
 
3
- Ruby bindings for the Intercom API (https://developers.intercom.io/reference).
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
- gem install intercom
33
+ ```bash
34
+ gem install intercom
35
+ ```
21
36
 
22
37
  Using bundler:
23
38
 
24
- gem 'intercom', '~> 4.0'
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.1')
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
- https://api.intercom.io/contacts
50
- https://api.intercom.io/visitors
51
- https://api.intercom.io/companies
52
- https://api.intercom.io/data_attributes
53
- https://api.intercom.io/events
54
- https://api.intercom.io/tags
55
- https://api.intercom.io/notes
56
- https://api.intercom.io/segments
57
- https://api.intercom.io/conversations
58
- https://api.intercom.io/messages
59
- https://api.intercom.io/admins
60
- https://api.intercom.io/teams
61
- https://api.intercom.io/counts
62
- https://api.intercom.io/subscriptions
63
- https://api.intercom.io/jobs
64
- https://api.intercom.io/articles
65
- https://api.intercom.io/help_center/collections
66
- https://api.intercom.io/help_center/sections
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
@@ -86,6 +105,12 @@ intercom.contacts.save(contact)
86
105
  contact.role = "user"
87
106
  intercom.contacts.save(contact)
88
107
 
108
+ # Archive a contact
109
+ intercom.contacts.archive(contact)
110
+
111
+ # Unarchive a contact
112
+ intercom.contacts.unarchive(contact)
113
+
89
114
  # Delete a contact permanently
90
115
  intercom.contacts.delete(contact)
91
116
 
@@ -125,6 +150,9 @@ contact.create_note(body: "<p>Text for the note</p>")
125
150
  # List notes for a contact
126
151
  contact.notes.each {|n| p n.body}
127
152
 
153
+ # List segments for a contact
154
+ contact.segments.each {|segment| p segment.name}
155
+
128
156
  # Add a contact to a company
129
157
  company = intercom.companies.find(id: "123")
130
158
  contact.add_company(id: company.id)
@@ -137,6 +165,7 @@ contact.companies.each {|c| p c.name}
137
165
  ```
138
166
 
139
167
  #### Visitors
168
+
140
169
  ```ruby
141
170
  # Get and update a visitor
142
171
  visitor = intercom.visitors.find(id: "5dd570e7b1b922452676af23")
@@ -152,6 +181,7 @@ intercom.visitors.convert(visitor, user)
152
181
  ```
153
182
 
154
183
  #### Companies
184
+
155
185
  ```ruby
156
186
  # Find a company by company_id
157
187
  company = intercom.companies.find(company_id: "44")
@@ -166,6 +196,9 @@ company = intercom.companies.find(id: "41e66f0313708347cb0000d0")
166
196
  company.name = 'Updated company name'
167
197
  intercom.companies.save(company)
168
198
 
199
+ # Delete a company
200
+ intercom.companies.delete(company)
201
+
169
202
  # Iterate over all companies
170
203
  intercom.companies.all.each {|company| puts %Q(#{company.name} - #{company.custom_attributes["referral_source"]}) }
171
204
  intercom.companies.all.map {|company| company.name }
@@ -176,7 +209,9 @@ intercom.companies.scroll.each { |comp| puts comp.name}
176
209
  ```
177
210
 
178
211
  #### Data Attributes
212
+
179
213
  Data Attributes are a type of metadata used to describe your customer and company models. These include standard and custom attributes.
214
+
180
215
  ```ruby
181
216
  # Create a new custom data attribute
182
217
  intercom.data_attributes.create({ name: "test_attribute", model: "contact", data_type: "string" })
@@ -196,10 +231,11 @@ intercom.data_attributes.save(attribute)
196
231
 
197
232
  # Find all customer attributes including archived
198
233
  customer_attributes_incl_archived = intercom.data_attributes.find_all({"model": "contact", "include_archived": true})
199
- customer_attributes_incl_archived.each { |attr| p attribute.name }
234
+ customer_attributes_incl_archived.each { |attr| p attr.name }
200
235
  ```
201
236
 
202
237
  #### Events
238
+
203
239
  ```ruby
204
240
  intercom.events.create(
205
241
  event_name: "invited-friend",
@@ -245,7 +281,8 @@ intercom.events.create(
245
281
  )
246
282
  ```
247
283
 
248
- The metadata key values in the example are treated as follows-
284
+ The metadata key values in the example are treated as follows:
285
+
249
286
  - order_date: a Date (key ends with '_date')
250
287
  - stripe_invoice: The identifier of the Stripe invoice (has a 'stripe_invoice' key)
251
288
  - order_number: a Rich Link (value contains 'url' and 'value' keys)
@@ -254,6 +291,7 @@ The metadata key values in the example are treated as follows-
254
291
  *NB:* This version of the gem reserves the field name `type` in Event data.
255
292
 
256
293
  #### Tags
294
+
257
295
  ```ruby
258
296
  # Iterate over all tags
259
297
  intercom.tags.all.each {|tag| "#{tag.id} - #{tag.name}" }
@@ -261,15 +299,20 @@ intercom.tags.all.map {|tag| tag.name }
261
299
 
262
300
  # Tag companies
263
301
  tag = intercom.tags.tag(name: 'blue', companies: [{company_id: "42ea2f1b93891f6a99000427"}])
302
+
303
+ # Untag Companies
304
+ tag = intercom.tags.untag(name: 'blue', companies: [{ company_id: "42ea2f1b93891f6a99000427" }])
264
305
  ```
265
306
 
266
307
  #### Notes
308
+
267
309
  ```ruby
268
310
  # Find a note by id
269
311
  note = intercom.notes.find(id: "123")
270
312
  ```
271
313
 
272
314
  #### Segments
315
+
273
316
  ```ruby
274
317
  # Find a segment
275
318
  segment = intercom.segments.find(id: segment_id)
@@ -279,6 +322,7 @@ intercom.segments.all.each {|segment| puts "id: #{segment.id} name: #{segment.na
279
322
  ```
280
323
 
281
324
  #### Conversations
325
+
282
326
  ```ruby
283
327
  # Iterate over all conversations for your app
284
328
  intercom.conversations.all.each { |convo| ... }
@@ -409,6 +453,7 @@ conversation.remove_contact(id: contact.id, admin_id: admin.id)
409
453
  ```
410
454
 
411
455
  #### Full loading of an embedded entity
456
+
412
457
  ```ruby
413
458
  # Given a conversation with a partial contact, load the full contact. This can be
414
459
  # done for any entity
@@ -416,6 +461,7 @@ intercom.contacts.load(conversation.contacts.first)
416
461
  ```
417
462
 
418
463
  #### Sending messages
464
+
419
465
  ```ruby
420
466
 
421
467
  # InApp message from admin to user
@@ -482,6 +528,7 @@ intercom.messages.create({
482
528
  ```
483
529
 
484
530
  #### Admins
531
+
485
532
  ```ruby
486
533
  # Find access token owner (only with Personal Access Token and OAuth)
487
534
  intercom.admins.me
@@ -492,6 +539,7 @@ intercom.admins.all.each {|admin| puts admin.email }
492
539
  ```
493
540
 
494
541
  #### Teams
542
+
495
543
  ```ruby
496
544
  # Find a team by id
497
545
  intercom.teams.find(id: team_id)
@@ -529,6 +577,7 @@ intercom.subscriptions.all
529
577
  ```
530
578
 
531
579
  #### Articles
580
+
532
581
  ```ruby
533
582
  # Create an article
534
583
  article = intercom.articles.create(title: "New Article", author_id: "123456")
@@ -562,6 +611,7 @@ intercom.articles.delete(article)
562
611
  ```
563
612
 
564
613
  #### Collections
614
+
565
615
  ```ruby
566
616
  # Create a collection
567
617
  collection = intercom.collections.create(name: "New Collection")
@@ -594,6 +644,7 @@ intercom.collections.delete(collection)
594
644
  ```
595
645
 
596
646
  #### Sections
647
+
597
648
  ```ruby
598
649
  # Create a section
599
650
  section = intercom.sections.create(name: "New Section", parent_id: "123456")
@@ -645,6 +696,7 @@ Intercom::RateLimitExceeded
645
696
  Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
646
697
  Intercom::MultipleMatchingUsersError
647
698
  Intercom::HttpError # Raised when response object is unexpectedly nil
699
+ Intercom::GatewayTimeoutError
648
700
  ```
649
701
 
650
702
  ### Rate Limiting
@@ -659,7 +711,7 @@ intercom.rate_limit_details
659
711
  You can handle the rate limits yourself but a simple option is to use the handle_rate_limit flag.
660
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.
661
713
 
662
- ```
714
+ ```ruby
663
715
  intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
664
716
  ```
665
717
 
@@ -685,13 +737,13 @@ intercom = Intercom::Client.new(token: ENV['AT'], handle_rate_limit: true)
685
737
 
686
738
  ```bash
687
739
  # all tests
688
- bundle exec spec
740
+ bundle exec rake spec
689
741
 
690
742
  # unit tests
691
- bundle exec spec:unit
743
+ bundle exec rake spec:unit
692
744
 
693
745
  # integration tests
694
- bundle exec spec:integration
746
+ bundle exec rake spec:integration
695
747
 
696
748
  # single test file
697
749
  bundle exec m spec/unit/intercom/job_spec.rb
data/changes.txt CHANGED
@@ -1,3 +1,20 @@
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
+
8
+ 4.1.1
9
+ - Fixed bug with deprecated lead resource.
10
+
11
+ 4.1.0
12
+ - Added support for new Articles API.
13
+ - Added support for new Collections API.
14
+ - Added support for new Sections API.
15
+ - Added support to equate two resources.
16
+ - Fixed issue for dirty tracking nested typed objects.
17
+
1
18
  4.0.1
2
19
  - Fixed bug with nested resources.
3
20
  - Support for add/remove contact on conversation object.
@@ -58,6 +58,7 @@ module Intercom
58
58
  @params[:starting_after] = paging_next['starting_after']
59
59
  return true
60
60
  else
61
+ @params[:starting_after] = nil
61
62
  return false
62
63
  end
63
64
  end
@@ -104,6 +104,10 @@ module Intercom
104
104
  Intercom::Service::User.new(self)
105
105
  end
106
106
 
107
+ def leads
108
+ Intercom::Service::Lead.new(self)
109
+ end
110
+
107
111
  def visitors
108
112
  Intercom::Service::Visitor.new(self)
109
113
  end
@@ -13,6 +13,7 @@ module Intercom
13
13
  nested_resource_methods :tag, operations: %i[add delete list]
14
14
  nested_resource_methods :note, operations: %i[create list]
15
15
  nested_resource_methods :company, operations: %i[add delete list]
16
+ nested_resource_methods :segment, operations: %i[list]
16
17
 
17
18
  def self.collection_proxy_class
18
19
  Intercom::BaseCollectionProxy
@@ -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, klass)
9
+ define_date_based_accessors(attribute, value, object)
11
10
  elsif object.flat_store_attribute?(attribute)
12
- define_flat_store_based_accessors(attribute, value, klass)
11
+ define_flat_store_based_accessors(attribute, value, object)
13
12
  else
14
- define_standard_accessors(attribute, value, klass)
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, klass)
21
- klass.class_eval %Q"
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, klass)
33
- klass.class_eval %Q"
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, klass)
45
- klass.class_eval %Q"
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
@@ -26,7 +26,7 @@ module Intercom
26
26
  raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash
27
27
 
28
28
  @scroll_param = extract_scroll_param(response_hash)
29
- top_level_entity_key = deserialize_response_hash(response_hash)
29
+ top_level_entity_key = entity_key_from_response(response_hash)
30
30
  response_hash[top_level_entity_key] = response_hash[top_level_entity_key].map do |object_json|
31
31
  Lib::TypedJsonDeserializer.new(object_json, @client).deserialize
32
32
  end
@@ -44,7 +44,8 @@ module Intercom
44
44
  end
45
45
  raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash
46
46
 
47
- response_hash[deserialize_response_hash(response_hash)].each do |object_json|
47
+ top_level_entity_key = entity_key_from_response(response_hash)
48
+ response_hash[top_level_entity_key].each do |object_json|
48
49
  block.call Lib::TypedJsonDeserializer.new(object_json, @client).deserialize
49
50
  end
50
51
  scroll_param = extract_scroll_param(response_hash)
@@ -55,8 +56,8 @@ module Intercom
55
56
 
56
57
  private
57
58
 
58
- def deserialize_response_hash(response_hash)
59
- top_level_type = response_hash.delete('type')
59
+ def entity_key_from_response(response_hash)
60
+ top_level_type = response_hash['type']
60
61
  if resource_name == 'subscriptions'
61
62
  'items'
62
63
  else
@@ -65,7 +66,7 @@ module Intercom
65
66
  end
66
67
 
67
68
  def records_present?(response_hash)
68
- !response_hash[@resource_name].empty?
69
+ !response_hash[entity_key_from_response(response_hash)].empty?
69
70
  end
70
71
 
71
72
  def extract_scroll_param(response_hash)
@@ -3,5 +3,9 @@ require 'intercom/traits/api_resource'
3
3
  module Intercom
4
4
  class Segment
5
5
  include Traits::ApiResource
6
+
7
+ def self.collection_proxy_class
8
+ Intercom::BaseCollectionProxy
9
+ end
6
10
  end
7
11
  end
@@ -1,4 +1,5 @@
1
1
  require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/delete'
2
3
  require 'intercom/api_operations/list'
3
4
  require 'intercom/api_operations/scroll'
4
5
  require 'intercom/api_operations/find'
@@ -11,6 +12,7 @@ require 'intercom/extended_api_operations/segments'
11
12
  module Intercom
12
13
  module Service
13
14
  class Company < BaseService
15
+ include ApiOperations::Delete
14
16
  include ApiOperations::Find
15
17
  include ApiOperations::FindAll
16
18
  include ApiOperations::Load
@@ -33,6 +33,16 @@ module Intercom
33
33
  user.from_response(response)
34
34
  end
35
35
 
36
+ def archive(contact)
37
+ @client.post("/#{collection_name}/#{contact.id}/archive", {})
38
+ contact
39
+ end
40
+
41
+ def unarchive(contact)
42
+ @client.post("/#{collection_name}/#{contact.id}/unarchive", {})
43
+ contact
44
+ end
45
+
36
46
  private def raise_invalid_merge_error
37
47
  raise Intercom::InvalidMergeError, 'Merging can only be performed on a lead into a user'
38
48
  end
@@ -58,7 +58,7 @@ module Intercom
58
58
 
59
59
  def run_assignment_rules(id)
60
60
  collection_name = Utils.resource_class_to_collection_name(collection_class)
61
- response = @client.post("/#{collection_name}/#{id}/run_assignment_rules")
61
+ response = @client.post("/#{collection_name}/#{id}/run_assignment_rules", {})
62
62
  collection_class.new.from_response(response)
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "4.1.0"
2
+ VERSION = "4.1.3"
3
3
  end
@@ -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", {}). returns(page_of_contacts(false))
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
@@ -35,4 +35,10 @@ describe Intercom::Company do
35
35
  _(proxy.url).must_equal '/companies/1/contacts'
36
36
  _(proxy.resource_class).must_equal Intercom::Contact
37
37
  end
38
+
39
+ it "deletes a company" do
40
+ company = Intercom::Company.new("id" => "1")
41
+ client.expects(:delete).with("/companies/1", {})
42
+ client.companies.delete(company)
43
+ end
38
44
  end
@@ -248,6 +248,18 @@ describe Intercom::Contact do
248
248
  client.contacts.delete(contact)
249
249
  end
250
250
 
251
+ it 'archives a contact' do
252
+ contact = Intercom::Contact.new('id' => '1')
253
+ client.expects(:post).with('/contacts/1/archive', {})
254
+ client.contacts.archive(contact)
255
+ end
256
+
257
+ it 'unarchives a contact' do
258
+ contact = Intercom::Contact.new('id' => '1')
259
+ client.expects(:post).with('/contacts/1/unarchive', {})
260
+ client.contacts.unarchive(contact)
261
+ end
262
+
251
263
  describe 'merging' do
252
264
  let(:lead) { Intercom::Contact.from_api(external_id: 'contact_id', role: 'lead') }
253
265
  let(:user) { Intercom::Contact.from_api(id: 'external_id', role: 'user') }
@@ -262,6 +274,7 @@ describe Intercom::Contact do
262
274
 
263
275
  describe 'nested resources' do
264
276
  let(:contact) { Intercom::Contact.new(id: '1', client: client) }
277
+ let(:contact_no_tags) { Intercom::Contact.new(id: '2', client: client, tags: []) }
265
278
  let(:company) { Intercom::Company.new(id: '1') }
266
279
  let(:tag) { Intercom::Tag.new(id: '1') }
267
280
  let(:note) { Intercom::Note.new(body: "<p>Text for the note</p>") }
@@ -273,6 +286,13 @@ describe Intercom::Contact do
273
286
  _(proxy.resource_class).must_equal Intercom::Note
274
287
  end
275
288
 
289
+ it 'returns a collection proxy for listing segments' do
290
+ proxy = contact.segments
291
+ _(proxy.resource_name).must_equal 'segments'
292
+ _(proxy.url).must_equal '/contacts/1/segments'
293
+ _(proxy.resource_class).must_equal Intercom::Segment
294
+ end
295
+
276
296
  it 'returns a collection proxy for listing tags' do
277
297
  proxy = contact.tags
278
298
  _(proxy.resource_name).must_equal 'tags'
@@ -280,6 +300,27 @@ describe Intercom::Contact do
280
300
  _(proxy.resource_class).must_equal Intercom::Tag
281
301
  end
282
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
+
283
324
  it 'returns a collection proxy for listing companies' do
284
325
  proxy = contact.companies
285
326
  _(proxy.resource_name).must_equal 'companies'
@@ -54,7 +54,7 @@ describe "Intercom::Conversation" do
54
54
  end
55
55
 
56
56
  it 'runs assignment rules on a conversation' do
57
- client.expects(:post).with('/conversations/147/run_assignment_rules').returns(test_conversation)
57
+ client.expects(:post).with('/conversations/147/run_assignment_rules', {}).returns(test_conversation)
58
58
  client.conversations.run_assignment_rules('147')
59
59
  end
60
60
 
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.0
4
+ version: 4.1.3
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: 2020-07-14 00:00:00.000000000 Z
18
+ date: 2022-03-01 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -271,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  - !ruby/object:Gem::Version
272
272
  version: '0'
273
273
  requirements: []
274
- rubygems_version: 3.0.3
274
+ rubygems_version: 3.2.16
275
275
  signing_key:
276
276
  specification_version: 4
277
277
  summary: Ruby bindings for the Intercom API