intercom 3.7.7 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +11 -5
- data/changes.txt +3 -0
- data/lib/intercom.rb +2 -0
- data/lib/intercom/api_operations/search.rb +17 -0
- data/lib/intercom/client.rb +4 -0
- data/lib/intercom/customer.rb +10 -0
- data/lib/intercom/search_collection_proxy.rb +82 -0
- data/lib/intercom/service/customer.rb +14 -0
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +23 -0
- data/spec/unit/intercom/search_collection_proxy_spec.rb +56 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da9b3a3eada2fcf56d0d91d948bf4bed01fd27db5d5175293666be7cc702ef20
|
4
|
+
data.tar.gz: e2d4b731ce51e10b3d3bcba67024e3926595aea618d4cdee7a9bde38fca45f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef7cde04e9affeb408ec48d0767d39c88923aa4249ad89b6f30029f2e0e172972e105310078d1139a804bae9290b683e86f38a079beedf23441bd1fe4dafb8d
|
7
|
+
data.tar.gz: 6b088e5a334fcd48df68ed57293ee3e7c0b8cfaf26e0ba67bc724d24b4d7ce7177dec4b7cd9d69f8aa893a358268109356dc0369771131aafb77c63c1240ce2f
|
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.7.
|
25
|
+
gem 'intercom', '~> 3.7.7'
|
26
26
|
|
27
27
|
## Basic Usage
|
28
28
|
|
@@ -97,7 +97,7 @@ intercom.users.find_all(type: 'users', page: 1, per_page: 10, created_since: 2,
|
|
97
97
|
# Paginate through your list of users choosing how many to return per page (default and max is 50 per page)
|
98
98
|
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}"}
|
99
99
|
|
100
|
-
# Duplicate users? If you have duplicate users you can search for them via their email address.
|
100
|
+
# Duplicate users? If you have duplicate users you can search for them via their email address.
|
101
101
|
# Note this feature is only available from version 1.1 of the API so you will need to switch to that version
|
102
102
|
# This will return multiple users if they have the same email address
|
103
103
|
usrs = intercom.users.find_all(type: 'users', email: 'myemail@example.com', page: 1, per_page: 10, order: :asc)
|
@@ -402,7 +402,7 @@ The metadata key values in the example are treated as follows-
|
|
402
402
|
|
403
403
|
*NB:* This version of the gem reserves the field name `type` in Event data.
|
404
404
|
|
405
|
-
|
405
|
+
#### Contacts
|
406
406
|
|
407
407
|
`Contacts` represent logged out users of your application.
|
408
408
|
Note that `contacts` are referred to as `leads` in the [Intercom](https://developers.intercom.com/intercom-api-reference/reference#leads)
|
@@ -458,7 +458,13 @@ intercom.contacts.scroll.each { |lead| puts lead.id}
|
|
458
458
|
# Please see users scroll for more details of how to use scroll
|
459
459
|
```
|
460
460
|
|
461
|
-
|
461
|
+
#### Customers
|
462
|
+
|
463
|
+
# Search for customers
|
464
|
+
customers = intercom.customers.search(query: { "field": "name", "operator": "=", "value": "Alice"}, per_page: 50, sort_field: "name", sort_order: "ascending")
|
465
|
+
customers.each { |customer| p customer.name }
|
466
|
+
|
467
|
+
#### Counts
|
462
468
|
|
463
469
|
```ruby
|
464
470
|
# App-wide counts
|
@@ -468,7 +474,7 @@ intercom.counts.for_app
|
|
468
474
|
intercom.counts.for_type(type: 'user', count: 'segment')
|
469
475
|
```
|
470
476
|
|
471
|
-
|
477
|
+
#### Subscriptions
|
472
478
|
|
473
479
|
Subscribe to events in Intercom to receive webhooks.
|
474
480
|
|
data/changes.txt
CHANGED
data/lib/intercom.rb
CHANGED
@@ -4,6 +4,7 @@ require 'intercom/service/company'
|
|
4
4
|
require 'intercom/service/contact'
|
5
5
|
require 'intercom/service/conversation'
|
6
6
|
require 'intercom/service/count'
|
7
|
+
require 'intercom/service/customer'
|
7
8
|
require 'intercom/service/event'
|
8
9
|
require 'intercom/service/message'
|
9
10
|
require 'intercom/service/note'
|
@@ -17,6 +18,7 @@ require 'intercom/options'
|
|
17
18
|
require 'intercom/client'
|
18
19
|
require "intercom/contact"
|
19
20
|
require "intercom/count"
|
21
|
+
require "intercom/customer"
|
20
22
|
require "intercom/user"
|
21
23
|
require "intercom/company"
|
22
24
|
require "intercom/note"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'intercom/search_collection_proxy'
|
2
|
+
require 'intercom/utils'
|
3
|
+
|
4
|
+
module Intercom
|
5
|
+
module ApiOperations
|
6
|
+
module Search
|
7
|
+
def search(params)
|
8
|
+
collection_name = Utils.resource_class_to_collection_name(collection_class)
|
9
|
+
search_details = {
|
10
|
+
url: "/#{collection_name}/search",
|
11
|
+
params: params
|
12
|
+
}
|
13
|
+
SearchCollectionProxy.new(collection_name, search_details: search_details, client: @client)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/intercom/client.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
require "intercom/utils"
|
2
|
+
|
3
|
+
module Intercom
|
4
|
+
class SearchCollectionProxy
|
5
|
+
|
6
|
+
attr_reader :resource_name, :resource_class
|
7
|
+
|
8
|
+
def initialize(resource_name, search_details: {}, client:)
|
9
|
+
@resource_name = resource_name
|
10
|
+
@resource_class = Utils.constantize_resource_name(resource_name)
|
11
|
+
@search_url = search_details[:url]
|
12
|
+
@search_params = search_details[:params]
|
13
|
+
@client = client
|
14
|
+
end
|
15
|
+
|
16
|
+
def each(&block)
|
17
|
+
loop do
|
18
|
+
response_hash = @client.post(@search_url, payload)
|
19
|
+
raise Intercom::HttpError.new('Http Error - No response entity returned') unless response_hash
|
20
|
+
deserialize_response_hash(response_hash, block)
|
21
|
+
break unless has_next_link?(response_hash)
|
22
|
+
end
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](target_index)
|
27
|
+
self.each_with_index do |item, index|
|
28
|
+
return item if index == target_index
|
29
|
+
end
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
include Enumerable
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def deserialize_response_hash(response_hash, block)
|
38
|
+
top_level_type = response_hash.delete('type')
|
39
|
+
top_level_entity_key = Utils.entity_key_from_type(top_level_type)
|
40
|
+
response_hash[top_level_entity_key].each do |object_json|
|
41
|
+
block.call Lib::TypedJsonDeserializer.new(object_json).deserialize
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def has_next_link?(response_hash)
|
46
|
+
paging_info = response_hash.delete('pages')
|
47
|
+
paging_next = paging_info["next"]
|
48
|
+
if paging_next
|
49
|
+
@search_params[:starting_after] = paging_next["starting_after"]
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def payload
|
57
|
+
payload = {
|
58
|
+
query: @search_params[:query]
|
59
|
+
}
|
60
|
+
if @search_params[:sort_field] || @search_params[:sort_order]
|
61
|
+
payload[:sort] = {}
|
62
|
+
if @search_params[:sort_field]
|
63
|
+
payload[:sort][:field] = @search_params[:sort_field]
|
64
|
+
end
|
65
|
+
if @search_params[:sort_order]
|
66
|
+
payload[:sort][:order] = @search_params[:sort_order]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
if @search_params[:per_page] || @search_params[:starting_after]
|
70
|
+
payload[:pagination] = {}
|
71
|
+
if @search_params[:per_page]
|
72
|
+
payload[:pagination][:per_page] = @search_params[:per_page]
|
73
|
+
end
|
74
|
+
if @search_params[:starting_after]
|
75
|
+
payload[:pagination][:starting_after] = @search_params[:starting_after]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return payload
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/search'
|
3
|
+
|
4
|
+
module Intercom
|
5
|
+
module Service
|
6
|
+
class Customer < BaseService
|
7
|
+
include ApiOperations::Search
|
8
|
+
|
9
|
+
def collection_class
|
10
|
+
Intercom::Customer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,6 +5,13 @@ require 'webmock'
|
|
5
5
|
require 'time'
|
6
6
|
include WebMock::API
|
7
7
|
|
8
|
+
def test_customer(email="bob@example.com")
|
9
|
+
customer = test_user(email)
|
10
|
+
customer["type"] = "customer"
|
11
|
+
customer["role"] = "user"
|
12
|
+
customer
|
13
|
+
end
|
14
|
+
|
8
15
|
def test_user(email="bob@example.com")
|
9
16
|
{
|
10
17
|
"type" =>"user",
|
@@ -228,6 +235,22 @@ def page_of_users(include_next_link= false)
|
|
228
235
|
}
|
229
236
|
end
|
230
237
|
|
238
|
+
def page_of_customers(include_starting_after= false)
|
239
|
+
{
|
240
|
+
"type"=>"customer.list",
|
241
|
+
"pages"=>
|
242
|
+
{
|
243
|
+
"type"=>"pages",
|
244
|
+
"next"=> (include_starting_after ? { "page" => 2, "starting_after" => "EnCrYpTeDsTrInG" } : nil),
|
245
|
+
"page"=>1,
|
246
|
+
"per_page"=>50,
|
247
|
+
"total_pages"=>7
|
248
|
+
},
|
249
|
+
"customers"=> [test_customer("user1@example.com"), test_customer("user2@example.com"), test_customer("user3@example.com")],
|
250
|
+
"total_count"=>314
|
251
|
+
}
|
252
|
+
end
|
253
|
+
|
231
254
|
def users_scroll(include_users= false)
|
232
255
|
{
|
233
256
|
"type"=>"user.list",
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Intercom::SearchCollectionProxy do
|
4
|
+
let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
|
5
|
+
|
6
|
+
it "send query to the customer search endpoint" do
|
7
|
+
client.expects(:post).with("/customers/search", { query: {} }). returns(page_of_customers(false))
|
8
|
+
client.customers.search(query: {}).first
|
9
|
+
end
|
10
|
+
|
11
|
+
it "send query to the customer search endpoint with sort_field" do
|
12
|
+
client.expects(:post).with("/customers/search", { query: {}, sort: { field: "name" } }). returns(page_of_customers(false))
|
13
|
+
client.customers.search(query: {}, sort_field: "name").first
|
14
|
+
end
|
15
|
+
|
16
|
+
it "send query to the customer search endpoint with sort_field and sort_order" do
|
17
|
+
client.expects(:post).with("/customers/search", { query: {}, sort: { field: "name", order: "ascending" } }). returns(page_of_customers(false))
|
18
|
+
client.customers.search(query: {}, sort_field: "name", sort_order: "ascending").first
|
19
|
+
end
|
20
|
+
|
21
|
+
it "send query to the customer search endpoint with per_page" do
|
22
|
+
client.expects(:post).with("/customers/search", { query: {}, pagination: { per_page: 10 }}). returns(page_of_customers(false))
|
23
|
+
client.customers.search(query: {}, per_page: 10).first
|
24
|
+
end
|
25
|
+
|
26
|
+
it "send query to the customer search endpoint with starting_after" do
|
27
|
+
client.expects(:post).with("/customers/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}). returns(page_of_customers(false))
|
28
|
+
client.customers.search(query: {}, starting_after: "EnCrYpTeDsTrInG").first
|
29
|
+
end
|
30
|
+
|
31
|
+
it "stops iterating if no starting_after value" do
|
32
|
+
client.expects(:post).with("/customers/search", { query: {} }). returns(page_of_customers(false))
|
33
|
+
emails = []
|
34
|
+
client.customers.search(query: {}).each { |user| emails << user.email }
|
35
|
+
emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "keeps iterating if starting_after value" do
|
39
|
+
client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(true))
|
40
|
+
client.expects(:post).with("/customers/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_customers(false))
|
41
|
+
emails = []
|
42
|
+
client.customers.search(query: {}).each { |user| emails << user.email }
|
43
|
+
end
|
44
|
+
|
45
|
+
it "supports indexed array access" do
|
46
|
+
client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(false))
|
47
|
+
client.customers.search(query: {})[0].email.must_equal 'user1@example.com'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "supports map" do
|
51
|
+
client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(false))
|
52
|
+
emails = client.customers.search(query: {}).map { |user| user.email }
|
53
|
+
emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
|
54
|
+
end
|
55
|
+
|
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.
|
4
|
+
version: 3.8.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: 2019-
|
18
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -143,12 +143,14 @@ files:
|
|
143
143
|
- lib/intercom/api_operations/request_hard_delete.rb
|
144
144
|
- lib/intercom/api_operations/save.rb
|
145
145
|
- lib/intercom/api_operations/scroll.rb
|
146
|
+
- lib/intercom/api_operations/search.rb
|
146
147
|
- lib/intercom/client.rb
|
147
148
|
- lib/intercom/client_collection_proxy.rb
|
148
149
|
- lib/intercom/company.rb
|
149
150
|
- lib/intercom/contact.rb
|
150
151
|
- lib/intercom/conversation.rb
|
151
152
|
- lib/intercom/count.rb
|
153
|
+
- lib/intercom/customer.rb
|
152
154
|
- lib/intercom/errors.rb
|
153
155
|
- lib/intercom/event.rb
|
154
156
|
- lib/intercom/extended_api_operations/segments.rb
|
@@ -163,6 +165,7 @@ files:
|
|
163
165
|
- lib/intercom/options.rb
|
164
166
|
- lib/intercom/request.rb
|
165
167
|
- lib/intercom/scroll_collection_proxy.rb
|
168
|
+
- lib/intercom/search_collection_proxy.rb
|
166
169
|
- lib/intercom/segment.rb
|
167
170
|
- lib/intercom/service/admin.rb
|
168
171
|
- lib/intercom/service/base_service.rb
|
@@ -170,6 +173,7 @@ files:
|
|
170
173
|
- lib/intercom/service/contact.rb
|
171
174
|
- lib/intercom/service/conversation.rb
|
172
175
|
- lib/intercom/service/count.rb
|
176
|
+
- lib/intercom/service/customer.rb
|
173
177
|
- lib/intercom/service/event.rb
|
174
178
|
- lib/intercom/service/job.rb
|
175
179
|
- lib/intercom/service/message.rb
|
@@ -203,6 +207,7 @@ files:
|
|
203
207
|
- spec/unit/intercom/note_spec.rb
|
204
208
|
- spec/unit/intercom/request_spec.rb
|
205
209
|
- spec/unit/intercom/scroll_collection_proxy_spec.rb
|
210
|
+
- spec/unit/intercom/search_collection_proxy_spec.rb
|
206
211
|
- spec/unit/intercom/segment_spec.rb
|
207
212
|
- spec/unit/intercom/subscription_spec.rb
|
208
213
|
- spec/unit/intercom/tag_spec.rb
|
@@ -230,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
235
|
version: '0'
|
231
236
|
requirements: []
|
232
237
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.7.8
|
234
239
|
signing_key:
|
235
240
|
specification_version: 4
|
236
241
|
summary: Ruby bindings for the Intercom API
|
@@ -250,6 +255,7 @@ test_files:
|
|
250
255
|
- spec/unit/intercom/note_spec.rb
|
251
256
|
- spec/unit/intercom/request_spec.rb
|
252
257
|
- spec/unit/intercom/scroll_collection_proxy_spec.rb
|
258
|
+
- spec/unit/intercom/search_collection_proxy_spec.rb
|
253
259
|
- spec/unit/intercom/segment_spec.rb
|
254
260
|
- spec/unit/intercom/subscription_spec.rb
|
255
261
|
- spec/unit/intercom/tag_spec.rb
|