intercom 3.9.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +235 -222
  3. data/Rakefile +1 -1
  4. data/changes.txt +6 -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 +5 -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/base_collection_proxy.rb +72 -0
  16. data/lib/intercom/client.rb +20 -25
  17. data/lib/intercom/client_collection_proxy.rb +17 -39
  18. data/lib/intercom/company.rb +8 -0
  19. data/lib/intercom/contact.rb +21 -3
  20. data/lib/intercom/conversation.rb +4 -0
  21. data/lib/intercom/data_attribute.rb +7 -0
  22. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  23. data/lib/intercom/deprecated_resources.rb +13 -0
  24. data/lib/intercom/errors.rb +3 -0
  25. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  26. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  27. data/lib/intercom/lead.rb +21 -0
  28. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  29. data/lib/intercom/note.rb +4 -0
  30. data/lib/intercom/request.rb +37 -33
  31. data/lib/intercom/scroll_collection_proxy.rb +33 -38
  32. data/lib/intercom/search_collection_proxy.rb +30 -65
  33. data/lib/intercom/service/base_service.rb +7 -0
  34. data/lib/intercom/service/company.rb +0 -12
  35. data/lib/intercom/service/contact.rb +21 -10
  36. data/lib/intercom/service/conversation.rb +12 -3
  37. data/lib/intercom/service/data_attribute.rb +20 -0
  38. data/lib/intercom/service/lead.rb +41 -0
  39. data/lib/intercom/service/note.rb +4 -8
  40. data/lib/intercom/service/subscription.rb +2 -2
  41. data/lib/intercom/service/tag.rb +9 -9
  42. data/lib/intercom/service/visitor.rb +17 -8
  43. data/lib/intercom/tag.rb +4 -0
  44. data/lib/intercom/traits/api_resource.rb +28 -17
  45. data/lib/intercom/user.rb +12 -3
  46. data/lib/intercom/utils.rb +13 -2
  47. data/lib/intercom/version.rb +1 -1
  48. data/lib/intercom/visitor.rb +0 -2
  49. data/lib/intercom.rb +27 -22
  50. data/spec/spec_helper.rb +738 -513
  51. data/spec/unit/intercom/admin_spec.rb +2 -2
  52. data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
  53. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  54. data/spec/unit/intercom/client_spec.rb +28 -25
  55. data/spec/unit/intercom/company_spec.rb +13 -15
  56. data/spec/unit/intercom/contact_spec.rb +289 -33
  57. data/spec/unit/intercom/conversation_spec.rb +29 -7
  58. data/spec/unit/intercom/count_spec.rb +4 -4
  59. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  60. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  61. data/spec/unit/intercom/event_spec.rb +9 -11
  62. data/spec/unit/intercom/job_spec.rb +24 -24
  63. data/spec/unit/intercom/lead_spec.rb +57 -0
  64. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  65. data/spec/unit/intercom/message_spec.rb +1 -1
  66. data/spec/unit/intercom/note_spec.rb +4 -10
  67. data/spec/unit/intercom/request_spec.rb +1 -1
  68. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  69. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  70. data/spec/unit/intercom/segment_spec.rb +2 -2
  71. data/spec/unit/intercom/subscription_spec.rb +5 -6
  72. data/spec/unit/intercom/tag_spec.rb +22 -14
  73. data/spec/unit/intercom/team_spec.rb +2 -2
  74. data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
  75. data/spec/unit/intercom/user_spec.rb +224 -226
  76. data/spec/unit/intercom/visitor_spec.rb +49 -0
  77. data/spec/unit/intercom_spec.rb +5 -3
  78. metadata +22 -7
  79. data/lib/intercom/customer.rb +0 -10
  80. data/lib/intercom/service/customer.rb +0 -14
  81. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,283 +1,284 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe "Intercom::User" do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
3
+ require 'spec_helper'
4
+
5
+ describe 'Intercom::User' do
6
+ let (:client) { Intercom::Client.new(token: 'token') }
5
7
 
6
8
  it "to_hash'es itself" do
7
9
  created_at = Time.now
8
- user = Intercom::User.new(:email => "jim@example.com", :user_id => "12345", :created_at => created_at, :name => "Jim Bob")
10
+ user = Intercom::User.new(email: 'jim@example.com', user_id: '12345', created_at: created_at, name: 'Jim Bob')
9
11
  as_hash = user.to_hash
