intercom 3.9.5 → 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.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +235 -222
  3. data/Rakefile +1 -1
  4. data/changes.txt +3 -0
  5. data/lib/intercom.rb +27 -22
  6. data/lib/intercom/api_operations/archive.rb +2 -1
  7. data/lib/intercom/api_operations/delete.rb +16 -0
  8. data/lib/intercom/api_operations/find.rb +5 -2
  9. data/lib/intercom/api_operations/find_all.rb +4 -3
  10. data/lib/intercom/api_operations/list.rb +4 -1
  11. data/lib/intercom/api_operations/load.rb +4 -2
  12. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  13. data/lib/intercom/api_operations/save.rb +5 -4
  14. data/lib/intercom/api_operations/scroll.rb +4 -5
  15. data/lib/intercom/api_operations/search.rb +3 -2
  16. data/lib/intercom/base_collection_proxy.rb +72 -0
  17. data/lib/intercom/client.rb +20 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/company.rb +8 -0
  20. data/lib/intercom/contact.rb +21 -3
  21. data/lib/intercom/conversation.rb +4 -0
  22. data/lib/intercom/data_attribute.rb +7 -0
  23. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  24. data/lib/intercom/deprecated_resources.rb +13 -0
  25. data/lib/intercom/errors.rb +3 -0
  26. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  27. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  28. data/lib/intercom/lead.rb +21 -0
  29. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  30. data/lib/intercom/note.rb +4 -0
  31. data/lib/intercom/request.rb +37 -33
  32. data/lib/intercom/scroll_collection_proxy.rb +33 -38
  33. data/lib/intercom/search_collection_proxy.rb +30 -65
  34. data/lib/intercom/service/base_service.rb +7 -0
  35. data/lib/intercom/service/company.rb +0 -12
  36. data/lib/intercom/service/contact.rb +21 -10
  37. data/lib/intercom/service/conversation.rb +12 -3
  38. data/lib/intercom/service/data_attribute.rb +20 -0
  39. data/lib/intercom/service/lead.rb +41 -0
  40. data/lib/intercom/service/note.rb +4 -8
  41. data/lib/intercom/service/subscription.rb +2 -2
  42. data/lib/intercom/service/tag.rb +9 -9
  43. data/lib/intercom/service/visitor.rb +17 -8
  44. data/lib/intercom/tag.rb +4 -0
  45. data/lib/intercom/traits/api_resource.rb +28 -17
  46. data/lib/intercom/user.rb +12 -3
  47. data/lib/intercom/utils.rb +13 -2
  48. data/lib/intercom/version.rb +1 -1
  49. data/lib/intercom/visitor.rb +0 -2
  50. data/spec/spec_helper.rb +738 -513
  51. data/spec/unit/intercom/admin_spec.rb +2 -2
  52. data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
  53. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  54. data/spec/unit/intercom/client_spec.rb +25 -26
  55. data/spec/unit/intercom/company_spec.rb +13 -15
  56. data/spec/unit/intercom/contact_spec.rb +289 -33
  57. data/spec/unit/intercom/conversation_spec.rb +29 -7
  58. data/spec/unit/intercom/count_spec.rb +4 -4
  59. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  60. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  61. data/spec/unit/intercom/event_spec.rb +9 -11
  62. data/spec/unit/intercom/job_spec.rb +24 -24
  63. data/spec/unit/intercom/lead_spec.rb +57 -0
  64. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  65. data/spec/unit/intercom/message_spec.rb +1 -1
  66. data/spec/unit/intercom/note_spec.rb +4 -10
  67. data/spec/unit/intercom/request_spec.rb +1 -1
  68. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  69. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  70. data/spec/unit/intercom/segment_spec.rb +2 -2
  71. data/spec/unit/intercom/subscription_spec.rb +5 -6
  72. data/spec/unit/intercom/tag_spec.rb +22 -14
  73. data/spec/unit/intercom/team_spec.rb +2 -2
  74. data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
  75. data/spec/unit/intercom/user_spec.rb +224 -226
  76. data/spec/unit/intercom/visitor_spec.rb +49 -0
  77. data/spec/unit/intercom_spec.rb +5 -3
  78. metadata +22 -7
  79. data/lib/intercom/customer.rb +0 -10
  80. data/lib/intercom/service/customer.rb +0 -14
  81. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -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/archive'
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::Archive
14
+ include ApiOperations::Delete
15
15
 
16
16
  def collection_class
17
17
  Intercom::Subscription
@@ -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::Archive
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
- users_or_companies(params).each do |user_or_company|
26
- user_or_company[:untag] = true
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/convert'
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::Convert
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
@@ -3,5 +3,9 @@ require 'intercom/traits/api_resource'
3
3
  module Intercom
4
4
  class Tag
5
5
  include Traits::ApiResource
6
+
7
+ def self.collection_proxy_class
8
+ Intercom::BaseCollectionProxy
9
+ end
6
10
  end
7
11
  end
@@ -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.inject({}) do |hash, variable|
35
- hash[variable.to_s.delete("@")] = instance_variable_get(variable)
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
- define_accessors_or_call { super }
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
- (respond_to?(:flat_store_attributes)) && (flat_store_attributes.map(&:to_s).include?(attribute.to_s))
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
- value_to_set = Intercom::Lib::TypedJsonDeserializer.new(value).deserialize
83
+ Intercom::Lib::TypedJsonDeserializer.new(value, client).deserialize
71
84
  elsif flat_store_attribute?(attribute)
72
- value_to_set = Intercom::Lib::FlatStore.new(value)
85
+ Intercom::Lib::FlatStore.new(value)
73
86
  else
74
- value_to_set = value
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? Hash and !!value['type']
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.to_s}="
105
- self.send(setter_method, value)
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 = self.new
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
@@ -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 ; [:id, :email, :user_id] ; end
10
- def flat_store_attributes ; [:custom_attributes] ; end
11
- def update_verb ; 'post' ; end
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
@@ -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].downcase
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 ? Utils.pluralize(entity_name) : entity_name
68
+ is_list ? Utils.pluralize(entity_name) : entity_name
58
69
  end
59
70
  end
60
71
  end
@@ -1,3 +1,3 @@
1
1
  module Intercom #:nodoc:
2
- VERSION = "3.9.5"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -8,7 +8,5 @@ module Intercom
8
8
 
9
9
  def identity_vars ; [:id, :email, :user_id] ; end
10
10
  def flat_store_attributes ; [:custom_attributes] ; end
11
- def update_verb ; 'put' ; end
12
-
13
11
  end
14
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'intercom'
2
4
  require 'minitest/autorun'
3
5
  require 'mocha/setup'
@@ -6,132 +8,175 @@ require 'time'
6
8
  require 'pry'
7
9
  include WebMock::API
8
10
 
