intercom 3.9.4 → 4.0.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 +235 -222
- data/Rakefile +1 -1
- data/changes.txt +6 -0
- data/lib/intercom/api_operations/archive.rb +2 -1
- data/lib/intercom/api_operations/delete.rb +16 -0
- data/lib/intercom/api_operations/find.rb +5 -2
- data/lib/intercom/api_operations/find_all.rb +4 -3
- data/lib/intercom/api_operations/list.rb +4 -1
- data/lib/intercom/api_operations/load.rb +4 -2
- data/lib/intercom/api_operations/nested_resource.rb +70 -0
- data/lib/intercom/api_operations/save.rb +5 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +3 -2
- data/lib/intercom/base_collection_proxy.rb +72 -0
- data/lib/intercom/client.rb +20 -25
- data/lib/intercom/client_collection_proxy.rb +17 -39
- data/lib/intercom/company.rb +8 -0
- data/lib/intercom/contact.rb +21 -3
- data/lib/intercom/conversation.rb +4 -0
- data/lib/intercom/data_attribute.rb +7 -0
- data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
- data/lib/intercom/deprecated_resources.rb +13 -0
- data/lib/intercom/errors.rb +3 -0
- data/lib/intercom/extended_api_operations/segments.rb +3 -1
- data/lib/intercom/extended_api_operations/tags.rb +3 -1
- data/lib/intercom/lead.rb +21 -0
- data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
- data/lib/intercom/note.rb +4 -0
- data/lib/intercom/request.rb +37 -33
- data/lib/intercom/scroll_collection_proxy.rb +33 -38
- data/lib/intercom/search_collection_proxy.rb +30 -65
- data/lib/intercom/service/base_service.rb +7 -0
- data/lib/intercom/service/company.rb +0 -12
- data/lib/intercom/service/contact.rb +21 -10
- data/lib/intercom/service/conversation.rb +12 -3
- data/lib/intercom/service/data_attribute.rb +20 -0
- data/lib/intercom/service/lead.rb +41 -0
- data/lib/intercom/service/note.rb +4 -8
- data/lib/intercom/service/subscription.rb +2 -2
- data/lib/intercom/service/tag.rb +9 -9
- data/lib/intercom/service/visitor.rb +17 -8
- data/lib/intercom/tag.rb +4 -0
- data/lib/intercom/traits/api_resource.rb +28 -17
- data/lib/intercom/user.rb +12 -3
- data/lib/intercom/utils.rb +13 -2
- data/lib/intercom/version.rb +1 -1
- data/lib/intercom/visitor.rb +0 -2
- data/lib/intercom.rb +27 -22
- data/spec/spec_helper.rb +738 -513
- data/spec/unit/intercom/admin_spec.rb +2 -2
- data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
- data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
- data/spec/unit/intercom/client_spec.rb +28 -25
- data/spec/unit/intercom/company_spec.rb +13 -15
- data/spec/unit/intercom/contact_spec.rb +289 -33
- data/spec/unit/intercom/conversation_spec.rb +29 -7
- data/spec/unit/intercom/count_spec.rb +4 -4
- data/spec/unit/intercom/data_attribute_spec.rb +40 -0
- data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
- data/spec/unit/intercom/event_spec.rb +9 -11
- data/spec/unit/intercom/job_spec.rb +24 -24
- data/spec/unit/intercom/lead_spec.rb +57 -0
- data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
- data/spec/unit/intercom/message_spec.rb +1 -1
- data/spec/unit/intercom/note_spec.rb +4 -10
- data/spec/unit/intercom/request_spec.rb +1 -1
- data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
- data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
- data/spec/unit/intercom/segment_spec.rb +2 -2
- data/spec/unit/intercom/subscription_spec.rb +5 -6
- data/spec/unit/intercom/tag_spec.rb +22 -14
- data/spec/unit/intercom/team_spec.rb +2 -2
- data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
- data/spec/unit/intercom/user_spec.rb +224 -226
- data/spec/unit/intercom/visitor_spec.rb +49 -0
- data/spec/unit/intercom_spec.rb +5 -3
- metadata +22 -7
- data/lib/intercom/customer.rb +0 -10
- data/lib/intercom/service/customer.rb +0 -14
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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/scroll'
|
10
|
+
require 'intercom/api_operations/convert'
|
11
|
+
require 'intercom/api_operations/archive'
|
12
|
+
require 'intercom/api_operations/request_hard_delete'
|
13
|
+
require 'intercom/deprecated_leads_collection_proxy'
|
14
|
+
|
15
|
+
module Intercom
|
16
|
+
module Service
|
17
|
+
class Lead < BaseService
|
18
|
+
include ApiOperations::Load
|
19
|
+
include ApiOperations::List
|
20
|
+
include ApiOperations::Find
|
21
|
+
include ApiOperations::FindAll
|
22
|
+
include ApiOperations::Save
|
23
|
+
include ApiOperations::Scroll
|
24
|
+
include ApiOperations::Convert
|
25
|
+
include ApiOperations::Archive
|
26
|
+
include ApiOperations::RequestHardDelete
|
27
|
+
|
28
|
+
def collection_proxy_class
|
29
|
+
Intercom::DeprecatedLeadsCollectionProxy
|
30
|
+
end
|
31
|
+
|
32
|
+
def collection_class
|
33
|
+
Intercom::Lead
|
34
|
+
end
|
35
|
+
|
36
|
+
def collection_name
|
37
|
+
'contacts'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,22 +1,18 @@
|
|
1
1
|
require 'intercom/service/base_service'
|
2
|
-
require 'intercom/api_operations/list'
|
3
|
-
require 'intercom/api_operations/find_all'
|
4
2
|
require 'intercom/api_operations/find'
|
5
|
-
require 'intercom/api_operations/load'
|
6
|
-
require 'intercom/api_operations/save'
|
7
3
|
|
8
4
|
module Intercom
|
9
5
|
module Service
|
10
6
|
class Note < BaseService
|
11
|
-
include ApiOperations::Save
|
12
|
-
include ApiOperations::List
|
13
|
-
include ApiOperations::FindAll
|
14
7
|
include ApiOperations::Find
|
15
|
-
include ApiOperations::Load
|
16
8
|
|
17
9
|
def collection_class
|
18
10
|
Intercom::Note
|
19
11
|
end
|
12
|
+
|
13
|
+
def collection_proxy_class
|
14
|
+
Intercom::BaseCollectionProxy
|
15
|
+
end
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
@@ -2,7 +2,7 @@ require 'intercom/api_operations/list'
|
|
2
2
|
require 'intercom/api_operations/find_all'
|
3
3
|
require 'intercom/api_operations/find'
|
4
4
|
require 'intercom/api_operations/save'
|
5
|
-
require 'intercom/api_operations/
|
5
|
+
require 'intercom/api_operations/delete'
|
6
6
|
|
7
7
|
module Intercom
|
8
8
|
module Service
|
@@ -11,7 +11,7 @@ module Intercom
|
|
11
11
|
include ApiOperations::Find
|
12
12
|
include ApiOperations::FindAll
|
13
13
|
include ApiOperations::Save
|
14
|
-
include ApiOperations::
|
14
|
+
include ApiOperations::Delete
|
15
15
|
|
16
16
|
def collection_class
|
17
17
|
Intercom::Subscription
|
data/lib/intercom/service/tag.rb
CHANGED
@@ -2,6 +2,7 @@ require 'intercom/service/base_service'
|
|
2
2
|
require 'intercom/api_operations/save'
|
3
3
|
require 'intercom/api_operations/list'
|
4
4
|
require 'intercom/api_operations/find_all'
|
5
|
+
require 'intercom/api_operations/find'
|
5
6
|
|
6
7
|
module Intercom
|
7
8
|
module Service
|
@@ -9,12 +10,17 @@ module Intercom
|
|
9
10
|
include ApiOperations::Save
|
10
11
|
include ApiOperations::List
|
11
12
|
include ApiOperations::FindAll
|
12
|
-
include ApiOperations::
|
13
|
+
include ApiOperations::Delete
|
14
|
+
include ApiOperations::Find
|
13
15
|
|
14
16
|
def collection_class
|
15
17
|
Intercom::Tag
|
16
18
|
end
|
17
19
|
|
20
|
+
def collection_proxy_class
|
21
|
+
Intercom::BaseCollectionProxy
|
22
|
+
end
|
23
|
+
|
18
24
|
def tag(params)
|
19
25
|
params['tag_or_untag'] = 'tag'
|
20
26
|
create(params)
|
@@ -22,17 +28,11 @@ module Intercom
|
|
22
28
|
|
23
29
|
def untag(params)
|
24
30
|
params['tag_or_untag'] = 'untag'
|
25
|
-
|
26
|
-
|
31
|
+
params[:companies].each do |company|
|
32
|
+
company[:untag] = true
|
27
33
|
end
|
28
34
|
create(params)
|
29
35
|
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def users_or_companies(params)
|
34
|
-
params[:users] || params[:companies]
|
35
|
-
end
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -1,26 +1,35 @@
|
|
1
1
|
require 'intercom/service/base_service'
|
2
2
|
require 'intercom/api_operations/load'
|
3
|
-
require 'intercom/api_operations/list'
|
4
3
|
require 'intercom/api_operations/find'
|
5
|
-
require 'intercom/api_operations/find_all'
|
6
4
|
require 'intercom/api_operations/save'
|
7
|
-
require 'intercom/api_operations/
|
8
|
-
require 'intercom/api_operations/archive'
|
5
|
+
require 'intercom/api_operations/delete'
|
9
6
|
|
10
7
|
module Intercom
|
11
8
|
module Service
|
12
9
|
class Visitor < BaseService
|
13
10
|
include ApiOperations::Load
|
14
|
-
include ApiOperations::List
|
15
11
|
include ApiOperations::Find
|
16
|
-
include ApiOperations::FindAll
|
17
12
|
include ApiOperations::Save
|
18
|
-
include ApiOperations::
|
19
|
-
include ApiOperations::Archive
|
13
|
+
include ApiOperations::Delete
|
20
14
|
|
21
15
|
def collection_class
|
22
16
|
Intercom::Visitor
|
23
17
|
end
|
18
|
+
|
19
|
+
def convert(visitor, contact = false)
|
20
|
+
req = { visitor: { user_id: visitor.user_id } }
|
21
|
+
if contact
|
22
|
+
req[:user] = identity_hash(contact)
|
23
|
+
req[:type] = 'user'
|
24
|
+
else
|
25
|
+
req[:type] = 'lead'
|
26
|
+
end
|
27
|
+
Intercom::Contact.new.from_response(
|
28
|
+
@client.post(
|
29
|
+
"/visitors/convert", req
|
30
|
+
)
|
31
|
+
)
|
32
|
+
end
|
24
33
|
end
|
25
34
|
end
|
26
35
|
end
|
data/lib/intercom/tag.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'intercom/lib/flat_store'
|
2
4
|
require 'intercom/lib/dynamic_accessors'
|
3
5
|
require 'intercom/lib/dynamic_accessors_on_method_missing'
|
@@ -6,11 +8,10 @@ require 'intercom/lib/typed_json_deserializer'
|
|
6
8
|
|
7
9
|
module Intercom
|
8
10
|
module Traits
|
9
|
-
|
10
11
|
module ApiResource
|
11
12
|
include DirtyTracking
|
12
13
|
|
13
|
-
attr_accessor :id
|
14
|
+
attr_accessor :id, :client
|
14
15
|
|
15
16
|
def initialize(attributes = {})
|
16
17
|
from_hash(attributes)
|
@@ -31,9 +32,8 @@ module Intercom
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def to_hash
|
34
|
-
instance_variables_excluding_dirty_tracking_field.
|
35
|
-
hash[variable.to_s.delete(
|
36
|
-
hash
|
35
|
+
instance_variables_excluding_dirty_tracking_field.each_with_object({}) do |variable, hash|
|
36
|
+
hash[variable.to_s.delete('@')] = instance_variable_get(variable)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -46,34 +46,46 @@ module Intercom
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def method_missing(method_sym, *arguments, &block)
|
49
|
-
Lib::DynamicAccessorsOnMethodMissing.new(method_sym, *arguments, self)
|
50
|
-
|
49
|
+
Lib::DynamicAccessorsOnMethodMissing.new(method_sym, *arguments, self)
|
50
|
+
.define_accessors_or_call { super }
|
51
51
|
end
|
52
52
|
|
53
53
|
def flat_store_attribute?(attribute)
|
54
|
-
|
54
|
+
respond_to?(:flat_store_attributes) && flat_store_attributes.map(&:to_s).include?(attribute.to_s)
|
55
55
|
end
|
56
56
|
|
57
57
|
private
|
58
58
|
|
59
59
|
def initialize_property(attribute, value)
|
60
|
+
return if addressable_list?(attribute, value)
|
61
|
+
|
60
62
|
Lib::DynamicAccessors.define_accessors(attribute, value, self) unless accessors_already_defined?(attribute)
|
61
63
|
set_property(attribute, value)
|
62
64
|
end
|
63
65
|
|
66
|
+
def addressable_list?(attribute, value)
|
67
|
+
return false unless typed_property?(attribute, value)
|
68
|
+
|
69
|
+
value['type'] == 'list' && value['url']
|
70
|
+
end
|
71
|
+
|
64
72
|
def accessors_already_defined?(attribute)
|
65
73
|
respond_to?(attribute) && respond_to?("#{attribute}=")
|
66
74
|
end
|
67
75
|
|
68
76
|
def set_property(attribute, value)
|
77
|
+
value_to_set = parsed_value_for_attribute(attribute, value)
|
78
|
+
call_setter_for_attribute(attribute, value_to_set)
|
79
|
+
end
|
80
|
+
|
81
|
+
def parsed_value_for_attribute(attribute, value)
|
69
82
|
if typed_property?(attribute, value)
|
70
|
-
|
83
|
+
Intercom::Lib::TypedJsonDeserializer.new(value, client).deserialize
|
71
84
|
elsif flat_store_attribute?(attribute)
|
72
|
-
|
85
|
+
Intercom::Lib::FlatStore.new(value)
|
73
86
|
else
|
74
|
-
|
87
|
+
value
|
75
88
|
end
|
76
|
-
call_setter_for_attribute(attribute, value_to_set)
|
77
89
|
end
|
78
90
|
|
79
91
|
def custom_attribute_field?(attribute)
|
@@ -97,12 +109,12 @@ module Intercom
|
|
97
109
|
end
|
98
110
|
|
99
111
|
def typed_value?(value)
|
100
|
-
value.is_a?
|
112
|
+
value.is_a?(Hash) && !!value['type']
|
101
113
|
end
|
102
114
|
|
103
115
|
def call_setter_for_attribute(attribute, value)
|
104
|
-
setter_method = "#{attribute
|
105
|
-
|
116
|
+
setter_method = "#{attribute}="
|
117
|
+
send(setter_method, value)
|
106
118
|
end
|
107
119
|
|
108
120
|
def initialize_missing_flat_store_attributes
|
@@ -120,7 +132,7 @@ module Intercom
|
|
120
132
|
|
121
133
|
module ClassMethods
|
122
134
|
def from_api(api_response)
|
123
|
-
object =
|
135
|
+
object = new
|
124
136
|
object.from_response(api_response)
|
125
137
|
object
|
126
138
|
end
|
@@ -129,7 +141,6 @@ module Intercom
|
|
129
141
|
def self.included(base)
|
130
142
|
base.extend(ClassMethods)
|
131
143
|
end
|
132
|
-
|
133
144
|
end
|
134
145
|
end
|
135
146
|
end
|
data/lib/intercom/user.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'intercom/traits/incrementable_attributes'
|
2
4
|
require 'intercom/traits/api_resource'
|
3
5
|
|
@@ -6,9 +8,16 @@ module Intercom
|
|
6
8
|
include Traits::IncrementableAttributes
|
7
9
|
include Traits::ApiResource
|
8
10
|
|
9
|
-
def identity_vars
|
10
|
-
|
11
|
-
|
11
|
+
def identity_vars
|
12
|
+
%i[id email user_id]
|
13
|
+
end
|
14
|
+
|
15
|
+
def flat_store_attributes
|
16
|
+
[:custom_attributes]
|
17
|
+
end
|
12
18
|
|
19
|
+
def update_verb
|
20
|
+
'post'
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
data/lib/intercom/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Intercom
|
2
4
|
module Utils
|
3
5
|
class << self
|
@@ -7,6 +9,7 @@ module Intercom
|
|
7
9
|
|
8
10
|
def pluralize(str)
|
9
11
|
return str.gsub(/y$/, 'ies') if str =~ /y$/
|
12
|
+
|
10
13
|
"#{str}s"
|
11
14
|
end
|
12
15
|
|
@@ -23,7 +26,13 @@ module Intercom
|
|
23
26
|
end
|
24
27
|
|
25
28
|
def resource_class_to_singular_name(resource_class)
|
26
|
-
resource_class.to_s.split('::')[-1]
|
29
|
+
resource_name = resource_class.to_s.split('::')[-1]
|
30
|
+
resource_name = maybe_underscore_name(resource_name)
|
31
|
+
resource_name.downcase
|
32
|
+
end
|
33
|
+
|
34
|
+
def maybe_underscore_name(resource_name)
|
35
|
+
resource_name.gsub!(/(.)([A-Z])/, '\1_\2') || resource_name
|
27
36
|
end
|
28
37
|
|
29
38
|
def resource_class_to_collection_name(resource_class)
|
@@ -52,9 +61,11 @@ module Intercom
|
|
52
61
|
end
|
53
62
|
|
54
63
|
def entity_key_from_type(type)
|
64
|
+
return 'data' if type == 'list'
|
65
|
+
|
55
66
|
is_list = type.split('.')[1] == 'list'
|
56
67
|
entity_name = type.split('.')[0]
|
57
|
-
is_list ?
|
68
|
+
is_list ? Utils.pluralize(entity_name) : entity_name
|
58
69
|
end
|
59
70
|
end
|
60
71
|
end
|
data/lib/intercom/version.rb
CHANGED
data/lib/intercom/visitor.rb
CHANGED
data/lib/intercom.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'intercom/version'
|
2
4
|
require 'intercom/service/admin'
|
3
5
|
require 'intercom/service/company'
|
4
6
|
require 'intercom/service/contact'
|
5
7
|
require 'intercom/service/conversation'
|
6
8
|
require 'intercom/service/count'
|
7
|
-
require 'intercom/service/customer'
|
8
9
|
require 'intercom/service/event'
|
9
10
|
require 'intercom/service/message'
|
10
11
|
require 'intercom/service/note'
|
@@ -13,29 +14,33 @@ require 'intercom/service/subscription'
|
|
13
14
|
require 'intercom/service/segment'
|
14
15
|
require 'intercom/service/tag'
|
15
16
|
require 'intercom/service/team'
|
16
|
-
require 'intercom/service/user'
|
17
17
|
require 'intercom/service/visitor'
|
18
|
+
require 'intercom/service/user'
|
19
|
+
require 'intercom/service/lead'
|
20
|
+
require 'intercom/deprecated_resources.rb'
|
18
21
|
require 'intercom/options'
|
19
22
|
require 'intercom/client'
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
34
|
-
require
|
35
|
-
require
|
36
|
-
require
|
37
|
-
require
|
38
|
-
require
|
23
|
+
require 'intercom/contact'
|
24
|
+
require 'intercom/user'
|
25
|
+
require 'intercom/lead'
|
26
|
+
require 'intercom/count'
|
27
|
+
require 'intercom/company'
|
28
|
+
require 'intercom/service/data_attribute'
|
29
|
+
require 'intercom/note'
|
30
|
+
require 'intercom/job'
|
31
|
+
require 'intercom/tag'
|
32
|
+
require 'intercom/segment'
|
33
|
+
require 'intercom/event'
|
34
|
+
require 'intercom/conversation'
|
35
|
+
require 'intercom/message'
|
36
|
+
require 'intercom/admin'
|
37
|
+
require 'intercom/request'
|
38
|
+
require 'intercom/subscription'
|
39
|
+
require 'intercom/team'
|
40
|
+
require 'intercom/errors'
|
41
|
+
require 'intercom/visitor'
|
42
|
+
require 'intercom/data_attribute'
|
43
|
+
require 'json'
|
39
44
|
|
40
45
|
##
|
41
46
|
# Intercom is a customer relationship management and messaging tool for web app owners
|