10
- as_hash["email"].must_equal "jim@example.com"
11
- as_hash["user_id"].must_equal "12345"
12
- as_hash["created_at"].must_equal created_at.to_i
13
- as_hash["name"].must_equal "Jim Bob"
12
+ _(as_hash['email']).must_equal 'jim@example.com'
13
+ _(as_hash['user_id']).must_equal '12345'
14
+ _(as_hash['created_at']).must_equal created_at.to_i
15
+ _(as_hash['name']).must_equal 'Jim Bob'
14
16
  end
15
17
 
16
- it "presents created_at and last_impression_at as Date" do
18
+ it 'presents created_at and last_impression_at as Date' do
17
19
  now = Time.now
18
- user = Intercom::User.from_api(:created_at => now, :last_impression_at => now)
19
- user.created_at.must_be_kind_of Time
20
- user.created_at.to_s.must_equal now.to_s
21
- user.last_impression_at.must_be_kind_of Time
22
- user.last_impression_at.to_s.must_equal now.to_s
20
+ user = Intercom::User.from_api(created_at: now, last_impression_at: now)
21
+ _(user.created_at).must_be_kind_of Time
22
+ _(user.created_at.to_s).must_equal now.to_s
23
+ _(user.last_impression_at).must_be_kind_of Time
24
+ _(user.last_impression_at.to_s).must_equal now.to_s
23
25
  end
24
26
 
25
- it "is throws a Intercom::AttributeNotSetError on trying to access an attribute that has not been set" do
27
+ it 'is throws a Intercom::AttributeNotSetError on trying to access an attribute that has not been set' do
26
28
  user = Intercom::User.new
27
- proc { user.foo_property }.must_raise Intercom::AttributeNotSetError
29
+ _(proc { user.foo_property }).must_raise Intercom::AttributeNotSetError
28
30
  end
29
31
 
30
- it "presents a complete user record correctly" do
32
+ it 'presents a complete user record correctly' do
31
33
  user = Intercom::User.from_api(test_user)
32
- user.user_id.must_equal 'id-from-customers-app'
33
- user.email.must_equal 'bob@example.com'
34
- user.name.must_equal 'Joe Schmoe'
35
- user.app_id.must_equal 'the-app-id'
36
- user.session_count.must_equal 123
37
- user.created_at.to_i.must_equal 1401970114
38
- user.remote_created_at.to_i.must_equal 1393613864
39
- user.updated_at.to_i.must_equal 1401970114
40
-
41
- user.avatar.must_be_kind_of Intercom::Avatar
42
- user.avatar.image_url.must_equal 'https://graph.facebook.com/1/picture?width=24&height=24'
43
-
44
- user.companies.must_be_kind_of Array
45
- user.companies.size.must_equal 1
46
- user.companies[0].must_be_kind_of Intercom::Company
47
- user.companies[0].company_id.must_equal "123"
48
- user.companies[0].id.must_equal "bbbbbbbbbbbbbbbbbbbbbbbb"
49
- user.companies[0].app_id.must_equal "the-app-id"
50
- user.companies[0].name.must_equal "Company 1"
51
- user.companies[0].remote_created_at.to_i.must_equal 1390936440
52
- user.companies[0].created_at.to_i.must_equal 1401970114
53
- user.companies[0].updated_at.to_i.must_equal 1401970114
54
- user.companies[0].last_request_at.to_i.must_equal 1401970113
55
- user.companies[0].monthly_spend.must_equal 0
56
- user.companies[0].session_count.must_equal 0
57
- user.companies[0].user_count.must_equal 1
58
- user.companies[0].tag_ids.must_equal []
59
-
60
- user.custom_attributes.must_be_kind_of Intercom::Lib::FlatStore
61
- user.custom_attributes["a"].must_equal "b"
62
- user.custom_attributes["b"].must_equal 2
63
-
64
- user.social_profiles.size.must_equal 4
34
+ _(user.user_id).must_equal 'id-from-customers-app'
35
+ _(user.email).must_equal 'bob@example.com'
36
+ _(user.name).must_equal 'Joe Schmoe'
37
+ _(user.app_id).must_equal 'the-app-id'
38
+ _(user.session_count).must_equal 123
39
+ _(user.created_at.to_i).must_equal 1_401_970_114
40
+ _(user.remote_created_at.to_i).must_equal 1_393_613_864
41
+ _(user.updated_at.to_i).must_equal 1_401_970_114
42
+
43
+ _(user.avatar).must_be_kind_of Intercom::Avatar
44
+ _(user.avatar.image_url).must_equal 'https://graph.facebook.com/1/picture?width=24&height=24'
45
+
46
+ _(user.companies).must_be_kind_of Array
47
+ _(user.companies.size).must_equal 1
48
+ _(user.companies[0]).must_be_kind_of Intercom::Company
49
+ _(user.companies[0].company_id).must_equal '123'
50
+ _(user.companies[0].id).must_equal 'bbbbbbbbbbbbbbbbbbbbbbbb'
51
+ _(user.companies[0].app_id).must_equal 'the-app-id'
52
+ _(user.companies[0].name).must_equal 'Company 1'
53
+ _(user.companies[0].remote_created_at.to_i).must_equal 1_390_936_440
54
+ _(user.companies[0].created_at.to_i).must_equal 1_401_970_114
55
+ _(user.companies[0].updated_at.to_i).must_equal 1_401_970_114
56
+ _(user.companies[0].last_request_at.to_i).must_equal 1_401_970_113
57
+ _(user.companies[0].monthly_spend).must_equal 0
58
+ _(user.companies[0].session_count).must_equal 0
59
+ _(user.companies[0].user_count).must_equal 1
60
+ _(user.companies[0].tag_ids).must_equal []
61
+
62
+ _(user.custom_attributes).must_be_kind_of Intercom::Lib::FlatStore
63
+ _(user.custom_attributes['a']).must_equal 'b'
64
+ _(user.custom_attributes['b']).must_equal 2
65
+
66
+ _(user.social_profiles.size).must_equal 4
65
67
  twitter_account = user.social_profiles.first