9
- def test_customer(email="bob@example.com")
10
- customer = test_user(email)
11
- customer["type"] = "customer"
12
- customer["role"] = "user"
13
- customer
11
+ def test_user(email = 'bob@example.com')
12
+ {
13
+ 'type' => 'user',
14
+ 'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
15
+ 'user_id' => 'id-from-customers-app',
16
+ 'email' => email,
17
+ 'name' => 'Joe Schmoe',
18
+ 'avatar' => { 'type' => 'avatar', 'image_url' => 'https://graph.facebook.com/1/picture?width=24&height=24' },
19
+ 'app_id' => 'the-app-id',
20
+ 'custom_attributes' => { 'a' => 'b', 'b' => 2 },
21
+ 'companies' =>
22
+ { 'type' => 'company.list',
23
+ 'companies' =>
24
+ [{ 'type' => 'company',
25
+ 'company_id' => '123',
26
+ 'id' => 'bbbbbbbbbbbbbbbbbbbbbbbb',
27
+ 'app_id' => 'the-app-id',
28
+ 'name' => 'Company 1',
29
+ 'remote_created_at' => 1_390_936_440,
30
+ 'created_at' => 1_401_970_114,
31
+ 'updated_at' => 1_401_970_114,
32
+ 'last_request_at' => 1_401_970_113,
33
+ 'monthly_spend' => 0,
34
+ 'session_count' => 0,
35
+ 'user_count' => 1,
36
+ 'tag_ids' => [],
37
+ 'custom_attributes' => { 'category' => 'Tech' } }] },
38
+ 'session_count' => 123,
39
+ 'unsubscribed_from_emails' => true,
40
+ 'last_request_at' => 1_401_970_113,
41
+ 'created_at' => 1_401_970_114,
42
+ 'remote_created_at' => 1_393_613_864,
43
+ 'updated_at' => 1_401_970_114,
44
+ 'user_agent_data' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
45
+ 'social_profiles' => { 'type' => 'social_profile.list',
46
+ 'social_profiles' => [
47
+ { 'type' => 'social_profile', 'name' => 'twitter', 'url' => 'http://twitter.com/abc', 'username' => 'abc', 'id' => nil },
48
+ { 'type' => 'social_profile', 'name' => 'twitter', 'username' => 'abc2', 'url' => 'http://twitter.com/abc2', 'id' => nil },
49
+ { 'type' => 'social_profile', 'name' => 'facebook', 'url' => 'http://facebook.com/abc', 'username' => 'abc', 'id' => '1234242' },
50
+ { 'type' => 'social_profile', 'name' => 'quora', 'url' => 'http://facebook.com/abc', 'username' => 'abc', 'id' => '1234242' }
51
+ ] },
52
+ 'location_data' =>
53
+ { 'type' => 'location_data',
54
+ 'city_name' => 'Dublin',
55
+ 'continent_code' => 'EU',
56
+ 'country_name' => 'Ireland',
57
+ 'latitude' => '90',
58
+ 'longitude' => '10',
59
+ 'postal_code' => 'IE',
60
+ 'region_name' => 'Europe',
61
+ 'timezone' => '+1000',
62
+ 'country_code' => 'IRL' }
63
+ }
14
64
  end
15
65
 
