intercom 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -8
- data/Gemfile +3 -0
- data/README.md +208 -52
- data/changes.txt +3 -0
- data/intercom.gemspec +2 -2
- data/lib/ext/hash.rb +18 -0
- data/lib/intercom.rb +38 -43
- 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 +22 -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 +15 -0
- data/lib/intercom/api_operations/save.rb +44 -0
- data/lib/intercom/collection_proxy.rb +66 -0
- data/lib/intercom/company.rb +29 -0
- data/lib/intercom/conversation.rb +15 -0
- data/lib/intercom/count.rb +21 -0
- data/lib/intercom/errors.rb +52 -0
- data/lib/intercom/event.rb +4 -101
- 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 +52 -0
- data/lib/intercom/message.rb +9 -0
- data/lib/intercom/note.rb +14 -42
- data/lib/intercom/request.rb +40 -4
- data/lib/intercom/segment.rb +14 -0
- data/lib/intercom/tag.rb +19 -78
- data/lib/intercom/traits/api_resource.rb +120 -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 +23 -0
- data/lib/intercom/user.rb +25 -361
- data/lib/intercom/utils.rb +50 -0
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +64 -33
- data/spec/unit/intercom/collection_proxy_spec.rb +34 -0
- data/spec/unit/intercom/event_spec.rb +25 -0
- data/spec/unit/intercom/{flat_store_spec.rb → lib/flat_store_spec.rb} +7 -7
- data/spec/unit/intercom/note_spec.rb +5 -4
- data/spec/unit/intercom/tag_spec.rb +3 -3
- data/spec/unit/intercom/traits/api_resource_spec.rb +79 -0
- data/spec/unit/intercom/user_spec.rb +101 -119
- data/spec/unit/intercom_spec.rb +7 -7
- metadata +50 -26
- data/lib/intercom/flat_store.rb +0 -27
- data/lib/intercom/hashable_object.rb +0 -22
- data/lib/intercom/impression.rb +0 -63
- data/lib/intercom/message_thread.rb +0 -189
- data/lib/intercom/requires_parameters.rb +0 -10
- data/lib/intercom/social_profile.rb +0 -24
- data/lib/intercom/unix_timestamp_unwrapper.rb +0 -12
- data/lib/intercom/user_collection_proxy.rb +0 -52
- data/lib/intercom/user_resource.rb +0 -82
- data/spec/integration/fixtures/v1-user.json +0 -45
- data/spec/integration/fixtures/v1-users-impression.json +0 -3
- data/spec/integration/fixtures/v1-users-message_thread.json +0 -44
- data/spec/integration/fixtures/v1-users-message_threads.json +0 -46
- data/spec/integration/fixtures/v1-users-note.json +0 -49
- data/spec/integration/fixtures/v1-users.json +0 -144
- data/spec/integration/intercom_api_integration_spec.rb +0 -134
- data/spec/unit/intercom/impression_spec.rb +0 -18
- data/spec/unit/intercom/message_thread_spec.rb +0 -74
- data/spec/unit/intercom/user_collection_proxy_spec.rb +0 -46
- data/spec/unit/intercom/user_event_spec.rb +0 -83
- data/spec/unit/intercom/user_resource_spec.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d0a3f10338e77b6c5f8e60e17ee6de1114a340
|
4
|
+
data.tar.gz: f6727eea4a0bcc322852e3b0ea412a02e287f3e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 873daa77201675582588235753bf341518ffb3df63eb994fb5e64aac6b43cad2b3e99c13ab865b0506f242402ba0bd87e534d641796924a6cb0eb972e27880a2
|
7
|
+
data.tar.gz: e3bd531c5f11afe27a1df6e0efc9289edf20e34a2b8625821a8635637845574da24994b955b3622634d10fef03332a6e0b74e20d2ee74f580a5a249547cf8fe3
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,13 +8,16 @@ Ruby bindings for the Intercom API (https://api.intercom.io).
|
|
8
8
|
|
9
9
|
For generating Intercom javascript script tags for Rails, please see https://github.com/intercom/intercom-rails
|
10
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
|
+
|
11
14
|
## Installation
|
12
15
|
|
13
16
|
gem install intercom
|
14
17
|
|
15
18
|
Using bundler:
|
16
19
|
|
17
|
-
gem 'intercom'
|
20
|
+
gem 'intercom', "~> 2.0"
|
18
21
|
|
19
22
|
## Basic Usage
|
20
23
|
|
@@ -22,104 +25,249 @@ Using bundler:
|
|
22
25
|
|
23
26
|
```ruby
|
24
27
|
Intercom.app_id = "my_app_id"
|
25
|
-
Intercom.
|
28
|
+
Intercom.app_api_key = "my-super-crazy-api-key"
|
26
29
|
```
|
27
30
|
|
28
31
|
### Resources
|
29
32
|
|
30
|
-
|
33
|
+
Resources this API supports:
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
https://api.intercom.io/users
|
36
|
+
https://api.intercom.io/companies
|
37
|
+
https://api.intercom.io/tags
|
38
|
+
https://api.intercom.io/notes
|
39
|
+
https://api.intercom.io/segments
|
40
|
+
https://api.intercom.io/events
|
41
|
+
https://api.intercom.io/conversations
|
42
|
+
https://api.intercom.io/messages
|
43
|
+
https://api.intercom.io/counts
|
36
44
|
|
37
45
|
### Examples
|
38
46
|
|
39
47
|
#### Users
|
40
48
|
|
41
49
|
```ruby
|
42
|
-
user
|
43
|
-
user
|
44
|
-
user
|
45
|
-
user = Intercom::User.
|
50
|
+
# Find user by email
|
51
|
+
user = Intercom::User.find(:email => "bob@example.com")
|
52
|
+
# Find user by user_id
|
53
|
+
user = Intercom::User.find(:user_id => "1")
|
54
|
+
# Find user by id
|
55
|
+
user = Intercom::User.find(:id => "1")
|
56
|
+
# Create a user
|
46
57
|
user = Intercom::User.create(:email => "bob@example.com", :name => "Bob Smith")
|
47
|
-
|
48
|
-
user.save
|
49
|
-
|
50
|
-
|
58
|
+
# Update custom_attributes for a user
|
59
|
+
user.custom_attributes["average_monthly_spend"] = 1234.56; user.save
|
60
|
+
# Perform incrementing
|
61
|
+
user.increment('karma'); user.save
|
62
|
+
# Iterate over all users
|
63
|
+
Intercom::User.all.each {|user| puts %Q(#{user.email} - #{user.custom_attributes["average_monthly_spend"]}) }
|
51
64
|
Intercom::User.all.map {|user| user.email }
|
52
65
|
```
|
53
66
|
|
54
67
|
#### Companies
|
55
68
|
```ruby
|
56
|
-
user
|
57
|
-
user
|
58
|
-
user.companies = [{:
|
69
|
+
# Add a user to one or more companies
|
70
|
+
user = Intercom::User.find(:email => "bob@example.com")
|
71
|
+
user.companies = [{:company_id => 6, :name => "Intercom"}, {:company_id => 9, :name => "Test Company"}]; user.save
|
72
|
+
# You can also pass custom attributes within a company as you do this
|
73
|
+
user.companies = [{:id => 6, :name => "Intercom", :custom_attributes => {:referral_source => "Google"} } ]; user.save
|
74
|
+
# Find a company by company_id
|
75
|
+
company = Intercom::Company.find(:company_id => "44")
|
76
|
+
# Find a company by name
|
77
|
+
company = Intercom::Company.find(:name => "Some company")
|
78
|
+
# Find a company by id
|
79
|
+
company = Intercom::Company.find(:id => "41e66f0313708347cb0000d0")
|
80
|
+
# Update a company
|
81
|
+
company.name = 'Updated company name'; company.save
|
82
|
+
# Iterate over all companies
|
83
|
+
Intercom::Company.all.each {|company| puts %Q(#{company.name} - #{company.custom_attributes["referral_source"]}) }
|
84
|
+
Intercom::Company.all.map {|company| company.name }
|
85
|
+
# Get a list of users in a company
|
86
|
+
company.users
|
59
87
|
```
|
60
88
|
|
61
|
-
|
89
|
+
#### Tags
|
90
|
+
```ruby
|
91
|
+
# Tag users
|
92
|
+
tag = Intercom::Tag.tag_users('blue', ["42ea2f1b93891f6a99000427"])
|
93
|
+
# Untag users
|
94
|
+
Intercom::Tag.untag_users('blue', ["42ea2f1b93891f6a99000427"])
|
95
|
+
# Iterate over all tags
|
96
|
+
Intercom::Tag.all.each {|tag| "#{tag.id} - #{tag.name}" }
|
97
|
+
Intercom::Tag.all.map {|tag| tag.name }
|
98
|
+
# Iterate over all tags for user
|
99
|
+
Intercom::Tag.find_all_for_user(:id => '53357ddc3c776629e0000029')
|
100
|
+
Intercom::Tag.find_all_for_user(:email => 'declan+declan@intercom.io')
|
101
|
+
Intercom::Tag.find_all_for_user(:user_id => '3')
|
102
|
+
# Tag companies
|
103
|
+
tag = Intercom::Tag.tag_companies('red', ["42ea2f1b93891f6a99000427"])
|
104
|
+
# Untag companies
|
105
|
+
Intercom::Tag.untag_users('blue', ["42ea2f1b93891f6a99000427"])
|
106
|
+
# Iterate over all tags for company
|
107
|
+
Intercom::Tag.find_all_for_company(:id => '43357e2c3c77661e25000026')
|
108
|
+
Intercom::Tag.find_all_for_company(:company_id => '6')
|
109
|
+
```
|
62
110
|
|
111
|
+
#### Segments
|
63
112
|
```ruby
|
64
|
-
|
113
|
+
# Find a segment
|
114
|
+
segment = Intercom::Segment.find(:id => segment_id)
|
115
|
+
# Update a segment
|
116
|
+
segment.name = 'Updated name'; segment.save
|
117
|
+
# Iterate over all segments
|
118
|
+
Intercom::Segment.all.each {|segment| puts "id: #{segment.id} name: #{segment.name}"}
|
65
119
|
```
|
66
120
|
|
67
|
-
####
|
121
|
+
#### Notes
|
68
122
|
```ruby
|
69
|
-
|
70
|
-
Intercom::
|
71
|
-
|
72
|
-
Intercom::
|
123
|
+
# Find a note by id
|
124
|
+
note = Intercom::Note.find(:id => note)
|
125
|
+
# Create a note for a user
|
126
|
+
note = Intercom::Note.create(:body => "<p>Text for the note</p>", :email => 'joe@example.com')
|
127
|
+
# Iterate over all notes for a user via their email address
|
128
|
+
Intercom::Note.find_all(:email => 'joe@example.com').each {|note| puts note.body}
|
129
|
+
# Iterate over all notes for a user via their user_id
|
130
|
+
Intercom::Note.find_all(:user_id => '123').each {|note| puts note.body}
|
73
131
|
```
|
74
132
|
|
75
|
-
####
|
133
|
+
#### Conversations
|
76
134
|
```ruby
|
77
|
-
|
135
|
+
# FINDING CONVERSATIONS FOR AN ADMIN
|
136
|
+
# Iterate over all conversations (open and closed) assigned to an admin
|
137
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => '7').each do {|convo| ... }
|
138
|
+
# Iterate over all open conversations assigned to an admin
|
139
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => true).each do {|convo| ... }
|
140
|
+
# Iterate over closed conversations assigned to an admin
|
141
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => false).each do {|convo| ... }
|
142
|
+
# Iterate over closed conversations for assigned an admin, before a certain moment in time
|
143
|
+
Intercom::Conversation.find_all(:type => 'admin', :id => 7, :open => false, :before => 1374844930).each do {|convo| ... }
|
144
|
+
|
145
|
+
# FINDING CONVERSATIONS FOR A USER
|
146
|
+
# Iterate over all conversations (read + unread, correct) with a user based on the users email
|
147
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user').each do {|convo| ... }
|
148
|
+
# Iterate over through all conversations (read + unread) with a user based on the users email
|
149
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user', :unread => false).each do {|convo| ... }
|
150
|
+
# Iterate over all unread conversations with a user based on the users email
|
151
|
+
Intercom::Conversation.find_all(:email => 'joe@example.com', :type => 'user', :unread => true).each do {|convo| ... }
|
152
|
+
|
153
|
+
# FINDING A SINGLE CONVERSATION
|
154
|
+
conversation = Intercom::Conversation.find(:id => '1')
|
155
|
+
|
156
|
+
# INTERACTING WITH THE PARTS OF A CONVERSATION
|
157
|
+
# Getting the subject of a part (only applies to email-based conversations)
|
158
|
+
conversation.rendered_message.subject
|
159
|
+
# Get the part_type of the first part
|
160
|
+
conversation.conversation_parts[0].part_type
|
161
|
+
# Get the body of the second part
|
162
|
+
conversation.conversation_parts[1].body
|
163
|
+
|
164
|
+
# REPLYING TO CONVERSATIONS
|
165
|
+
# User (identified by email) replies with a comment
|
166
|
+
conversation.reply(:type => 'user', :email => 'joe@example.com', :message_type => 'comment', :body => 'foo')
|
167
|
+
# Admin (identified by email) replies with a comment
|
168
|
+
conversation.reply(:type => 'admin', :email => 'bob@example.com', :message_type => 'comment', :body => 'bar')
|
78
169
|
```
|
79
170
|
|
80
|
-
####
|
171
|
+
#### Counts
|
81
172
|
```ruby
|
82
|
-
|
173
|
+
# Get Conversation per Admin
|
174
|
+
conversation_counts_for_each_admin = Intercom::Count.conversation_counts_for_each_admin
|
175
|
+
conversation_counts_for_each_admin.each{|count| puts "Admin: #{count.name} (id: #{count.id}) Open: #{count.open} Closed: #{count.closed}" }
|
176
|
+
# Get User Tag Count Object
|
177
|
+
Intercom::Count.user_counts_for_each_tag
|
178
|
+
# Get User Segment Count Object
|
179
|
+
Intercom::Count.user_counts_for_each_segment
|
180
|
+
# Get Company Segment Count Object
|
181
|
+
Intercom::Count.company_counts_for_each_segment
|
182
|
+
# Get Company Tag Count Object
|
183
|
+
Intercom::Count.company_counts_for_each_tag
|
184
|
+
# Get Company User Count Object
|
185
|
+
Intercom::Count.company_counts_for_each_user
|
186
|
+
# Get total count of companies, users, segments or tags across app
|
187
|
+
Intercom::Company.count
|
188
|
+
Intercom::User.count
|
189
|
+
Intercom::Segment.count
|
190
|
+
Intercom::Tag.count
|
83
191
|
```
|
84
192
|
|
85
|
-
####
|
86
|
-
The simplest way to create an event is directly on the user
|
193
|
+
#### Full loading of and embedded entity
|
87
194
|
```ruby
|
88
|
-
user
|
89
|
-
user.
|
195
|
+
# Given a converation with a partial user, load the full user. This can be done for any entity
|
196
|
+
conversation.user.load
|
90
197
|
```
|
91
198
|
|
92
|
-
|
199
|
+
#### Sending messages
|
93
200
|
```ruby
|
94
|
-
Intercom::Event.create(:event_name => "invited-friend", :user => user)
|
95
201
|
|
96
|
-
#
|
97
|
-
Intercom::
|
202
|
+
# InApp message from admin to user
|
203
|
+
Intercom::Message.create({
|
204
|
+
:message_type => 'inapp',
|
205
|
+
:body => "What's up :)",
|
206
|
+
:from => {
|
207
|
+
:type => 'admin',
|
208
|
+
:id => "1234"
|
209
|
+
},
|
210
|
+
:to => {
|
211
|
+
:type => :user,
|
212
|
+
:id => "5678"
|
213
|
+
}
|
214
|
+
})
|
98
215
|
|
99
|
-
#
|
100
|
-
Intercom::
|
101
|
-
|
102
|
-
|
103
|
-
|
216
|
+
# Email message from admin to user
|
217
|
+
Intercom::Message.create({
|
218
|
+
:message_type => 'email',
|
219
|
+
:subject => 'Hey there',
|
220
|
+
:body => "What's up :)",
|
221
|
+
:template => "plain", # or "personal",
|
222
|
+
:from => {
|
223
|
+
:type => "admin",
|
224
|
+
:id => "1234"
|
225
|
+
},
|
226
|
+
:to => {
|
227
|
+
:type => "user",
|
228
|
+
:id => "536e564f316c83104c000020"
|
229
|
+
}
|
230
|
+
})
|
231
|
+
|
232
|
+
# Message from a user
|
233
|
+
Intercom::Message.create({
|
234
|
+
:from => {
|
235
|
+
:type => "user",
|
236
|
+
:id => "536e564f316c83104c000020"
|
237
|
+
},
|
238
|
+
:body => "halp"
|
239
|
+
})
|
240
|
+
```
|
241
|
+
|
242
|
+
#### Events
|
243
|
+
```ruby
|
244
|
+
Intercom::Event.create(
|
245
|
+
:event_name => "invited-friend", :created_at => Time.now.to_i,
|
246
|
+
:email => user.email,
|
247
|
+
:metadata => {
|
248
|
+
"invitee_email" => "pi@example.org",
|
249
|
+
:invite_code => "ADDAFRIEND",
|
250
|
+
"found_date" => 12909364407
|
104
251
|
}
|
105
252
|
)
|
106
253
|
```
|
107
254
|
|
108
|
-
Metadata Objects support a few simple types that Intercom can present on your behalf
|
255
|
+
Metadata Objects support a few simple types that Intercom can present on your behalf
|
109
256
|
|
110
257
|
```ruby
|
111
|
-
Intercom::Event.create(:event_name => "placed-order", :
|
112
|
-
|
258
|
+
Intercom::Event.create(:event_name => "placed-order", :email => current_user.email,
|
259
|
+
:created_at => 1403001013
|
260
|
+
:metadata => {
|
113
261
|
:order_date => Time.now.to_i,
|
114
|
-
:stripe_invoice => 'inv_3434343434',
|
115
|
-
:order_number => {
|
116
|
-
:value => '3434-3434',
|
117
|
-
:url => 'https://example.org/orders/3434-3434'
|
262
|
+
:stripe_invoice => 'inv_3434343434',
|
263
|
+
:order_number => {
|
264
|
+
:value => '3434-3434',
|
265
|
+
:url => 'https://example.org/orders/3434-3434'
|
118
266
|
},
|
119
|
-
price: {
|
267
|
+
price: {
|
120
268
|
:currency => 'usd',
|
121
|
-
:amount => 2999
|
122
|
-
}
|
269
|
+
:amount => 2999
|
270
|
+
}
|
123
271
|
}
|
124
272
|
)
|
125
273
|
```
|
@@ -131,9 +279,17 @@ The metadata key values in the example are treated as follows-
|
|
131
279
|
- price: An Amount in US Dollars (value contains 'amount' and 'currency' keys)
|
132
280
|
|
133
281
|
### Errors
|
282
|
+
You do not need to deal with the HTTP response from an API call directly. If there is an unsuccessful response then an error that is a subclass of Intercom:Error will be raised. If desired, you can get at the http_code of an Intercom::Error via it's `http_code` method.
|
283
|
+
|
284
|
+
The list of different error subclasses are listed below. As they all inherit off Intercom::Error you can choose to rescue Intercom::Error or
|
285
|
+
else rescue the more specific error subclass.
|
286
|
+
|
134
287
|
```ruby
|
135
288
|
Intercom::AuthenticationError
|
136
289
|
Intercom::ServerError
|
137
290
|
Intercom::ServiceUnavailableError
|
138
291
|
Intercom::ResourceNotFound
|
292
|
+
Intercom::BadRequestError
|
293
|
+
Intercom::RateLimitExceeded
|
294
|
+
Intercom::AttributeNotSetError # Raised when you try to call a getter that does not exist on an object
|
139
295
|
```
|
data/changes.txt
CHANGED
data/intercom.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "intercom/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "intercom"
|
8
8
|
spec.version = Intercom::VERSION
|
9
|
-
spec.authors = ["Ben McRedmond", "Ciaran Lee", "Darragh Curran", "Jeff Gardner", "Kyle Daigle", "Declan McGrath", "Jamie Osler"]
|
10
|
-
spec.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io", "jeff@intercom.io", "kyle@digitalworkbox.com", "declan@intercom.io", "jamie@intercom.io"]
|
9
|
+
spec.authors = ["Ben McRedmond", "Ciaran Lee", "Darragh Curran", "Jeff Gardner", "Kyle Daigle", "Declan McGrath", "Jamie Osler", "Bob Long"]
|
10
|
+
spec.email = ["ben@intercom.io", "ciaran@intercom.io", "darragh@intercom.io", "jeff@intercom.io", "kyle@digitalworkbox.com", "declan@intercom.io", "jamie@intercom.io", "bob@intercom.io"]
|
11
11
|
spec.homepage = "https://www.intercom.io"
|
12
12
|
spec.summary = %q{Ruby bindings for the Intercom API}
|
13
13
|
spec.description = %Q{Intercom (https://www.intercom.io) is a customer relationship management and messaging tool for web app owners. This library wraps the api provided by Intercom. See http://docs.intercom.io/api for more details. }
|
data/lib/ext/hash.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Hash
|
2
|
+
# Return a hash that includes everything but the given keys.
|
3
|
+
def except(*keys)
|
4
|
+
dup.except!(*keys)
|
5
|
+
end
|
6
|
+
|
7
|
+
# Replaces the hash without the given keys.
|
8
|
+
def except!(*keys)
|
9
|
+
keys.each { |key| delete(key) }
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return a hash that includes only the given keys.
|
14
|
+
def slice(*keys)
|
15
|
+
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
|
16
|
+
keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
|
17
|
+
end
|
18
|
+
end
|
data/lib/intercom.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require "intercom/version"
|
2
|
-
require "intercom/user_resource"
|
3
2
|
require "intercom/user"
|
4
|
-
require "intercom/
|
5
|
-
require "intercom/impression"
|
3
|
+
require "intercom/company"
|
6
4
|
require "intercom/note"
|
7
5
|
require "intercom/tag"
|
8
|
-
require "intercom/
|
6
|
+
require "intercom/segment"
|
9
7
|
require "intercom/event"
|
8
|
+
require "intercom/conversation"
|
9
|
+
require "intercom/message"
|
10
|
+
require "intercom/count"
|
11
|
+
require "intercom/request"
|
12
|
+
require "intercom/utils"
|
13
|
+
require "intercom/errors"
|
10
14
|
require "json"
|
11
15
|
|
12
16
|
##
|
@@ -17,23 +21,19 @@ require "json"
|
|
17
21
|
# == Basic Usage
|
18
22
|
# === Configure Intercom with your access credentials
|
19
23
|
# Intercom.app_id = "my_app_id"
|
20
|
-
# Intercom.
|
24
|
+
# Intercom.app_api_key = "my_api_key"
|
21
25
|
# === Make requests to the API
|
22
26
|
# Intercom::User.find(:email => "bob@example.com")
|
23
27
|
#
|
24
28
|
module Intercom
|
25
29
|
@hostname = "api.intercom.io"
|
26
30
|
@protocol = "https"
|
31
|
+
|
27
32
|
@endpoints = nil
|
28
33
|
@current_endpoint = nil
|
29
34
|
@app_id = nil
|
30
|
-
@
|
35
|
+
@app_api_key = nil
|
31
36
|
|
32
|
-
##
|
33
|
-
# Set the id of the application you want to interact with.
|
34
|
-
# When logged into your intercom console, the app_id is in the url after /apps (eg https://www.intercom.io/apps/<app-id>)
|
35
|
-
# @param [String] app_id
|
36
|
-
# @return [String]
|
37
37
|
def self.app_id=(app_id)
|
38
38
|
@app_id = app_id
|
39
39
|
end
|
@@ -42,27 +42,42 @@ module Intercom
|
|
42
42
|
@app_id
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
def self.api_key=(api_key)
|
51
|
-
@api_key = api_key
|
45
|
+
def self.app_api_key=(app_api_key)
|
46
|
+
@app_api_key = app_api_key
|
47
|
+
end
|
48
|
+
def self.app_api_key
|
49
|
+
@app_api_key
|
52
50
|
end
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
# This method is obsolete and used to warn of backwards incompatible changes on upgrading
|
53
|
+
def self.api_key=(val)
|
54
|
+
raise ArgumentError, "#{compatibility_warning_text} #{compatibility_workaround_text} #{related_docs_text}"
|
56
55
|
end
|
57
56
|
|
58
57
|
private
|
59
58
|
|
60
59
|
def self.target_base_url
|
61
|
-
raise ArgumentError, "
|
62
|
-
basic_auth_part = "#{@app_id}:#{@
|
60
|
+
raise ArgumentError, "#{configuration_required_text} #{related_docs_text}" if [@app_id, @app_api_key].any?(&:nil?)
|
61
|
+
basic_auth_part = "#{@app_id}:#{@app_api_key}@"
|
63
62
|
current_endpoint.gsub(/(https?:\/\/)(.*)/, "\\1#{basic_auth_part}\\2")
|
64
63
|
end
|
65
64
|
|
65
|
+
def self.related_docs_text
|
66
|
+
"See https://github.com/intercom/intercom-ruby for usage examples."
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.compatibility_warning_text
|
70
|
+
"It looks like you are upgrading from an older version of the intercom-ruby gem. Please note that this new version (#{Intercom::VERSION}) is not backwards compatible. "
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.compatibility_workaround_text
|
74
|
+
"To get rid of this error please set Intercom.app_api_key and don't set Intercom.api_key."
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.configuration_required_text
|
78
|
+
"You must set both Intercom.app_id and Intercom.app_api_key to use this client."
|
79
|
+
end
|
80
|
+
|
66
81
|
def self.send_request_to_path(request)
|
67
82
|
request.execute(target_base_url)
|
68
83
|
rescue Intercom::ServiceUnavailableError => e
|
@@ -144,24 +159,4 @@ module Intercom
|
|
144
159
|
@endpoints || ["#{@protocol}://#{hostname}"]
|
145
160
|
end
|
146
161
|
|
147
|
-
|
148
|
-
# Check that you have set <b>Intercom.app_id=</b> and <b>Intercom.api_key=</b> correctly.
|
149
|
-
class AuthenticationError < StandardError;
|
150
|
-
end
|
151
|
-
|
152
|
-
# Raised when something does wrong on within the Intercom API service.
|
153
|
-
class ServerError < StandardError;
|
154
|
-
end
|
155
|
-
|
156
|
-
# Raised when we have bad gateway errors.
|
157
|
-
class BadGatewayError < StandardError;
|
158
|
-
end
|
159
|
-
|
160
|
-
# Raised when we reach socket connect timeout
|
161
|
-
class ServiceUnavailableError < StandardError;
|
162
|
-
end
|
163
|
-
|
164
|
-
# Raised when requesting resources on behalf of a user that doesn't exist in your application on Intercom.
|
165
|
-
class ResourceNotFound < StandardError;
|
166
|
-
end
|
167
|
-
end
|
162
|
+
end
|