66
- twitter_account.must_be_kind_of Intercom::SocialProfile
67
- twitter_account.name.must_equal "twitter"
68
- twitter_account.username.must_equal "abc"
69
- twitter_account.url.must_equal "http://twitter.com/abc"
70
-
71
- user.location_data.must_be_kind_of Intercom::LocationData
72
- user.location_data.city_name.must_equal "Dublin"
73
- user.location_data.continent_code.must_equal "EU"
74
- user.location_data.country_name.must_equal "Ireland"
75
- user.location_data.latitude.must_equal "90"
76
- user.location_data.longitude.must_equal "10"
77
- user.location_data.country_code.must_equal "IRL"
78
-
79
- user.unsubscribed_from_emails.must_equal true
80
- user.user_agent_data.must_equal "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"
68
+ _(twitter_account).must_be_kind_of Intercom::SocialProfile
69
+ _(twitter_account.name).must_equal 'twitter'
70
+ _(twitter_account.username).must_equal 'abc'
71
+ _(twitter_account.url).must_equal 'http://twitter.com/abc'
72
+
73
+ _(user.location_data).must_be_kind_of Intercom::LocationData
74
+ _(user.location_data.city_name).must_equal 'Dublin'
75
+ _(user.location_data.continent_code).must_equal 'EU'
76
+ _(user.location_data.country_name).must_equal 'Ireland'
77
+ _(user.location_data.latitude).must_equal '90'
78
+ _(user.location_data.longitude).must_equal '10'
79
+ _(user.location_data.country_code).must_equal 'IRL'
80
+
81
+ _(user.unsubscribed_from_emails).must_equal true
82
+ _(user.user_agent_data).must_equal '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'
81
83
  end
82
84
 
83
85
  it 'allows update_last_request_at' do
84
- client.expects(:post).with("/users", {"user_id" => "1224242", 'update_last_request_at' => true, "custom_attributes" => {}}).returns({"user_id" => "i-1224242", "last_request_at" => 1414509439})
85
- client.users.create(user_id: '1224242', update_last_request_at: true)
86
+ client.expects(:post).with('/users', 'user_id' => '1224242', 'update_last_request_at' => true, 'custom_attributes' => {}).returns('user_id' => 'i-1224242', 'last_request_at' => 1_414_509_439)
87
+ client.deprecated__users.create(user_id: '1224242', update_last_request_at: true)
86
88
  end
87
89
 
88
- it "allows easy setting of custom data" do
90
+ it 'allows easy setting of custom data' do
89
91
  now = Time.now
90
92
  user = Intercom::User.new
