intercom 3.5.3 → 3.5.4

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: 2cb77431bc9d029fc727badd60a0ff01a015646d
4
- data.tar.gz: 4e29db4fae3a6d8451bd35fc4ab63fc3bf97d39c
3
+ metadata.gz: 65f8ee35be573105827b5e3b6241d07154e0a075
4
+ data.tar.gz: 5a61122d948cd69ea4d2b6ddade7ab6a614de8a5
5
5
  SHA512:
6
- metadata.gz: b2c07f366f514edbc42ca1fdfe75f568eda7b7b8cd1ba7737d29503474e875c98c01d2288df14d2ab6ad8f6557f77ade20bea102793a8487cfc64348fb607244
7
- data.tar.gz: 1d13a52bc103466aa225e0bda5426ff54b6294c6d5a303f302f84430732857f61ec6df572ba46d7b49a393fd804dace30b1bf9d0a8bb14eb6ca2948a56787b05
6
+ metadata.gz: 74f22fb60b9c7ac2b65eaa1921be6cb44a18c1862254ba961f3f6bb57187cfbf56f56c555e241ac7681a6cd79ef28f11329b5c9dc5c0a49368710bcfaad85df9
7
+ data.tar.gz: 4561b5bdf72b92be0a91eebd9ad049239d5682b5b37b4f3f93e41a3cd8a5faa3a861a2d9f51a3ecdb1924e24cedadcc2cf756ab69553eb3570deafa244257141
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.5.2"
25
+ gem 'intercom', "~> 3.5.3"
26
26
 
27
27
  ## Basic Usage
28
28
 
data/changes.txt CHANGED
@@ -1,3 +1,6 @@
1
+ 3.5.4
2
+ - Add support for scoll API feature
3
+
1
4
  3.5.3
2
5
  - Add support for global conversation counts
3
6
 
@@ -0,0 +1,16 @@
1
+ require 'intercom/scroll_collection_proxy'
2
+
3
+ module Intercom
4
+ module ApiOperations
5
+ module Scroll
6
+
7
+ def scroll()
8
+ collection_name = Utils.resource_class_to_collection_name(collection_class)
9
+ finder_details = {}
10
+ finder_details[:url] = "/#{collection_name}"
11
+ ScrollCollectionProxy.new(collection_name, finder_details: finder_details, client: @client)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,83 @@
1
+ require "intercom/utils"
2
+ require "ext/sliceable_hash"
3
+
4
+ module Intercom
5
+ class ScrollCollectionProxy
6
+
7
+ attr_reader :resource_name, :scroll_url, :resource_class, :scroll_param, :records
8
+
9
+ def initialize(resource_name, finder_details: {}, client:)
10
+ @resource_name = resource_name
11
+ @resource_class = Utils.constantize_resource_name(resource_name)
12
+ @scroll_url = (finder_details[:url] || "/#{@resource_name}") + '/scroll'
13
+ @client = client
14
+
15
+ end
16
+
17
+ def next(scroll_parameter=nil)
18
+ @records = []
19
+ if not scroll_parameter
20
+ #First time so do initial get without scroll_param
21
+ response_hash = @client.get(@scroll_url, '')
22
+ else
23
+ #Not first call so use get next page
24
+ response_hash = @client.get(@scroll_url, scroll_param: scroll_parameter)
25
+ end
26
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
27
+ @scroll_param = extract_scroll_param(response_hash)
28
+ top_level_entity_key = deserialize_response_hash(response_hash)
29
+ response_hash[top_level_entity_key] = response_hash[top_level_entity_key].map do |object_json|
30
+ Lib::TypedJsonDeserializer.new(object_json).deserialize
31
+ end
32
+ @records = response_hash[@resource_name]
33
+ self
34
+ end
35
+
36
+ def each(&block)
37
+ scroll_param = nil
38
+ loop do
39
+ if not scroll_param
40
+ response_hash = @client.get(@scroll_url, '')
41
+ else
42
+ response_hash = @client.get(@scroll_url, scroll_param: scroll_param)
43
+ end
44
+ raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
45
+ response_hash[deserialize_response_hash(response_hash)].each do |object_json|
46
+ block.call Lib::TypedJsonDeserializer.new(object_json).deserialize
47
+ end
48
+ scroll_param = extract_scroll_param(response_hash)
49
+ break if not records_present?(response_hash)
50
+ end
51
+ self
52
+ end
53
+
54
+ def [](target_index)
55
+ self.each_with_index do |item, index|
56
+ return item if index == target_index
57
+ end
58
+ nil
59
+ end
60
+
61
+ include Enumerable
62
+
63
+ private
64
+
65
+ def deserialize_response_hash(response_hash)
66
+ top_level_type = response_hash.delete('type')
67
+ if resource_name == 'subscriptions'
68
+ top_level_entity_key = 'items'
69
+ else
70
+ top_level_entity_key = Utils.entity_key_from_type(top_level_type)
71
+ end
72
+ end
73
+
74
+ def records_present?(response_hash)
75
+ (response_hash[@resource_name].length > 0)
76
+ end
77
+
78
+ def extract_scroll_param(response_hash)
79
+ return nil unless records_present?(response_hash)
80
+ response_hash['scroll_param']
81
+ end
82
+ end
83
+ end
@@ -1,6 +1,7 @@
1
1
  require 'intercom/service/base_service'
