intercom 3.9.5 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +406 -236
  3. data/Rakefile +1 -1
  4. data/changes.txt +32 -0
  5. data/lib/intercom/api_operations/archive.rb +2 -1
  6. data/lib/intercom/api_operations/delete.rb +16 -0
  7. data/lib/intercom/api_operations/find.rb +5 -2
  8. data/lib/intercom/api_operations/find_all.rb +4 -3
  9. data/lib/intercom/api_operations/list.rb +4 -1
  10. data/lib/intercom/api_operations/load.rb +4 -2
  11. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  12. data/lib/intercom/api_operations/save.rb +6 -4
  13. data/lib/intercom/api_operations/scroll.rb +4 -5
  14. data/lib/intercom/api_operations/search.rb +3 -2
  15. data/lib/intercom/article.rb +7 -0
  16. data/lib/intercom/base_collection_proxy.rb +73 -0
  17. data/lib/intercom/client.rb +36 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/collection.rb +7 -0
  20. data/lib/intercom/company.rb +8 -0
  21. data/lib/intercom/contact.rb +22 -3
  22. data/lib/intercom/conversation.rb +5 -0
  23. data/lib/intercom/data_attribute.rb +7 -0
  24. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  25. data/lib/intercom/deprecated_resources.rb +13 -0
  26. data/lib/intercom/errors.rb +3 -0
  27. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  28. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  29. data/lib/intercom/lead.rb +21 -0
  30. data/lib/intercom/lib/dynamic_accessors.rb +9 -10
  31. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  32. data/lib/intercom/note.rb +4 -0
  33. data/lib/intercom/request.rb +37 -33
  34. data/lib/intercom/scroll_collection_proxy.rb +38 -42
  35. data/lib/intercom/search_collection_proxy.rb +30 -65
  36. data/lib/intercom/section.rb +23 -0
  37. data/lib/intercom/segment.rb +4 -0
  38. data/lib/intercom/service/article.rb +20 -0
  39. data/lib/intercom/service/base_service.rb +7 -0
  40. data/lib/intercom/service/collection.rb +24 -0
  41. data/lib/intercom/service/company.rb +2 -12
  42. data/lib/intercom/service/contact.rb +31 -10
  43. data/lib/intercom/service/conversation.rb +12 -3
  44. data/lib/intercom/service/data_attribute.rb +20 -0
  45. data/lib/intercom/service/lead.rb +41 -0
  46. data/lib/intercom/service/note.rb +4 -8
  47. data/lib/intercom/service/section.rb +7 -0
  48. data/lib/intercom/service/subscription.rb +2 -2
  49. data/lib/intercom/service/tag.rb +9 -9
  50. data/lib/intercom/service/visitor.rb +17 -8
  51. data/lib/intercom/tag.rb +4 -0
  52. data/lib/intercom/traits/api_resource.rb +44 -18
  53. data/lib/intercom/traits/dirty_tracking.rb +8 -1
  54. data/lib/intercom/user.rb +12 -3
  55. data/lib/intercom/utils.rb +13 -2
  56. data/lib/intercom/version.rb +1 -1
  57. data/lib/intercom/visitor.rb +0 -2
  58. data/lib/intercom.rb +33 -22
  59. data/spec/spec_helper.rb +843 -520
  60. data/spec/unit/intercom/admin_spec.rb +2 -2
  61. data/spec/unit/intercom/article_spec.rb +40 -0
  62. data/spec/unit/intercom/base_collection_proxy_spec.rb +47 -0
  63. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  64. data/spec/unit/intercom/client_spec.rb +25 -26
  65. data/spec/unit/intercom/collection_spec.rb +32 -0
  66. data/spec/unit/intercom/company_spec.rb +18 -14
  67. data/spec/unit/intercom/contact_spec.rb +385 -33
  68. data/spec/unit/intercom/conversation_spec.rb +55 -7
  69. data/spec/unit/intercom/count_spec.rb +4 -4
  70. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  71. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  72. data/spec/unit/intercom/event_spec.rb +9 -11
  73. data/spec/unit/intercom/job_spec.rb +24 -24
  74. data/spec/unit/intercom/lead_spec.rb +57 -0
  75. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  76. data/spec/unit/intercom/message_spec.rb +1 -1
  77. data/spec/unit/intercom/note_spec.rb +4 -10
  78. data/spec/unit/intercom/request_spec.rb +1 -1
  79. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  80. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  81. data/spec/unit/intercom/section_spec.rb +32 -0
  82. data/spec/unit/intercom/segment_spec.rb +2 -2
  83. data/spec/unit/intercom/subscription_spec.rb +5 -6
  84. data/spec/unit/intercom/tag_spec.rb +22 -14
  85. data/spec/unit/intercom/team_spec.rb +2 -2
  86. data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
  87. data/spec/unit/intercom/user_spec.rb +224 -226
  88. data/spec/unit/intercom/visitor_spec.rb +49 -0
  89. data/spec/unit/intercom_spec.rb +5 -3
  90. metadata +34 -8
  91. data/lib/intercom/customer.rb +0 -10
  92. data/lib/intercom/service/customer.rb +0 -14
  93. data/spec/unit/intercom/visitors_spec.rb +0 -61