16
- def test_user(email="bob@example.com")
66
+ def test_contact(email = 'bob@example.com', role = 'user')
17
67
  {
18
- "type" =>"user",
19
- "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa",
20
- "user_id" => 'id-from-customers-app',
21
- "email" => email,
22
- "name" => "Joe Schmoe",
23
- "avatar" => {"type"=>"avatar", "image_url"=>"https://graph.facebook.com/1/picture?width=24&height=24"},
24
- "app_id" => "the-app-id",
25
- "custom_attributes" => {"a" => "b", "b" => 2},
26
- "companies" =>
27
- {"type"=>"company.list",
28
- "companies"=>
29
- [{"type"=>"company",
30
- "company_id"=>"123",
31
- "id"=>"bbbbbbbbbbbbbbbbbbbbbbbb",
32
- "app_id"=>"the-app-id",
33
- "name"=>"Company 1",
34
- "remote_created_at"=>1390936440,
35
- "created_at"=>1401970114,
36
- "updated_at"=>1401970114,
37
- "last_request_at"=>1401970113,
38
- "monthly_spend"=>0,
39
- "session_count"=>0,
40
- "user_count"=>1,
41
- "tag_ids"=>[],
42
- "custom_attributes"=>{"category"=>"Tech"}}]},
43
- "session_count" => 123,
44
- "unsubscribed_from_emails" => true,
45
- "last_request_at" =>1401970113,
46
- "created_at" =>1401970114,
47
- "remote_created_at" =>1393613864,
48
- "updated_at" =>1401970114,
49
- "user_agent_data" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
50
- "social_profiles" =>{"type"=>"social_profile.list",
51
- "social_profiles" => [
52
- {"type" => "social_profile", "name" => "twitter", "url" => "http://twitter.com/abc", "username" => "abc", "id" => nil},
53
- {"type" => "social_profile", "name" => "twitter", "username" => "abc2", "url" => "http://twitter.com/abc2", "id" => nil},
54
- {"type" => "social_profile", "name" => "facebook", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"},
55
- {"type" => "social_profile", "name" => "quora", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"}
56
- ]},
57
- "location_data"=>
58
- {"type"=>"location_data",
59
- "city_name"=> 'Dublin',
60
- "continent_code"=> 'EU',
61
- "country_name"=> 'Ireland',
62
- "latitude"=> '90',
63
- "longitude"=> '10',
64
- "postal_code"=> 'IE',
65
- "region_name"=> 'Europe',
66
- "timezone"=> '+1000',
67
- "country_code" => "IRL"}
68
+ 'type' => 'contact',
69
+ 'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
70
+ 'external_id' => 'id-from-customers-app',
71
+ 'role' => role,
72
+ 'email' => email,
73
+ 'name' => 'Joe Schmoe',
74
+ 'avatar' => { 'type' => 'avatar', 'image_url' => 'https://graph.facebook.com/1/picture?width=24&height=24' },
75
+ 'workspace_id' => 'the-workspace-id',
76
+ 'custom_attributes' => { 'a' => 'b', 'b' => 2 },
77
+ 'companies' => {
78
+ 'type' => 'list',
79
+ 'data' =>
80
+ [{ 'type' => 'company',
81
+ 'company_id' => '123',
82
+ 'id' => 'bbbbbbbbbbbbbbbbbbbbbbbb',
83
+ 'workspace_id' => 'the-workspace-id',
84
+ 'name' => 'Company 1',
85
+ 'remote_created_at' => 1_390_936_440,
86
+ 'created_at' => 1_401_970_114,
87
+ 'updated_at' => 1_401_970_114,
88
+ 'last_request_at' => 1_401_970_113,
89
+ 'monthly_spend' => 0,
90
+ 'session_count' => 0,
91
+ 'contact_count' => 1,
92
+ 'tag_ids' => [],
93
+ 'custom_attributes' => { 'category' => 'Tech' } }],
94
+ 'url' => '/contacts/12345/companies'
95
+ },
96
+ 'tags' => {
97
+ 'type' => 'list',
98
+ 'data' => [],
99
+ 'url' => '/contacts/12345/tags'
100
+ },
101
+ 'notes' => {
102
+ 'type' => 'list',
103
+ 'data' => [],
104
+ 'url' => '/contacts/12345/notes'
105
+ },
106
+ 'session_count' => 123,
107
+ 'unsubscribed_from_emails' => true,
108
+ 'last_request_at' => 1_401_970_113,
109
+ 'created_at' => 1_401_970_114,
110
+ 'remote_created_at' => 1_393_613_864,
111
+ 'updated_at' => 1_401_970_114,
112
+ 'user_agent_data' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
113
+ 'social_profiles' => { 'type' => 'social_profile.list',
114
+ 'social_profiles' => [
115
+ { 'type' => 'social_profile', 'name' => 'twitter', 'url' => 'http://twitter.com/abc', 'username' => 'abc', 'id' => nil },
116
+ { 'type' => 'social_profile', 'name' => 'twitter', 'username' => 'abc2', 'url' => 'http://twitter.com/abc2', 'id' => nil },
117
+ { 'type' => 'social_profile', 'name' => 'facebook', 'url' => 'http://facebook.com/abc', 'username' => 'abc', 'id' => '1234242' },
118
+ { 'type' => 'social_profile', 'name' => 'quora', 'url' => 'http://facebook.com/abc', 'username' => 'abc', 'id' => '1234242' }
119
+ ] },
120
+ 'location_data' =>
121
+ { 'type' => 'location_data',
122
+ 'city_name' => 'Dublin',
123
+ 'continent_code' => 'EU',
124
+ 'country_name' => 'Ireland',
125
+ 'latitude' => '90',
126
+ 'longitude' => '10',
127
+ 'postal_code' => 'IE',
128
+ 'region_name' => 'Europe',
129
+ 'timezone' => '+1000',
130
+ 'country_code' => 'IRL' }
68
131
  }
69
132
  end
70
133
 
71
- def test_user_dates(email="bob@example.com", created_at=1401970114, last_request_at=1401970113)
134
+ def test_visitor
72
135
  {
73
- "type" =>"user",
74
- "id" =>"aaaaaaaaaaaaaaaaaaaaaaaa",
75
- "user_id" => 'id-from-customers-app',
76
- "email" => email,
77
- "name" => "Joe Schmoe",
78
- "avatar" => {"type"=>"avatar", "image_url"=>"https://graph.facebook.com/1/picture?width=24&height=24"},
79
- "app_id" => "the-app-id",
80
- "custom_attributes" => {"a" => "b", "b" => 2},
81
- "companies" =>
82
- {"type"=>"company.list",
83
- "companies"=>
84
- [{"type"=>"company",
85
- "company_id"=>"123",
86
- "id"=>"bbbbbbbbbbbbbbbbbbbbbbbb",
87
- "app_id"=>"the-app-id",
88
- "name"=>"Company 1",
89
- "remote_created_at"=>1390936440,
90
- "created_at"=>1401970114,
91
- "updated_at"=>1401970114,
92
- "last_request_at"=>1401970113,
93
- "monthly_spend"=>0,
94
- "session_count"=>0,
95
- "user_count"=>1,
96
- "tag_ids"=>[],
97
- "custom_attributes"=>{"category"=>"Tech"}}]},
98
- "session_count" => 123,
99
- "unsubscribed_from_emails" => true,
100
- "last_request_at" =>last_request_at,
101
- "created_at" =>created_at,
102
- "remote_created_at" =>1393613864,
103
- "updated_at" =>1401970114,
104
- "user_agent_data" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
105
- "social_profiles" =>{"type"=>"social_profile.list",
106
- "social_profiles" => [
107
- {"type" => "social_profile", "name" => "twitter", "url" => "http://twitter.com/abc", "username" => "abc", "id" => nil},
108
- {"type" => "social_profile", "name" => "twitter", "username" => "abc2", "url" => "http://twitter.com/abc2", "id" => nil},
109
- {"type" => "social_profile", "name" => "facebook", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"},
110
- {"type" => "social_profile", "name" => "quora", "url" => "http://facebook.com/abc", "username" => "abc", "id" => "1234242"}
111
- ]},
112
- "location_data"=>
113
- {"type"=>"location_data",
114
- "city_name"=> 'Dublin',
115
- "continent_code"=> 'EU',
116
- "country_name"=> 'Ireland',
117
- "latitude"=> '90',
118
- "longitude"=> '10',
119
- "postal_code"=> 'IE',
120
- "region_name"=> 'Europe',
121
- "timezone"=> '+1000',
122
- "country_code" => "IRL"}
136
+ 'type' => 'visitor',
137
+ 'id' => '123',
138
+ 'user_id' => '12334',
139
+ 'anonymous' => true,
140
+ 'email' => nil,
141
+ 'phone' => nil,
142
+ 'name' => nil,
143
+ 'pseudonym' => nil,
144
+ 'app_id' => 'abcd1234',
145
+ 'companies' => { 'type' => 'company.list', 'companies' => [] },
146
+ 'location_data' => {},
147
+ 'last_request_at' => nil,
148
+ 'created_at' => 1_401_970_114,
149
+ 'remote_created_at' => 1_401_970_114,
150
+ 'signed_up_at' => 1_401_970_114,
151
+ 'updated_at' => 1_401_970_114,
152
+ 'session_count' => 0,
153
+ 'social_profiles' => { 'type' => 'social_profile.list', 'social_profiles' => [] },
154
+ 'owner_id' => nil,
155
+ 'unsubscribed_from_emails' => false,
156
+ 'marked_email_as_spam' => false,
157
+ 'has_hard_bounced' => false,
158
+ 'tags' => { 'type' => 'tag.list', 'tags' => [] },
159
+ 'segments' => { 'type' => 'segment.list', 'segments' => [] },
160
+ 'custom_attributes' => {},
161
+ 'referrer' => nil,
162
+ 'utm_campaign' => nil,
163
+ 'utm_content' => nil,
164
+ 'utm_medium' => nil,
165
+ 'utm_source' => nil,
166
+ 'utm_term' => nil,
167
+ 'do_not_track' => nil
123
168
  }
124
169
  end
125
170
 
126
171
  def test_admin_list
127
172
  {
128
- "type" => "admin.list",
129
- "admins" => [
173
+ 'type' => 'admin.list',
174
+ 'admins' => [
130
175
  {
131
- "type" => "admin",
132
- "id" => "1234",
133
- "name" => "Hoban Washburne",
134
- "email" => "wash@serenity.io"
176
+ 'type' => 'admin',
177
+ 'id' => '1234',
178
+ 'name' => 'Hoban Washburne',
179
+ 'email' => 'wash@serenity.io'
135
180
  }
136
181
  ]
137
182
  }
@@ -139,63 +184,88 @@ end
139
184
 
140
185
  def test_admin
141
186
  {
142
- "type" => "admin",
143
- "id" => "1234",
144
- "name" => "Hoban Washburne",
145
- "email" => "wash@serenity.io"
187
+ 'type' => 'admin',
188
+ 'id' => '1234',
189
+ 'name' => 'Hoban Washburne',
190
+ 'email' => 'wash@serenity.io'
146
191
  }
147
192
  end
148
193
 
149
194
  def test_team_list
150
195
  {
151
- "type"=> "team.list",
152
- "teams" => [
196
+ 'type' => 'team.list',
197
+ 'teams' => [
153
198
  {
154
- "type"=> "team",
155
- "id"=> "2744328",
156
- "name"=> "the_a_team",
157
- "admin_ids"=> [646303, 814860],
199
+ 'type' => 'team',
200
+ 'id' => '2744328',
201
+ 'name' => 'the_a_team',
202
+ 'admin_ids' => [646_303, 814_860]
158
203
  },
159
204
  {
160
- "type"=> "team",
161
- "id"=> "814865",
162
- "name"=> "BA_App",
163
- "admin_ids" => [492881, 1195856]
164
- },
205
+ 'type' => 'team',
206
+ 'id' => '814865',
207
+ 'name' => 'BA_App',
208
+ 'admin_ids' => [492_881, 1_195_856]
209
+ }
165
210
  ]
166
211
  }
167
212
  end
168
213
 
169
214
  def test_team
170
215
  {
171
- "type" => "team",
172
- "id" => "2744328",
173
- "name" => "the_a_team",
174
- "admin_ids" => [646303, 814860]
216
+ 'type' => 'team',
217
+ 'id' => '2744328',
218
+ 'name' => 'the_a_team',
219
+ 'admin_ids' => [646_303, 814_860]
220
+ }
221
+ end
222
+
223
+ def test_company(name = 'Blue Sun')
224
+ {
225
+ 'type' => 'company',
226
+ 'id' => '531ee472cce572a6ec000006',
227
+ 'name' => name,
228
+ 'plan' => {
229
+ 'type' => 'plan',
230
+ 'id' => '1',
231
+ 'name' => 'Paid'
232
+ },
233
+ 'company_id' => '6',
234
+ 'remote_created_at' => 1_394_531_169,
235
+ 'created_at' => 1_394_533_506,
236
+ 'updated_at' => 1_396_874_658,
237
+ 'last_request_at' => 1_396_874_658,
238
+ 'monthly_spend' => 49,
239
+ 'session_count' => 26,
240
+ 'user_count' => 10,
241
+ 'custom_attributes' => {
242
+ 'paid_subscriber' => true,
243
+ 'team_mates' => 0
244
+ }
175
245
  }
176
246
  end
177
247
 
178
- def test_company
248
+ def test_company_dates(name = 'Blue Sun', created_at = 1_401_970_114, last_request_at = 1_401_970_113)
179
249
  {
180
- "type" => "company",
181
- "id" => "531ee472cce572a6ec000006",
182
- "name" => "Blue Sun",
183
- "plan" => {
184
- "type" =>"plan",
185
- "id" =>"1",
186
- "name" =>"Paid"
250
+ 'type' => 'company',
251
+ 'id' => '531ee472cce572a6ec000006',
252
+ 'name' => name,
253
+ 'plan' => {
254
+ 'type' => 'plan',
255
+ 'id' => '1',
256
+ 'name' => 'Paid'
187
257
  },
188
- "company_id" => "6",
189
- "remote_created_at" => 1394531169,
190
- "created_at" => 1394533506,
191
- "updated_at" => 1396874658,
192
- "last_request_at" => 1396874658,
193
- "monthly_spend" => 49,
194
- "session_count" => 26,
195
- "user_count" => 10,
196
- "custom_attributes" => {
197
- "paid_subscriber" => true,
198
- "team_mates" => 0
258
+ 'company_id' => '6',
259
+ 'remote_created_at' => 1_394_531_169,
260
+ 'created_at' => created_at,
261
+ 'updated_at' => 1_396_874_658,
262
+ 'last_request_at' => last_request_at,
263
+ 'monthly_spend' => 49,
264
+ 'session_count' => 26,
265
+ 'user_count' => 10,
266
+ 'custom_attributes' => {
267
+ 'paid_subscriber' => true,
268
+ 'team_mates' => 0
199
269
  }
200
270
  }
201
271
  end
@@ -206,140 +276,238 @@ end
206
276
 
207
277
  def test_message
208
278
  {
209
- "created_at" => 1329837506,
210
- "updated_at" => 1329664706,
211
- "read" => true,
212
- "created_by_user" => true,
213
- "thread_id" => 5591,
214
- "messages" => [
215
- {
216
- "created_at" => 1329837506,
217
- "html" => "<p>Hey Intercom, What is up?</p>\n",
218
- "from" => {
219
- "email" => "bob@example.com",
220
- "name" => "Bob",
221
- "user_id" => "123",
222
- "is_admin" => false
223
- }
224
- },
225
- {
226
- "created_at" => 1329664706,
227
- "rendered_body" => "<p>Not much, you?</p>\n",
228
- "from" => {
229
- "name" => "Super Duper Admin",
230
- "avatar" => {
231
- "square_25" => "https://static.intercomcdn.com/avatars/13347/square_25/Ruairi_Profile.png?1375368166",
232
- "square_50" => "https://static.intercomcdn.com/avatars/13347/square_50/Ruairi_Profile.png?1375368166",
233
- "square_128" => "https://static.intercomcdn.com/avatars/13347/square_128/Ruairi_Profile.png?1375368166"
234
- },
235
- "is_admin" => true
236
- }
279
+ 'created_at' => 1_329_837_506,
280
+ 'updated_at' => 1_329_664_706,
281
+ 'read' => true,
282
+ 'created_by_user' => true,
283
+ 'thread_id' => 5591,
284
+ 'messages' => [
285
+ {
286
+ 'created_at' => 1_329_837_506,
287
+ 'html' => "<p>Hey Intercom, What is up?</p>\n",
288
+ 'from' => {
289
+ 'email' => 'bob@example.com',
290
+ 'name' => 'Bob',
291
+ 'user_id' => '123',
292
+ 'is_admin' => false
293
+ }
294
+ },
295
+ {
296
+ 'created_at' => 1_329_664_706,
297
+ 'rendered_body' => "<p>Not much, you?</p>\n",
298
+ 'from' => {
299
+ 'name' => 'Super Duper Admin',
300
+ 'avatar' => {
301
+ 'square_25' => 'https://static.intercomcdn.com/avatars/13347/square_25/Ruairi_Profile.png?1375368166',
302
+ 'square_50' => 'https://static.intercomcdn.com/avatars/13347/square_50/Ruairi_Profile.png?1375368166',
303
+ 'square_128' => 'https://static.intercomcdn.com/avatars/13347/square_128/Ruairi_Profile.png?1375368166'
237
304
  },
238
- {
239
- "created_at" => 1329664806,
240
- "rendered_body" => "<p>Not much either :(</p>\n",
241
- "from" => {
242
- "email" => "bob@example.com",
243
- "name" => "Bob",
244
- "user_id" => "123",
245
- "is_admin" => false
246
- }
247
- }
248
- ]
305
+ 'is_admin' => true
306
+ }
307
+ },
308
+ {
309
+ 'created_at' => 1_329_664_806,
310
+ 'rendered_body' => "<p>Not much either :(</p>\n",
311
+ 'from' => {
312
+ 'email' => 'bob@example.com',
313
+ 'name' => 'Bob',
314
+ 'user_id' => '123',
315
+ 'is_admin' => false
316
+ }
317
+ }
318
+ ]
249
319
  }
250
320
  end
251
321
 
252
- def page_of_users(include_next_link= false)
322
+ def page_of_users(include_next_link = false)
253
323
  {
254
- "type"=>"user.list",
255
- "pages"=>
324
+ 'type' => 'user.list',
325
+ 'pages' =>
256
326
  {
257
- "type"=>"pages",
258
- "next"=> (include_next_link ? "https://api.intercom.io/users?per_page=50&page=2" : nil),
259
- "page"=>1,
260
- "per_page"=>50,
261
- "total_pages"=>7
327
+ 'type' => 'pages',
328
+ 'next' => (include_next_link ? 'https://api.intercom.io/users?per_page=50&page=2' : nil),
329
+ 'page' => 1,
330
+ 'per_page' => 50,
331
+ 'total_pages' => 7
262
332
  },
263
- "users"=> [test_user("user1@example.com"), test_user("user2@example.com"), test_user("user3@example.com")],
264
- "total_count"=>314
333
+ 'users' => [test_user('user1@example.com'), test_user('user2@example.com'), test_user('user3@example.com')],
334
+ 'total_count' => 314
265
335
  }
266
336
  end
267
337
 
268
- def page_of_customers(include_starting_after= false)
338
+ def page_of_contacts(include_starting_after = false)
339
+ { 'type' => 'list',
340
+ 'data' => [
341
+ {
342
+ 'type' => 'contact',
343
+ 'id' => '123',
344
+ 'workspace_id' => 'abc',
345
+ 'external_id' => '12345',
346
+ 'role' => 'lead',
347
+ 'email' => 'test1@example.com',
348
+ 'name' => 'Test',
349
+ 'unsubscribed_from_emails' => false,
350
+ 'created_at' => 1_573_035_771,
351
+ 'updated_at' => 1_573_035_771,
352
+ 'custom_attributes' => {},
353
+ 'tags' => {
354
+ 'type' => 'list',
355
+ 'data' => [],
356
+ 'url' => '/contacts/12345/tags'
357
+ },
358
+ 'notes' => {
359
+ 'type' => 'list',
360
+ 'data' => [],
361
+ 'url' => '/contacts/12345/notes'
362
+ },
363
+ 'companies' => {
364
+ 'type' => 'list',
365
+ 'data' => [],
366
+ 'url' => '/contacts/12345/companies'
367
+ }
368
+ },
369
+ {
370
+ 'type' => 'contact',
371
+ 'id' => '321',
372
+ 'workspace_id' => 'abc',
373
+ 'external_id' => '54321',
374
+ 'role' => 'user',
375
+ 'email' => 'test2@example.com',
376
+ 'name' => 'Test',
377
+ 'unsubscribed_from_emails' => false,
378
+ 'created_at' => 1_573_035_771,
379
+ 'updated_at' => 1_573_035_771,
380
+ 'custom_attributes' => {},
381
+ 'tags' => {
382
+ 'type' => 'list',
383
+ 'data' => [],
384
+ 'url' => '/contacts/54321/tags'
385
+ },
386
+ 'notes' => {
387
+ 'type' => 'list',
388
+ 'data' => [],
389
+ 'url' => '/contacts/54321/notes'
390
+ },
391
+ 'companies' => {
392
+ 'type' => 'list',
393
+ 'data' => [],
394
+ 'url' => '/contacts/54321/companies'
395
+ }
396
+ },
397
+ {
398
+ 'type' => 'contact',
399
+ 'id' => '111',
400
+ 'workspace_id' => 'abc',
401
+ 'external_id' => '111',
402
+ 'role' => 'lead',
403
+ 'email' => 'test3@example.com',
404
+ 'name' => 'Test',
405
+ 'unsubscribed_from_emails' => false,
406
+ 'created_at' => 1_573_035_771,
407
+ 'updated_at' => 1_573_035_771,
408
+ 'custom_attributes' => {},
409
+ 'tags' => {
410
+ 'type' => 'list',
411
+ 'data' => [],
412
+ 'url' => '/contacts/111/tags'
413
+ },
414
+ 'notes' => {
415
+ 'type' => 'list',
416
+ 'data' => [],
417
+ 'url' => '/contacts/111/notes'
418
+ },
419
+ 'companies' => {
420
+ 'type' => 'list',
421
+ 'data' => [],
422
+ 'url' => '/contacts/111/companies'
423
+ }
424
+ }
425
+ ],
426
+ 'total_count' => 3,
427
+ 'pages' => {
428
+ 'type' => 'pages',
429
+ 'next' => (include_starting_after ? { 'page' => 2, 'starting_after' => 'EnCrYpTeDsTrInG' } : nil),
430
+ 'page' => 1,
431
+ 'per_page' => 50,
432
+ 'total_pages' => 1
433
+ } }
434
+ end
435
+
436
+ def page_of_companies(include_next_link = false)
269
437
  {
270
- "type"=>"customer.list",
271
- "pages"=>
272
- {
273
- "type"=>"pages",
274
- "next"=> (include_starting_after ? { "page" => 2, "starting_after" => "EnCrYpTeDsTrInG" } : nil),
275
- "page"=>1,
276
- "per_page"=>50,
277
- "total_pages"=>7
278
- },
279
- "customers"=> [test_customer("user1@example.com"), test_customer("user2@example.com"), test_customer("user3@example.com")],
280
- "total_count"=>314
438
+ 'type' => 'company.list',
439
+ 'pages' =>
440
+ {
441
+ 'type' => 'pages',
442
+ 'next' => (include_next_link ? 'https://api.intercom.io/companies?per_page=50&page=2' : nil),
443
+ 'page' => 1,
444
+ 'per_page' => 50,
445
+ 'total_pages' => 7
446
+ },
447
+ 'companies' => [test_company('company1'), test_company('company2'), test_company('company3')],
448
+ 'total_count' => 314
281
449
  }
282
450
  end
283
451
 
284
- def users_scroll(include_users= false)
452
+ def companies_scroll(include_companies = false)
285
453
  {
286
- "type"=>"user.list",
287
- "scroll_param"=> ("da6bbbac-25f6-4f07-866b-b911082d7"),
288
- "users"=> (include_users ? [test_user("user1@example.com"), test_user("user2@example.com"), test_user("user3@example.com")] : []),
454
+ 'type' => 'company.list',
455
+ 'scroll_param' => 'da6bbbac-25f6-4f07-866b-b911082d7',
456
+ 'companies' => (include_companies ? [test_company('company1'), test_company('company2'), test_company('company3')] : [])
289
457
  }
290
458
  end
291
459
 
292
- def users_pagination(include_next_link:, per_page:, page:, total_pages:, total_count:, user_list:)
460
+ def companies_pagination(include_next_link:, per_page:, page:, total_pages:, total_count:, company_list:)
293
461
  {
294
- "type"=>"user.list",
295
- "pages"=>
462
+ 'type' => 'company.list',
463
+ 'pages' =>
296
464
  {
297
- "type"=>"pages",
298
- "next"=> (include_next_link ? "https://api.intercom.io/users?per_page=" \
299
- + per_page.to_s + "&page=" + (page+1).to_s : nil),
300
- "page"=>page,
301
- "per_page"=>per_page,
302
- "total_pages"=>total_pages
465
+ 'type' => 'pages',
466
+ 'next' => (include_next_link ? 'https://api.intercom.io/companies?per_page=' \
467
+ + per_page.to_s + '&page=' + (page + 1).to_s : nil),
468
+ 'page' => page,
469
+ 'per_page' => per_page,
470
+ 'total_pages' => total_pages
303
471
  },
304
- "users"=> user_list,
305
- "total_count"=>total_count
472
+ 'companies' => company_list,
473
+ 'total_count' => total_count
306
474
  }
307
475
  end
308
476
 
309
477
  def test_conversation
310
478
  {
311
- "type" => "conversation",
312
- "id" => "147",
313
- "created_at" => 1400850973,
314
- "updated_at" => 1400857494,
315
- "conversation_message" => {
316
- "type" => "conversation_message",
317
- "subject" => "",
318
- "body" => "<p>Hi Alice,</p>\n\n<p>We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
319
- "author" => {
320
- "type" => "admin",
321
- "id" => "25"
479
+ 'type' => 'conversation',
480
+ 'id' => '147',
481
+ 'created_at' => 1_400_850_973,
482
+ 'updated_at' => 1_400_857_494,
483
+ 'conversation_message' => {
484
+ 'type' => 'conversation_message',
485
+ 'subject' => '',
486
+ 'body' => "<p>Hi Alice,</p>\n\n<p>We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
487
+ 'author' => {
488
+ 'type' => 'admin',
489
+ 'id' => '25'
322
490
  },
323
- "attachments" => [
491
+ 'attachments' => [
324
492
  {
325
- "name" => "signature",
326
- "url" => "http =>//someurl.com/signature.jpg"
493
+ 'name' => 'signature',
494
+ 'url' => 'http =>//someurl.com/signature.jpg'
327
495
  }
328
496
  ]
329
497
  },
330
- "user" => {
331
- "type" => "user",
332
- "id" => "536e564f316c83104c000020"
498
+ 'user' => {
499
+ 'type' => 'user',
500
+ 'id' => '536e564f316c83104c000020'
333
501
  },
334
- "assignee" => {
335
- "type" => "admin",
336
- "id" => "25"
502
+ 'assignee' => {
503
+ 'type' => 'admin',
504
+ 'id' => '25'
337
505
  },
338
- "open" => true,
339
- "read" => true,
340
- "conversation_parts" => {
341
- "type" => "conversation_part.list",
342
- "conversation_parts" => [
506
+ 'open' => true,
507
+ 'read' => true,
508
+ 'conversation_parts' => {
509
+ 'type' => 'conversation_part.list',
510
+ 'conversation_parts' => [
343
511
  ]
344
512
  }
345
513
  }
@@ -347,88 +515,88 @@ end
347
515
 
348
516
  def test_conversation_list
349
517
  {
350
- "type" => "conversation.list",
351
- "pages" => {
352
- "type" => "pages",
353
- "page" => 1,
354
- "per_page" => 20,
355
- "total_pages" => 1
356
- },
357
- "conversations" => [
358
- {
359
- "type" => "conversation",
360
- "id" => "147",
361
- "created_at" => 1400850973,
362
- "updated_at" => 1400857494,
363
- "conversation_message" => {
364
- "type" => "conversation_message",
365
- "subject" => "",
366
- "body" => "<p>Hi Alice,</p>\n\n<p>We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
367
- "author" => {
368
- "type" => "admin",
369
- "id" => "25"
370
- },
371
- "attachments" => [
372
- {
373
- "name" => "signature",
374
- "url" => "http =>//someurl.com/signature.jpg"
375
- }
376
- ]
377
- },
378
- "user" => {
379
- "type" => "user",
380
- "id" => "536e564f316c83104c000020"
381
- },
382
- "assignee" => {
383
- "type" => "admin",
384
- "id" => "25"
385
- },
386
- "open" => true,
387
- "read" => true,
388
- "conversation_parts" => {
389
- "type" => "conversation_part.list",
390
- "conversation_parts" => [
391
- ]
392
- }
393
- }
394
- ]
518
+ 'type' => 'conversation.list',
519
+ 'pages' => {
520
+ 'type' => 'pages',
521
+ 'page' => 1,
522
+ 'per_page' => 20,
523
+ 'total_pages' => 1
524
+ },
525
+ 'conversations' => [
526
+ {
527
+ 'type' => 'conversation',
528
+ 'id' => '147',
529
+ 'created_at' => 1_400_850_973,
530
+ 'updated_at' => 1_400_857_494,
531
+ 'conversation_message' => {
532
+ 'type' => 'conversation_message',
533
+ 'subject' => '',
534
+ 'body' => "<p>Hi Alice,</p>\n\n<p>We noticed you using our Product, do you have any questions?</p> \n<p>- Jane</p>",
535
+ 'author' => {
536
+ 'type' => 'admin',
537
+ 'id' => '25'
538
+ },
539
+ 'attachments' => [
540
+ {
541
+ 'name' => 'signature',
542
+ 'url' => 'http =>//someurl.com/signature.jpg'
543
+ }
544
+ ]
545
+ },
546
+ 'user' => {
547
+ 'type' => 'user',
548
+ 'id' => '536e564f316c83104c000020'
549
+ },
550
+ 'assignee' => {
551
+ 'type' => 'admin',
552
+ 'id' => '25'
553
+ },
554
+ 'open' => true,
555
+ 'read' => true,
556
+ 'conversation_parts' => {
557
+ 'type' => 'conversation_part.list',
558
+ 'conversation_parts' => [
559
+ ]
560
+ }
561
+ }
562
+ ]
395
563
  }
396
564
  end
397
565
 
398
566
  def segment
399
567
  {
400
- "type" => "segment",
401
- "id" => "5310d8e7598c9a0b24000002",
402
- "name" => "Active",
403
- "created_at" => 1393613031,
404
- "updated_at" => 1393613031
568
+ 'type' => 'segment',
569
+ 'id' => '5310d8e7598c9a0b24000002',
570
+ 'name' => 'Active',
571
+ 'created_at' => 1_393_613_031,
572
+ 'updated_at' => 1_393_613_031
405
573
  }
406
574
  end
407
575
 
408
576
  def segment_list
409
577
  {
410
- "type" => "segment.list",
411
- "segments" => [
578
+ 'type' => 'segment.list',
579
+ 'segments' => [
412
580
  {
413
- "created_at" => 1393613031,
414
- "id" => "5310d8e7598c9a0b24000002",
415
- "name" => "Active",
416
- "type" => "segment",
417
- "updated_at" => 1393613031
581
+ 'created_at' => 1_393_613_031,
582
+ 'id' => '5310d8e7598c9a0b24000002',
583
+ 'name' => 'Active',
584
+ 'type' => 'segment',
585
+ 'updated_at' => 1_393_613_031
418
586
  },
419
587
  {
420
- "created_at" => 1393613030,
421
- "id" => "5310d8e6598c9a0b24000001",
422
- "name" => "New",
423
- "type" => "segment",
424
- "updated_at" => 1393613030
588
+ 'created_at' => 1_393_613_030,
589
+ 'id' => '5310d8e6598c9a0b24000001',
590
+ 'name' => 'New',
591
+ 'type' => 'segment',
592
+ 'updated_at' => 1_393_613_030
425
593
  },
426
594
  {
427
- "created_at" => 1393613031,
428
- "id" => "5310d8e7598c9a0b24000003",
429
- "name" => "Slipping Away",
430
- "type" => "segment",
431
- "updated_at" => 1393613031
595
+ 'created_at' => 1_393_613_031,
596
+ 'id' => '5310d8e7598c9a0b24000003',
597
+ 'name' => 'Slipping Away',
598
+ 'type' => 'segment',
599
+ 'updated_at' => 1_393_613_031
432
600
  }
433
601
  ]
434
602
  }
@@ -436,207 +604,210 @@ end
436
604
 
437
605
  def test_tag
438
606
  {
439
- "id" => "4f73428b5e4dfc000b000112",
440
- "name" => "Test Tag",
441
- "segment" => false,
442
- "tagged_user_count" => 2
607
+ 'id' => '4f73428b5e4dfc000b000112',
608
+ 'name' => 'Test Tag',
609
+ 'segment' => false,
610
+ 'tagged_company_count' => 2
443
611
  }
444
612
  end
445
613
 
446
614
  def test_user_notification
447
615
  {
448
- "type" => "notification_event",
449
- "id" => "notif_123456-56465-546546",
450
- "topic" => "user.created",
451
- "app_id" => "aaaaaa",
452
- "data" =>
453
- {
454
- "type" => "notification_event_data",
455
- "item" =>
456
- {
457
- "type" => "user",
458
- "id" => "aaaaaaaaaaaaaaaaaaaaaaaa",
459
- "user_id" => nil,
460
- "email" => "joe@example.com",
461
- "name" => "Joe Schmoe",
462
- "avatar" =>
463
- {
464
- "type" => "avatar",
465
- "image_url" => nil
466
- },
467
- "app_id" => "aaaaa",
468
- "companies" =>
469
- {
470
- "type" => "company.list",
471
- "companies" => [ ]
472
- },
473
- "location_data" =>
474
- {
475
- },
476
- "last_request_at" => nil,
477
- "created_at" => "1401970114",
478
- "remote_created_at" => nil,
479
- "updated_at" => "1401970114",
480
- "session_count" => 0,
481
- "social_profiles" =>
482
- {
483
- "type" => "social_profile.list",
484
- "social_profiles" => [ ]
485
- },
486
- "unsubscribed_from_emails" => false,
487
- "user_agent_data" => nil,
488
- "tags" =>
489
- {
490
- "type" => "tag.list",
491
- "tags" => [ ]
492
- },
493
- "segments" =>
494
- {
495
- "type" => "segment.list",
496
- "segments" => [ ]
497
- },
498
- "custom_attributes" =>
499
- {
500
- }
501
- }
502
- },
503
- "delivery_status" => nil,
504
- "delivery_attempts" => 1,
505
- "delivered_at" => 0,
506
- "first_sent_at" => 1410188629,
507
- "created_at" => 1410188628,
508
- "links" => { },
509
- "self" => nil
616
+ 'type' => 'notification_event',
617
+ 'id' => 'notif_123456-56465-546546',
618
+ 'topic' => 'user.created',
619
+ 'app_id' => 'aaaaaa',
620
+ 'data' =>
621
+ {
622
+ 'type' => 'notification_event_data',
623
+ 'item' =>
624
+ {
625
+ 'type' => 'user',
626
+ 'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
627
+ 'user_id' => nil,
628
+ 'email' => 'joe@example.com',
629
+ 'name' => 'Joe Schmoe',
630
+ 'avatar' =>
631
+ {
632
+ 'type' => 'avatar',
633
+ 'image_url' => nil
634
+ },
635
+ 'app_id' => 'aaaaa',
636
+ 'companies' =>
637
+ {
638
+ 'type' => 'company.list',
639
+ 'companies' => []
640
+ },
641
+ 'location_data' =>
642
+ {
643
+ },
644
+ 'last_request_at' => nil,
645
+ 'created_at' => '1401970114',
646
+ 'remote_created_at' => nil,
647
+ 'updated_at' => '1401970114',
648
+ 'session_count' => 0,
649
+ 'social_profiles' =>
650
+ {
651
+ 'type' => 'social_profile.list',
652
+ 'social_profiles' => []
653
+ },
654
+ 'unsubscribed_from_emails' => false,
655
+ 'user_agent_data' => nil,
656
+ 'tags' =>
657
+ {
658
+ 'type' => 'tag.list',
659
+ 'tags' => []
660
+ },
661
+ 'segments' =>
662
+ {
663
+ 'type' => 'segment.list',
664
+ 'segments' => []
665
+ },
666
+ 'custom_attributes' =>
667
+ {
668
+ }
669
+ }
670
+ },
671
+ 'delivery_status' => nil,
672
+ 'delivery_attempts' => 1,
673
+ 'delivered_at' => 0,
674
+ 'first_sent_at' => 1_410_188_629,
675
+ 'created_at' => 1_410_188_628,
676
+ 'links' => {},
677
+ 'self' => nil
510
678
  }
511
679
  end
512
680
 
513
681
  def test_conversation_notification
514
682
  {
515
- "type"=>"notification_event",
516
- "id"=>"notif_123456-56465-546546",
517
- "topic"=>"conversation.user.created",
518
- "app_id"=>"aaaaa",
519
- "data"=>
520
- {
521
- "type"=>"notification_event_data",
522
- "item"=>
683
+ 'type' => 'notification_event',
684
+ 'id' => 'notif_123456-56465-546546',
685
+ 'topic' => 'conversation.user.created',
686
+ 'app_id' => 'aaaaa',
687
+ 'data' =>
523
688
  {
524
- "type"=>"conversation",
525
- "id"=>"123456789",
526
- "created_at"=>"1410335293",
527
- "updated_at"=>"1410335293",
528
- "user"=>
529
- {
530
- "type"=>"user",
531
- "id"=>"540f1de7112d3d1d51001637",
532
- "name"=>"Kill Bill",
533
- "email"=>"bill@bill.bill"},
534
- "assignee"=>
535
- {
536
- "type"=>"nobody_admin",
537
- "id"=>nil
538
- },
539
- "conversation_message"=>
540
- {
541
- "type"=>"conversation_message",
542
- "id"=>"321546",
543
- "subject"=>"",
544
- "body"=>"<p>An important message</p>",
545
- "author"=>
546
- {
547
- "type"=>"user",
548
- "id"=>"aaaaaaaaaaaaaaaaaaaaaa",
549
- "name"=>"Kill Bill",
550
- "email"=>"bill@bill.bill"},
551
- "attachments"=>[]
552
- },
553
- "conversation_parts"=>
554
- {
555
- "type"=>"conversation_part.list",
556
- "conversation_parts"=>[]
557
- },
558
- "open"=>nil,
559
- "read"=>true,
560
- "links"=>
561
- {
562
- "conversation_web"=>
563
- "https://app.intercom.io/a/apps/aaaaaa/inbox/all/conversations/123456789"}
564
- }
565
- },
566
- "delivery_status"=>nil,
567
- "delivery_attempts"=>1,
568
- "delivered_at"=>0,
569
- "first_sent_at"=>1410335293,
570
- "created_at"=>1410335293,
571
- "links"=>{},
572
- "self"=>nil
689
+ 'type' => 'notification_event_data',
690
+ 'item' =>
691
+ {
692
+ 'type' => 'conversation',
693
+ 'id' => '123456789',
694
+ 'created_at' => '1410335293',
695
+ 'updated_at' => '1410335293',
696
+ 'user' =>
697
+ {
698
+ 'type' => 'user',
699
+ 'id' => '540f1de7112d3d1d51001637',
700
+ 'name' => 'Kill Bill',
701
+ 'email' => 'bill@bill.bill'
702
+ },
703
+ 'assignee' =>
704
+ {
705
+ 'type' => 'nobody_admin',
706
+ 'id' => nil
707
+ },
708
+ 'conversation_message' =>
709
+ {
710
+ 'type' => 'conversation_message',
711
+ 'id' => '321546',
712
+ 'subject' => '',
713
+ 'body' => '<p>An important message</p>',
714
+ 'author' =>
715
+ {
716
+ 'type' => 'user',
717
+ 'id' => 'aaaaaaaaaaaaaaaaaaaaaa',
718
+ 'name' => 'Kill Bill',
719
+ 'email' => 'bill@bill.bill'
720
+ },
721
+ 'attachments' => []
722
+ },
723
+ 'conversation_parts' =>
724
+ {
725
+ 'type' => 'conversation_part.list',
726
+ 'conversation_parts' => []
727
+ },
728
+ 'open' => nil,
729
+ 'read' => true,
730
+ 'links' =>
731
+ {
732
+ 'conversation_web' =>
733
+ 'https://app.intercom.io/a/apps/aaaaaa/inbox/all/conversations/123456789'
734
+ }
735
+ }
736
+ },
737
+ 'delivery_status' => nil,
738
+ 'delivery_attempts' => 1,
739
+ 'delivered_at' => 0,
740
+ 'first_sent_at' => 1_410_335_293,
741
+ 'created_at' => 1_410_335_293,
742
+ 'links' => {},
743
+ 'self' => nil
573
744
  }
574
745
  end
575
746
 
576
747
  def test_subscription
577
- {"request"=>
578
- {"type"=>"notification_subscription",
579
- "id"=>"nsub_123456789",
580
- "created_at"=>1410368642,
581
- "updated_at"=>1410368642,
582
- "service_type"=>"web",
583
- "app_id"=>"3qmk5gyg",
584
- "url"=>
585
- "http://example.com",
586
- "self"=>
587
- "https://api.intercom.io/subscriptions/nsub_123456789",
588
- "topics"=>["user.created", "conversation.user.replied", "conversation.admin.replied"],
589
- "active"=>true,
590
- "metadata"=>{},
591
- "hub_secret"=>nil,
592
- "mode"=>"point",
593
- "links"=>
594
- {"sent"=>
595
- "https://api.intercom.io/subscriptions/nsub_123456789/sent",
596
- "retry"=>
597
- "https://api.intercom.io/subscriptions/nsub_123456789/retry",
598
- "errors"=>
599
- "https://api.intercom.io/subscriptions/nsub_123456789/errors"},
600
- "notes"=>[]}}
748
+ { 'request' =>
749
+ { 'type' => 'notification_subscription',
750
+ 'id' => 'nsub_123456789',
751
+ 'created_at' => 1_410_368_642,
752
+ 'updated_at' => 1_410_368_642,
753
+ 'service_type' => 'web',
754
+ 'app_id' => '3qmk5gyg',
755
+ 'url' =>
756
+ 'http://example.com',
757
+ 'self' =>
758
+ 'https://api.intercom.io/subscriptions/nsub_123456789',
759
+ 'topics' => ['user.created', 'conversation.user.replied', 'conversation.admin.replied'],
760
+ 'active' => true,
761
+ 'metadata' => {},
762
+ 'hub_secret' => nil,
763
+ 'mode' => 'point',
764
+ 'links' =>
765
+ { 'sent' =>
766
+ 'https://api.intercom.io/subscriptions/nsub_123456789/sent',
767
+ 'retry' =>
768
+ 'https://api.intercom.io/subscriptions/nsub_123456789/retry',
769
+ 'errors' =>
770
+ 'https://api.intercom.io/subscriptions/nsub_123456789/errors' },
771
+ 'notes' => [] } }
601
772
  end
602
773
 
603
774
  def test_app_count
604
775
  {
605
- "type" => "count.hash",
606
- "company" => {
607
- "count" => 8
776
+ 'type' => 'count.hash',
777
+ 'company' => {
778
+ 'count' => 8
608
779
  },
609
- "segment" => {
610
- "count" => 47
780
+ 'segment' => {
781
+ 'count' => 47
611
782
  },
612
- "tag" => {
613
- "count" => 341
783
+ 'tag' => {
784
+ 'count' => 341
614
785
  },
615
- "user" => {
616
- "count" => 12239
786
+ 'user' => {
787
+ 'count' => 12_239
617
788
  }
618
789
  }
619
790
  end
620
791
 
621
792
  def test_segment_count
622
793
  {
623
- "type" => "count",
624
- "user" => {
625
- "segment" => [
794
+ 'type' => 'count',
795
+ 'user' => {
796
+ 'segment' => [
626
797
  {
627
- "Active" => 1
798
+ 'Active' => 1
628
799
  },
629
800
  {
630
- "New" => 0
801
+ 'New' => 0
631
802
  },
632
803
  {
633
- "VIP" => 0
804
+ 'VIP' => 0
634
805
  },
635
806
  {
636
- "Slipping Away" => 0
807
+ 'Slipping Away' => 0
637
808
  },
638
809
  {
639
- "segment 1" => 1
810
+ 'segment 1' => 1
640
811
  }
641
812
  ]
642
813
  }
@@ -645,36 +816,36 @@ end
645
816
 
646
817
  def test_conversation_count
647
818
  {
648
- "type" => "count",
649
- "conversation" => {
650
- "assigned" => 1,
651
- "closed" => 15,
652
- "open" => 1,
653
- "unassigned" => 0
819
+ 'type' => 'count',
820
+ 'conversation' => {
821
+ 'assigned' => 1,
822
+ 'closed' => 15,
823
+ 'open' => 1,
824
+ 'unassigned' => 0
654
825
  }
655
826
  }
656
827
  end
657
828
 
658
829
  def test_event
659
- {
660
- "type" => "event",
661
- "event_name" => "invited-friend",
662
- "created_at" => 1389913941,
663
- "user_id" => "314159",
664
- "metadata" => {
665
- "type" => "user",
666
- "invitee_email" => "pi@example.org",
667
- "invite_code" => "ADDAFRIEND"
668
- }
830
+ {
831
+ 'type' => 'event',
832
+ 'event_name' => 'invited-friend',
833
+ 'created_at' => 1_389_913_941,
834
+ 'user_id' => '314159',
835
+ 'metadata' => {
836
+ 'type' => 'user',
837
+ 'invitee_email' => 'pi@example.org',
838
+ 'invite_code' => 'ADDAFRIEND'
669
839
  }
840
+ }
670
841
  end
671
842
 
672
843
  def test_event_list
673
844
  {
674
- "type" => "event.list",
675
- "events" => [ test_event ],
676
- "pages" => {
677
- "next" => "https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550"
845
+ 'type' => 'event.list',
846
+ 'events' => [test_event],
847
+ 'pages' => {
848
+ 'next' => 'https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550'
678
849
  }
679
850
  }
680
851
  end
@@ -683,28 +854,82 @@ def tomorrow
683
854
  (DateTime.now.to_time + 1).to_i
684
855
  end
685
856
 
686
- def page_of_events(include_next_link=false)
857
+ def page_of_events(include_next_link = false)
687
858
  {
688
- "type" => "event.list",
689
- "events" => [ test_event ],
690
- "pages" =>
859
+ 'type' => 'event.list',
860
+ 'events' => [test_event],
861
+ 'pages' =>
691
862
  {
692
- "next" => (include_next_link ? "https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550" : nil),
863
+ 'next' => (include_next_link ? 'https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550' : nil)
693
864
  }
694
865
  }
695
866
  end
696
867
 
868
+ def test_data_attribute
869
+ {
870
+ 'type' => 'data_attribute',
871
+ 'model' => 'contact',
872
+ 'name' => 'region_name',
873
+ 'full_name' => 'location_data.region_name',
874
+ 'label' => 'Region',
875
+ 'description' => '',
876
+ 'data_type' => 'string',
877
+ 'api_writable' => false,
878
+ 'ui_writable' => true,
879
+ 'custom' => false,
880
+ 'archived' => false
881
+ }
882
+ end
883
+
884
+ def test_data_attribute_list
885
+ {
886
+ 'type' => 'data_attribute.list',
887
+ 'data_attributes' => [
888
+ {
889
+ 'type' => 'data_attribute',
890
+ 'model' => 'customer',
891
+ 'name' => 'paid_subscriber',
892
+ 'full_name' => 'custom_attributes.paid_subscriber',
893
+ 'label' => 'paid_subscriber',
894
+ 'description' => '',
895
+ 'data_type' => 'string',
896
+ 'options' => %w[
897
+ pick_value_1
898
+ pick_value_2
899
+ ],
900
+ 'api_writable' => true,
901
+ 'ui_writable' => true,
902
+ 'custom' => true,
903
+ 'archived' => false,
904
+ 'admin_id' => '1',
905
+ 'created_at' => 1_392_734_388,
906
+ 'updated_at' => 1_392_734_388
907
+ },
908
+ {
909
+ 'type' => 'data_attribute',
910
+ 'model' => 'customer',
911
+ 'name' => 'region_name',
912
+ 'full_name' => 'location_data.region_name',
913
+ 'label' => 'Region',
914
+ 'description' => '',
915
+ 'data_type' => 'string',
916
+ 'api_writable' => false,
917
+ 'ui_writable' => true,
918
+ 'custom' => false,
919
+ 'archived' => false
920
+ }
921
+ ]
922
+ }
923
+ end
697
924
 
698
925
  def error_on_modify_frozen
699
926
  RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
700
927
  end
701
928
 
702
929
  def capture_exception(&block)
703
- begin
704
- block.call
705
- rescue => e
706
- return e
707
- end
930
+ block.call
931
+ rescue StandardError => e
932
+ e
708
933
  end
709
934
 
710
935
  def unshuffleable_array(array)