intercom 3.5.10 → 4.1.2

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