intercom 3.9.5 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +235 -222
  3. data/Rakefile +1 -1
  4. data/changes.txt +3 -0
  5. data/lib/intercom.rb +27 -22
  6. data/lib/intercom/api_operations/archive.rb +2 -1
  7. data/lib/intercom/api_operations/delete.rb +16 -0
  8. data/lib/intercom/api_operations/find.rb +5 -2
  9. data/lib/intercom/api_operations/find_all.rb +4 -3
  10. data/lib/intercom/api_operations/list.rb +4 -1
  11. data/lib/intercom/api_operations/load.rb +4 -2
  12. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  13. data/lib/intercom/api_operations/save.rb +5 -4
  14. data/lib/intercom/api_operations/scroll.rb +4 -5
  15. data/lib/intercom/api_operations/search.rb +3 -2
  16. data/lib/intercom/base_collection_proxy.rb +72 -0
  17. data/lib/intercom/client.rb +20 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/company.rb +8 -0
  20. data/lib/intercom/contact.rb +21 -3
  21. data/lib/intercom/conversation.rb +4 -0
  22. data/lib/intercom/data_attribute.rb +7 -0
  23. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  24. data/lib/intercom/deprecated_resources.rb +13 -0
  25. data/lib/intercom/errors.rb +3 -0
  26. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  27. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  28. data/lib/intercom/lead.rb +21 -0
  29. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  30. data/lib/intercom/note.rb +4 -0
  31. data/lib/intercom/request.rb +37 -33
  32. data/lib/intercom/scroll_collection_proxy.rb +33 -38
  33. data/lib/intercom/search_collection_proxy.rb +30 -65
  34. data/lib/intercom/service/base_service.rb +7 -0
  35. data/lib/intercom/service/company.rb +0 -12
  36. data/lib/intercom/service/contact.rb +21 -10
  37. data/lib/intercom/service/conversation.rb +12 -3
  38. data/lib/intercom/service/data_attribute.rb +20 -0
  39. data/lib/intercom/service/lead.rb +41 -0
  40. data/lib/intercom/service/note.rb +4 -8
  41. data/lib/intercom/service/subscription.rb +2 -2
  42. data/lib/intercom/service/tag.rb +9 -9
  43. data/lib/intercom/service/visitor.rb +17 -8
  44. data/lib/intercom/tag.rb +4 -0
  45. data/lib/intercom/traits/api_resource.rb +28 -17
  46. data/lib/intercom/user.rb +12 -3
  47. data/lib/intercom/utils.rb +13 -2
  48. data/lib/intercom/version.rb +1 -1
  49. data/lib/intercom/visitor.rb +0 -2
  50. data/spec/spec_helper.rb +738 -513
  51. data/spec/unit/intercom/admin_spec.rb +2 -2
  52. data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
  53. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  54. data/spec/unit/intercom/client_spec.rb +25 -26
  55. data/spec/unit/intercom/company_spec.rb +13 -15
  56. data/spec/unit/intercom/contact_spec.rb +289 -33
  57. data/spec/unit/intercom/conversation_spec.rb +29 -7
  58. data/spec/unit/intercom/count_spec.rb +4 -4
  59. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  60. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  61. data/spec/unit/intercom/event_spec.rb +9 -11
  62. data/spec/unit/intercom/job_spec.rb +24 -24
  63. data/spec/unit/intercom/lead_spec.rb +57 -0
  64. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  65. data/spec/unit/intercom/message_spec.rb +1 -1
  66. data/spec/unit/intercom/note_spec.rb +4 -10
  67. data/spec/unit/intercom/request_spec.rb +1 -1
  68. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  69. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  70. data/spec/unit/intercom/segment_spec.rb +2 -2
  71. data/spec/unit/intercom/subscription_spec.rb +5 -6
  72. data/spec/unit/intercom/tag_spec.rb +22 -14
  73. data/spec/unit/intercom/team_spec.rb +2 -2
  74. data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
  75. data/spec/unit/intercom/user_spec.rb +224 -226
  76. data/spec/unit/intercom/visitor_spec.rb +49 -0
  77. data/spec/unit/intercom_spec.rb +5 -3
  78. metadata +22 -7
  79. data/lib/intercom/customer.rb +0 -10
  80. data/lib/intercom/service/customer.rb +0 -14
  81. data/spec/unit/intercom/visitors_spec.rb +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 204538ee7ce2d0d8b41b4c0b8ff4c6d80084570c410850ba02fc936a14292b8d
