intercom 3.9.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +235 -222
  3. data/Rakefile +1 -1
  4. data/changes.txt +3 -0
  5. data/lib/intercom.rb +27 -22
  6. data/lib/intercom/api_operations/archive.rb +2 -1
  7. data/lib/intercom/api_operations/delete.rb +16 -0
  8. data/lib/intercom/api_operations/find.rb +5 -2
  9. data/lib/intercom/api_operations/find_all.rb +4 -3
  10. data/lib/intercom/api_operations/list.rb +4 -1
  11. data/lib/intercom/api_operations/load.rb +4 -2
  12. data/lib/intercom/api_operations/nested_resource.rb +70 -0
  13. data/lib/intercom/api_operations/save.rb +5 -4
  14. data/lib/intercom/api_operations/scroll.rb +4 -5
  15. data/lib/intercom/api_operations/search.rb +3 -2
  16. data/lib/intercom/base_collection_proxy.rb +72 -0
  17. data/lib/intercom/client.rb +20 -25
  18. data/lib/intercom/client_collection_proxy.rb +17 -39
  19. data/lib/intercom/company.rb +8 -0
  20. data/lib/intercom/contact.rb +21 -3
  21. data/lib/intercom/conversation.rb +4 -0
  22. data/lib/intercom/data_attribute.rb +7 -0
  23. data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
  24. data/lib/intercom/deprecated_resources.rb +13 -0
  25. data/lib/intercom/errors.rb +3 -0
  26. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  27. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  28. data/lib/intercom/lead.rb +21 -0
  29. data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
  30. data/lib/intercom/note.rb +4 -0
  31. data/lib/intercom/request.rb +37 -33
  32. data/lib/intercom/scroll_collection_proxy.rb +33 -38
  33. data/lib/intercom/search_collection_proxy.rb +30 -65
  34. data/lib/intercom/service/base_service.rb +7 -0
  35. data/lib/intercom/service/company.rb +0 -12
  36. data/lib/intercom/service/contact.rb +21 -10
  37. data/lib/intercom/service/conversation.rb +12 -3
  38. data/lib/intercom/service/data_attribute.rb +20 -0
  39. data/lib/intercom/service/lead.rb +41 -0
  40. data/lib/intercom/service/note.rb +4 -8
  41. data/lib/intercom/service/subscription.rb +2 -2
  42. data/lib/intercom/service/tag.rb +9 -9
  43. data/lib/intercom/service/visitor.rb +17 -8
  44. data/lib/intercom/tag.rb +4 -0
  45. data/lib/intercom/traits/api_resource.rb +28 -17
  46. data/lib/intercom/user.rb +12 -3
  47. data/lib/intercom/utils.rb +13 -2
  48. data/lib/intercom/version.rb +1 -1
  49. data/lib/intercom/visitor.rb +0 -2
  50. data/spec/spec_helper.rb +738 -513
  51. data/spec/unit/intercom/admin_spec.rb +2 -2
  52. data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
  53. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  54. data/spec/unit/intercom/client_spec.rb +25 -26
  55. data/spec/unit/intercom/company_spec.rb +13 -15
  56. data/spec/unit/intercom/contact_spec.rb +289 -33
  57. data/spec/unit/intercom/conversation_spec.rb +29 -7
  58. data/spec/unit/intercom/count_spec.rb +4 -4
  59. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  60. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  61. data/spec/unit/intercom/event_spec.rb +9 -11
  62. data/spec/unit/intercom/job_spec.rb +24 -24
  63. data/spec/unit/intercom/lead_spec.rb +57 -0
  64. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  65. data/spec/unit/intercom/message_spec.rb +1 -1
  66. data/spec/unit/intercom/note_spec.rb +4 -10
  67. data/spec/unit/intercom/request_spec.rb +1 -1
  68. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  69. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  70. data/spec/unit/intercom/segment_spec.rb +2 -2
  71. data/spec/unit/intercom/subscription_spec.rb +5 -6
  72. data/spec/unit/intercom/tag_spec.rb +22 -14
  73. data/spec/unit/intercom/team_spec.rb +2 -2
  74. data/spec/unit/intercom/traits/api_resource_spec.rb +53 -51
  75. data/spec/unit/intercom/user_spec.rb +224 -226
  76. data/spec/unit/intercom/visitor_spec.rb +49 -0
  77. data/spec/unit/intercom_spec.rb +5 -3
  78. metadata +22 -7
  79. data/lib/intercom/customer.rb +0 -10
  80. data/lib/intercom/service/customer.rb +0 -14
  81. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,56 +1,60 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Intercom::SearchCollectionProxy do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