91
- user.custom_attributes["mad"] = 123
92
- user.custom_attributes["other"] = now.to_i
93
- user.custom_attributes["thing"] = "yay"
94
- user.to_hash["custom_attributes"].must_equal "mad" => 123, "other" => now.to_i, "thing" => "yay"
93
+ user.custom_attributes['mad'] = 123
94
+ user.custom_attributes['other'] = now.to_i
95
+ user.custom_attributes['thing'] = 'yay'
96
+ _(user.to_hash['custom_attributes']).must_equal 'mad' => 123, 'other' => now.to_i, 'thing' => 'yay'
95
97
  end
96
98
 
97
- it "allows easy setting of multiple companies" do
98
- user = Intercom::User.new()
99
+ it 'allows easy setting of multiple companies' do
100
+ user = Intercom::User.new
99
101
  companies = [
100
- {"name" => "Intercom", "company_id" => "6"},
101
- {"name" => "Test", "company_id" => "9"}
102
+ { 'name' => 'Intercom', 'company_id' => '6' },
103
+ { 'name' => 'Test', 'company_id' => '9' }
102
104
  ]
103
105
  user.companies = companies
104
- user.to_hash["companies"].must_equal companies
106
+ _(user.to_hash['companies']).must_equal companies
105
107
  end
106
108
 
107
- it "rejects nested data structures in custom_attributes" do
108
- user = Intercom::User.new()
109
+ it 'rejects nested data structures in custom_attributes' do
110
+ user = Intercom::User.new
109
111
 
110
- proc { user.custom_attributes["thing"] = [1] }.must_raise(ArgumentError)
111
- proc { user.custom_attributes["thing"] = {1 => 2} }.must_raise(ArgumentError)
112
- proc { user.custom_attributes["thing"] = {1 => {2 => 3}} }.must_raise(ArgumentError)
112
+ _(proc { user.custom_attributes['thing'] = [1] }).must_raise(ArgumentError)
113
+ _(proc { user.custom_attributes['thing'] = { 1 => 2 } }).must_raise(ArgumentError)
114
+ _(proc { user.custom_attributes['thing'] = { 1 => { 2 => 3 } } }).must_raise(ArgumentError)
113
115
 
114
116
  user = Intercom::User.from_api(test_user)
115
- proc { user.custom_attributes["thing"] = [1] }.must_raise(ArgumentError)
117
+ _(proc { user.custom_attributes['thing'] = [1] }).must_raise(ArgumentError)
116
118
  end
117
119
 
118
- describe "incrementing custom_attributes fields" do
120
+ describe 'incrementing custom_attributes fields' do
119
121
  before :each do
120
122
  @now = Time.now
121
- @user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :custom_attributes => {"mad" => 123, "another" => 432, "other" => @now.to_i, :thing => "yay"})
123
+ @user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :custom_attributes => { 'mad' => 123, 'another' => 432, 'other' => @now.to_i, :thing => 'yay' })
122
124
  end
123
125
 
124
- it "increments up by 1 with no args" do
125
- @user.increment("mad")
126
- @user.to_hash["custom_attributes"]["mad"].must_equal 124
126
+ it 'increments up by 1 with no args' do
127
+ @user.increment('mad')
128
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 124
127
129
  end
128
130
 
129
- it "increments up by given value" do
130
- @user.increment("mad", 4)
131
- @user.to_hash["custom_attributes"]["mad"].must_equal 127
131
+ it 'increments up by given value' do
132
+ @user.increment('mad', 4)
133
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 127
132
134
  end
133
135
 
134
- it "increments down by given value" do
135
- @user.increment("mad", -1)
136
- @user.to_hash["custom_attributes"]["mad"].must_equal 122
136
+ it 'increments down by given value' do
137
+ @user.increment('mad', -1)
138
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 122
137
139
  end
138
140
 
139
- it "can increment new custom data fields" do
140
- @user.increment("new_field", 3)
141
- @user.to_hash["custom_attributes"]["new_field"].must_equal 3
141
+ it 'can increment new custom data fields' do
142
+ @user.increment('new_field', 3)
143
+ _(@user.to_hash['custom_attributes']['new_field']).must_equal 3
142
144
  end
143
145
 
144
- it "can call increment on the same key twice and increment by 2" do
145
- @user.increment("mad")
146
- @user.increment("mad")
147
- @user.to_hash["custom_attributes"]["mad"].must_equal 125
146
+ it 'can call increment on the same key twice and increment by 2' do
147
+ @user.increment('mad')
148
+ @user.increment('mad')
149
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 125
148
150
  end