4
- data.tar.gz: 6704e411dcc92ae860d3d519bdd592e35ac2b931fb20e188b934bb4228232f12
2
+ SHA1:
3
+ metadata.gz: 5c53964236b264ffc6d830868e44ca4a49aa5e99
4
+ data.tar.gz: b2780da686165e965b18a36e9ab3016e78283178
5
5
  SHA512:
6
- metadata.gz: 496d153506de79e3527db4ba20176dd375a29ad37ab259121030f8b70ab5ba934db19fa917c28755d7205f092df2756f493742f47dbbc1eab895ac8ffa15a330
7
- data.tar.gz: 7248e5d8c2734a256c499b3145758965b2efd48b0b531a337e1337553724c40f156263b67f8db5612ed5bc2c92fb6a57b3d3068d2360647e412f8861c1a9f205
6
+ metadata.gz: '002628c67583066ae5994bfaf1a2ff90b8111f761ab031c13a573eeeab97456572bdc821bd64e67f20fba10548edf090b4bd39ec4d8b16b77f619f754c1c3118'
7
+ data.tar.gz: e7d16ab3173ad4ebdfdd2f616179483b24d82f8182e250d251a9723d6ca81ce0fa117b04bc98d99eda45a07ec360e5f0daa6755f32ec76004bca8816a0f585fe
data/README.md CHANGED
@@ -6,13 +6,11 @@ Ruby bindings for the Intercom API (https://developers.intercom.io/reference).
6
6
 
7
7
  [Gem Documentation](http://rubydoc.info/github/intercom/intercom-ruby/master/frames)
8
8
 
9
- For generating Intercom javascript script tags for Rails, please see https://github.com/intercom/intercom-rails.
9
+ For generating Intercom JavaScript script tags for Rails, please see https://github.com/intercom/intercom-rails.
10
10
 
11
11
  ## Upgrading information
12
12
 
13
- Version 3 of intercom-ruby is not backwards compatible with previous versions.
14
-
15
- Version 3 moves away from a global setup approach to the use of an Intercom Client.
13
+ Version 4 of intercom-ruby is not backwards compatible with previous versions. Please see our [migration guide](https://github.com/intercom/intercom-ruby/wiki/Migration-guide-for-v4) for full details of breaking changes.
16
14
 
17
15
  This version of the gem is compatible with `Ruby 2.1` and above.
18
16
 
@@ -23,7 +21,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
23
21
 
24
22
  Using bundler:
25
23
 
26
- gem 'intercom', '~> 3.9.4'
24
+ gem 'intercom', '~> 4.0'
27
25
 
28
26
  ## Basic Usage
29
27
 
@@ -38,7 +36,7 @@ intercom = Intercom::Client.new(token: 'my_token')
38
36
 
39
37
  ```ruby
40
38
  # With a versioned app:
41
- intercom = Intercom::Client.new(token: 'my_token', api_version: '1.0')
39
+ intercom = Intercom::Client.new(token: 'my_token', api_version: '2.0')
42
40
  ```
43
41
 
44
42
  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.
@@ -48,159 +46,235 @@ You can also use the [omniauth-intercom lib](https://github.com/intercom/omniaut
48
46
 
49
47
  Resources this API supports:
50
48
 
51
- https://api.intercom.io/users
52
- https://api.intercom.io/teams
53
49
  https://api.intercom.io/contacts
50
+ https://api.intercom.io/visitors
54
51
  https://api.intercom.io/companies
55
- https://api.intercom.io/counts
52
+ https://api.intercom.io/data_attributes
53
+ https://api.intercom.io/events
56
54
  https://api.intercom.io/tags
57
55
  https://api.intercom.io/notes
58
56
  https://api.intercom.io/segments
59
- https://api.intercom.io/events
60
57
  https://api.intercom.io/conversations
61
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
62
  https://api.intercom.io/subscriptions
63
63
  https://api.intercom.io/jobs
64
+
64
65
 
65
66
  ### Examples
66
67
 
67
- #### Users
68
+ #### Contacts
69
+ 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.
68
70
 
69
71
  ```ruby
70
- # Find user by email
71
- user = intercom.users.find(email: "bob@example.com")
72
- # Find user by user_id
73
- user = intercom.users.find(user_id: "1")
74
- # Find user by id
75
- user = intercom.users.find(id: "1")
76
- # Create a user
77
- user = intercom.users.create(email: "bob@example.com", name: "Bob Smith", signed_up_at: Time.now.to_i)
78
- # archive a user
79
- user = intercom.users.find(id: "1")
80
- archived_user = intercom.users.archive(user)
81
- # request a hard delete for a user
82
- (https://developers.intercom.com/intercom-api-reference/reference#delete-users)
83
- user = intercom.users.find(id: "1")
84
- deleted_user = intercom.users.request_hard_delete(user)
85
- # Update custom_attributes for a user
86
- user.custom_attributes["average_monthly_spend"] = 1234.56
87
- intercom.users.save(user)
88
- # Perform incrementing
89
- user.increment('karma')
90
- intercom.users.save(user)
91
- # Perform decrementing
92
- user.decrement('karma', 5)
93
- intercom.users.save(user)
94
- # Iterate over all users
95
- intercom.users.all.each {|user| puts %Q(#{user.email} - #{user.custom_attributes["average_monthly_spend"]}) }
96
- intercom.users.all.map {|user| user.email }
97
- # List your users create in the last two days
98
- intercom.users.find_all(type: 'users', page: 1, per_page: 10, created_since: 2, order: :asc).to_a.each_with_index {|usr, i| puts "#{i+1}: #{usr.name}"};
99
- # Paginate through your list of users choosing how many to return per page (default and max is 50 per page)
100
- intercom.users.find_all(type: 'users', page: 1, per_page: 10, order: :asc).to_a.each_with_index {|usr, i| puts "#{i+1}: #{usr.name}"}
101
-
102
- # Duplicate users? If you have duplicate users you can search for them via their email address.
103
- # Note this feature is only available from version 1.1 of the API so you will need to switch to that version
104
- # This will return multiple users if they have the same email address
105
- usrs = intercom.users.find_all(type: 'users', email: 'myemail@example.com', page: 1, per_page: 10, order: :asc)
106
- # This returns a user.list so you can access it via
107
- usrs.to_a.each_with_index {|usr, i| puts "#{i+1}: #{usr.id}"};
108
-
109
- # If you have over 10,000 users then you will need to use the scroll function to list your users
110
- # otherwise you will encounter a page limit with list all your users
111
- # You can use the scroll method to list all your users
112
- intercom.users.scroll.each { |user| puts user.name}
113
- # Alternatively you can use the scroll.next method to get 100 users with each request
114
- result = intercom.users.scroll.next
115
- # The result object then contains a records attributes that is an array of your user objects and it also contains a scroll_param which
116
- # you can then use to request the next 100 users. Note that the scroll parameter will time out after one minute and you will need to
117
- # make a new request
118
- result.scroll_param
119
- => "0730e341-63ef-44da-ab9c-9113f886326d"
120
- result = intercom.users.scroll.next("0730e341-63ef-44da-ab9c-9113f886326d");
121
- ```
72
+ # Create a contact with "lead" role
73
+ contact = intercom.contacts.create(email: "some_contact2@example.com", role: "lead")
122
74
 
123
- #### Admins
124
- ```ruby
125
- # Find access token owner (only with Personal Access Token and OAuth)
126
- intercom.admins.me
127
- # Find an admin by id
128
- intercom.admins.find(id: admin_id)
129
- # Iterate over all admins
130
- intercom.admins.all.each {|admin| puts admin.email }
75
+ # Get a single contact using their intercom_id
76
+ intercom.contacts.find(id: contact.id)
77
+
78
+ # Update a contact
79
+ contact.name = "New name"
80
+ intercom.contacts.save(contact)
81
+
82
+ # Update a contact's role from "lead" to "user"
83
+ contact.role = "user"
84
+ intercom.contacts.save(contact)
85
+
86
+ # Delete a contact permanently
87
+ intercom.contacts.delete(contact)
88
+
89
+ # List all contacts
90
+ contacts = intercom.contacts.all
91
+ contacts.each { |contact| p contact.name }
92
+
93
+ # Search for contacts by email
94
+ contacts = intercom.contacts.search(
95
+ "query": {
96
+ "field": 'email',
97
+ "operator": '=',
98
+ "value": 'some_contact@example.com'
99
+ }
100
+ )
101
+ contacts.each {|c| p c.email}
102
+ # For full detail on possible queries, please refer to the API documentation:
103
+ # https://developers.intercom.com/intercom-api-reference/reference
104
+
105
+ # Merge a lead into an existing user
106
+ lead = intercom.contacts.create(email: "some_contact2@example.com", role: "lead")
107
+ intercom.contacts.merge(lead, intercom.contacts.find(id: "5db2e80ab1b92243d2188cfe"))
108
+
109
+ # Add a tag to a contact
110
+ tag = intercom.tags.find(id: "123")
111
+ contact.add_tag(id: tag.id)
112
+
113
+ # Remove a tag
114
+ contact.remove_tag(id: tag.id)
115
+
116
+ # List tags for a contact
117
+ contact.tags.each {|t| p t.name}
118
+
119
+ # Create a note on a contact
120
+ contact.create_note(body: "<p>Text for the note</p>")
121
+
122
+ # List notes for a contact
123
+ contact.notes.each {|n| p n.body}
124
+
125
+ # Add a contact to a company
126
+ company = intercom.companies.find(id: "123")
127
+ contact.add_company(id: company.id)
128
+
129
+ # Remove a contact from a company
130
+ contact.remove_company(id: company.id)
131
+
132
+ # List companies for a contact
133
+ contact.companies.each {|c| p c.name}
131
134
  ```
132
135
 
133
- #### Teams
136
+ #### Visitors
134
137
  ```ruby
135
- # Find a team by id
136
- intercom.teams.find(id: team_id)
137
- # Iterate over all teams
138
- intercom.teams.all.each {|team| puts team.name }
138
+ # Get and update a visitor
139
+ visitor = intercom.visitors.find(id: "5dd570e7b1b922452676af23")
140
+ visitor.name = "New name"
141
+ intercom.visitors.save(visitor)
142
+
143
+ # Convert a visitor into a lead
144
+ intercom.visitors.convert(visitor)
145
+
146
+ # Convert a visitor into a user
147
+ user = intercom.contacts.find(id: "5db2e7f5b1b92243d2188cb3")
148
+ intercom.visitors.convert(visitor, user)
139
149
  ```
140
150
 
141
151
  #### Companies
142
152
  ```ruby
143
- # Add a user to one or more companies
144
- user = intercom.users.find(email: "bob@example.com")
145
- user.companies = [{company_id: 6, name: "Intercom"}, {company_id: 9, name: "Test Company"}]
146
- intercom.users.save(user)
147
- # You can also pass custom attributes within a company as you do this
148
- user.companies = [{id: 6, name: "Intercom", custom_attributes: {referral_source: "Google"} } ]
149
- intercom.users.save(user)
150
153
  # Find a company by company_id
151
154
  company = intercom.companies.find(company_id: "44")
155
+
152
156
  # Find a company by name
153
157
  company = intercom.companies.find(name: "Some company")
158
+
154
159
  # Find a company by id
155
160
  company = intercom.companies.find(id: "41e66f0313708347cb0000d0")
161
+
156
162
  # Update a company
157
163
  company.name = 'Updated company name'
158
164
  intercom.companies.save(company)
165
+
159
166
  # Iterate over all companies
160
167
  intercom.companies.all.each {|company| puts %Q(#{company.name} - #{company.custom_attributes["referral_source"]}) }
161
168
  intercom.companies.all.map {|company| company.name }
162
- # Get a list of users in a company by Intercom Company ID
163
- intercom.companies.users_by_intercom_company_id(company.id)
164
- # Get a list of users in a company by external company_id
165
- intercom.companies.users_by_company_id(company.company_id)
169
+
166
170
  # Get a large list of companies using scroll
167
171
  intercom.companies.scroll.each { |comp| puts comp.name}
168
172
  # Please see users scroll for more details of how to use scroll
169
173
  ```
170
174
 
175
+ #### Data Attributes
176
+ Data Attributes are a type of metadata used to describe your customer and company models. These include standard and custom attributes.
177
+ ```ruby
178
+ # Create a new custom data attribute
179
+ intercom.data_attributes.create({ name: "test_attribute", model: "contact", data_type: "string" })
180
+
181
+ # List all data attributes
182
+ attributes = intercom.data_attributes.all
183
+ attributes.each { |attribute| p attribute.name }
184
+
185
+ # Update an attribute
186
+ attribute = intercom.data_attributes.all.first
187
+ attribute.label = "New label"
188
+ intercom.data_attributes.save(attribute)
189
+
190
+ # Archive an attribute
191
+ attribute.archived = true
192
+ intercom.data_attributes.save(attribute)
193
+
194
+ # Find all customer attributes including archived
195
+ customer_attributes_incl_archived = intercom.data_attributes.find_all({"model": "contact", "include_archived": true})
196
+ customer_attributes_incl_archived.each { |attr| p attribute.name }
197
+ ```
198
+
199
+ #### Events
200
+ ```ruby
201
+ intercom.events.create(
202
+ event_name: "invited-friend",
203
+ created_at: Time.now.to_i,
204
+ email: user.email,
205
+ metadata: {
206
+ "invitee_email" => "pi@example.org",
207
+ invite_code: "ADDAFRIEND",
208
+ "found_date" => 12909364407
209
+ }
210
+ )
211
+
212
+ # Alternatively, use "user_id" in case your app allows multiple accounts having the same email
213
+ intercom.events.create(
214
+ event_name: "invited-friend",
215
+ created_at: Time.now.to_i,
216
+ user_id: user.uuid,
217
+ )
218
+
219
+ # Retrieve event list for user with id:'123abc'
220
+ intercom.events.find_all("type" => "user", "intercom_user_id" => "123abc")
221
+ ```
222
+
223
+ Metadata Objects support a few simple types that Intercom can present on your behalf
224
+
225
+ ```ruby
226
+ intercom.events.create(
227
+ event_name: "placed-order",
228
+ email: current_user.email,
229
+ created_at: 1403001013,
230
+ metadata: {
231
+ order_date: Time.now.to_i,
232
+ stripe_invoice: 'inv_3434343434',
233
+ order_number: {
234
+ value: '3434-3434',
235
+ url: 'https://example.org/orders/3434-3434'
236
+ },
237
+ price: {
238
+ currency: 'usd',
239
+ amount: 2999
240
+ }
241
+ }
242
+ )
243
+ ```
244
+
245
+ The metadata key values in the example are treated as follows-
246
+ - order_date: a Date (key ends with '_date')
247
+ - stripe_invoice: The identifier of the Stripe invoice (has a 'stripe_invoice' key)
248
+ - order_number: a Rich Link (value contains 'url' and 'value' keys)
249
+ - price: An Amount in US Dollars (value contains 'amount' and 'currency' keys)
250
+
251
+ *NB:* This version of the gem reserves the field name `type` in Event data.
252
+
171
253
  #### Tags
172
254
  ```ruby
173
- # Tag users
174
- tag = intercom.tags.tag(name: 'blue', users: [{email: "test1@example.com"}])
175
- # Untag users
176
- intercom.tags.untag(name: 'blue', users: [{user_id: "42ea2f1b93891f6a99000427"}])
177
255
  # Iterate over all tags
178
256
  intercom.tags.all.each {|tag| "#{tag.id} - #{tag.name}" }
179
257
  intercom.tags.all.map {|tag| tag.name }
258
+
180
259
  # Tag companies
181
260
  tag = intercom.tags.tag(name: 'blue', companies: [{company_id: "42ea2f1b93891f6a99000427"}])
182
261
  ```
183
262
 
263
+ #### Notes
264
+ ```ruby
265
+ # Find a note by id
266
+ note = intercom.notes.find(id: "123")
267
+ ```
268
+
184
269
  #### Segments
185
270
  ```ruby
186
271
  # Find a segment
187
272
  segment = intercom.segments.find(id: segment_id)
273
+
188
274
  # Iterate over all segments
189
275
  intercom.segments.all.each {|segment| puts "id: #{segment.id} name: #{segment.name}"}
190
276
  ```
191
277
 
192
- #### Notes
193
- ```ruby
194
- # Find a note by id
195
- note = intercom.notes.find(id: note)
196
- # Create a note for a user
197
- note = intercom.notes.create(body: "<p>Text for the note</p>", email: 'joe@example.com')
198
- # Iterate over all notes for a user via their email address
199
- intercom.notes.find_all(email: 'joe@example.com').each {|note| puts note.body}
200
- # Iterate over all notes for a user via their user_id
201
- intercom.notes.find_all(user_id: '123').each {|note| puts note.body}
202
- ```
203
-
204
278
  #### Conversations
205
279
  ```ruby
206
280
  # Iterate over all conversations for your app
@@ -234,12 +308,21 @@ conversation = intercom.conversations.find(id: '1')
234
308
 
235
309
  # INTERACTING WITH THE PARTS OF A CONVERSATION
236
310
  # Getting the subject of a part (only applies to email-based conversations)
237
- conversation.rendered_message.subject
311
+ conversation.source.subject
312
+
238
313
  # Get the part_type of the first part
239
- conversation.conversation_parts[0].part_type
314
+ conversation.conversation_parts.first.part_type
315
+
240
316
  # Get the body of the second part
241
317
  conversation.conversation_parts[1].body
242
318
 
319
+ # Get statistics related to the conversation
320
+ conversation.statistics.time_to_admin_reply
321
+ conversation.statistics.last_assignment_at
322
+
323
+ # Get information on the sla applied to a conversation
324
+ conversation.sla_applied.sla_name
325
+
243
326
  # REPLYING TO CONVERSATIONS
244
327
  # User (identified by email) replies with a comment
245
328
  intercom.conversations.reply(id: conversation.id, type: 'user', email: 'joe@example.com', message_type: 'comment', body: 'foo')
@@ -282,13 +365,46 @@ intercom.conversations.reply(id: conversation.id, type: 'admin', assignee_id: as
282
365
 
283
366
  # MARKING A CONVERSATION AS READ
284
367
  intercom.conversations.mark_read(conversation.id)
368
+
369
+ # RUN ASSIGNMENT RULES
370
+ intercom.conversations.run_assignment_rules(conversation.id)
371
+
372
+ # Search for conversations
373
+ # For full detail on possible queries, please refer to the API documentation:
374
+ # https://developers.intercom.com/intercom-api-reference/reference
375
+
376
+ # Search for open conversations sorted by the created_at date
377
+ conversations = intercom.conversations.search(
378
+ query: {
379
+ field: "open",
380
+ operator: "=",
381
+ value: true
382
+ },
383
+ sort_field: "created_at",
384
+ sort_order: "descending"
385
+ )
386
+ conversations.each {|c| p c.id}
387
+
388
+ # Tagging for conversations
389
+ tag = intercom.tags.find(id: "2")
390
+ conversation = intercom.conversations.find(id: "1")
391
+
392
+ # An Admin ID is required to add or remove tag on a conversation
393
+ admin = intercom.admins.find(id: "1")
394
+
395
+ # Add a tag to a conversation
396
+ conversation.add_tag(id: tag.id, admin_id: admin.id)
397
+
398
+ # Remove a tag from a conversation
399
+ conversation.remove_tag(id: tag.id, admin_id: admin.id)
400
+
285
401
  ```
286
402
 
287
403
  #### Full loading of an embedded entity
288
404
  ```ruby
289
- # Given a conversation with a partial user, load the full user. This can be
405
+ # Given a conversation with a partial contact, load the full contact. This can be
290
406
  # done for any entity
291
- intercom.users.load(conversation.user)
407
+ intercom.contacts.load(conversation.contacts.first)
292
408
  ```
293
409
 
294
410
  #### Sending messages
@@ -357,125 +473,22 @@ intercom.messages.create({
357
473
  })
358
474
  ```
359
475
 
360
- #### Events
361
- ```ruby
362
- intercom.events.create(
363
- event_name: "invited-friend",
364
- created_at: Time.now.to_i,
365
- email: user.email,
366
- metadata: {
367
- "invitee_email" => "pi@example.org",
368
- invite_code: "ADDAFRIEND",
369
- "found_date" => 12909364407
370
- }
371
- )
372
-
373
- # Alternatively, use "user_id" in case your app allows multiple accounts having the same email
374
- intercom.events.create(
375
- event_name: "invited-friend",
376
- created_at: Time.now.to_i,
377
- user_id: user.uuid,
378
- )
379
-
380
- # Retrieve event list for user with id:'123abc'
381
- intercom.events.find_all("type" => "user", "intercom_user_id" => "123abc")
382
-
383
- ```
384
-
385
- Metadata Objects support a few simple types that Intercom can present on your behalf
386
-
387
- ```ruby
388
- intercom.events.create(
389
- event_name: "placed-order",
390
- email: current_user.email,
391
- created_at: 1403001013,
392
- metadata: {
393
- order_date: Time.now.to_i,
394
- stripe_invoice: 'inv_3434343434',
395
- order_number: {
396
- value: '3434-3434',
397
- url: 'https://example.org/orders/3434-3434'
398
- },
399
- price: {
400
- currency: 'usd',
401
- amount: 2999
402
- }
403
- }
404
- )
405
- ```
406
-
407
- The metadata key values in the example are treated as follows-
408
- - order_date: a Date (key ends with '_date')
409
- - stripe_invoice: The identifier of the Stripe invoice (has a 'stripe_invoice' key)
410
- - order_number: a Rich Link (value contains 'url' and 'value' keys)
411
- - price: An Amount in US Dollars (value contains 'amount' and 'currency' keys)
412
-
413
- *NB:* This version of the gem reserves the field name `type` in Event data.
414
-
415
- #### Contacts
416
-
417
- `Contacts` represent logged out users of your application.
418
- Note that `contacts` are referred to as `leads` in the [Intercom](https://developers.intercom.com/intercom-api-reference/reference#leads)
419
-
476
+ #### Admins
420
477
  ```ruby
421
- # Create a contact
422
- contact = intercom.contacts.create(email: "some_contact@example.com")
423
-
424
- # Update a contact (via create method)
425
- # You can update a contact by calling the create method but you MUST provide an id or user_id
426
- # If you just provide an email, for example, it will create a new contact
427
- # See https://developers.intercom.com/intercom-api-reference/reference#update-lead for more detail
428
- contact = intercom.contacts.create(email: "some_contact@example.com", id: "3be0398668071a6bc6850413", name:"update_contact")
429
-
430
- # Update a contact (via contact object)
431
- contact.custom_attributes['foo'] = 'bar'
432
- intercom.contacts.save(contact)
433
-
434
- # Find contacts by email
435
- contacts = intercom.contacts.find_all(email: "some_contact@example.com")
436
-
437
- # Using find to search for contacts by email
438
- contact_list = intercom.contacts.find(email: "some_contact@example.com")
439
- # This returns a Contact object with type contact.list
440
- # Note: Multiple contacts can be returned in this list if there are multiple matching contacts found
441
- # #<Intercom::Contact:0x00007ff3a80789f8
442
- # @changed_fields=#<Set: {}>,
443
- # @contacts=
444
- # [{"type"=>"contact",
445
- # "id"=>"5b7fd9b683681ac52274b9c7",
446
- # "user_id"=>"05bc4d17-72cc-433e-88ae-0bf88db5d0e6",
447
- # "anonymous"=>true,
448
- # "email"=>"some_contact@example.com",
449
- # ...}],
450
- # @custom_attributes={},
451
- # @limited=false,
452
- # @pages=#<Intercom::Pages:0x00007ff3a7413c58 @changed_fields=#<Set: {}>, @next=nil, @page=1, @per_page=50, @total_pages=1, @type="pages">,
453
- # @total_count=1,
454
- # @type="contact.list">
455
- # Access the contact's data
456
- contact_list.contacts.first
457
-
458
- # Convert a contact into a user
459
- contact = intercom.contacts.find(id: "536e564f316c83104c000020")
460
- intercom.contacts.convert(contact, Intercom::User.new(email: email))
461
- # Using find with email will not work here. See https://github.com/intercom/intercom-ruby/issues/419 for more information
462
-
463
- # archive a contact
464
- intercom.contacts.archive(contact)
465
-
466
- # Get a large list of contacts using scroll
467
- intercom.contacts.scroll.each { |lead| puts lead.id}
468
- # Please see users scroll for more details of how to use scroll
478
+ # Find access token owner (only with Personal Access Token and OAuth)
479
+ intercom.admins.me
480
+ # Find an admin by id
481
+ intercom.admins.find(id: admin_id)
482
+ # Iterate over all admins
483
+ intercom.admins.all.each {|admin| puts admin.email }
469
484
  ```
470
485
 
471
- #### Customers
472
-
473
- Our Customer API is a central place for all the information on your customers, whether they're users or leads. More detail in our API documentation on [Customers](https://developers.intercom.com/intercom-api-reference/v0/reference#customers).
474
-
486
+ #### Teams
475
487
  ```ruby
476
- # Search for customers
477
- customers = intercom.customers.search(query: { "field": "name", "operator": "=", "value": "Alice"}, per_page: 50, sort_field: "name", sort_order: "ascending")
478
- customers.each { |customer| p customer.name }
488
+ # Find a team by id
489
+ intercom.teams.find(id: team_id)
490
+ # Iterate over all teams
491
+ intercom.teams.all.each {|team| puts team.name }
479
492
  ```
480
493
 
481
494
  #### Counts