- it "send query to the customer search endpoint" do
7
- client.expects(:post).with("/customers/search", { query: {} }). returns(page_of_customers(false))
8
- client.customers.search(query: {}).first
6
+ it "sends query to the contact search endpoint" do
7
+ client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
8
+ client.contacts.search(query: {}).first
9
9
  end
10
10
 
11
- it "send query to the customer search endpoint with sort_field" do
12
- client.expects(:post).with("/customers/search", { query: {}, sort: { field: "name" } }). returns(page_of_customers(false))
13
- client.customers.search(query: {}, sort_field: "name").first
11
+ it "sends query to the conversation search endpoint" do
12
+ client.expects(:post).with("/conversations/search", { query: {} }).returns(test_conversation_list)
13
+ client.conversations.search(query: {}).first
14
14
  end
15
15
 
16
- it "send query to the customer search endpoint with sort_field and sort_order" do
17
- client.expects(:post).with("/customers/search", { query: {}, sort: { field: "name", order: "ascending" } }). returns(page_of_customers(false))
18
- client.customers.search(query: {}, sort_field: "name", sort_order: "ascending").first
16
+ it "sends query to the contact search endpoint with sort_field" do
17
+ client.expects(:post).with("/contacts/search", { query: {}, sort: { field: "name" } }).returns(page_of_contacts(false))
18
+ client.contacts.search(query: {}, sort_field: "name").first
19
19
  end
20
20
 
21
- it "send query to the customer search endpoint with per_page" do
22
- client.expects(:post).with("/customers/search", { query: {}, pagination: { per_page: 10 }}). returns(page_of_customers(false))
23
- client.customers.search(query: {}, per_page: 10).first
21
+ it "sends query to the contact search endpoint with sort_field and sort_order" do
22
+ client.expects(:post).with("/contacts/search", { query: {}, sort: { field: "name", order: "ascending" } }).returns(page_of_contacts(false))
23
+ client.contacts.search(query: {}, sort_field: "name", sort_order: "ascending").first
24
24
  end
25
25
 
26
- it "send query to the customer search endpoint with starting_after" do
27
- client.expects(:post).with("/customers/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}). returns(page_of_customers(false))
28
- client.customers.search(query: {}, starting_after: "EnCrYpTeDsTrInG").first
26
+ it "sends query to the contact search endpoint with per_page" do
27
+ client.expects(:post).with("/contacts/search", { query: {}, pagination: { per_page: 10 }}).returns(page_of_contacts(false))
28
+ client.contacts.search(query: {}, per_page: 10).first
29
+ end
30
+
31
+ it "sends query to the contact search endpoint with starting_after" do
32
+ client.expects(:post).with("/contacts/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_contacts(false))
33
+ client.contacts.search(query: {}, starting_after: "EnCrYpTeDsTrInG").first
29
34
  end
30
35
 
31
36
  it "stops iterating if no starting_after value" do
32
- client.expects(:post).with("/customers/search", { query: {} }). returns(page_of_customers(false))
37
+ client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
33
38
  emails = []
34
- client.customers.search(query: {}).each { |user| emails << user.email }
35
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
39
+ client.contacts.search(query: {}).each { |contact| emails << contact.email }
40
+ _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
36
41
  end
37
42
 
38
43
  it "keeps iterating if starting_after value" do
39
- client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(true))
40
- client.expects(:post).with("/customers/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_customers(false))
44
+ client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(true))
45
+ client.expects(:post).with("/contacts/search", { query: {}, pagination: { starting_after: "EnCrYpTeDsTrInG" }}).returns(page_of_contacts(false))
41
46
  emails = []
42
- client.customers.search(query: {}).each { |user| emails << user.email }
47
+ client.contacts.search(query: {}).each { |contact| emails << contact.email }
43
48
  end
44
49
 
45
50
  it "supports indexed array access" do
46
- client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(false))
47
- client.customers.search(query: {})[0].email.must_equal 'user1@example.com'
51
+ client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
52
+ _(client.contacts.search(query: {})[0].email).must_equal 'test1@example.com'
48
53
  end
