intercom 2.5.4 → 3.0.0b1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/README.md +97 -118
- data/changes.txt +3 -0
- data/intercom.gemspec +1 -1
- data/lib/intercom.rb +13 -153
- data/lib/intercom/admin.rb +0 -2
- data/lib/intercom/api_operations/convert.rb +5 -5
- data/lib/intercom/api_operations/delete.rb +4 -6
- data/lib/intercom/api_operations/find.rb +9 -15
- data/lib/intercom/api_operations/find_all.rb +16 -21
- data/lib/intercom/api_operations/list.rb +4 -10
- data/lib/intercom/api_operations/load.rb +6 -6
- data/lib/intercom/api_operations/save.rb +23 -28
- data/lib/intercom/client.rb +95 -0
- data/lib/intercom/{collection_proxy.rb → client_collection_proxy.rb} +5 -8
- data/lib/intercom/company.rb +0 -16
- data/lib/intercom/contact.rb +0 -11
- data/lib/intercom/conversation.rb +0 -10
- data/lib/intercom/event.rb +0 -2
- data/lib/intercom/extended_api_operations/segments.rb +13 -0
- data/lib/intercom/extended_api_operations/tags.rb +4 -5
- data/lib/intercom/extended_api_operations/users.rb +3 -5
- data/lib/intercom/message.rb +0 -2
- data/lib/intercom/note.rb +1 -10
- data/lib/intercom/options.rb +11 -0
- data/lib/intercom/request.rb +9 -5
- data/lib/intercom/segment.rb +0 -7
- data/lib/intercom/service/admin.rb +14 -0
- data/lib/intercom/service/base_service.rb +21 -0
- data/lib/intercom/service/company.rb +28 -0
- data/lib/intercom/service/contact.rb +22 -0
- data/lib/intercom/service/conversation.rb +31 -0
- data/lib/intercom/service/event.rb +14 -0
- data/lib/intercom/service/message.rb +14 -0
- data/lib/intercom/service/note.rb +22 -0
- data/lib/intercom/service/segment.rb +16 -0
- data/lib/intercom/service/subscription.rb +21 -0
- data/lib/intercom/service/tag.rb +30 -0
- data/lib/intercom/service/user.rb +28 -0
- data/lib/intercom/subscription.rb +0 -8
- data/lib/intercom/tag.rb +0 -16
- data/lib/intercom/user.rb +0 -16
- data/lib/intercom/utils.rb +0 -1
- data/lib/intercom/version.rb +1 -1
- data/spec/spec_helper.rb +117 -0
- data/spec/unit/intercom/admin_spec.rb +11 -4
- data/spec/unit/intercom/client_collection_proxy_spec.rb +35 -0
- data/spec/unit/intercom/client_spec.rb +21 -0
- data/spec/unit/intercom/company_spec.rb +24 -11
- data/spec/unit/intercom/contact_spec.rb +7 -5
- data/spec/unit/intercom/conversation_spec.rb +28 -0
- data/spec/unit/intercom/event_spec.rb +6 -5
- data/spec/unit/intercom/message_spec.rb +9 -8
- data/spec/unit/intercom/note_spec.rb +9 -2
- data/spec/unit/intercom/segment_spec.rb +12 -0
- data/spec/unit/intercom/subscription_spec.rb +7 -5
- data/spec/unit/intercom/tag_spec.rb +13 -7
- data/spec/unit/intercom/user_spec.rb +41 -33
- data/spec/unit/intercom_spec.rb +0 -83
- metadata +30 -20
- data/lib/intercom/api_operations/count.rb +0 -16
- data/lib/intercom/count.rb +0 -21
- data/lib/intercom/extended_api_operations/reply.rb +0 -16
- data/lib/intercom/generic_handlers/base_handler.rb +0 -22
- data/lib/intercom/generic_handlers/count.rb +0 -59
- data/lib/intercom/generic_handlers/tag.rb +0 -71
- data/lib/intercom/generic_handlers/tag_find_all.rb +0 -47
- data/lib/intercom/notification.rb +0 -20
- data/lib/intercom/traits/generic_handler_binding.rb +0 -29
- data/spec/unit/intercom/collection_proxy_spec.rb +0 -34
- data/spec/unit/intercom/notification_spec.rb +0 -68
data/lib/intercom/event.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'intercom/traits/api_resource'
|
2
|
+
require 'intercom/client_collection_proxy'
|
3
|
+
|
4
|
+
module Intercom
|
5
|
+
module ExtendedApiOperations
|
6
|
+
module Segments
|
7
|
+
def by_segment(id)
|
8
|
+
collection_name = Utils.resource_class_to_collection_name(collection_class)
|
9
|
+
ClientCollectionProxy.new(collection_name, finder_details: {url: "/#{collection_name}?segment_id=#{id}"}, client: @client)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'intercom/traits/api_resource'
|
2
|
+
require 'intercom/client_collection_proxy'
|
2
3
|
|
3
4
|
module Intercom
|
4
5
|
module ExtendedApiOperations
|
5
6
|
module Tags
|
6
|
-
|
7
|
-
|
8
|
-
collection_name
|
9
|
-
self.id ? Intercom::Tag.send("find_all_for_#{collection_name}", :id => id) : []
|
7
|
+
def by_tag(id)
|
8
|
+
collection_name = Utils.resource_class_to_collection_name(collection_class)
|
9
|
+
ClientCollectionProxy.new(collection_name, finder_details: {url: "/#{collection_name}?tag_id=#{id}"}, client: @client)
|
10
10
|
end
|
11
|
-
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -3,15 +3,13 @@ require 'intercom/traits/api_resource'
|
|
3
3
|
module Intercom
|
4
4
|
module ExtendedApiOperations
|
5
5
|
module Users
|
6
|
-
|
7
|
-
|
8
|
-
collection_name = Utils.resource_class_to_collection_name(self.class)
|
6
|
+
def users(id)
|
7
|
+
collection_name = Utils.resource_class_to_collection_name(collection_class)
|
9
8
|
finder_details = {}
|
10
9
|
finder_details[:url] = "/#{collection_name}/#{id}/users"
|
11
10
|
finder_details[:params] = {}
|
12
|
-
|
11
|
+
ClientCollectionProxy.new("users", finder_details: finder_details, client: @client)
|
13
12
|
end
|
14
|
-
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
data/lib/intercom/message.rb
CHANGED
data/lib/intercom/note.rb
CHANGED
@@ -1,17 +1,8 @@
|
|
1
|
-
|
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'
|
1
|
+
|
6
2
|
require 'intercom/traits/api_resource'
|
7
3
|
|
8
4
|
module Intercom
|
9
5
|
class Note
|
10
|
-
include ApiOperations::Save
|
11
|
-
include ApiOperations::List
|
12
|
-
include ApiOperations::FindAll
|
13
|
-
include ApiOperations::Find
|
14
|
-
include ApiOperations::Load
|
15
6
|
include Traits::ApiResource
|
16
7
|
end
|
17
8
|
end
|
data/lib/intercom/request.rb
CHANGED
@@ -3,7 +3,7 @@ require 'net/https'
|
|
3
3
|
|
4
4
|
module Intercom
|
5
5
|
class Request
|
6
|
-
attr_accessor :path, :net_http_method
|
6
|
+
attr_accessor :path, :net_http_method, :rate_limit_details
|
7
7
|
|
8
8
|
def initialize(path, net_http_method)
|
9
9
|
self.path = path
|
@@ -11,10 +11,13 @@ module Intercom
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def set_common_headers(method, base_uri)
|
14
|
-
method.basic_auth(CGI.unescape(base_uri.user), CGI.unescape(base_uri.password))
|
15
14
|
method.add_field('AcceptEncoding', 'gzip, deflate')
|
16
15
|
end
|
17
16
|
|
17
|
+
def set_basic_auth(method, username, secret)
|
18
|
+
method.basic_auth(CGI.unescape(username), CGI.unescape(secret))
|
19
|
+
end
|
20
|
+
|
18
21
|
def self.get(path, params)
|
19
22
|
new(path, Net::HTTP::Get.new(append_query_string_to_url(path, params), default_headers))
|
20
23
|
end
|
@@ -54,9 +57,10 @@ module Intercom
|
|
54
57
|
net
|
55
58
|
end
|
56
59
|
|
57
|
-
def execute(target_base_url=nil)
|
60
|
+
def execute(target_base_url=nil, username:, secret: nil)
|
58
61
|
base_uri = URI.parse(target_base_url)
|
59
62
|
set_common_headers(net_http_method, base_uri)
|
63
|
+
set_basic_auth(net_http_method, username, secret)
|
60
64
|
begin
|
61
65
|
client(base_uri).start do |http|
|
62
66
|
begin
|
@@ -74,7 +78,7 @@ module Intercom
|
|
74
78
|
raise Intercom::ServiceConnectionError.new('Failed to connect to service [connection attempt timed out]')
|
75
79
|
end
|
76
80
|
end
|
77
|
-
|
81
|
+
|
78
82
|
def decode_body(response)
|
79
83
|
decode(response['content-encoding'], response.body)
|
80
84
|
end
|
@@ -96,7 +100,7 @@ module Intercom
|
|
96
100
|
rate_limit_details[:limit] = response['X-RateLimit-Limit'].to_i if response['X-RateLimit-Limit']
|
97
101
|
rate_limit_details[:remaining] = response['X-RateLimit-Remaining'].to_i if response['X-RateLimit-Remaining']
|
98
102
|
rate_limit_details[:reset_at] = Time.at(response['X-RateLimit-Reset'].to_i) if response['X-RateLimit-Reset']
|
99
|
-
|
103
|
+
@rate_limit_details = rate_limit_details
|
100
104
|
end
|
101
105
|
|
102
106
|
def decode(content_encoding, body)
|
data/lib/intercom/segment.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
|
-
require 'intercom/api_operations/count'
|
2
|
-
require 'intercom/api_operations/find'
|
3
|
-
require 'intercom/api_operations/save'
|
4
1
|
require 'intercom/traits/api_resource'
|
5
2
|
|
6
3
|
module Intercom
|
7
4
|
class Segment
|
8
|
-
include ApiOperations::List
|
9
|
-
include ApiOperations::Find
|
10
|
-
include ApiOperations::Save
|
11
|
-
include ApiOperations::Count
|
12
5
|
include Traits::ApiResource
|
13
6
|
end
|
14
7
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Intercom
|
2
|
+
module Service
|
3
|
+
class BaseService
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def collection_class
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def from_api(api_response)
|
15
|
+
object = collection_class.new
|
16
|
+
object.from_response(api_response)
|
17
|
+
object
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/list'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
require 'intercom/api_operations/find_all'
|
5
|
+
require 'intercom/api_operations/save'
|
6
|
+
require 'intercom/api_operations/load'
|
7
|
+
require 'intercom/extended_api_operations/users'
|
8
|
+
require 'intercom/extended_api_operations/tags'
|
9
|
+
require 'intercom/extended_api_operations/segments'
|
10
|
+
|
11
|
+
module Intercom
|
12
|
+
module Service
|
13
|
+
class Company < BaseService
|
14
|
+
include ApiOperations::Find
|
15
|
+
include ApiOperations::FindAll
|
16
|
+
include ApiOperations::Load
|
17
|
+
include ApiOperations::List
|
18
|
+
include ApiOperations::Save
|
19
|
+
include ExtendedApiOperations::Users
|
20
|
+
include ExtendedApiOperations::Tags
|
21
|
+
include ExtendedApiOperations::Segments
|
22
|
+
|
23
|
+
def collection_class
|
24
|
+
Intercom::Company
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/load'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
require 'intercom/api_operations/find_all'
|
5
|
+
require 'intercom/api_operations/save'
|
6
|
+
require 'intercom/api_operations/convert'
|
7
|
+
|
8
|
+
module Intercom
|
9
|
+
module Service
|
10
|
+
class Contact < BaseService
|
11
|
+
include ApiOperations::Load
|
12
|
+
include ApiOperations::Find
|
13
|
+
include ApiOperations::FindAll
|
14
|
+
include ApiOperations::Save
|
15
|
+
include ApiOperations::Convert
|
16
|
+
|
17
|
+
def collection_class
|
18
|
+
Intercom::Contact
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/find_all'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
require 'intercom/api_operations/load'
|
5
|
+
require 'intercom/api_operations/save'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
module Service
|
9
|
+
class Conversation < BaseService
|
10
|
+
include ApiOperations::FindAll
|
11
|
+
include ApiOperations::Find
|
12
|
+
include ApiOperations::Load
|
13
|
+
include ApiOperations::Save
|
14
|
+
|
15
|
+
def collection_class
|
16
|
+
Intercom::Conversation
|
17
|
+
end
|
18
|
+
|
19
|
+
def mark_read(id)
|
20
|
+
@client.put("/conversations/#{id}", read: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def reply(reply_data)
|
24
|
+
id = reply_data.delete(:id)
|
25
|
+
collection_name = Utils.resource_class_to_collection_name(collection_class)
|
26
|
+
response = @client.post("/#{collection_name}/#{id}/reply", reply_data.merge(:conversation_id => id))
|
27
|
+
collection_class.new.from_response(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
+
|
8
|
+
module Intercom
|
9
|
+
module Service
|
10
|
+
class Note < BaseService
|
11
|
+
include ApiOperations::Save
|
12
|
+
include ApiOperations::List
|
13
|
+
include ApiOperations::FindAll
|
14
|
+
include ApiOperations::Find
|
15
|
+
include ApiOperations::Load
|
16
|
+
|
17
|
+
def collection_class
|
18
|
+
Intercom::Note
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/list'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
|
5
|
+
module Intercom
|
6
|
+
module Service
|
7
|
+
class Segment < BaseService
|
8
|
+
include ApiOperations::List
|
9
|
+
include ApiOperations::Find
|
10
|
+
|
11
|
+
def collection_class
|
12
|
+
Intercom::Segment
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'intercom/api_operations/list'
|
2
|
+
require 'intercom/api_operations/find_all'
|
3
|
+
require 'intercom/api_operations/find'
|
4
|
+
require 'intercom/api_operations/save'
|
5
|
+
require 'intercom/api_operations/delete'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
module Service
|
9
|
+
class Subscription < BaseService
|
10
|
+
include ApiOperations::List
|
11
|
+
include ApiOperations::Find
|
12
|
+
include ApiOperations::FindAll
|
13
|
+
include ApiOperations::Save
|
14
|
+
include ApiOperations::Delete
|
15
|
+
|
16
|
+
def collection_class
|
17
|
+
Intercom::Subscription
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'intercom/service/base_service'
|
2
|
+
require 'intercom/api_operations/save'
|
3
|
+
require 'intercom/api_operations/list'
|
4
|
+
require 'intercom/api_operations/find'
|
5
|
+
require 'intercom/api_operations/find_all'
|
6
|
+
|
7
|
+
module Intercom
|
8
|
+
module Service
|
9
|
+
class Tag < BaseService
|
10
|
+
include ApiOperations::Save
|
11
|
+
include ApiOperations::List
|
12
|
+
include ApiOperations::Find
|
13
|
+
include ApiOperations::FindAll
|
14
|
+
|
15
|
+
def collection_class
|
16
|
+
Intercom::Tag
|
17
|
+
end
|
18
|
+
|
19
|
+
def tag(params)
|
20
|
+
params['tag_or_untag'] = 'tag'
|
21
|
+
create(params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def untag(params)
|
25
|
+
params['tag_or_untag'] = 'untag'
|
26
|
+
create(params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'intercom/extended_api_operations/tags'
|
2
|
+
require 'intercom/extended_api_operations/segments'
|
3
|
+
require 'intercom/service/base_service'
|
4
|
+
require 'intercom/api_operations/load'
|
5
|
+
require 'intercom/api_operations/list'
|
6
|
+
require 'intercom/api_operations/find'
|
7
|
+
require 'intercom/api_operations/find_all'
|
8
|
+
require 'intercom/api_operations/save'
|
9
|
+
require 'intercom/api_operations/delete'
|
10
|
+
|
11
|
+
module Intercom
|
12
|
+
module Service
|
13
|
+
class User < BaseService
|
14
|
+
include ApiOperations::Find
|
15
|
+
include ApiOperations::FindAll
|
16
|
+
include ApiOperations::Load
|
17
|
+
include ApiOperations::List
|
18
|
+
include ApiOperations::Save
|
19
|
+
include ApiOperations::Delete
|
20
|
+
include ExtendedApiOperations::Tags
|
21
|
+
include ExtendedApiOperations::Segments
|
22
|
+
|
23
|
+
def collection_class
|
24
|
+
Intercom::User
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|