intercom 3.9.5 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +483 -234
- data/Rakefile +1 -1
- data/changes.txt +37 -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 +68 -0
- data/lib/intercom/api_operations/save.rb +6 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +3 -2
- data/lib/intercom/article.rb +7 -0
- data/lib/intercom/base_collection_proxy.rb +74 -0
- data/lib/intercom/client.rb +48 -25
- data/lib/intercom/client_collection_proxy.rb +17 -39
- data/lib/intercom/collection.rb +7 -0
- data/lib/intercom/company.rb +8 -0
- data/lib/intercom/contact.rb +23 -3
- data/lib/intercom/conversation.rb +5 -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 +6 -0
- data/lib/intercom/export_content.rb +7 -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/dynamic_accessors.rb +9 -10
- data/lib/intercom/lib/typed_json_deserializer.rb +45 -35
- data/lib/intercom/note.rb +4 -0
- data/lib/intercom/phone_call_redirect.rb +7 -0
- data/lib/intercom/request.rb +39 -33
- data/lib/intercom/scroll_collection_proxy.rb +38 -42
- data/lib/intercom/search_collection_proxy.rb +30 -65
- data/lib/intercom/section.rb +23 -0
- data/lib/intercom/segment.rb +4 -0
- data/lib/intercom/service/article.rb +20 -0
- data/lib/intercom/service/base_service.rb +7 -0
- data/lib/intercom/service/collection.rb +24 -0
- data/lib/intercom/service/company.rb +2 -12
- data/lib/intercom/service/contact.rb +35 -10
- data/lib/intercom/service/conversation.rb +16 -3
- data/lib/intercom/service/data_attribute.rb +20 -0
- data/lib/intercom/service/export_content.rb +30 -0
- data/lib/intercom/service/lead.rb +41 -0
- data/lib/intercom/service/note.rb +4 -8
- data/lib/intercom/service/phone_call_redirect.rb +15 -0
- data/lib/intercom/service/section.rb +7 -0
- data/lib/intercom/service/subscription.rb +2 -2
- data/lib/intercom/service/subscription_type.rb +18 -0
- data/lib/intercom/service/tag.rb +9 -9
- data/lib/intercom/service/visitor.rb +17 -8
- data/lib/intercom/subscription_type.rb +12 -0
- data/lib/intercom/tag.rb +4 -0
- data/lib/intercom/traits/api_resource.rb +44 -18
- data/lib/intercom/traits/dirty_tracking.rb +8 -1
- data/lib/intercom/user.rb +12 -3
- data/lib/intercom/utils.rb +19 -3
- data/lib/intercom/version.rb +1 -1
- data/lib/intercom/visitor.rb +0 -2
- data/lib/intercom.rb +39 -22
- data/spec/spec_helper.rb +843 -520
- data/spec/unit/intercom/admin_spec.rb +2 -2
- data/spec/unit/intercom/article_spec.rb +40 -0
- data/spec/unit/intercom/base_collection_proxy_spec.rb +52 -0
- data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
- data/spec/unit/intercom/client_spec.rb +25 -26
- data/spec/unit/intercom/collection_spec.rb +32 -0
- data/spec/unit/intercom/company_spec.rb +19 -15
- data/spec/unit/intercom/contact_spec.rb +402 -33
- data/spec/unit/intercom/conversation_spec.rb +60 -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 +16 -11
- data/spec/unit/intercom/export_content_spec.rb +28 -0
- 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/phone_call_redirect.rb +12 -0
- data/spec/unit/intercom/request_spec.rb +14 -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/section_spec.rb +32 -0
- 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 +28 -14
- data/spec/unit/intercom/team_spec.rb +2 -2
- data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
- 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 +44 -8
- data/lib/intercom/customer.rb +0 -10
- data/lib/intercom/service/customer.rb +0 -14
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -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,16 +8,19 @@ 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)
|
17
18
|
end
|
18
19
|
|
20
|
+
def ==(other)
|
21
|
+
self.class == other.class && to_json == other.to_json
|
22
|
+
end
|
23
|
+
|
19
24
|
def from_response(response)
|
20
25
|
from_hash(response)
|
21
26
|
reset_changed_fields!
|
@@ -31,49 +36,71 @@ module Intercom
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def to_hash
|
34
|
-
instance_variables_excluding_dirty_tracking_field.
|
35
|
-
hash[variable.to_s.delete(
|
36
|
-
|
39
|
+
instance_variables_excluding_dirty_tracking_field.each_with_object({}) do |variable, hash|
|
40
|
+
hash[variable.to_s.delete('@')] = instance_variable_get(variable)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_json(*args)
|
45
|
+
instance_variables_excluding_dirty_tracking_field.each_with_object({}) do |variable, hash|
|
46
|
+
next if variable == :@client
|
47
|
+
|
48
|
+
value = instance_variable_get(variable)
|
49
|
+
hash[variable.to_s.delete('@')] = value.respond_to?(:to_json) ? value.to_json(*args) : value
|
37
50
|
end
|
38
51
|
end
|
39
52
|
|
40
53
|
def to_submittable_hash
|
41
54
|
submittable_hash = {}
|
42
55
|
to_hash.each do |attribute, value|
|
43
|
-
|
56
|
+
next unless submittable_attribute?(attribute, value)
|
57
|
+
|
58
|
+
submittable_hash[attribute] = value.respond_to?(:to_submittable_hash) ? value.to_submittable_hash : value
|
44
59
|
end
|
45
60
|
submittable_hash
|
46
61
|
end
|
47
62
|
|
48
63
|
def method_missing(method_sym, *arguments, &block)
|
49
|
-
Lib::DynamicAccessorsOnMethodMissing.new(method_sym, *arguments, self)
|
50
|
-
|
64
|
+
Lib::DynamicAccessorsOnMethodMissing.new(method_sym, *arguments, self)
|
65
|
+
.define_accessors_or_call { super }
|
51
66
|
end
|
52
67
|
|
53
68
|
def flat_store_attribute?(attribute)
|
54
|
-
|
69
|
+
respond_to?(:flat_store_attributes) && flat_store_attributes.map(&:to_s).include?(attribute.to_s)
|
55
70
|
end
|
56
71
|
|
57
72
|
private
|
58
73
|
|
59
74
|
def initialize_property(attribute, value)
|
75
|
+
return if addressable_list?(attribute, value)
|
76
|
+
|
60
77
|
Lib::DynamicAccessors.define_accessors(attribute, value, self) unless accessors_already_defined?(attribute)
|
61
78
|
set_property(attribute, value)
|
62
79
|
end
|
63
80
|
|
81
|
+
def addressable_list?(attribute, value)
|
82
|
+
return false unless typed_property?(attribute, value)
|
83
|
+
|
84
|
+
value['type'] == 'list' && value['url']
|
85
|
+
end
|
86
|
+
|
64
87
|
def accessors_already_defined?(attribute)
|
65
88
|
respond_to?(attribute) && respond_to?("#{attribute}=")
|
66
89
|
end
|
67
90
|
|
68
91
|
def set_property(attribute, value)
|
92
|
+
value_to_set = parsed_value_for_attribute(attribute, value)
|
93
|
+
call_setter_for_attribute(attribute, value_to_set)
|
94
|
+
end
|
95
|
+
|
96
|
+
def parsed_value_for_attribute(attribute, value)
|
69
97
|
if typed_property?(attribute, value)
|
70
|
-
|
98
|
+
Intercom::Lib::TypedJsonDeserializer.new(value, client).deserialize
|
71
99
|
elsif flat_store_attribute?(attribute)
|
72
|
-
|
100
|
+
Intercom::Lib::FlatStore.new(value)
|
73
101
|
else
|
74
|
-
|
102
|
+
value
|
75
103
|
end
|
76
|
-
call_setter_for_attribute(attribute, value_to_set)
|
77
104
|
end
|
78
105
|
|
79
106
|
def custom_attribute_field?(attribute)
|
@@ -97,12 +124,12 @@ module Intercom
|
|
97
124
|
end
|
98
125
|
|
99
126
|
def typed_value?(value)
|
100
|
-
value.is_a?
|
127
|
+
value.is_a?(Hash) && !!value['type']
|
101
128
|
end
|
102
129
|
|
103
130
|
def call_setter_for_attribute(attribute, value)
|
104
|
-
setter_method = "#{attribute
|
105
|
-
|
131
|
+
setter_method = "#{attribute}="
|
132
|
+
send(setter_method, value)
|
106
133
|
end
|
107
134
|
|
108
135
|
def initialize_missing_flat_store_attributes
|
@@ -120,7 +147,7 @@ module Intercom
|
|
120
147
|
|
121
148
|
module ClassMethods
|
122
149
|
def from_api(api_response)
|
123
|
-
object =
|
150
|
+
object = new
|
124
151
|
object.from_response(api_response)
|
125
152
|
object
|
126
153
|
end
|
@@ -129,7 +156,6 @@ module Intercom
|
|
129
156
|
def self.included(base)
|
130
157
|
base.extend(ClassMethods)
|
131
158
|
end
|
132
|
-
|
133
159
|
end
|
134
160
|
end
|
135
161
|
end
|
@@ -22,7 +22,14 @@ module Intercom
|
|
22
22
|
|
23
23
|
def field_changed?(field_name)
|
24
24
|
@changed_fields ||= Set.new
|
25
|
-
|
25
|
+
field = instance_variable_get("@#{field_name}")
|
26
|
+
if field.respond_to?(:field_changed?)
|
27
|
+
field.to_hash.any? do |attribute, _|
|
28
|
+
field.field_changed?(attribute)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
@changed_fields.include?(field_name.to_s)
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
def instance_variables_excluding_dirty_tracking_field
|
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
|
|
@@ -22,8 +25,18 @@ module Intercom
|
|
22
25
|
constant
|
23
26
|
end
|
24
27
|
|
28
|
+
def camelize(snake_cased_word)
|
29
|
+
snake_cased_word.split(/_/).map(&:capitalize).join
|
30
|
+
end
|
31
|
+
|
25
32
|
def resource_class_to_singular_name(resource_class)
|
26
|
-
resource_class.to_s.split('::')[-1]
|
33
|
+
resource_name = resource_class.to_s.split('::')[-1]
|
34
|
+
resource_name = maybe_underscore_name(resource_name)
|
35
|
+
resource_name.downcase
|
36
|
+
end
|
37
|
+
|
38
|
+
def maybe_underscore_name(resource_name)
|
39
|
+
resource_name.gsub!(/(.)([A-Z])/, '\1_\2') || resource_name
|
27
40
|
end
|
28
41
|
|
29
42
|
def resource_class_to_collection_name(resource_class)
|
@@ -31,7 +44,7 @@ module Intercom
|
|
31
44
|
end
|
32
45
|
|
33
46
|
def constantize_resource_name(resource_name)
|
34
|
-
class_name = Utils.singularize(resource_name.capitalize)
|
47
|
+
class_name = camelize Utils.singularize(resource_name.capitalize)
|
35
48
|
define_lightweight_class(class_name) unless Intercom.const_defined?(class_name, false)
|
36
49
|
namespaced_class_name = "Intercom::#{class_name}"
|
37
50
|
constantize namespaced_class_name
|
@@ -52,9 +65,12 @@ module Intercom
|
|
52
65
|
end
|
53
66
|
|
54
67
|
def entity_key_from_type(type)
|
68
|
+
return 'data' if type == 'list'
|
69
|
+
|
55
70
|
is_list = type.split('.')[1] == 'list'
|
56
71
|
entity_name = type.split('.')[0]
|
57
|
-
|
72
|
+
return Utils.pluralize(entity_name) if entity_name == 'event'
|
73
|
+
is_list ? Utils.pluralize(entity_name) : entity_name
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
data/lib/intercom/version.rb
CHANGED
data/lib/intercom/visitor.rb
CHANGED
data/lib/intercom.rb
CHANGED
@@ -1,41 +1,58 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'intercom/version'
|
2
4
|
require 'intercom/service/admin'
|
5
|
+
require 'intercom/service/article'
|
6
|
+
require 'intercom/service/collection'
|
3
7
|
require 'intercom/service/company'
|
4
8
|
require 'intercom/service/contact'
|
5
9
|
require 'intercom/service/conversation'
|
6
10
|
require 'intercom/service/count'
|
7
|
-
require 'intercom/service/customer'
|
8
11
|
require 'intercom/service/event'
|
9
12
|
require 'intercom/service/message'
|
10
13
|
require 'intercom/service/note'
|
11
14
|
require 'intercom/service/job'
|
15
|
+
require 'intercom/service/subscription_type'
|
12
16
|
require 'intercom/service/subscription'
|
13
17
|
require 'intercom/service/segment'
|
18
|
+
require 'intercom/service/section'
|
14
19
|
require 'intercom/service/tag'
|
15
20
|
require 'intercom/service/team'
|
16
|
-
require 'intercom/service/user'
|
17
21
|
require 'intercom/service/visitor'
|
22
|
+
require 'intercom/service/user'
|
23
|
+
require 'intercom/service/lead'
|
24
|
+
require 'intercom/deprecated_resources.rb'
|
25
|
+
require 'intercom/service/export_content'
|
26
|
+
require 'intercom/service/phone_call_redirect'
|
18
27
|
require 'intercom/options'
|
19
28
|
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
|
29
|
+
require 'intercom/contact'
|
30
|
+
require 'intercom/user'
|
31
|
+
require 'intercom/lead'
|
32
|
+
require 'intercom/count'
|
33
|
+
require 'intercom/collection'
|
34
|
+
require 'intercom/company'
|
35
|
+
require 'intercom/service/data_attribute'
|
36
|
+
require 'intercom/note'
|
37
|
+
require 'intercom/job'
|
38
|
+
require 'intercom/tag'
|
39
|
+
require 'intercom/segment'
|
40
|
+
require 'intercom/section'
|
41
|
+
require 'intercom/event'
|
42
|
+
require 'intercom/conversation'
|
43
|
+
require 'intercom/message'
|
44
|
+
require 'intercom/admin'
|
45
|
+
require 'intercom/article'
|
46
|
+
require 'intercom/request'
|
47
|
+
require 'intercom/subscription'
|
48
|
+
require 'intercom/subscription_type'
|
49
|
+
require 'intercom/team'
|
50
|
+
require 'intercom/errors'
|
51
|
+
require 'intercom/visitor'
|
52
|
+
require 'intercom/data_attribute'
|
53
|
+
require 'intercom/export_content'
|
54
|
+
require 'intercom/phone_call_redirect'
|
55
|
+
require 'json'
|
39
56
|
|
40
57
|
##
|
41
58
|
# Intercom is a customer relationship management and messaging tool for web app owners
|