intercom 3.4.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +19 -0
- data/README.md +3 -3
- data/lib/intercom.rb +2 -0
- data/lib/intercom/api_operations/convert.rb +26 -9
- data/lib/intercom/client.rb +4 -0
- data/lib/intercom/errors.rb +6 -6
- data/lib/intercom/request.rb +1 -1
- data/lib/intercom/service/tag.rb +0 -2
- data/lib/intercom/service/visitor.rb +26 -0
- data/lib/intercom/version.rb +1 -1
- data/lib/intercom/visitor.rb +14 -0
- data/spec/unit/intercom/tag_spec.rb +0 -6
- data/spec/unit/intercom/visitors_spec.rb +61 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af771d03313306122d7cd15732e481d1be985ea2
|
4
|
+
data.tar.gz: 5868caffd6bb8f2f66a674e6610b7e2278a13882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b5dec841b7297280ddfddcb79400fc606e73c27324177bbc6f7fee6614851e06e409273b95c271773eec588ddd5b7aca332344ae9f4bd0c793c5f7312a822a
|
7
|
+
data.tar.gz: c74408ea271f4ab2695d8e9cde03a5e862ad5c59993423f478ca98d05617fea3880daf97dbc583e4ca6cf69936b167085176a9543a151c12b6bd0fb3ebee3e91
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Please use the following template to submit your issue. Following this template will allow us to quickly investigate and help you with your issue. Please be aware that issues which do not conform to this template may be closed.
|
2
|
+
|
3
|
+
For feature requests please contact us at team@intercom.io
|
4
|
+
|
5
|
+
|
6
|
+
## Version info
|
7
|
+
- intercom-ruby version:
|
8
|
+
- Ruby version:
|
9
|
+
|
10
|
+
## Expected behavior
|
11
|
+
|
12
|
+
## Actual behavior
|
13
|
+
|
14
|
+
## Steps to reproduce
|
15
|
+
1.
|
16
|
+
2.
|
17
|
+
3.
|
18
|
+
|
19
|
+
## Logs
|
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.
|
25
|
+
gem 'intercom', "~> 3.5.0"
|
26
26
|
|
27
27
|
## Basic Usage
|
28
28
|
|
@@ -191,7 +191,7 @@ intercom.conversations.reply(:id => conversation.id, :type => 'user', :email =>
|
|
191
191
|
# Admin (identified by id) replies with a comment
|
192
192
|
intercom.conversations.reply(:id => conversation.id, :type => 'admin', :admin_id => '123', :message_type => 'comment', :body => 'bar')
|
193
193
|
# User (identified by email) replies with a comment and attachment
|
194
|
-
intercom.conversations.reply(:id => conversation.id, :type => 'user', :email => 'joe@example.com', :message_type => 'comment', :body => 'foo', :
|
194
|
+
intercom.conversations.reply(:id => conversation.id, :type => 'user', :email => 'joe@example.com', :message_type => 'comment', :body => 'foo', :attachment_urls => ['http://www.example.com/attachment.jpg'])
|
195
195
|
|
196
196
|
# Open
|
197
197
|
intercom.conversations.open(id: conversation.id, admin_id: '123')
|
@@ -439,7 +439,7 @@ intercom.jobs.errors(id: 'job_abcd1234')
|
|
439
439
|
|
440
440
|
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.
|
441
441
|
|
442
|
-
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
|
442
|
+
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.
|
443
443
|
|
444
444
|
The list of different error subclasses are listed below. As they all inherit off Intercom::IntercomError you can choose to rescue Intercom::IntercomError or
|
445
445
|
else rescue the more specific error subclass.
|
data/lib/intercom.rb
CHANGED
@@ -12,6 +12,7 @@ require 'intercom/service/subscription'
|
|
12
12
|
require 'intercom/service/segment'
|
13
13
|
require 'intercom/service/tag'
|
14
14
|
require 'intercom/service/user'
|
15
|
+
require 'intercom/service/visitor'
|
15
16
|
require 'intercom/options'
|
16
17
|
require 'intercom/client'
|
17
18
|
require "intercom/contact"
|
@@ -30,6 +31,7 @@ require "intercom/request"
|
|
30
31
|
require "intercom/subscription"
|
31
32
|
require "intercom/utils"
|
32
33
|
require "intercom/errors"
|
34
|
+
require "intercom/visitor"
|
33
35
|
require "json"
|
34
36
|
|
35
37
|
##
|
@@ -3,16 +3,33 @@ require 'intercom/traits/api_resource'
|
|
3
3
|
module Intercom
|
4
4
|
module ApiOperations
|
5
5
|
module Convert
|
6
|
-
def convert(contact, user)
|
7
|
-
Intercom::
|
8
|
-
|
9
|
-
|
10
|
-
{
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def convert(contact, user = false)
|
7
|
+
if contact.class == Intercom::Visitor
|
8
|
+
visitor = contact
|
9
|
+
req = {
|
10
|
+
visitor: { user_id: visitor.user_id },
|
11
|
+
}
|
12
|
+
if user
|
13
|
+
req[:user] = identity_hash(user)
|
14
|
+
req[:type] = 'user'
|
15
|
+
else
|
16
|
+
req[:type] = 'lead'
|
17
|
+
end
|
18
|
+
Intercom::User.new.from_response(
|
19
|
+
@client.post(
|
20
|
+
"/visitors/convert", req
|
21
|
+
)
|
14
22
|
)
|
15
|
-
|
23
|
+
else
|
24
|
+
Intercom::User.new.from_response(
|
25
|
+
@client.post(
|
26
|
+
"/contacts/convert", {
|
27
|
+
contact: { user_id: contact.user_id },
|
28
|
+
user: identity_hash(user)
|
29
|
+
}
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
16
33
|
end
|
17
34
|
end
|
18
35
|
end
|
data/lib/intercom/client.rb
CHANGED
data/lib/intercom/errors.rb
CHANGED
@@ -14,7 +14,7 @@ module Intercom
|
|
14
14
|
# Check that you have set <b>Intercom.app_id=</b> and <b>Intercom.app_api_key=</b> correctly.
|
15
15
|
class AuthenticationError < IntercomError; end
|
16
16
|
|
17
|
-
# Raised when something
|
17
|
+
# Raised when something goes wrong on within the Intercom API service.
|
18
18
|
class ServerError < IntercomError; end
|
19
19
|
|
20
20
|
# Raised when we have bad gateway errors.
|
@@ -29,21 +29,21 @@ module Intercom
|
|
29
29
|
# Raised when requesting resources on behalf of a user that doesn't exist in your application on Intercom.
|
30
30
|
class ResourceNotFound < IntercomError; end
|
31
31
|
|
32
|
-
# Raised when the request has
|
32
|
+
# Raised when the request has bad syntax
|
33
33
|
class BadRequestError < IntercomError; end
|
34
34
|
|
35
|
-
# Raised when you have
|
35
|
+
# Raised when you have exceeded the API rate limit
|
36
36
|
class RateLimitExceeded < IntercomError; end
|
37
37
|
|
38
38
|
# Raised when the request throws an error not accounted for
|
39
39
|
class UnexpectedError < IntercomError; end
|
40
|
-
|
40
|
+
|
41
41
|
# Raised when multiple users match the query (typically duplicate email addresses)
|
42
42
|
class MultipleMatchingUsersError < IntercomError; end
|
43
43
|
|
44
44
|
# Raised when you try to call a non-setter method that does not exist on an object
|
45
45
|
class Intercom::AttributeNotSetError < IntercomError ; end
|
46
|
-
|
46
|
+
|
47
47
|
# Raised when unexpected nil returned from server
|
48
48
|
class Intercom::HttpError < IntercomError ; end
|
49
49
|
|
@@ -51,7 +51,7 @@ module Intercom
|
|
51
51
|
# Non-public errors (internal to the gem)
|
52
52
|
#
|
53
53
|
|
54
|
-
# Base class exception from which all
|
54
|
+
# Base class exception from which all private Intercom exceptions will be derived
|
55
55
|
class IntercomInternalError < StandardError; end
|
56
56
|
|
57
57
|
# Raised when we attempt to handle a method missing but are unsuccessful
|
data/lib/intercom/request.rb
CHANGED
@@ -105,7 +105,7 @@ module Intercom
|
|
105
105
|
|
106
106
|
def decode(content_encoding, body)
|
107
107
|
return body if (!body) || body.empty? || content_encoding != 'gzip'
|
108
|
-
Zlib::GzipReader.new(StringIO.new(body)).read
|
108
|
+
Zlib::GzipReader.new(StringIO.new(body)).read.force_encoding("utf-8")
|
109
109
|
end
|
110
110
|
|
111
111
|
def raise_errors_on_failure(res)
|
data/lib/intercom/service/tag.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'intercom/service/base_service'
|
2
2
|
require 'intercom/api_operations/save'
|
3
3
|
require 'intercom/api_operations/list'
|
4
|
-
require 'intercom/api_operations/find'
|
5
4
|
require 'intercom/api_operations/find_all'
|
6
5
|
|
7
6
|
module Intercom
|
@@ -9,7 +8,6 @@ module Intercom
|
|
9
8
|
class Tag < BaseService
|
10
9
|
include ApiOperations::Save
|
11
10
|
include ApiOperations::List
|
12
|
-
include ApiOperations::Find
|
13
11
|
include ApiOperations::FindAll
|
14
12
|
include ApiOperations::Delete
|
15
13
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/load'
|
3
|
+
require 'intercom/api_operations/list'
|
4
|
+
require 'intercom/api_operations/find'
|
5
|
+
require 'intercom/api_operations/find_all'
|
6
|
+
require 'intercom/api_operations/save'
|
7
|
+
require 'intercom/api_operations/convert'
|
8
|
+
require 'intercom/api_operations/delete'
|
9
|
+
|
10
|
+
module Intercom
|
11
|
+
module Service
|
12
|
+
class Visitor < BaseService
|
13
|
+
include ApiOperations::Load
|
14
|
+
include ApiOperations::List
|
15
|
+
include ApiOperations::Find
|
16
|
+
include ApiOperations::FindAll
|
17
|
+
include ApiOperations::Save
|
18
|
+
include ApiOperations::Convert
|
19
|
+
include ApiOperations::Delete
|
20
|
+
|
21
|
+
def collection_class
|
22
|
+
Intercom::Visitor
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/intercom/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'intercom/traits/incrementable_attributes'
|
2
|
+
require 'intercom/traits/api_resource'
|
3
|
+
|
4
|
+
module Intercom
|
5
|
+
class Visitor
|
6
|
+
include Traits::IncrementableAttributes
|
7
|
+
include Traits::ApiResource
|
8
|
+
|
9
|
+
def identity_vars ; [:id, :email, :user_id] ; end
|
10
|
+
def flat_store_attributes ; [:custom_attributes] ; end
|
11
|
+
def update_verb ; 'put' ; end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -3,12 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe "Intercom::Tag" do
|
4
4
|
let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
|
5
5
|
|
6
|
-
it "gets a tag" do
|
7
|
-
client.expects(:get).with("/tags", {:name => "Test Tag"}).returns(test_tag)
|
8
|
-
tag = client.tags.find(:name => "Test Tag")
|
9
|
-
tag.name.must_equal "Test Tag"
|
10
|
-
end
|
11
|
-
|
12
6
|
it "creates a tag" do
|
13
7
|
client.expects(:post).with("/tags", {'name' => "Test Tag"}).returns(test_tag)
|
14
8
|
tag = client.tags.create(:name => "Test Tag")
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Intercom::Visitors" do
|
4
|
+
let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
|
5
|
+
|
6
|
+
it 'should be listable' do
|
7
|
+
proxy = client.visitors.all
|
8
|
+
proxy.resource_name.must_equal 'visitors'
|
9
|
+
proxy.finder_url.must_equal '/visitors'
|
10
|
+
proxy.resource_class.must_equal Intercom::Visitor
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can update a visitor with an id' do
|
14
|
+
visitor = Intercom::Visitor.new(:id => "de45ae78gae1289cb")
|
15
|
+
client.expects(:put).with("/visitors/de45ae78gae1289cb", {'custom_attributes' => {}})
|
16
|
+
client.visitors.save(visitor)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'converting' do
|
20
|
+
let(:visitor) { Intercom::Visitor.from_api(user_id: 'visitor_id') }
|
21
|
+
let(:user) { Intercom::User.from_api(id: 'user_id') }
|
22
|
+
|
23
|
+
it 'visitor to user' do
|
24
|
+
client.expects(:post).with(
|
25
|
+
"/visitors/convert",
|
26
|
+
{
|
27
|
+
visitor: { user_id: visitor.user_id },
|
28
|
+
user: { 'id' => user.id },
|
29
|
+
type:'user'
|
30
|
+
}
|
31
|
+
).returns(test_user)
|
32
|
+
|
33
|
+
client.visitors.convert(visitor, user)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'visitor to lead' do
|
37
|
+
client.expects(:post).with(
|
38
|
+
"/visitors/convert",
|
39
|
+
{
|
40
|
+
visitor: { user_id: visitor.user_id },
|
41
|
+
type:'lead'
|
42
|
+
}
|
43
|
+
).returns(test_user)
|
44
|
+
|
45
|
+
client.visitors.convert(visitor)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns a ClientCollectionProxy for all without making any requests" do
|
50
|
+
client.expects(:execute_request).never
|
51
|
+
all = client.visitors.all
|
52
|
+
all.must_be_instance_of(Intercom::ClientCollectionProxy)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "deletes a visitor" do
|
56
|
+
visitor = Intercom::Visitor.new("id" => "1")
|
57
|
+
client.expects(:delete).with("/visitors/1", {}).returns(visitor)
|
58
|
+
client.visitors.delete(visitor)
|
59
|
+
end
|
60
|
+
|
61
|
+
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.5.1
|
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-
|
18
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -117,6 +117,7 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
+
- ".github/ISSUE_TEMPLATE.md"
|
120
121
|
- ".gitignore"
|
121
122
|
- ".travis.yml"
|
122
123
|
- Gemfile
|
@@ -173,6 +174,7 @@ files:
|
|
173
174
|
- lib/intercom/service/subscription.rb
|
174
175
|
- lib/intercom/service/tag.rb
|
175
176
|
- lib/intercom/service/user.rb
|
177
|
+
- lib/intercom/service/visitor.rb
|
176
178
|
- lib/intercom/subscription.rb
|
177
179
|
- lib/intercom/tag.rb
|
178
180
|
- lib/intercom/traits/api_resource.rb
|
@@ -181,6 +183,7 @@ files:
|
|
181
183
|
- lib/intercom/user.rb
|
182
184
|
- lib/intercom/utils.rb
|
183
185
|
- lib/intercom/version.rb
|
186
|
+
- lib/intercom/visitor.rb
|
184
187
|
- spec/spec_helper.rb
|
185
188
|
- spec/unit/intercom/admin_spec.rb
|
186
189
|
- spec/unit/intercom/client_collection_proxy_spec.rb
|
@@ -200,6 +203,7 @@ files:
|
|
200
203
|
- spec/unit/intercom/tag_spec.rb
|
201
204
|
- spec/unit/intercom/traits/api_resource_spec.rb
|
202
205
|
- spec/unit/intercom/user_spec.rb
|
206
|
+
- spec/unit/intercom/visitors_spec.rb
|
203
207
|
- spec/unit/intercom_spec.rb
|
204
208
|
homepage: https://www.intercom.io
|
205
209
|
licenses:
|
@@ -221,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
225
|
version: '0'
|
222
226
|
requirements: []
|
223
227
|
rubyforge_project: intercom
|
224
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.4.8
|
225
229
|
signing_key:
|
226
230
|
specification_version: 4
|
227
231
|
summary: Ruby bindings for the Intercom API
|
@@ -245,5 +249,6 @@ test_files:
|
|
245
249
|
- spec/unit/intercom/tag_spec.rb
|
246
250
|
- spec/unit/intercom/traits/api_resource_spec.rb
|
247
251
|
- spec/unit/intercom/user_spec.rb
|
252
|
+
- spec/unit/intercom/visitors_spec.rb
|
248
253
|
- spec/unit/intercom_spec.rb
|
249
254
|
has_rdoc:
|