149
151
  end
150
152
 
151
- describe "decrementing custom_attributes fields" do
153
+ describe 'decrementing custom_attributes fields' do
152
154
  before :each do
153
155
  @now = Time.now
154
- @user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :custom_attributes => {"mad" => 123, "another" => 432, "other" => @now.to_i, :thing => "yay"})
156
+ @user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :custom_attributes => { 'mad' => 123, 'another' => 432, 'other' => @now.to_i, :thing => 'yay' })
155
157
  end
156
158
 
157
- it "decrements down by 1 with no args" do
158
- @user.decrement("mad")
159
- @user.to_hash["custom_attributes"]["mad"].must_equal 122
159
+ it 'decrements down by 1 with no args' do
160
+ @user.decrement('mad')
161
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 122
160
162
  end
161
163
 
162
- it "decrements down by given value" do
163
- @user.decrement("mad", 3)
164
- @user.to_hash["custom_attributes"]["mad"].must_equal 120
164
+ it 'decrements down by given value' do
165
+ @user.decrement('mad', 3)
166
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 120
165
167
  end
166
168
 
167
- it "can decrement new custom data fields" do
168
- @user.decrement("new_field", 5)
169
- @user.to_hash["custom_attributes"]["new_field"].must_equal -5
169
+ it 'can decrement new custom data fields' do
170
+ @user.decrement('new_field', 5)
171
+ _(@user.to_hash['custom_attributes']['new_field']).must_equal(-5)
170
172
  end
171
173
 
172
- it "can call decrement on the same key twice and decrement by 2" do
173
- @user.decrement("mad")
174
- @user.decrement("mad")
175
- @user.to_hash["custom_attributes"]["mad"].must_equal 121
174
+ it 'can call decrement on the same key twice and decrement by 2' do
175
+ @user.decrement('mad')
176
+ @user.decrement('mad')
177
+ _(@user.to_hash['custom_attributes']['mad']).must_equal 121
176
178
  end
177
179
  end
178
180
 
179
- it "fetches a user" do
180
- client.expects(:get).with("/users", {"email" => "bo@example.com"}).returns(test_user)
181
- user = client.users.find("email" => "bo@example.com")
182
- user.email.must_equal "bob@example.com"
183
- user.name.must_equal "Joe Schmoe"
184
- user.session_count.must_equal 123
181
+ it 'fetches a user' do
182
+ client.expects(:get).with('/users', 'email' => 'bo@example.com').returns(test_user)
183
+ user = client.deprecated__users.find('email' => 'bo@example.com')
184
+ _(user.email).must_equal 'bob@example.com'
185
+ _(user.name).must_equal 'Joe Schmoe'
186
+ _(user.session_count).must_equal 123
185
187
  end
186
188
 
187
189
  it 'gets users by tag' do
188
- client.expects(:get).with("/users?tag_id=124", {}).returns(page_of_users(false))
189
- client.users.by_tag(124).each { |t| }
190
+ client.expects(:get).with('/users?tag_id=124', {}).returns(page_of_users(false))
191
+ client.deprecated__users.by_tag(124).each { |t| }
190
192
  end
191
193
 
192
194
  it 'gets users by segment' do
193
- client.expects(:get).with("/users?segment_id=124", {}).returns(page_of_users(false))
194
- client.users.by_segment(124).each { |t| }
195
+ client.expects(:get).with('/users?segment_id=124', {}).returns(page_of_users(false))
196
+ client.deprecated__users.by_segment(124).each { |t| }
195
197
  end
196
198
 
197
- it "saves a user (always sends custom_attributes)" do
198
- user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242")
199
- client.expects(:post).with("/users", {"email" => "jo@example.com", "user_id" => "i-1224242", "custom_attributes" => {}}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
200
- client.users.save(user)
199
+ it 'saves a user (always sends custom_attributes)' do
200
+ user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242')
201
+ client.expects(:post).with('/users', 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'custom_attributes' => {}).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
202
+ client.deprecated__users.save(user)
201
203
  end
202
204
 
203
- it "saves a user with a company" do
204
- user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :company => {'company_id' => 6, 'name' => "Intercom"})
205
- client.expects(:post).with("/users", {'custom_attributes' => {}, "user_id" => "i-1224242", "email" => "jo@example.com", "company" => {"company_id" => 6, "name" => "Intercom"}}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
206
- client.users.save(user)
205
+ it 'saves a user with a company' do
206
+ user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :company => { 'company_id' => 6, 'name' => 'Intercom' })
207
+ client.expects(:post).with('/users', 'custom_attributes' => {}, 'user_id' => 'i-1224242', 'email' => 'jo@example.com', 'company' => { 'company_id' => 6, 'name' => 'Intercom' }).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
208
+ client.deprecated__users.save(user)
207
209
  end