data/spec/spec_helper.rb CHANGED
@@ -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,236 @@ 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
14
- end
15
-
16
- def test_user(email="bob@example.com")
17
- {
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
- }
69
- end
70
-
71
- def test_user_dates(email="bob@example.com", created_at=1401970114, last_request_at=1401970113)
72
- {
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"}
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
91
+
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
123
229
  }
124
230
  end
125
231
 
126
232
  def test_admin_list
127
233
  {
128
- "type" => "admin.list",
129
- "admins" => [
234
+ 'type' => 'admin.list',
235
+ 'admins' => [
130
236
  {
131
- "type" => "admin",
132
- "id" => "1234",
133
- "name" => "Hoban Washburne",
134
- "email" => "wash@serenity.io"
237
+ 'type' => 'admin',
238
+ 'id' => '1234',
239
+ 'name' => 'Hoban Washburne',
240
+ 'email' => 'wash@serenity.io'
135
241
  }
136
242
  ]
137
243
  }
@@ -139,63 +245,88 @@ end
139
245
 
140
246
  def test_admin
141
247
  {
142
- "type" => "admin",
143
- "id" => "1234",
144
- "name" => "Hoban Washburne",
145
- "email" => "wash@serenity.io"
248
+ 'type' => 'admin',
249
+ 'id' => '1234',
250
+ 'name' => 'Hoban Washburne',
251
+ 'email' => 'wash@serenity.io'
146
252
  }
147
253
  end
148
254
 
149
255
  def test_team_list
150
256
  {
151
- "type"=> "team.list",
152
- "teams" => [
257
+ 'type' => 'team.list',
258
+ 'teams' => [
153
259
  {
154
- "type"=> "team",
155
- "id"=> "2744328",
156
- "name"=> "the_a_team",
157
- "admin_ids"=> [646303, 814860],
260
+ 'type' => 'team',
261
+ 'id' => '2744328',
262
+ 'name' => 'the_a_team',
263
+ 'admin_ids' => [646_303, 814_860]
158
264
  },
159
265
  {
160
- "type"=> "team",
161
- "id"=> "814865",
162
- "name"=> "BA_App",
163
- "admin_ids" => [492881, 1195856]
164
- },
266
+ 'type' => 'team',
267
+ 'id' => '814865',
268
+ 'name' => 'BA_App',
269
+ 'admin_ids' => [492_881, 1_195_856]
270
+ }
165
271
  ]
166
272
  }
167
273
  end
168
274
 
169
275
  def test_team
170
276
  {
171
- "type" => "team",
172
- "id" => "2744328",
173
- "name" => "the_a_team",
174
- "admin_ids" => [646303, 814860]
277
+ 'type' => 'team',
278
+ 'id' => '2744328',
279
+ 'name' => 'the_a_team',
280
+ 'admin_ids' => [646_303, 814_860]
175
281
  }
176
282
  end
177
283
 
178
- def test_company
284
+ def test_company(name = 'Blue Sun')
179
285
  {
180
- "type" => "company",
181
- "id" => "531ee472cce572a6ec000006",
182
- "name" => "Blue Sun",
183
- "plan" => {
184
- "type" =>"plan",
185
- "id" =>"1",
186
- "name" =>"Paid"
286
+ 'type' => 'company',
287
+ 'id' => '531ee472cce572a6ec000006',
288
+ 'name' => name,
289
+ 'plan' => {
290
+ 'type' => 'plan',
291
+ 'id' => '1',
292
+ 'name' => 'Paid'
187
293
  },
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
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
+ }
306
+ }
307
+ end
308
+
309
+ def test_company_dates(name = 'Blue Sun', created_at = 1_401_970_114, last_request_at = 1_401_970_113)
310
+ {
311
+ 'type' => 'company',
312
+ 'id' => '531ee472cce572a6ec000006',
313
+ 'name' => name,
314
+ 'plan' => {
315
+ 'type' => 'plan',
316
+ 'id' => '1',
317
+ 'name' => 'Paid'
318
+ },
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
199
330
  }
200
331
  }
201
332
  end
@@ -206,140 +337,238 @@ end
206
337
 
207
338
  def test_message
208
339
  {
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
- }
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'
237
365
  },
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
- ]
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
+ ]
249
380
  }
250
381
  end
251
382
 
252
- def page_of_users(include_next_link= false)
383
+ def page_of_users(include_next_link = false)
253
384
  {
254
- "type"=>"user.list",
255
- "pages"=>
385
+ 'type' => 'user.list',
386
+ 'pages' =>
256
387
  {
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
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
262
393
  },
263
- "users"=> [test_user("user1@example.com"), test_user("user2@example.com"), test_user("user3@example.com")],
264
- "total_count"=>314
394
+ 'users' => [test_user('user1@example.com'), test_user('user2@example.com'), test_user('user3@example.com')],
395
+ 'total_count' => 314
265
396
  }
266
397
  end
267
398
 
268
- def page_of_customers(include_starting_after= false)
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)
269
498
  {
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
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
281
510
  }
282
511
  end
283
512
 
284
- def users_scroll(include_users= false)
513
+ def companies_scroll(include_companies = false)
285
514
  {
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")] : []),
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')] : [])
289
518
  }
290
519
  end
291
520
 
292
- def users_pagination(include_next_link:, per_page:, page:, total_pages:, total_count:, user_list:)
521
+ def companies_pagination(include_next_link:, per_page:, page:, total_pages:, total_count:, company_list:)
293
522
  {
294
- "type"=>"user.list",
295
- "pages"=>
523
+ 'type' => 'company.list',
524
+ 'pages' =>
296
525
  {
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
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
303
532
  },
304
- "users"=> user_list,
305
- "total_count"=>total_count
533
+ 'companies' => company_list,
534
+ 'total_count' => total_count
306
535
  }
307
536
  end
308
537
 
309
538
  def test_conversation
310
539
  {
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"
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'
322
551
  },
323
- "attachments" => [
552
+ 'attachments' => [
324
553
  {
325
- "name" => "signature",
326
- "url" => "http =>//someurl.com/signature.jpg"
554
+ 'name' => 'signature',
555
+ 'url' => 'http =>//someurl.com/signature.jpg'
327
556
  }
328
557
  ]
329
558
  },
330
- "user" => {
331
- "type" => "user",
332
- "id" => "536e564f316c83104c000020"
559
+ 'user' => {
560
+ 'type' => 'user',
561
+ 'id' => '536e564f316c83104c000020'
333
562
  },
334
- "assignee" => {
335
- "type" => "admin",
336
- "id" => "25"
563
+ 'assignee' => {
564
+ 'type' => 'admin',
565
+ 'id' => '25'
337
566
  },
338
- "open" => true,
339
- "read" => true,
340
- "conversation_parts" => {
341
- "type" => "conversation_part.list",
342
- "conversation_parts" => [
567
+ 'open' => true,
568
+ 'read' => true,
569
+ 'conversation_parts' => {
570
+ 'type' => 'conversation_part.list',
571
+ 'conversation_parts' => [
343
572
  ]
344
573
  }
345
574
  }
@@ -347,88 +576,88 @@ end
347
576
 
348
577
  def test_conversation_list
349
578
  {
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
- ]
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
+ ]
395
624
  }
396
625
  end
397
626
 
398
627
  def segment
399
628
  {
400
- "type" => "segment",
401
- "id" => "5310d8e7598c9a0b24000002",
402
- "name" => "Active",
403
- "created_at" => 1393613031,
404
- "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
405
634
  }
406
635
  end
407
636
 
408
637
  def segment_list
409
638
  {
410
- "type" => "segment.list",
411
- "segments" => [
639
+ 'type' => 'segment.list',
640
+ 'segments' => [
412
641
  {
413
- "created_at" => 1393613031,
414
- "id" => "5310d8e7598c9a0b24000002",
415
- "name" => "Active",
416
- "type" => "segment",
417
- "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
418
647
  },
419
648
  {
420
- "created_at" => 1393613030,
421
- "id" => "5310d8e6598c9a0b24000001",
422
- "name" => "New",
423
- "type" => "segment",
424
- "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
425
654
  },
426
655
  {
427
- "created_at" => 1393613031,
428
- "id" => "5310d8e7598c9a0b24000003",
429
- "name" => "Slipping Away",
430
- "type" => "segment",
431
- "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
432
661
  }
433
662
  ]
434
663
  }
@@ -436,207 +665,247 @@ end
436
665
 
437
666
  def test_tag
438
667
  {
439
- "id" => "4f73428b5e4dfc000b000112",
440
- "name" => "Test Tag",
441
- "segment" => false,
442
- "tagged_user_count" => 2
668
+ 'id' => '4f73428b5e4dfc000b000112',
669
+ 'name' => 'Test Tag',
670
+ 'segment' => false,
671
+ 'tagged_company_count' => 2
443
672
  }
444
673
  end
445
674
 
446
675
  def test_user_notification
447
676
  {
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
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
510
739
  }
511
740
  end
512
741
 
513
742
  def test_conversation_notification
514
743
  {
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"=>
744
+ 'type' => 'notification_event',
745
+ 'id' => 'notif_123456-56465-546546',
746
+ 'topic' => 'conversation.user.created',
747
+ 'app_id' => 'aaaaa',
748
+ 'data' =>
523
749
  {
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
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
573
805
  }
574
806
  end
575
807
 
576
808
  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"=>[]}}
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' => [] } }
601
833
  end
602
834
 
603
835
  def test_app_count
604
836
  {
605
- "type" => "count.hash",
606
- "company" => {
607
- "count" => 8
837
+ 'type' => 'count.hash',
838
+ 'company' => {
839
+ 'count' => 8
608
840
  },
609
- "segment" => {
610
- "count" => 47
841
+ 'segment' => {
842
+ 'count' => 47
611
843
  },
612
- "tag" => {
613
- "count" => 341
844
+ 'tag' => {
845
+ 'count' => 341
614
846
  },
615
- "user" => {
616
- "count" => 12239
847
+ 'user' => {
848
+ 'count' => 12_239
617
849
  }
618
850
  }
619
851
  end
620
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
+
621
890
  def test_segment_count
622
891
  {
623
- "type" => "count",
624
- "user" => {
625
- "segment" => [
892
+ 'type' => 'count',
893
+ 'user' => {
894
+ 'segment' => [
626
895
  {
627
- "Active" => 1
896
+ 'Active' => 1
628
897
  },
629
898
  {
630
- "New" => 0
899
+ 'New' => 0
631
900
  },
632
901
  {
633
- "VIP" => 0
902
+ 'VIP' => 0
634
903
  },
635
904
  {
636
- "Slipping Away" => 0
905
+ 'Slipping Away' => 0
637
906
  },
638
907
  {
639
- "segment 1" => 1
908
+ 'segment 1' => 1
640
909
  }
641
910
  ]
642
911
  }
@@ -645,36 +914,36 @@ end
645
914
 
646
915
  def test_conversation_count
647
916
  {
648
- "type" => "count",
649
- "conversation" => {
650
- "assigned" => 1,
651
- "closed" => 15,
652
- "open" => 1,
653
- "unassigned" => 0
917
+ 'type' => 'count',
918
+ 'conversation' => {
919
+ 'assigned' => 1,
920
+ 'closed' => 15,
921
+ 'open' => 1,
922
+ 'unassigned' => 0
654
923
  }
655
924
  }
656
925
  end
657
926
 
658
927
  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
- }
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'
669
937
  }
938
+ }
670
939
  end
671
940
 
672
941
  def test_event_list
673
942
  {
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"
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'
678
947
  }
679
948
  }
680
949
  end
@@ -683,28 +952,82 @@ def tomorrow
683
952
  (DateTime.now.to_time + 1).to_i
684
953
  end
685
954
 
686
- def page_of_events(include_next_link=false)
955
+ def page_of_events(include_next_link = false)
687
956
  {
688
- "type" => "event.list",
689
- "events" => [ test_event ],
690
- "pages" =>
957
+ 'type' => 'event.list',
958
+ 'events' => [test_event],
959
+ 'pages' =>
691
960
  {
692
- "next" => (include_next_link ? "https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550" : nil),
961
+ 'next' => (include_next_link ? 'https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550' : nil)
693
962
  }
694
963
  }
695
964
  end
696
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
697
1022
 
698
1023
  def error_on_modify_frozen
699
1024
  RUBY_VERSION =~ /1.8/ ? TypeError : RuntimeError
700
1025
  end
701
1026
 
702
1027
  def capture_exception(&block)
703
- begin
704
- block.call
705
- rescue => e
706
- return e
707
- end
1028
+ block.call
1029
+ rescue StandardError => e
1030
+ e
708
1031
  end
709
1032
 
710
1033
  def unshuffleable_array(array)