49
54
 
50
55
  it "supports map" do
51
- client.expects(:post).with("/customers/search", { query: {} }).returns(page_of_customers(false))
52
- emails = client.customers.search(query: {}).map { |user| user.email }
53
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
56
+ client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
57
+ emails = client.contacts.search(query: {}).map { |contact| contact.email }
58
+ _(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
54
59
  end
55
-
56
60
  end
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe "Intercom::Segment" do
4
4
 
5
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
5
+ let(:client) { Intercom::Client.new(token: 'token') }
6
6
 
7
7
  it 'lists segments' do
8
8
  client.expects(:get).with('/segments', {}).returns(segment_list)
9
9
  segments = client.segments.all.to_a
10
- segments[0].name.must_equal('Active')
10
+ _(segments[0].name).must_equal('Active')
11
11
  end
12
12
  end
@@ -1,20 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Intercom::Subscription" do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
6
  it "gets a subscription" do
7
7
  client.expects(:get).with("/subscriptions/nsub_123456789", {}).returns(test_subscription)
8
8
  subscription = client.subscriptions.find(:id => "nsub_123456789")
9
- subscription.request.topics[0].must_equal "user.created"
10
- subscription.request.topics[1].must_equal "conversation.user.replied"
9
+ _(subscription.request.topics[0]).must_equal "user.created"
10
+ _(subscription.request.topics[1]).must_equal "conversation.user.replied"
11
11
  end
12
12
 
13
13
  it "creates a subscription" do
14
14
  client.expects(:post).with("/subscriptions", {'url' => "http://example.com", 'topics' => ["user.created"]}).returns(test_subscription)
15
15
  subscription = client.subscriptions.create(:url => "http://example.com", :topics => ["user.created"])
16
- subscription.request.topics[0].must_equal "user.created"
17
- subscription.request.url.must_equal "http://example.com"
16
+ _(subscription.request.topics[0]).must_equal "user.created"
17
+ _(subscription.request.url).must_equal "http://example.com"
18
18
  end
19
-
20
19
  end
@@ -1,23 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe "Intercom::Tag" do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
5
+ describe 'Intercom::Tag' do
6
+ let(:client) { Intercom::Client.new(token: 'token') }
7
+
8
+ it 'creates a tag' do
9
+ client.expects(:post).with('/tags', 'name' => 'Test Tag').returns(test_tag)
10
+ tag = client.tags.create(name: 'Test Tag')
11
+ _(tag.name).must_equal 'Test Tag'
12
+ end
5
13
 
6
- it "creates a tag" do
7
- client.expects(:post).with("/tags", {'name' => "Test Tag"}).returns(test_tag)
8
- tag = client.tags.create(:name => "Test Tag")
9
- tag.name.must_equal "Test Tag"
14
+ it 'finds a tag by id' do
15
+ client.expects(:get).with('/tags/4f73428b5e4dfc000b000112', {}).returns(test_tag)
16
+ tag = client.tags.find(id: '4f73428b5e4dfc000b000112')
17
+ _(tag.name).must_equal 'Test Tag'
10
18
  end
11
19
 
12
- it "tags users" do
13
- client.expects(:post).with("/tags", {'name' => "Test Tag", 'users' => [ { user_id: 'abc123' }, { user_id: 'def456' } ], 'tag_or_untag' => 'tag'}).returns(test_tag)
14
- tag = client.tags.tag(:name => "Test Tag", :users => [ { user_id: "abc123" }, { user_id: "def456" } ] )
15
- tag.name.must_equal "Test Tag"
16
- tag.tagged_user_count.must_equal 2
20
+ it 'tags companies' do
21
+ client.expects(:post).with('/tags', 'name' => 'Test Tag', 'companies' => [{ company_id: 'abc123' }, { company_id: 'def456' }], 'tag_or_untag' => 'tag').returns(test_tag)
22
+ tag = client.tags.tag(name: 'Test Tag', companies: [{ company_id: 'abc123' }, { company_id: 'def456' }])
23
+ _(tag.name).must_equal 'Test Tag'
24
+ _(tag.tagged_company_count).must_equal 2
17
25
  end
18
26
 
19
- it 'untags users' do
20
- client.expects(:post).with("/tags", {'name' => "Test Tag", 'users' => [ { user_id: 'abc123', untag: true }, { user_id: 'def456', untag: true } ], 'tag_or_untag' => 'untag'}).returns(test_tag)
21
- client.tags.untag(:name => "Test Tag", :users => [ { user_id: "abc123" }, { user_id: "def456" } ])
27
+ it 'untags companies' do
28
+ client.expects(:post).with('/tags', 'name' => 'Test Tag', 'companies' => [{ company_id: 'abc123', untag: true }, { company_id: 'def456', untag: true }], 'tag_or_untag' => 'untag').returns(test_tag)
29
+ client.tags.untag(name: 'Test Tag', companies: [{ company_id: 'abc123' }, { company_id: 'def456' }])
22
30
  end
23
31
  end
@@ -1,12 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Intercom::Team" do
4
- let (:client) { Intercom::Client.new(token: 'token') }
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
5
 
6
6
  it "returns a CollectionProxy for all without making any requests" do
7
7
  client.expects(:execute_request).never
8
8
  all = client.teams.all
9
- all.must_be_instance_of(Intercom::ClientCollectionProxy)
9
+ _(all).must_be_instance_of(Intercom::ClientCollectionProxy)
10
10
  end
11
11
 
12
12
  it 'gets an team list' do
@@ -1,98 +1,100 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe Intercom::Traits::ApiResource do
4
6
  let(:object_json) do
5
- {"type"=>"company",
6
- "id"=>"aaaaaaaaaaaaaaaaaaaaaaaa",
7
- "app_id"=>"some-app-id",
8
- "name"=>"SuperSuite",
9
- "plan_id"=>1,
10
- "remote_company_id"=>"8",
11
- "remote_created_at"=>103201,
12
- "created_at"=>1374056196,
13
- "user_count"=>1,
14
- "custom_attributes"=>{},
15
- "metadata"=>{
16
- "type"=>"user",
17
- "color"=>"cyan"
18
- }}
7
+ { 'type' => 'company',
8
+ 'id' => 'aaaaaaaaaaaaaaaaaaaaaaaa',
9
+ 'app_id' => 'some-app-id',
10
+ 'name' => 'SuperSuite',
11
+ 'plan_id' => 1,
12
+ 'remote_company_id' => '8',
13
+ 'remote_created_at' => 103_201,
14
+ 'created_at' => 1_374_056_196,
15
+ 'user_count' => 1,
16
+ 'custom_attributes' => {},
17
+ 'metadata' => {
18
+ 'type' => 'user',
19
+ 'color' => 'cyan'
20
+ } }
19
21
  end
20
22
 
21
23
  let(:object_hash) do
22
24
  {
23
- type: "company",
24
- id: "aaaaaaaaaaaaaaaaaaaaaaaa",
25
- app_id: "some-app-id",
26
- name: "SuperSuite",
25
+ type: 'company',
26
+ id: 'aaaaaaaaaaaaaaaaaaaaaaaa',
27
+ app_id: 'some-app-id',
28
+ name: 'SuperSuite',
27
29
  plan_id: 1,
28
- remote_company_id: "8",
29
- remote_created_at: 103201,
30
- created_at: 1374056196,
30
+ remote_company_id: '8',
31
+ remote_created_at: 103_201,
32
+ created_at: 1_374_056_196,
31
33
  user_count: 1,
32
- custom_attributes: { type: "ping" },
34
+ custom_attributes: { type: 'ping' },
33
35
  metadata: {
34
- type: "user",
35
- color: "cyan"
36
+ type: 'user',
37
+ color: 'cyan'
36
38
  }
37
39
  }
38
40
  end
39
41
 
40
- let(:api_resource) { DummyClass.new.extend(Intercom::Traits::ApiResource)}
42
+ let(:api_resource) { DummyClass.new.extend(Intercom::Traits::ApiResource) }
41
43
 
42
44
  before(:each) { api_resource.from_response(object_json) }
43
45
 
44
- it "coerces time on parsing json" do
45
- assert_equal Time.at(1374056196), api_resource.created_at
46
+ it 'coerces time on parsing json' do
47
+ assert_equal Time.at(1_374_056_196), api_resource.created_at
46
48
  end
47
49
 
48
- it "exposes string" do
49
- assert_equal Time.at(1374056196), api_resource.created_at
50
+ it 'exposes string' do
51
+ assert_equal Time.at(1_374_056_196), api_resource.created_at
50
52
  end
51
53
 
52
54
  it "treats 'metadata' as a plain hash, not a typed object" do
53
55
  assert_equal Hash, api_resource.metadata.class
54
56
  end
55
57
 
56
- it "dynamically defines accessors when a non-existent property is called that looks like a setter" do
57
- api_resource.wont_respond_to :spiders
58
+ it 'dynamically defines accessors when a non-existent property is called that looks like a setter' do
59
+ _(api_resource).wont_respond_to :spiders
58
60
  api_resource.spiders = 4
59
- api_resource.must_respond_to :spiders
61
+ _(api_resource).must_respond_to :spiders
60
62
  end
61
63
 
62
- it "calls dynamically defined getter when asked" do
64
+ it 'calls dynamically defined getter when asked' do
63
65
  api_resource.foo = 4
64
66
  assert_equal 4, api_resource.foo
65
67
  end
66
68
 
67
- it "accepts unix timestamps into dynamically defined date setters" do
68
- api_resource.foo_at = 1401200468
69
- assert_equal 1401200468, api_resource.instance_variable_get(:@foo_at)
69
+ it 'accepts unix timestamps into dynamically defined date setters' do
70
+ api_resource.foo_at = 1_401_200_468
71
+ assert_equal 1_401_200_468, api_resource.instance_variable_get(:@foo_at)
70
72
  end
71
73
 
72
- it "exposes dates correctly for dynamically defined getters" do
73
- api_resource.foo_at = 1401200468
74
- assert_equal Time.at(1401200468), api_resource.foo_at
74
+ it 'exposes dates correctly for dynamically defined getters' do
75
+ api_resource.foo_at = 1_401_200_468
76
+ assert_equal Time.at(1_401_200_468), api_resource.foo_at
75
77
  end
76
78
 
77
- it "throws regular method missing error when non-existent getter is called that is backed by an instance variable" do
79
+ it 'throws regular method missing error when non-existent getter is called that is backed by an instance variable' do
78
80
  api_resource.instance_variable_set(:@bar, 'you cant see me')
79
- proc { api_resource.bar }.must_raise NoMethodError
81
+ _(proc { api_resource.bar }).must_raise NoMethodError
80
82
  end
81
83
 
82
- it "throws attribute not set error when non-existent getter is called that is not backed by an instance variable" do
83
- proc { api_resource.flubber }.must_raise Intercom::AttributeNotSetError
84
+ it 'throws attribute not set error when non-existent getter is called that is not backed by an instance variable' do
85
+ _(proc { api_resource.flubber }).must_raise Intercom::AttributeNotSetError
84
86
  end
85
87
 
86
- it "throws regular method missing error when non-existent method is called that cannot be an accessor" do
87
- proc { api_resource.flubber! }.must_raise NoMethodError
88
- proc { api_resource.flubber? }.must_raise NoMethodError
88
+ it 'throws regular method missing error when non-existent method is called that cannot be an accessor' do
89
+ _(proc { api_resource.flubber! }).must_raise NoMethodError
90
+ _(proc { api_resource.flubber? }).must_raise NoMethodError
89
91
  end
90
92
 
91
- it "throws regular method missing error when non-existent setter is called with multiple arguments" do
92
- proc { api_resource.send(:flubber=, 'a', 'b') }.must_raise NoMethodError
93
+ it 'throws regular method missing error when non-existent setter is called with multiple arguments' do
94
+ _(proc { api_resource.send(:flubber=, 'a', 'b') }).must_raise NoMethodError
93
95
  end
94
96
 
95
- it "an initialized ApiResource is equal to one generated from a response" do
97
+ it 'an initialized ApiResource is equal to one generated from a response' do
96
98
  class ConcreteApiResource; include Intercom::Traits::ApiResource; end
97
99
  initialized_api_resource = ConcreteApiResource.new(object_json)
98
100
  except(object_json, 'type').keys.each do |attribute|
@@ -100,7 +102,7 @@ describe Intercom::Traits::ApiResource do
100
102
  end
101
103
  end
102
104
 
103
- it "initialized ApiResource using hash is equal to one generated from response" do
105
+ it 'initialized ApiResource using hash is equal to one generated from response' do
104
106
  class ConcreteApiResource; include Intercom::Traits::ApiResource; end
105
107
 
106
108
  api_resource.from_hash(object_hash)
@@ -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