intercom 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5ef9d6fa028f29130786bb4e260112ddbbce668
4
- data.tar.gz: 23112e23cdf9f44f20d4a55d20bf7070aae80385
3
+ metadata.gz: 3ecabc64ed0e6223bb4b5af895a49b6dee13fdb5
4
+ data.tar.gz: 98f56f0bd24d589be44195af2d8470b469adfdd2
5
5
  SHA512:
6
- metadata.gz: 3e1c851b4481a5a17faf27240766e94b0b92060d0758e079a7f04cac11a9eb1725710b3744149d263737903f0c805d8cdf405d95d7bab8e36106ebe25e814672
7
- data.tar.gz: ab37cc7e537610f7fb6748dab499b975a1926043aac9ba313c15a7f097db5aec8ecf6611458675bf7aa716527903d55cb5534227a1e2afd97d9f5bc6c0e49df7
6
+ metadata.gz: ab1db67838ece4aeb6456060bd27b68b7a3762b1840dd5bed9cbeddab2c542eb1dbed37c78a2a0ffd2245601d896a19aac1974b5e79739b0809e3e729bbfc015
7
+ data.tar.gz: 74252ee9ad4f610e86d5c37fda98e36911211ba353a14c212347a5d5bf0e54c08999239c21638e59c5f44726242ad9f8b9555875f828459ce2bd7b6f6c563156
data/README.md CHANGED
@@ -22,7 +22,7 @@ This version of the gem is compatible with `Ruby 2.1` and above.
22
22
 
23
23
  Using bundler:
24
24
 
25
- gem 'intercom', "~> 3.2.0"
25
+ gem 'intercom', "~> 3.3.0"
26
26
 
27
27
  ## Basic Usage
28
28
 
@@ -49,6 +49,8 @@ Resources this API supports:
49
49
  https://api.intercom.io/conversations
50
50
  https://api.intercom.io/messages
51
51
  https://api.intercom.io/subscriptions
52
+ https://api.intercom.io/jobs
53
+ https://api.intercom.io/bulk
52
54
 
53
55
  ### Examples
54
56
 
@@ -75,6 +77,14 @@ intercom.users.save(user)
75
77
  # Iterate over all users