208
210
 
209
- it "saves a user with a companies" do
210
- user = Intercom::User.new("email" => "jo@example.com", :user_id => "i-1224242", :companies => [{'company_id' => 6, 'name' => "Intercom"}])
211
- client.expects(:post).with("/users", {'custom_attributes' => {}, "email" => "jo@example.com", "user_id" => "i-1224242", "companies" => [{"company_id" => 6, "name" => "Intercom"}]}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
212
- client.users.save(user)
211
+ it 'saves a user with a companies' do
212
+ user = Intercom::User.new('email' => 'jo@example.com', :user_id => 'i-1224242', :companies => [{ 'company_id' => 6, 'name' => 'Intercom' }])
213
+ client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'companies' => [{ 'company_id' => 6, 'name' => 'Intercom' }]).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
214
+ client.deprecated__users.save(user)
213
215
  end
214
216
 
215
217
  it 'can save a user with a nil email' do
216
- user = Intercom::User.new("email" => nil, :user_id => "i-1224242", :companies => [{'company_id' => 6, 'name' => "Intercom"}])
217
- client.expects(:post).with("/users", {'custom_attributes' => {}, "email" => nil, "user_id" => "i-1224242", "companies" => [{"company_id" => 6, "name" => "Intercom"}]}).returns({"email" => nil, "user_id" => "i-1224242"})
218
- client.users.save(user)
218
+ user = Intercom::User.new('email' => nil, :user_id => 'i-1224242', :companies => [{ 'company_id' => 6, 'name' => 'Intercom' }])
219
+ client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => nil, 'user_id' => 'i-1224242', 'companies' => [{ 'company_id' => 6, 'name' => 'Intercom' }]).returns('email' => nil, 'user_id' => 'i-1224242')
220
+ client.deprecated__users.save(user)
219
221
  end
220
222
 
221
- it "archives a user" do
222
- user = Intercom::User.new("id" => "1")
223
- client.expects(:delete).with("/users/1", {}).returns(user)
224
- client.users.archive(user)
223
+ it 'archives a user' do
224
+ user = Intercom::User.new('id' => '1')
225
+ client.expects(:delete).with('/users/1', {}).returns(user)
226
+ client.deprecated__users.archive(user)
227
+ end
228
+ it 'has an alias to archive a user' do
229
+ user = Intercom::User.new('id' => '1')
230
+ client.expects(:delete).with('/users/1', {}).returns(user)
231
+ client.deprecated__users.delete(user)
225
232
  end
226
- it "has an alias to archive a user" do
227
- user = Intercom::User.new("id" => "1")
228
- client.expects(:delete).with("/users/1", {}).returns(user)
229
- client.users.delete(user)
230
- end
231
-
232
233
 
233
- it "sends a request for a hard deletion" do
234
- user = Intercom::User.new("id" => "1")
235
- client.expects(:post).with("/user_delete_requests", {intercom_user_id: "1"}).returns({id: user.id})
236
- client.users.request_hard_delete(user)
234
+ it 'sends a request for a hard deletion' do
235
+ user = Intercom::User.new('id' => '1')
236
+ client.expects(:post).with('/user_delete_requests', intercom_user_id: '1').returns(id: user.id)
237
+ client.deprecated__users.request_hard_delete(user)
237
238
  end
238
239
 
239
- it "can use client.users.create for convenience" do
240
- client.expects(:post).with("/users", {'custom_attributes' => {}, "email" => "jo@example.com", "user_id" => "i-1224242"}).returns({"email" => "jo@example.com", "user_id" => "i-1224242"})
241
- user = client.users.create("email" => "jo@example.com", :user_id => "i-1224242")
242
- user.email.must_equal "jo@example.com"
240
+ it 'can use client.users.create for convenience' do
241
+ client.expects(:post).with('/users', 'custom_attributes' => {}, 'email' => 'jo@example.com', 'user_id' => 'i-1224242').returns('email' => 'jo@example.com', 'user_id' => 'i-1224242')
242
+ user = client.deprecated__users.create('email' => 'jo@example.com', :user_id => 'i-1224242')
243
+ _(user.email).must_equal 'jo@example.com'
243
244
  end
