cogniteev-intercom 2.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +6 -0
- data/Gemfile +13 -0
- data/MIT-LICENSE +21 -0
- data/README.md +378 -0
- data/Rakefile +21 -0
- data/changes.txt +168 -0
- data/intercom.gemspec +28 -0
- data/lib/data/cacert.pem +3965 -0
- data/lib/ext/sliceable_hash.rb +16 -0
- data/lib/intercom.rb +176 -0
- data/lib/intercom/admin.rb +9 -0
- data/lib/intercom/api_operations/convert.rb +19 -0
- data/lib/intercom/api_operations/count.rb +16 -0
- data/lib/intercom/api_operations/delete.rb +15 -0
- data/lib/intercom/api_operations/find.rb +23 -0
- data/lib/intercom/api_operations/find_all.rb +33 -0
- data/lib/intercom/api_operations/list.rb +17 -0
- data/lib/intercom/api_operations/load.rb +16 -0
- data/lib/intercom/api_operations/save.rb +51 -0
- data/lib/intercom/collection_proxy.rb +71 -0
- data/lib/intercom/company.rb +29 -0
- data/lib/intercom/contact.rb +22 -0
- data/lib/intercom/conversation.rb +17 -0
- data/lib/intercom/count.rb +21 -0
- data/lib/intercom/errors.rb +61 -0
- data/lib/intercom/event.rb +11 -0
- data/lib/intercom/extended_api_operations/reply.rb +16 -0
- data/lib/intercom/extended_api_operations/tags.rb +14 -0
- data/lib/intercom/extended_api_operations/users.rb +17 -0
- data/lib/intercom/generic_handlers/base_handler.rb +22 -0
- data/lib/intercom/generic_handlers/count.rb +59 -0
- data/lib/intercom/generic_handlers/tag.rb +71 -0
- data/lib/intercom/generic_handlers/tag_find_all.rb +47 -0
- data/lib/intercom/lib/dynamic_accessors.rb +59 -0
- data/lib/intercom/lib/dynamic_accessors_on_method_missing.rb +53 -0
- data/lib/intercom/lib/flat_store.rb +31 -0
- data/lib/intercom/lib/typed_json_deserializer.rb +53 -0
- data/lib/intercom/message.rb +9 -0
- data/lib/intercom/note.rb +17 -0
- data/lib/intercom/notification.rb +20 -0
- data/lib/intercom/request.rb +166 -0
- data/lib/intercom/segment.rb +14 -0
- data/lib/intercom/subscription.rb +15 -0
- data/lib/intercom/tag.rb +23 -0
- data/lib/intercom/traits/api_resource.rb +132 -0
- data/lib/intercom/traits/dirty_tracking.rb +33 -0
- data/lib/intercom/traits/generic_handler_binding.rb +29 -0
- data/lib/intercom/traits/incrementable_attributes.rb +12 -0
- data/lib/intercom/user.rb +30 -0
- data/lib/intercom/utils.rb +62 -0
- data/lib/intercom/version.rb +3 -0
- data/spec/spec_helper.rb +308 -0
- data/spec/unit/intercom/admin_spec.rb +9 -0
- data/spec/unit/intercom/collection_proxy_spec.rb +34 -0
- data/spec/unit/intercom/company_spec.rb +23 -0
- data/spec/unit/intercom/contact_spec.rb +25 -0
- data/spec/unit/intercom/event_spec.rb +25 -0
- data/spec/unit/intercom/lib/flat_store_spec.rb +29 -0
- data/spec/unit/intercom/message_spec.rb +21 -0
- data/spec/unit/intercom/note_spec.rb +19 -0
- data/spec/unit/intercom/notification_spec.rb +68 -0
- data/spec/unit/intercom/request_spec.rb +16 -0
- data/spec/unit/intercom/subscription_spec.rb +18 -0
- data/spec/unit/intercom/tag_spec.rb +23 -0
- data/spec/unit/intercom/traits/api_resource_spec.rb +85 -0
- data/spec/unit/intercom/user_spec.rb +230 -0
- data/spec/unit/intercom_spec.rb +90 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 092d21b0a4663909384dfa594af720394c5e30b0
|
4
|
+
data.tar.gz: 57ead001d7bb196b99453ef3485012a99ed2d23b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f86c48273b1ac011b7e1dc99e176cb5fefb09bb85bbd601f4632cbc3ef55466c23bb5c0330e91028d46997f746ff35a249ea07307e9d83c0a47ce1c5c9583f6
|
7
|
+
data.tar.gz: 29f3d796a2f455655ba157aee132548fa00204e7fb3b948a01b829ba8e1dd7f189d1da68106c4ecf0524b1e2a8f5ada61e3872bde7583d26c613e754268aa577
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011- Intercom, Inc. (https://www.intercom.io)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,378 @@
|
|
1
|
+
# intercom-ruby
|
2
|
+
|
3
|
+
Ruby bindings for the Intercom API (https://api.intercom.io).
|
4
|
+
|
5
|
+
[API Documentation](https://api.intercom.io/docs)
|
6
|
+
|
7
|
+
[Gem Documentation](http://rubydoc.info/github/intercom/intercom-ruby/master/frames)
|
8
|
+
|
9
|
+
For generating Intercom javascript script tags for Rails, please see https://github.com/intercom/intercom-rails
|
10
|
+
|
11
|
+
## Upgrading information
|
12
|
+
Version 2 of intercom-ruby is not backwards compatible with previous versions. Be sure to test this new version before deploying to production. One other change you will need to make as part of the upgrade is to set `Intercom.app_api_key` and not set `Intercom.api_key` (you can continue to use your existing API key).
|
13
|
+
|
14
|
+
This version of the gem is compatible with `Ruby 2.1`, `Ruby 2.0` & `Ruby 1.9.3`
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
gem install intercom
|
19
|
+
|
20
|
+
Using bundler:
|
21
|
+
|
22
|
+
gem 'intercom', "~> 2.5.4"
|
23
|
+
|
24
|
+
## Basic Usage
|
25
|
+
|
26
|
+
### Configure your access credentials
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Intercom.app_id = "my_app_id"
|
30
|
+
Intercom.app_api_key = "my-super-crazy-api-key"
|
31
|
+
```
|
32
|
+
|
33
|
+
You can get your `app_id` from the URL when you're logged into Intercom (it's the alphanumeric just after `/apps/`) and your API key from the API keys settings page (under your app settings in Intercom).
|
34
|
+
|
35
|
+
### Resources
|
36
|
+
|
37
|
+
Resources this API supports:
|
38
|
+
|
39
|
+
https://api.intercom.io/users
|
40
|
+
https://api.intercom.io/companies
|
41
|
+
https://api.intercom.io/tags
|
42
|
+
https://api.intercom.io/notes
|
43
|
+
https://api.intercom.io/segments
|
44
|
+
https://api.intercom.io/events
|
45
|
+
https://api.intercom.io/conversations
|
46
|
+
https://api.intercom.io/messages
|
47
|
+
https://api.intercom.io/counts
|
48
|
+
https://api.intercom.io/subscriptions
|
49
|
+
|
50
|
+
Additionally, the library can handle incoming webhooks from Intercom and convert to `Intercom::` models.
|
51
|
+
|
52
|
+
### Examples
|
53
|
+
|
54
|
+
#### Users
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# Find user by email
|
58
|
+
user = Intercom::User.find(:email => "bob@example.com")
|
59
|
+
# Find user by user_id
|
60
|
+
user = Intercom::User.find(:user_id => "1")
|
61
|
+
# Find user by id
|
62
|
+
user = Intercom::User.find(:id => "1")
|
63
|
+
# Create a user
|
64
|
+
user = Intercom::User.create(:email => "bob@example.com", :name => "Bob Smith", :signed_up_at => Time.now.to_i)
|
65
|
+
# Delete a user
|
66
|
+
deleted_user = Intercom::User.find(:id => "1").delete
|
67
|
+
# Update custom_attributes for a user
|
68
|
+
user.custom_attributes["average_monthly_spend"] = 1234.56; user.save
|
69
|
+
# Perform incrementing
|
70
|
+
user.increment('karma'); user.save
|
71
|
+
# Iterate over all users
|
72
|
+
Intercom::User.all.each {|user| puts %Q(#{user.email} - #{user.custom_attributes["average_monthly_spend"]}) }
|
73
|
+
Intercom::User.all.map {|user| user.email }
|
74
|
+
```
|
75
|
+
|
76
|
+
#### Admins
|
77
|
+
```ruby
|
78
|
+
# Iterate over all admins
|
79
|
+
Intercom::Admin.all.each {|admin| puts admin.email }
|
80
|
+
```
|
81
|
+
|
82
|
+
#### Companies
|
83
|
+
```ruby
|
84
|
+
# Add a user to one or more companies
|
85
|
+
user = Intercom::User.find(:email => "bob@example.com")
|
86
|
+
user.companies = [{:company_id => 6, :name => "Intercom"}, {:company_id => 9, :name => "Test Company"}]; user.save
|
87
|
+
# You can also pass custom attributes within a company as you do this
|
88
|
+
user.companies = [{:id => 6, :name => "Intercom", :custom_attributes => {:referral_source => "Google"} } ]; user.save
|
89
|
+
# Find a company by company_id
|
90
|
+
company = Intercom::Company.find(:company_id => "44")
|
91
|
+
# Find a company by name
|
92
|
+
company = Intercom::Company.find(:name => "Some company")
|
93
|
+
# Find a company by id
|
94
|
+
company = Intercom::Company.find(:id => "41e66f0313708347cb0000d0")
|
95
|
+
# Update a company
|
96
|
+
company.name = 'Updated company name'; company.save
|
97
|
+
# Iterate over all companies
|
98
|
+
Intercom::Company.all.each {|company| puts %Q(#{company.name} - #{company.custom_attributes["referral_source"]}) }
|
99
|
+
Intercom::Company.all.map {|company| company.name }
|
100
|
+
# Get a list of users in a company
|
101
|
+
company.users
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Tags
|
105
|
+
```ruby
|
106
|
+
# Tag users
|
107
|
+
tag = Intercom::Tag.tag_users('blue', ["42ea2f1b93891f6a99000427"])
|
108
|
+
# Untag users
|
109
|
+
Intercom::Tag.untag_users('blue', ["42ea2f1b93891f6a99000427"])
|
110
|
+
# Iterate over all tags
|
111
|
+
Intercom::Tag.all.each {|tag| "#{tag.id} - #{tag.name}" }
|
112
|
+
Intercom::Tag.all.map {|tag| tag.name }
|
113
|
+
# Iterate over all tags for user
|
114
|
+
Intercom::Tag.find_all_for_user(:id => '53357ddc3c776629e0000029')
|
115
|
+
Intercom::Tag.find_all_for_user(:email => 'declan+declan@intercom.io')
|
116
|
+
Intercom::Tag.find_all_for_user(:user_id => '3')
|
117
|
+
# Tag companies
|
118
|
+
tag = Intercom::Tag.tag_companies('red', ["42ea2f1b93891f6a99000427"])
|
119
|
+
# Untag companies
|
120
|
+
Intercom::Tag.untag_companies('blue', ["42ea2f1b93891f6a99000427"])
|
121
|
+
# Iterate over all tags for company
|
122
|
+
Intercom::Tag.find_all_for_company(:id => '43357e2c3c77661e25000026')
|
123
|
+
Intercom::Tag.find_all_for_company(:company_id => '6')
|
124
|
+
```
|
125
|
+
|
126
|
+
#### Segments
|
127
|
+
```ruby
|
128
|
+
# Find a segment
|
129
|
+
segment = Intercom::Segment.find(:id => segment_id)
|
130
|
+
# Update a segment
|
131
|
+
segment.name = 'Updated name'; segment.save
|
132
|
+
# Iterate over all segments
|
133
|
+
Intercom::Segment.all.each {|segment| puts "id: #{segment.id} name: #{segment.name}"}
|
134
|
+
```
|
135
|
+
|
136
|
+
#### Notes
|
137
|
+
```ruby
|
138
|
+
# Find a note by id
|
139
|
+
note = Intercom::Note.find(:id => note)
|
140
|
+
# Create a note for a user
|
141
|
+
note = Intercom::Note.create(:body => "<p>Text for the note</p>", :email => 'joe@example.com')
|
142
|
+
# Iterate over all notes for a user via their email address
|
143
|
+
Intercom::Note.find_all(:email => 'joe@example.com').each {|note| puts note.body}
|
144
|
+
# Iterate over all notes for a user via their user_id
|
145
|
+
Intercom::Note.find_all(:user_id => '123').each {|note| puts note.body}
|
146
|
+
```
|
147
|
+
|
148
|
+
#### Conversations
|
149
|
+
```ruby
|
150
|
+
# FINDING CONVERSATIONS FOR AN ADMIN
|
151
|
+
# Iterate over all conversations (open and closed) assigned to an admin
|
152
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => '7').each do {|convo| ... }
|
153
|
+
# Iterate over all open conversations assigned to an admin
|
154
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => true).each do {|convo| ... }
|
155
|
+
# Iterate over closed conversations assigned to an admin
|
156
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => false).each do {|convo| ... }
|
157
|
+
# Iterate over closed conversations for assigned an admin, before a certain moment in time
|
158
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => false, :before => 1374844930).each do {|convo| ... }
|
159
|
+
|
160
|
+
# FINDING CONVERSATIONS FOR A USER
|
161
|
+
# Iterate over all conversations (read + unread, correct) with a user based on the users email
|
162
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user').each do {|convo| ... }
|
163
|
+
# Iterate over through all conversations (read + unread) with a user based on the users email
|
164
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user', :unread => false).each do {|convo| ... }
|
165
|
+
# Iterate over all unread conversations with a user based on the users email
|
166
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user', :unread => true).each do {|convo| ... }
|
167
|
+
|
168
|
+
# FINDING A SINGLE CONVERSATION
|
169
|
+
conversation = Intercom::Conversation.find(:id => '1')
|
170
|
+
|
171
|
+
# INTERACTING WITH THE PARTS OF A CONVERSATION
|
172
|
+
# Getting the subject of a part (only applies to email-based conversations)
|
173
|
+
conversation.rendered_message.subject
|
174
|
+
# Get the part_type of the first part
|
175
|
+
conversation.conversation_parts[0].part_type
|
176
|
+
# Get the body of the second part
|
177
|
+
conversation.conversation_parts[1].body
|
178
|
+
|
179
|
+
# REPLYING TO CONVERSATIONS
|
180
|
+
# User (identified by email) replies with a comment
|
181
|
+
conversation.reply(:type => 'user', :email => 'joe@example.com', :message_type => 'comment', :body => 'foo')
|
182
|
+
# Admin (identified by email) replies with a comment
|
183
|
+
conversation.reply(:type => 'admin', :email => 'bob@example.com', :message_type => 'comment', :body => 'bar')
|
184
|
+
|
185
|
+
# MARKING A CONVERSATION AS READ
|
186
|
+
conversation.read = true
|
187
|
+
conversation.save
|
188
|
+
```
|
189
|
+
|
190
|
+
#### Counts
|
191
|
+
```ruby
|
192
|
+
# Get Conversation per Admin
|
193
|
+
conversation_counts_for_each_admin = Intercom::Count.conversation_counts_for_each_admin
|
194
|
+
conversation_counts_for_each_admin.each{|count| puts "Admin: #{count.name} (id: #{count.id}) Open: #{count.open} Closed: #{count.closed}" }
|
195
|
+
# Get User Tag Count Object
|
196
|
+
Intercom::Count.user_counts_for_each_tag
|
197
|
+
# Get User Segment Count Object
|
198
|
+
Intercom::Count.user_counts_for_each_segment
|
199
|
+
# Get Company Segment Count Object
|
200
|
+
Intercom::Count.company_counts_for_each_segment
|
201
|
+
# Get Company Tag Count Object
|
202
|
+
Intercom::Count.company_counts_for_each_tag
|
203
|
+
# Get Company User Count Object
|
204
|
+
Intercom::Count.company_counts_for_each_user
|
205
|
+
# Get total count of companies, users, segments or tags across app
|
206
|
+
Intercom::Company.count
|
207
|
+
Intercom::User.count
|
208
|
+
Intercom::Segment.count
|
209
|
+
Intercom::Tag.count
|
210
|
+
```
|
211
|
+
|
212
|
+
#### Full loading of an embedded entity
|
213
|
+
```ruby
|
214
|
+
# Given a conversation with a partial user, load the full user. This can be
|
215
|
+
# done for any entity
|
216
|
+
conversation.user.load
|
217
|
+
```
|
218
|
+
|
219
|
+
#### Sending messages
|
220
|
+
```ruby
|
221
|
+
|
222
|
+
# InApp message from admin to user
|
223
|
+
Intercom::Message.create({
|
224
|
+
:message_type => 'inapp',
|
225
|
+
:body => "What's up :)",
|
226
|
+
:from => {
|
227
|
+
:type => 'admin',
|
228
|
+
:id => "1234"
|
229
|
+
},
|
230
|
+
:to => {
|
231
|
+
:type => "user",
|
232
|
+
:id => "5678"
|
233
|
+
}
|
234
|
+
})
|
235
|
+
|
236
|
+
# Email message from admin to user
|
237
|
+
Intercom::Message.create({
|
238
|
+
:message_type => 'email',
|
239
|
+
:subject => 'Hey there',
|
240
|
+
:body => "What's up :)",
|
241
|
+
:template => "plain", # or "personal",
|
242
|
+
:from => {
|
243
|
+
:type => "admin",
|
244
|
+
:id => "1234"
|
245
|
+
},
|
246
|
+
:to => {
|
247
|
+
:type => "user",
|
248
|
+
:id => "536e564f316c83104c000020"
|
249
|
+
}
|
250
|
+
})
|
251
|
+
|
252
|
+
# Message from a user
|
253
|
+
Intercom::Message.create({
|
254
|
+
:from => {
|
255
|
+
:type => "user",
|
256
|
+
:id => "536e564f316c83104c000020"
|
257
|
+
},
|
258
|
+
:body => "halp"
|
259
|
+
})
|
260
|
+
```
|
261
|
+
|
262
|
+
#### Events
|
263
|
+
```ruby
|
264
|
+
Intercom::Event.create(
|
265
|
+
:event_name => "invited-friend", :created_at => Time.now.to_i,
|
266
|
+
:email => user.email,
|
267
|
+
:metadata => {
|
268
|
+
"invitee_email" => "pi@example.org",
|
269
|
+
:invite_code => "ADDAFRIEND",
|
270
|
+
"found_date" => 12909364407
|
271
|
+
}
|
272
|
+
)
|
273
|
+
```
|
274
|
+
|
275
|
+
Metadata Objects support a few simple types that Intercom can present on your behalf
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
Intercom::Event.create(:event_name => "placed-order", :email => current_user.email,
|
279
|
+
:created_at => 1403001013,
|
280
|
+
:metadata => {
|
281
|
+
:order_date => Time.now.to_i,
|
282
|
+
:stripe_invoice => 'inv_3434343434',
|
283
|
+
:order_number => {
|
284
|
+
:value => '3434-3434',
|
285
|
+
:url => 'https://example.org/orders/3434-3434'
|
286
|
+
},
|
287
|
+
price: {
|
288
|
+
:currency => 'usd',
|
289
|
+
:amount => 2999
|
290
|
+
}
|
291
|
+
}
|
292
|
+
)
|
293
|
+
```
|
294
|
+
|
295
|
+
The metadata key values in the example are treated as follows-
|
296
|
+
- order_date: a Date (key ends with '_date').
|
297
|
+
- stripe_invoice: The identifier of the Stripe invoice (has a 'stripe_invoice' key)
|
298
|
+
- order_number: a Rich Link (value contains 'url' and 'value' keys)
|
299
|
+
- price: An Amount in US Dollars (value contains 'amount' and 'currency' keys)
|
300
|
+
|
301
|
+
*NB:* This version of the gem reserves the field name `type` in Event data.
|
302
|
+
|
303
|
+
### Contacts
|
304
|
+
|
305
|
+
`Contacts` represent logged out users of your application.
|
306
|
+
|
307
|
+
```ruby
|
308
|
+
# Create a contact
|
309
|
+
contact = Intercom::Contact.create(email: "some_contact@example.com")
|
310
|
+
|
311
|
+
# Update a contact
|
312
|
+
contact.custom_attributes['foo'] = 'bar'
|
313
|
+
contact.save
|
314
|
+
|
315
|
+
# Find contacts by email
|
316
|
+
contacts = Intercom::Contact.find_all(email: "some_contact@example.com")
|
317
|
+
```
|
318
|
+
|
319
|
+
### Subscriptions
|
320
|
+
|
321
|
+
Subscribe to events in Intercom to receive webhooks.
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
# create a subscription
|
325
|
+
Intercom::Subscription.create(:url => "http://example.com", :topics => ["user.created"])
|
326
|
+
|
327
|
+
# fetch a subscription
|
328
|
+
Intercom::Subscription.find(:id => "nsub_123456789")
|
329
|
+
|
330
|
+
# list subscriptions
|
331
|
+
Intercom::Subscription.all
|
332
|
+
```
|
333
|
+
|
334
|
+
### Webhooks
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
# create a payload from the notification hash (from json).
|
338
|
+
payload = Intercom::Notification.new(notification_hash)
|
339
|
+
|
340
|
+
payload.type
|
341
|
+
# => 'user.created'
|
342
|
+
|
343
|
+
payload.model_type
|
344
|
+
# => Intercom::User
|
345
|
+
|
346
|
+
user = payload.model
|
347
|
+
# => Instance of Intercom::User
|
348
|
+
```
|
349
|
+
|
350
|
+
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.
|
351
|
+
|
352
|
+
### Errors
|
353
|
+
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 its `http_code` method.
|
354
|
+
|
355
|
+
The list of different error subclasses are listed below. As they all inherit off Intercom::IntercomError you can choose to rescue Intercom::IntercomError or
|
356
|
+
else rescue the more specific error subclass.
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
Intercom::AuthenticationError
|
360
|
+
Intercom::ServerError
|
361
|
+
Intercom::ServiceUnavailableError
|
362
|
+
Intercom::ServiceConnectionError
|
363
|
+
Intercom::ResourceNotFound
|
364
|
+
Intercom::BadRequestError
|
365
|
+
Intercom::RateLimitExceeded
|
366
|
+
Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
|
367
|
+
Intercom::MultipleMatchingUsersError
|
368
|
+
Intercom::HttpError # Raised when response object is unexpectedly nil
|
369
|
+
```
|
370
|
+
|
371
|
+
### Rate Limiting
|
372
|
+
|
373
|
+
Calling `Intercom.rate_limit_details` returns a Hash that contains details about your app's current rate limit.
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
Intercom.rate_limit_details
|
377
|
+
#=> {:limit=>180, :remaining=>179, :reset_at=>2014-10-07 14:58:00 +0100}
|
378
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
Rake::TestTask.new("spec:unit") do |spec|
|
6
|
+
spec.libs.push "lib"
|
7
|
+
spec.libs.push "spec"
|
8
|
+
spec.libs.push "spec/unit"
|
9
|
+
spec.test_files = FileList['spec/unit/**/*_spec.rb']
|
10
|
+
spec.warning = true
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::TestTask.new("spec:integration") do |spec|
|
14
|
+
spec.libs.push "lib"
|
15
|
+
spec.libs.push "spec"
|
16
|
+
spec.test_files = FileList['spec/integration/**/*_spec.rb']
|
17
|
+
spec.warning = true
|
18
|
+
end
|
19
|
+
|
20
|
+
task :spec => "spec:unit"
|
21
|
+
task :default => :spec
|