2
2
  require 'intercom/api_operations/load'
3
3
  require 'intercom/api_operations/list'
4
+ require 'intercom/api_operations/scroll'
4
5
  require 'intercom/api_operations/find'
5
6
  require 'intercom/api_operations/find_all'
6
7
  require 'intercom/api_operations/save'
@@ -14,6 +15,7 @@ module Intercom
14
15
  class User < BaseService
15
16
  include ApiOperations::Load
16
17
  include ApiOperations::List
18
+ include ApiOperations::Scroll
17
19
  include ApiOperations::Find
18
20
  include ApiOperations::FindAll
19
21
  include ApiOperations::Save
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.5.3"
2
+ VERSION = "3.5.4"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -216,6 +216,14 @@ def page_of_users(include_next_link= false)
216
216
  }
217
217
  end
218
218
 
219
+ def users_scroll(include_users= false)
220
+ {
221
+ "type"=>"user.list",
222
+ "scroll_param"=> ("da6bbbac-25f6-4f07-866b-b911082d7"),
223
+ "users"=> (include_users ? [test_user("user1@example.com"), test_user("user2@example.com"), test_user("user3@example.com")] : []),
224
+ }
225
+ end
226
+
219
227
  def users_pagination(include_next_link=false, per_page=0, page=0, total_pages=0, total_count=0, user_list=[])
220
228
  {
221
229
  "type"=>"user.list",
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Intercom::ScrollCollectionProxy do
4
+ let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
5
+
6
+ it "stops iterating if no users returned" do
7
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(false))
8
+ emails = []
9
+ client.users.scroll.each { |user| emails << user.email }
10
+ emails.must_equal %W()
11
+ end
12
+
13
+ it "keeps iterating if users returned" do
14
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
15
+ client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(false))
16
+ emails = []
17
+ client.users.scroll.each { |user| emails << user.email }
18
+ end
19
+
20
+ it "supports indexed array access" do
21
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
22
+ client.users.scroll[0].email.must_equal 'user1@example.com'
23
+ end
24
+
25
+ it "supports map" do
26
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
27
+ client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(false))
28
+ emails = client.users.scroll.map { |user| user.email }
29
+ emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
30
+ end
31
+
32
+ it "returns one page scroll" do
33
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
34
+ scroll = client.users.scroll.next
35
+ emails = []
36
+ scroll.records.each {|usr| emails << usr.email}
37
+ emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
38
+ end
39
+
40
+ it "keeps iterating if called with scroll_param" do
41
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
42
+ client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(true))
43
+ scroll = client.users.scroll.next
44
+ scroll = client.users.scroll.next('da6bbbac-25f6-4f07-866b-b911082d7')
45
+ emails =[]
46
+ scroll.records.each {|usr| puts usr.email}
47
+ end
48
+
49
+ it "works with an empty list" do
50
+ client.expects(:get).with("/users/scroll", '').returns(users_scroll(false))
51
+ scroll = client.users.scroll.next
52
+ emails = []
53
+ scroll.records.each {|usr| emails << usr.email}
54
+ emails.must_equal %W()
55
+ end
56
+ 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.5.3
4
+ version: 3.5.4
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: 2016-08-25 00:00:00.000000000 Z
18
+ date: 2016-08-30 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: minitest
@@ -139,6 +139,7 @@ files:
139
139
  - lib/intercom/api_operations/list.rb
140
140
  - lib/intercom/api_operations/load.rb
141
141
  - lib/intercom/api_operations/save.rb
142
+ - lib/intercom/api_operations/scroll.rb
142
143
  - lib/intercom/client.rb
143
144
  - lib/intercom/client_collection_proxy.rb
144
145
  - lib/intercom/company.rb
@@ -159,6 +160,7 @@ files:
159
160
  - lib/intercom/note.rb
160
161
  - lib/intercom/options.rb
161
162
  - lib/intercom/request.rb
163
+ - lib/intercom/scroll_collection_proxy.rb
162
164
  - lib/intercom/segment.rb
163
165
  - lib/intercom/service/admin.rb
164
166
  - lib/intercom/service/base_service.rb
@@ -198,6 +200,7 @@ files:
198
200
  - spec/unit/intercom/message_spec.rb
199
201
  - spec/unit/intercom/note_spec.rb
200
202
  - spec/unit/intercom/request_spec.rb
203
+ - spec/unit/intercom/scroll_collection_proxy_spec.rb
201
204
  - spec/unit/intercom/segment_spec.rb
202
205
  - spec/unit/intercom/subscription_spec.rb
203
206
  - spec/unit/intercom/tag_spec.rb
@@ -244,6 +247,7 @@ test_files:
244
247
  - spec/unit/intercom/message_spec.rb
245
248
  - spec/unit/intercom/note_spec.rb
246
249
  - spec/unit/intercom/request_spec.rb
250
+ - spec/unit/intercom/scroll_collection_proxy_spec.rb
247
251
  - spec/unit/intercom/segment_spec.rb
248
252
  - spec/unit/intercom/subscription_spec.rb
249
253
  - spec/unit/intercom/tag_spec.rb