244
245
 
245
- it "updates the user with attributes as set by the server" do
246
- client.expects(:post).with("/users", {"email" => "jo@example.com", "user_id" => "i-1224242", 'custom_attributes' => {}}).returns({"email" => "jo@example.com", "user_id" => "i-1224242", "session_count" => 4})
247
- user = client.users.create("email" => "jo@example.com", :user_id => "i-1224242")
248
- user.session_count.must_equal 4
246
+ it 'updates the user with attributes as set by the server' do
247
+ client.expects(:post).with('/users', 'email' => 'jo@example.com', 'user_id' => 'i-1224242', 'custom_attributes' => {}).returns('email' => 'jo@example.com', 'user_id' => 'i-1224242', 'session_count' => 4)
248
+ user = client.deprecated__users.create('email' => 'jo@example.com', :user_id => 'i-1224242')
249
+ _(user.session_count).must_equal 4
249
250
  end
250
251
 
251
- it "allows setting dates to nil without converting them to 0" do
252
- client.expects(:post).with("/users", {"email" => "jo@example.com", 'custom_attributes' => {}, "remote_created_at" => nil}).returns({"email" => "jo@example.com"})
253
- user = client.users.create("email" => "jo@example.com", "remote_created_at" => nil)
252
+ it 'allows setting dates to nil without converting them to 0' do
253
+ client.expects(:post).with('/users', 'email' => 'jo@example.com', 'custom_attributes' => {}, 'remote_created_at' => nil).returns('email' => 'jo@example.com')
254
+ user = client.deprecated__users.create('email' => 'jo@example.com', 'remote_created_at' => nil)
254
255
  assert_nil user.remote_created_at
255
256
  end
256
257
 
257
- it "sets/gets rw keys" do
258
- params = {"email" => "me@example.com", :user_id => "abc123", "name" => "Bob Smith", "last_seen_ip" => "1.2.3.4", "last_seen_user_agent" => "ie6", "created_at" => Time.now}
258
+ it 'sets/gets rw keys' do
259
+ params = { 'email' => 'me@example.com', :user_id => 'abc123', 'name' => 'Bob Smith', 'last_seen_ip' => '1.2.3.4', 'last_seen_user_agent' => 'ie6', 'created_at' => Time.now }
259
260
  user = Intercom::User.new(params)
260
261
  custom_attributes = (params.keys + ['custom_attributes']).map(&:to_s).sort
261
- user.to_hash.keys.sort.must_equal custom_attributes
262
+ _(user.to_hash.keys.sort).must_equal custom_attributes
262
263
  params.keys.each do |key|
263
- user.send(key).to_s.must_equal params[key].to_s
264
+ _(user.send(key).to_s).must_equal params[key].to_s
264
265
  end
265
266
  end
266
267
 
267
- it "will allow extra attributes in response from api" do
268
- user = Intercom::User.send(:from_api, {"new_param" => "some value"})
269
- user.new_param.must_equal "some value"
268
+ it 'will allow extra attributes in response from api' do
269
+ user = Intercom::User.send(:from_api, 'new_param' => 'some value')
270
+ _(user.new_param).must_equal 'some value'
270
271
  end
271
272
 
272
- it "returns a ClientCollectionProxy for all without making any requests" do
273
+ it 'returns a ClientCollectionProxy for all without making any requests' do
273
274
  client.expects(:execute_request).never
274
- all = client.users.all
275
- all.must_be_instance_of(Intercom::ClientCollectionProxy)
275
+ all = client.deprecated__users.all
276
+ _(all).must_be_instance_of(Intercom::ClientCollectionProxy)
276
277
  end
277
278
 
278
279
  it 'can print users without crashing' do
279
- client.expects(:get).with("/users", {"email" => "bo@example.com"}).returns(test_user)
280
- user = client.users.find("email" => "bo@example.com")
280
+ client.expects(:get).with('/users', 'email' => 'bo@example.com').returns(test_user)
281
+ user = client.deprecated__users.find('email' => 'bo@example.com')
281
282
 
282
283
  begin
283
284
  orignal_stdout = $stdout
@@ -285,91 +286,88 @@ describe "Intercom::User" do
285
286
 
286
287
  puts user
287
288
  p user
288
-
289
289
  ensure
290
290
  $stdout = orignal_stdout