76
78
  intercom.users.all.each {|user| puts %Q(#{user.email} - #{user.custom_attributes["average_monthly_spend"]}) }
77
79
  intercom.users.all.map {|user| user.email }
80
+
81
+ #Bulk operations.
82
+ # Submit bulk job, to create users
83
+ intercom.users.submit_bulk_job(create_items: [{user_id: 25, email: "alice@example.com"}, {user_id: 25, email: "bob@example.com"}])
84
+ # Submit bulk job, to delete users
85
+ intercom.users.submit_bulk_job(delete_items: [{user_id: 25, email: "alice@example.com"}, {user_id: 25, email: "bob@example.com"}])
86
+ # Submit bulk job, to add items to existing job
87
+ intercom.users.submit_bulk_job(create_items: [{user_id: 25, email: "alice@example.com"}], delete_items: [{user_id: 25, email: "bob@example.com"}], job_id:'job_abcd1234')
78
88
  ```
79
89
 
80
90
  #### Admins
@@ -286,6 +296,8 @@ intercom.events.create(
286
296
  "found_date" => 12909364407
287
297
  }
288
298
  )
299
+
300
+
289
301
  ```
290
302
 
291
303
  Metadata Objects support a few simple types that Intercom can present on your behalf
@@ -316,6 +328,54 @@ The metadata key values in the example are treated as follows-
316
328
 
317
329
  *NB:* This version of the gem reserves the field name `type` in Event data.
318
330
 
331
+ Bulk operations.
332
+ ```ruby
333
+ # Submit bulk job, to create events
334
+ intercom.events.submit_bulk_job(create_items: [
335
+ {
336
+ event_name: "ordered-item",
337
+ created_at: 1438944980,
338
+ user_id: "314159",
339
+ metadata: {
340
+ order_date: 1438944980,
341
+ stripe_invoice: "inv_3434343434"
342
+ }
343
+ },
344
+ {
345
+ event_name: "invited-friend",
346
+ created_at: 1438944979,
347
+ user_id: "314159",
348
+ metadata: {
349
+ invitee_email: "pi@example.org",
350
+ invite_code: "ADDAFRIEND"
351
+ }
352
+ }
353
+ ])
354
+
355
+
356
+ # Submit bulk job, to add items to existing job
357
+ intercom.events.submit_bulk_job(create_items: [
358
+ {
359
+ event_name: "ordered-item",
360
+ created_at: 1438944980,
361
+ user_id: "314159",
362
+ metadata: {
363
+ order_date: 1438944980,
364
+ stripe_invoice: "inv_3434343434"
365
+ }
366
+ },
367
+ {
368
+ event_name: "invited-friend",
369
+ created_at: 1438944979,
370
+ user_id: "314159",
371
+ metadata: {
372
+ invitee_email: "pi@example.org",
373
+ invite_code: "ADDAFRIEND"
374
+ }
375
+ }
376
+ ], job_id:'job_abcd1234')
377
+ ```
378
+
319
379
  ### Contacts
320
380
 
321
381
  `Contacts` represent logged out users of your application.
@@ -362,8 +422,20 @@ intercom.subscriptions.find(:id => "nsub_123456789")
362
422
  # list subscriptions
363
423
  intercom.subscriptions.all
364
424
  ```
425
+ ### Bulk jobs
426
+
427
+ ```ruby
428
+ # fetch a job
429
+ intercom.jobs.find(id: 'job_abcd1234')
430
+
431
+ # fetch a job's error feed
432
+ intercom.jobs.errors(id: 'job_abcd1234')
433
+ ```
365
434
 
366
435
  ### Errors
436
+
437
+ There are different styles for error handling - some people prefer exceptions; some prefer nil and check; some prefer error objects/codes. Balancing these preferences alongside our wish to provide an idiomatic gem has brought us to use the current mechanism of throwing specific exceptions. Our approach in the client is to propagate errors and signal our failure loudly so that erroneous data does not get propagated through our customers' systems - in other words, if you see a `Intercom::ServiceUnavailableError` you know where the problem is.
438
+
367
439
  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.
368
440
 
369
441
  The list of different error subclasses are listed below. As they all inherit off Intercom::IntercomError you can choose to rescue Intercom::IntercomError or
@@ -1,3 +1,6 @@
1
+ 3.3.0
2
+ - Add Bulk API support
3
+
1
4
  3.2.0
2
5
  - Add attachment support for conversations
3
6
  - Fix puts'ing api resources
@@ -7,6 +7,7 @@ require 'intercom/service/count'
7
7
  require 'intercom/service/event'
8
8
  require 'intercom/service/message'
9
9
  require 'intercom/service/note'
10
+ require 'intercom/service/job'
10
11
  require 'intercom/service/subscription'
11
12
  require 'intercom/service/segment'
12
13
  require 'intercom/service/tag'
@@ -18,6 +19,7 @@ require "intercom/count"
18
19
  require "intercom/user"
19
20
  require "intercom/company"
20
21
  require "intercom/note"
22
+ require "intercom/job"
21
23
  require "intercom/tag"
22
24
  require "intercom/segment"
23
25
  require "intercom/event"
@@ -0,0 +1,13 @@
1
+ module Intercom
2
+ module ApiOperations
3
+ module Bulk
4
+ module LoadErrorFeed
5
+ def errors(params)
6
+ response = @client.get("/jobs/#{params.fetch(:id)}/error", {})
7
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
8
+ from_api(response)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module Intercom
2
+ module ApiOperations
3
+ module Bulk
4
+ module Submit
5
+ def submit_bulk_job(params)
6
+ raise(ArgumentError, "events do not support bulk delete operations") if collection_class == Intercom::Event && !params.fetch(:delete_items, []).empty?
7
+ data_type = Utils.resource_class_to_singular_name(collection_class)
8
+ collection_name = Utils.resource_class_to_collection_name(collection_class)
9
+ create_items = params.fetch(:create_items, []).map { |item| item_for_api("post", data_type, item) }
10
+ delete_items = params.fetch(:delete_items, []).map { |item| item_for_api("delete", data_type, item) }
11
+ existing_job_id = params.fetch(:job_id, '')
12
+
13
+ bulk_request = {
14
+ items: create_items + delete_items
15
+ }
16
+ bulk_request[:job] = { id: existing_job_id } unless existing_job_id.empty?
17
+
18
+ response = @client.post("/bulk/#{collection_name}", bulk_request)
19
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
20
+ Intercom::Job.new.from_response(response)
21
+ end
22
+
23
+ private
24
+
25
+ def item_for_api(method, data_type, item)
26
+ {
27
+ method: method,
28
+ data_type: data_type,
29
+ data: item
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -68,6 +68,10 @@ module Intercom
68
68
  Intercom::Service::User.new(self)
69
69
  end
70
70
 
71
+ def jobs
72
+ Intercom::Service::Job.new(self)
73
+ end
74
+
71
75
  def get(path, params)
72
76
  execute_request Intercom::Request.get(path, params)
73
77
  end
@@ -0,0 +1,7 @@
1
+ require 'intercom/traits/api_resource'
2
+
3
+ module Intercom
4
+ class Job
5
+ include Traits::ApiResource
6
+ end
7
+ end
@@ -45,8 +45,8 @@ module Intercom
45
45
  end
46
46
 
47
47
  def trying_to_access_print_method?
48
- [:to_ary, :to_s].include? method_sym
49
- end
48
+ [:to_ary, :to_s].include? method_sym
49
+ end
50
50
 
51
51
  def attribute_not_set_error_message
52
52
  "'#{method_string}' called on #{klass} but it has not been set an " +
@@ -1,10 +1,12 @@
1
1
  require 'intercom/service/base_service'
2
2
  require 'intercom/api_operations/save'
3
+ require 'intercom/api_operations/bulk/submit'
3
4
 
4
5
  module Intercom
5
6
  module Service
6
7
  class Event < BaseService
7
8
  include ApiOperations::Save
9
+ include ApiOperations::Bulk::Submit
8
10
 
9
11
  def collection_class
10
12
  Intercom::Event
@@ -0,0 +1,24 @@
1
+ require 'intercom/service/base_service'
2
+ require 'intercom/api_operations/list'
3
+ require 'intercom/api_operations/find_all'
4
+ require 'intercom/api_operations/find'
5
+ require 'intercom/api_operations/load'
6
+ require 'intercom/api_operations/save'
7
+ require 'intercom/api_operations/bulk/load_error_feed'
8
+
9
+ module Intercom
10
+ module Service
11
+ class Job < BaseService
12
+ include ApiOperations::Save
13
+ include ApiOperations::List
14
+ include ApiOperations::FindAll
15
+ include ApiOperations::Find
16
+ include ApiOperations::Load
17
+ include ApiOperations::Bulk::LoadErrorFeed
18
+
19
+ def collection_class
20
+ Intercom::Job
21
+ end
22
+ end
23
+ end
24
+ end
@@ -5,6 +5,7 @@ require 'intercom/api_operations/find'
5
5
  require 'intercom/api_operations/find_all'
6
6
  require 'intercom/api_operations/save'
7
7
  require 'intercom/api_operations/delete'
8
+ require 'intercom/api_operations/bulk/submit'
8
9
  require 'intercom/extended_api_operations/tags'
9
10
  require 'intercom/extended_api_operations/segments'
10
11
 
@@ -17,6 +18,7 @@ module Intercom
17
18
  include ApiOperations::FindAll
18
19
  include ApiOperations::Save
19
20
  include ApiOperations::Delete
21
+ include ApiOperations::Bulk::Submit
20
22
  include ExtendedApiOperations::Tags
21
23
  include ExtendedApiOperations::Segments
22
24
 
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.2.0"
2
+ VERSION = "3.3.0"
3
3
  end
@@ -23,4 +23,105 @@ describe "Intercom::Event" do
23
23
  client.events.create(:event_name => "sale of item", :email => 'joe@example.com')
24
24
  end
25
25
 
26
+ describe 'bulk operations' do
27
+ let (:job) {
28
+ {
29
+ "app_id"=>"app_id",
30
+ "id"=>"super_awesome_job",
31
+ "created_at"=>1446033421,
32
+ "completed_at"=>1446048736,
33
+ "closing_at"=>1446034321,
34
+ "updated_at"=>1446048736,
35
+ "name"=>"api_bulk_job",
36
+ "state"=>"completed",
37
+ "links"=>
38
+ {
39
+ "error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
40
+ "self"=>"https://api.intercom.io/jobs/super_awesome_job"
41
+ },
42
+ "tasks"=>
43
+ [
44
+ {
45
+ "id"=>"super_awesome_task",
46
+ "item_count"=>2,
47
+ "created_at"=>1446033421,
48
+ "started_at"=>1446033709,
49
+ "completed_at"=>1446033709,
50
+ "state"=>"completed"
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ let(:bulk_request) {
56
+ {
57
+ items: [
58
+ {
59
+ method: "post",
60
+ data_type: "event",
61
+ data:{
62
+ event_name: "ordered-item",
63
+ created_at: 1438944980,
64
+ user_id: "314159",
65
+ metadata: {
66
+ order_date: 1438944980,
67
+ stripe_invoice: "inv_3434343434"
68
+ }
69
+ }
70
+ },
71
+ {
72
+ method: "post",
73
+ data_type: "event",
74
+ data:{
75
+ event_name: "invited-friend",
76
+ created_at: 1438944979,
77
+ user_id: "314159",
78
+ metadata: {
79
+ invitee_email: "pi@example.org",
80
+ invite_code: "ADDAFRIEND"
81
+ }
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ }
87
+ let(:events) {
88
+ [
89
+ {
90
+ event_name: "ordered-item",
91
+ created_at: 1438944980,
92
+ user_id: "314159",
93
+ metadata: {
94
+ order_date: 1438944980,
95
+ stripe_invoice: "inv_3434343434"
96
+ }
97
+ },
98
+ {
99
+ event_name: "invited-friend",
100
+ created_at: 1438944979,
101
+ user_id: "314159",
102
+ metadata: {
103
+ invitee_email: "pi@example.org",
104
+ invite_code: "ADDAFRIEND"
105
+ }
106
+ }
107
+ ]
108
+ }
109
+
110
+ it "submits a bulk job" do
111
+ client.expects(:post).with("/bulk/events", bulk_request).returns(job)
112
+ client.events.submit_bulk_job(create_items: events)
113
+ end
114
+
115
+ it "adds events to an existing bulk job" do
116
+ bulk_request[:job] = {id: 'super_awesome_job'}
117
+ client.expects(:post).with("/bulk/events", bulk_request).returns(job)
118
+ client.events.submit_bulk_job(create_items: events, job_id: 'super_awesome_job')
119
+ end
120
+
121
+ it "does not submit delete jobs" do
122
+ lambda { client.events.submit_bulk_job(delete_items: events) }.must_raise ArgumentError
123
+ end
124
+
125
+ end
126
+
26
127
  end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe "jobs" do
4
+ let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
5
+ let (:job) {
6
+ {
7
+ "app_id"=>"app_id",
8
+ "id"=>"super_awesome_job",
9
+ "created_at"=>1446033421,
10
+ "completed_at"=>1446048736,
11
+ "closing_at"=>1446034321,
12
+ "updated_at"=>1446048736,
13
+ "name"=>"api_bulk_job",
14
+ "state"=>"completed",
15
+ "links"=>
16
+ {
17
+ "error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
18
+ "self"=>"https://api.intercom.io/jobs/super_awesome_job"
19
+ },
20
+ "tasks"=>
21
+ [
22
+ {
23
+ "id"=>"super_awesome_task",
24
+ "item_count"=>2,
25
+ "created_at"=>1446033421,
26
+ "started_at"=>1446033709,
27
+ "completed_at"=>1446033709,
28
+ "state"=>"completed"
29
+ }
30
+ ]
31
+ }
32
+ }
33
+ let (:error_feed) {
34
+ {
35
+ "app_id"=>"app_id",
36
+ "job_id"=>"super_awesome_job",
37
+ "pages"=>{},
38
+ "items"=>[]
39
+ }
40
+ }
41
+
42
+ it 'gets a job' do
43
+ client.expects(:get).with("/jobs/super_awesome_job", {}).returns(job)
44
+ client.jobs.find(id: 'super_awesome_job')
45
+ end
46
+
47
+ it 'gets a job\'s error feed' do
48
+ client.expects(:get).with("/jobs/super_awesome_job/error", {}).returns(error_feed)
49
+ client.jobs.errors(id: 'super_awesome_job')
50
+ end
51
+ end
@@ -242,4 +242,85 @@ describe "Intercom::User" do
242
242
  p user
243
243
  end
244
244
 
245
+ describe 'bulk operations' do
246
+ let (:job) {
247
+ {
248
+ "app_id"=>"app_id",
249
+ "id"=>"super_awesome_job",
250
+ "created_at"=>1446033421,
251
+ "completed_at"=>1446048736,
252
+ "closing_at"=>1446034321,
253
+ "updated_at"=>1446048736,
254
+ "name"=>"api_bulk_job",
255
+ "state"=>"completed",
256
+ "links"=>
257
+ {
258
+ "error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
259
+ "self"=>"https://api.intercom.io/jobs/super_awesome_job"
260
+ },
261
+ "tasks"=>
262
+ [
263
+ {
264
+ "id"=>"super_awesome_task",
265
+ "item_count"=>2,
266
+ "created_at"=>1446033421,
267
+ "started_at"=>1446033709,
268
+ "completed_at"=>1446033709,
269
+ "state"=>"completed"
270
+ }
271
+ ]
272
+ }
273
+ }
274
+ let(:bulk_request) {
275
+ {
276
+ items: [
277
+ {
278
+ method: "post",
279
+ data_type: "user",
280
+ data:{
281
+ user_id: 25,
282
+ email: "alice@example.com"
283
+ }
284
+ },
285
+ {
286
+ method: "delete",
287
+ data_type: "user",
288
+ data:{
289
+ user_id: 26,
290
+ email: "bob@example.com"
291
+ }
292
+ }
293
+ ]
294
+ }
295
+ }
296
+ let(:users_to_create) {
297
+ [
298
+ {
299
+ user_id: 25,
300
+ email: "alice@example.com"
301
+ }
302
+ ]
303
+ }
304
+ let(:users_to_delete) {
305
+ [
306
+ {
307
+ user_id: 26,
308
+ email: "bob@example.com"
309
+ }
310
+ ]
311
+ }
312
+
313
+ it "submits a bulk job" do
314
+ client.expects(:post).with("/bulk/users", bulk_request).returns(job)
315
+ client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete)
316
+ end
317
+
318
+ it "adds users to an existing bulk job" do
319
+ bulk_request[:job] = {id: 'super_awesome_job'}
320
+ client.expects(:post).with("/bulk/users", bulk_request).returns(job)
321
+ client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete, job_id: 'super_awesome_job')
322
+ end
323
+
324
+ end
325
+
245
326
  end
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: 3.2.0
4
+ version: 3.3.0
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: 2015-09-16 00:00:00.000000000 Z
18
+ date: 2015-12-10 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -129,6 +129,8 @@ files:
129
129
  - lib/ext/sliceable_hash.rb
130
130
  - lib/intercom.rb
131
131
  - lib/intercom/admin.rb
132
+ - lib/intercom/api_operations/bulk/load_error_feed.rb
133
+ - lib/intercom/api_operations/bulk/submit.rb
132
134
  - lib/intercom/api_operations/convert.rb
133
135
  - lib/intercom/api_operations/delete.rb
134
136
  - lib/intercom/api_operations/find.rb
@@ -147,6 +149,7 @@ files:
147
149
  - lib/intercom/extended_api_operations/segments.rb
148
150
  - lib/intercom/extended_api_operations/tags.rb
149
151
  - lib/intercom/extended_api_operations/users.rb
152
+ - lib/intercom/job.rb
150
153
  - lib/intercom/lib/dynamic_accessors.rb
151
154
  - lib/intercom/lib/dynamic_accessors_on_method_missing.rb
152
155
  - lib/intercom/lib/flat_store.rb
@@ -163,6 +166,7 @@ files:
163
166
  - lib/intercom/service/conversation.rb
164
167
  - lib/intercom/service/count.rb
165
168
  - lib/intercom/service/event.rb
169
+ - lib/intercom/service/job.rb
166
170
  - lib/intercom/service/message.rb
167
171
  - lib/intercom/service/note.rb
168
172
  - lib/intercom/service/segment.rb
@@ -186,6 +190,7 @@ files:
186
190
  - spec/unit/intercom/conversation_spec.rb
187
191
  - spec/unit/intercom/count_spec.rb
188
192
  - spec/unit/intercom/event_spec.rb
193
+ - spec/unit/intercom/job_spec.rb
189
194
  - spec/unit/intercom/lib/flat_store_spec.rb
190
195
  - spec/unit/intercom/message_spec.rb
191
196
  - spec/unit/intercom/note_spec.rb
@@ -216,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
221
  version: '0'
217
222
  requirements: []
218
223
  rubyforge_project: intercom
219
- rubygems_version: 2.2.2
224
+ rubygems_version: 2.2.3
220
225
  signing_key:
221
226
  specification_version: 4
222
227
  summary: Ruby bindings for the Intercom API
@@ -230,6 +235,7 @@ test_files:
230
235
  - spec/unit/intercom/conversation_spec.rb
231
236
  - spec/unit/intercom/count_spec.rb
232
237
  - spec/unit/intercom/event_spec.rb
238
+ - spec/unit/intercom/job_spec.rb
233
239
  - spec/unit/intercom/lib/flat_store_spec.rb
234
240
  - spec/unit/intercom/message_spec.rb
235
241
  - spec/unit/intercom/note_spec.rb
@@ -240,4 +246,3 @@ test_files:
240
246
  - spec/unit/intercom/traits/api_resource_spec.rb
241
247
  - spec/unit/intercom/user_spec.rb
242
248
  - spec/unit/intercom_spec.rb
243
- has_rdoc: