intercom 3.5.4 → 3.5.5
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 +4 -4
- data/README.md +43 -3
- data/changes.txt +8 -0
- data/lib/intercom/errors.rb +17 -4
- data/lib/intercom/request.rb +4 -1
- data/lib/intercom/service/admin.rb +2 -0
- data/lib/intercom/service/contact.rb +2 -0
- data/lib/intercom/traits/incrementable_attributes.rb +6 -0
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/intercom/admin_spec.rb +5 -0
- data/spec/unit/intercom/user_spec.rb +39 -2
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a6847dce96b450a0a76df67eca84f56d3ef455
|
4
|
+
data.tar.gz: 22145c09b5d23cf751309bc7f270fa219f170d11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c319a85c4f7e6bc3de496f4d3730f656290da92ced3153b3d23c1deb75de58a38e03f7bc5e25f71d8b9f3377193112b8e16658285199cd2a1f3238fc29fd74f3
|
7
|
+
data.tar.gz: e4586310e90cfe1cbf5a87bf0988658bb04cb66aad4ae44feaf75f49e4c2fc735bc0530e76defb116f5e081a172185c48bf9542c47e4d4773aae28cba6a8b9fd
|
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.
|
25
|
+
gem 'intercom', "~> 3.5.5"
|
26
26
|
|
27
27
|
## Basic Usage
|
28
28
|
|
@@ -35,7 +35,7 @@ intercom = Intercom::Client.new(app_id: 'my_app_id', api_key: 'my_api_key')
|
|
35
35
|
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 integration settings page (under your app settings - integrations in Intercom).
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
# With an OAuth token:
|
38
|
+
# With an OAuth or Personal Access token:
|
39
39
|
intercom = Intercom::Client.new(token: 'my_token')
|
40
40
|
```
|
41
41
|
|
@@ -82,13 +82,34 @@ intercom.users.save(user)
|
|
82
82
|
# Perform incrementing
|
83
83
|
user.increment('karma')
|
84
84
|
intercom.users.save(user)
|
85
|
+
# Perform decrementing
|
86
|
+
user.decrement('karma', 5)
|
87
|
+
intercom.users.save(user)
|
85
88
|
# Iterate over all users
|
86
89
|
intercom.users.all.each {|user| puts %Q(#{user.email} - #{user.custom_attributes["average_monthly_spend"]}) }
|
87
90
|
intercom.users.all.map {|user| user.email }
|
91
|
+
# List your users create in the last two days
|
92
|
+
intercom.users.find_all(type: 'users', page: 1, per_page: 10, created_since: 2, order: :asc).to_a.each_with_index {|usr, i| puts "#{i+1}: #{usr.name}"};
|
93
|
+
# Paginate through your list of users choosing how many to return per page (default and max is 50 per page)
|
94
|
+
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}"}
|
95
|
+
# If you have over 10,000 users then you will need to use the scroll function to list your users
|
96
|
+
# otherwise you will encounter a page limit with list all your users
|
97
|
+
# You can use the scroll method to list all your users
|
98
|
+
intercom.users.scroll.each { |user| puts user.name}
|
99
|
+
# Alternatively you can use the scroll.next method to get 100 users with each request
|
100
|
+
result = intercom.users.scroll.next
|
101
|
+
# The result object then contains a records attributes that is an array of your user objects and it also contains a scroll_param which
|
102
|
+
# you can then use to request the next 100 users. Note that the scroll parameter will time out after one minute and you will need to
|
103
|
+
# make a new request
|
104
|
+
result.scroll_param
|
105
|
+
=> "0730e341-63ef-44da-ab9c-9113f886326d"
|
106
|
+
result = = intercom.users.scroll.next("0730e341-63ef-44da-ab9c-9113f886326d");
|
88
107
|
|
89
108
|
#Bulk operations.
|
90
|
-
# Submit bulk job
|
109
|
+
# Submit bulk job to create users. If any of the items in create_items match an existing user that user will be updated
|
91
110
|
intercom.users.submit_bulk_job(create_items: [{user_id: 25, email: "alice@example.com"}, {user_id: 25, email: "bob@example.com"}])
|
111
|
+
# Submit bulk job to create users with companies. Companies must be sent as an array of objects nested within each applicable user object
|
112
|
+
intercom.users.submit_bulk_job(create_items: [{user_id: 25, email: "alice@example.com", companies: [{:company_id => 9, :name => "Test Company"}]}])
|
92
113
|
# Submit bulk job, to delete users
|
93
114
|
intercom.users.submit_bulk_job(delete_items: [{user_id: 25, email: "alice@example.com"}, {user_id: 25, email: "bob@example.com"}])
|
94
115
|
# Submit bulk job, to add items to existing job
|
@@ -97,6 +118,8 @@ intercom.users.submit_bulk_job(create_items: [{user_id: 25, email: "alice@exampl
|
|
97
118
|
|
98
119
|
#### Admins
|
99
120
|
```ruby
|
121
|
+
# Find an admin by id
|
122
|
+
intercom.admins.find(:id => admin_id)
|
100
123
|
# Iterate over all admins
|
101
124
|
intercom.admins.all.each {|admin| puts admin.email }
|
102
125
|
```
|
@@ -469,3 +492,20 @@ Calling your client's `rate_limit_details` returns a Hash that contains details
|
|
469
492
|
intercom.rate_limit_details
|
470
493
|
#=> {:limit=>180, :remaining=>179, :reset_at=>2014-10-07 14:58:00 +0100}
|
471
494
|
```
|
495
|
+
|
496
|
+
|
497
|
+
### Pull Requests
|
498
|
+
|
499
|
+
- **Add tests!** Your patch won't be accepted if it doesn't have tests.
|
500
|
+
|
501
|
+
- **Document any change in behaviour**. Make sure the README and any other
|
502
|
+
relevant documentation are kept up-to-date.
|
503
|
+
|
504
|
+
- **Create topic branches**. Don't ask us to pull from your master branch.
|
505
|
+
|
506
|
+
- **One pull request per feature**. If you want to do more than one thing, send
|
507
|
+
multiple pull requests.
|
508
|
+
|
509
|
+
- **Send coherent history**. Make sure each individual commit in your pull
|
510
|
+
request is meaningful. If you had to make multiple intermediate commits while
|
511
|
+
developing, please squash them before sending them to us.
|
data/changes.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
3.5.5
|
2
|
+
- Add scroll api for contacts
|
3
|
+
- Add extra context to IntercomError
|
4
|
+
- Add support to find admin by id
|
5
|
+
- Add decrement method to incrementable traits
|
6
|
+
- Suppress printing of users during test runs
|
7
|
+
|
8
|
+
|
1
9
|
3.5.4
|
2
10
|
- Add support for scoll API feature
|
3
11
|
|
data/lib/intercom/errors.rb
CHANGED
@@ -2,12 +2,25 @@ module Intercom
|
|
2
2
|
|
3
3
|
# Base class exception from which all public Intercom exceptions will be derived
|
4
4
|
class IntercomError < StandardError
|
5
|
-
attr_reader :http_code, :application_error_code
|
6
|
-
def initialize(message,
|
7
|
-
@http_code = http_code
|
8
|
-
@application_error_code =
|
5
|
+
attr_reader :http_code, :application_error_code, :field, :request_id
|
6
|
+
def initialize(message, context={})
|
7
|
+
@http_code = context[:http_code]
|
8
|
+
@application_error_code = context[:application_error_code]
|
9
|
+
@field = context[:field]
|
10
|
+
@request_id = context[:request_id]
|
9
11
|
super(message)
|
10
12
|
end
|
13
|
+
def inspect
|
14
|
+
attributes = instance_variables.map do |var|
|
15
|
+
value = instance_variable_get(var).inspect
|
16
|
+
"#{var}=#{value}"
|
17
|
+
end
|
18
|
+
"##{self.class.name}:#{message} #{attributes.join(' ')}"
|
19
|
+
end
|
20
|
+
def to_hash
|
21
|
+
{message: message}
|
22
|
+
.merge(Hash[instance_variables.map{ |var| [var[1..-1], instance_variable_get(var)] }])
|
23
|
+
end
|
11
24
|
end
|
12
25
|
|
13
26
|
# Raised when the credentials you provide don't match a valid account on Intercom.
|
data/lib/intercom/request.rb
CHANGED
@@ -128,10 +128,13 @@ module Intercom
|
|
128
128
|
# Currently, we don't support multiple errors
|
129
129
|
error_details = error_list_details['errors'].first
|
130
130
|
error_code = error_details['type'] || error_details['code']
|
131
|
+
error_field = error_details['field']
|
131
132
|
parsed_http_code = (http_code > 0 ? http_code : nil)
|
132
133
|
error_context = {
|
133
134
|
:http_code => parsed_http_code,
|
134
|
-
:application_error_code => error_code
|
135
|
+
:application_error_code => error_code,
|
136
|
+
:field => error_field,
|
137
|
+
:request_id => error_list_details['request_id']
|
135
138
|
}
|
136
139
|
case error_code
|
137
140
|
when 'unauthorized', 'forbidden'
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'intercom/service/base_service'
|
2
2
|
require 'intercom/api_operations/list'
|
3
|
+
require 'intercom/api_operations/find'
|
3
4
|
|
4
5
|
module Intercom
|
5
6
|
module Service
|
6
7
|
class Admin < BaseService
|
7
8
|
include ApiOperations::List
|
9
|
+
include ApiOperations::Find
|
8
10
|
|
9
11
|
def collection_class
|
10
12
|
Intercom::Admin
|
@@ -4,6 +4,7 @@ require 'intercom/api_operations/list'
|
|
4
4
|
require 'intercom/api_operations/find'
|
5
5
|
require 'intercom/api_operations/find_all'
|
6
6
|
require 'intercom/api_operations/save'
|
7
|
+
require 'intercom/api_operations/scroll'
|
7
8
|
require 'intercom/api_operations/convert'
|
8
9
|
require 'intercom/api_operations/delete'
|
9
10
|
|
@@ -15,6 +16,7 @@ module Intercom
|
|
15
16
|
include ApiOperations::Find
|
16
17
|
include ApiOperations::FindAll
|
17
18
|
include ApiOperations::Save
|
19
|
+
include ApiOperations::Scroll
|
18
20
|
include ApiOperations::Convert
|
19
21
|
include ApiOperations::Delete
|
20
22
|
|
@@ -7,6 +7,12 @@ module Intercom
|
|
7
7
|
existing_value ||= 0
|
8
8
|
self.custom_attributes[key] = existing_value + value
|
9
9
|
end
|
10
|
+
|
11
|
+
def decrement(key, value=1)
|
12
|
+
existing_value = self.custom_attributes[key] || 0
|
13
|
+
self.custom_attributes[key] = existing_value - value
|
14
|
+
end
|
15
|
+
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
data/lib/intercom/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -126,6 +126,15 @@ def test_admin_list
|
|
126
126
|
}
|
127
127
|
end
|
128
128
|
|
129
|
+
def test_admin
|
130
|
+
{
|
131
|
+
"type" => "admin",
|
132
|
+
"id" => "1234",
|
133
|
+
"name" => "Hoban Washburne",
|
134
|
+
"email" => "wash@serenity.io"
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
129
138
|
def test_company
|
130
139
|
{
|
131
140
|
"type" => "company",
|
@@ -13,4 +13,9 @@ describe "Intercom::Admin" do
|
|
13
13
|
client.expects(:get).with("/admins", {}).returns(test_admin_list)
|
14
14
|
client.admins.all.each { |a| }
|
15
15
|
end
|
16
|
+
|
17
|
+
it "gets an admin" do
|
18
|
+
client.expects(:get).with("/admins/1234", {}).returns(test_admin)
|
19
|
+
client.admins.find(:id => "1234")
|
20
|
+
end
|
16
21
|
end
|
@@ -148,6 +148,34 @@ describe "Intercom::User" do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
+
describe "decrementing custom_attributes fields" do
|
152
|
+
before :each do
|
153
|
+
@now = Time.now
|
154
|
+
@user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :custom_attributes => {"mad" => 123, "another" => 432, "other" => @now.to_i, :thing => "yay"})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "decrements down by 1 with no args" do
|
158
|
+
@user.decrement("mad")
|
159
|
+
@user.to_hash["custom_attributes"]["mad"].must_equal 122
|
160
|
+
end
|
161
|
+
|
162
|
+
it "decrements down by given value" do
|
163
|
+
@user.decrement("mad", 3)
|
164
|
+
@user.to_hash["custom_attributes"]["mad"].must_equal 120
|
165
|
+
end
|
166
|
+
|
167
|
+
it "can decrement new custom data fields" do
|
168
|
+
@user.decrement("new_field", 5)
|
169
|
+
@user.to_hash["custom_attributes"]["new_field"].must_equal -5
|
170
|
+
end
|
171
|
+
|
172
|
+
it "can call decrement on the same key twice and decrement by 2" do
|
173
|
+
@user.decrement("mad")
|
174
|
+
@user.decrement("mad")
|
175
|
+
@user.to_hash["custom_attributes"]["mad"].must_equal 121
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
151
179
|
it "fetches a user" do
|
152
180
|
client.expects(:get).with("/users", {"email" => "bo@example.com"}).returns(test_user)
|
153
181
|
user = client.users.find("email" => "bo@example.com")
|
@@ -238,8 +266,17 @@ describe "Intercom::User" do
|
|
238
266
|
it 'can print users without crashing' do
|
239
267
|
client.expects(:get).with("/users", {"email" => "bo@example.com"}).returns(test_user)
|
240
268
|
user = client.users.find("email" => "bo@example.com")
|
241
|
-
|
242
|
-
|
269
|
+
|
270
|
+
begin
|
271
|
+
orignal_stdout = $stdout
|
272
|
+
$stdout = StringIO.new
|
273
|
+
|
274
|
+
puts user
|
275
|
+
p user
|
276
|
+
|
277
|
+
ensure
|
278
|
+
$stdout = orignal_stdout
|
279
|
+
end
|
243
280
|
end
|
244
281
|
|
245
282
|
describe 'bulk operations' do
|
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.
|
4
|
+
version: 3.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -15,90 +15,90 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2016-
|
18
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.4'
|
27
27
|
type: :development
|
28
28
|
prerelease: false
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '5.4'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rake
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.3'
|
41
41
|
type: :development
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.3'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: mocha
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: fakeweb
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.3'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: pry
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
- !ruby/object:Gem::Dependency
|
91
91
|
name: json
|
92
92
|
requirement: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.8'
|
97
97
|
type: :runtime
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '1.8'
|
104
104
|
description: 'Intercom (https://www.intercom.io) is a customer relationship management
|
@@ -117,9 +117,9 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
120
|
+
- .github/ISSUE_TEMPLATE.md
|
121
|
+
- .gitignore
|
122
|
+
- .travis.yml
|
123
123
|
- Gemfile
|
124
124
|
- MIT-LICENSE
|
125
125
|
- README.md
|
@@ -218,17 +218,17 @@ require_paths:
|
|
218
218
|
- lib
|
219
219
|
required_ruby_version: !ruby/object:Gem::Requirement
|
220
220
|
requirements:
|
221
|
-
- -
|
221
|
+
- - '>='
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: 2.1.0
|
224
224
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
225
|
requirements:
|
226
|
-
- -
|
226
|
+
- - '>='
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
230
|
rubyforge_project: intercom
|
231
|
-
rubygems_version: 2.
|
231
|
+
rubygems_version: 2.0.14.1
|
232
232
|
signing_key:
|
233
233
|
specification_version: 4
|
234
234
|
summary: Ruby bindings for the Intercom API
|