291
291
  end
292
292
  end
293
293
 
294
294
  describe 'bulk operations' do
295
- let (:job) {
295
+ let (:job) do
296
296
  {
297
- "app_id"=>"app_id",
298
- "id"=>"super_awesome_job",
299
- "created_at"=>1446033421,
300
- "completed_at"=>1446048736,
301
- "closing_at"=>1446034321,
302
- "updated_at"=>1446048736,
303
- "name"=>"api_bulk_job",
304
- "state"=>"completed",
305
- "links"=>
297
+ 'app_id' => 'app_id',
298
+ 'id' => 'super_awesome_job',
299
+ 'created_at' => 1_446_033_421,
300
+ 'completed_at' => 1_446_048_736,
301
+ 'closing_at' => 1_446_034_321,
302
+ 'updated_at' => 1_446_048_736,
303
+ 'name' => 'api_bulk_job',
304
+ 'state' => 'completed',
305
+ 'links' =>
306
306
  {
307
- "error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
308
- "self"=>"https://api.intercom.io/jobs/super_awesome_job"
307
+ 'error' => 'https://api.intercom.io/jobs/super_awesome_job/error',
308
+ 'self' => 'https://api.intercom.io/jobs/super_awesome_job'
309
309
  },
310
- "tasks"=>
310
+ 'tasks' =>
311
311
  [
312
312
  {
313
- "id"=>"super_awesome_task",
314
- "item_count"=>2,
315
- "created_at"=>1446033421,
316
- "started_at"=>1446033709,
317
- "completed_at"=>1446033709,
318
- "state"=>"completed"
313
+ 'id' => 'super_awesome_task',
314
+ 'item_count' => 2,
315
+ 'created_at' => 1_446_033_421,
316
+ 'started_at' => 1_446_033_709,
317
+ 'completed_at' => 1_446_033_709,
318
+ 'state' => 'completed'
319
319
  }
320
320
  ]
321
- }
322
- }
323
- let(:bulk_request) {
324
- {
321
+ }
322
+ end
323
+ let(:bulk_request) do
324
+ {
325
325
  items: [
326
326
  {
327
- method: "post",
328
- data_type: "user",
329
- data:{
327
+ method: 'post',
328
+ data_type: 'user',
329
+ data: {
330
330
  user_id: 25,
331
- email: "alice@example.com"
331
+ email: 'alice@example.com'
332
332
  }
333
333
  },
334
334
  {
335
- method: "delete",
336
- data_type: "user",
337
- data:{
335
+ method: 'delete',
336
+ data_type: 'user',
337
+ data: {
338
338
  user_id: 26,
339
- email: "bob@example.com"
339
+ email: 'bob@example.com'
340
340
  }
341
341
  }
342
342
  ]
343
343
  }
344
- }
345
- let(:users_to_create) {
344
+ end
345
+ let(:users_to_create) do
346
346
  [
347
347
  {
348
348
  user_id: 25,
349
- email: "alice@example.com"
349
+ email: 'alice@example.com'
350
350
  }
351
351
  ]
352
- }
353
- let(:users_to_delete) {
352
+ end
353
+ let(:users_to_delete) do
354
354
  [
355
355
  {
356
356
  user_id: 26,
357
- email: "bob@example.com"
357
+ email: 'bob@example.com'
358
358
  }
359
359
  ]
360
- }
361
-
362
- it "submits a bulk job" do
363
- client.expects(:post).with("/bulk/users", bulk_request).returns(job)
364
- client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete)
365
360
  end
366
361
 
367
- it "adds users to an existing bulk job" do
368
- bulk_request[:job] = {id: 'super_awesome_job'}
369
- client.expects(:post).with("/bulk/users", bulk_request).returns(job)
370
- client.users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete, job_id: 'super_awesome_job')
362
+ it 'submits a bulk job' do
363
+ client.expects(:post).with('/bulk/users', bulk_request).returns(job)
364
+ client.deprecated__users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete)
371
365
  end
372
366
 
367
+ it 'adds users to an existing bulk job' do
368
+ bulk_request[:job] = { id: 'super_awesome_job' }
369
+ client.expects(:post).with('/bulk/users', bulk_request).returns(job)
370
+ client.deprecated__users.submit_bulk_job(create_items: users_to_create, delete_items: users_to_delete, job_id: 'super_awesome_job')
371
+ end
373
372
  end
374
-
375
373
  end