intercom 3.9.5 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +483 -234
  3. data/Rakefile +1 -1
  4. data/changes.txt +37 -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 +68 -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 +74 -0
  17. data/lib/intercom/client.rb +48 -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 +23 -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 +6 -0
  27. data/lib/intercom/export_content.rb +7 -0
  28. data/lib/intercom/extended_api_operations/segments.rb +3 -1
  29. data/lib/intercom/extended_api_operations/tags.rb +3 -1
  30. data/lib/intercom/lead.rb +21 -0
  31. data/lib/intercom/lib/dynamic_accessors.rb +9 -10
  32. data/lib/intercom/lib/typed_json_deserializer.rb +45 -35
  33. data/lib/intercom/note.rb +4 -0
  34. data/lib/intercom/phone_call_redirect.rb +7 -0
  35. data/lib/intercom/request.rb +39 -33
  36. data/lib/intercom/scroll_collection_proxy.rb +38 -42
  37. data/lib/intercom/search_collection_proxy.rb +30 -65
  38. data/lib/intercom/section.rb +23 -0
  39. data/lib/intercom/segment.rb +4 -0
  40. data/lib/intercom/service/article.rb +20 -0
  41. data/lib/intercom/service/base_service.rb +7 -0
  42. data/lib/intercom/service/collection.rb +24 -0
  43. data/lib/intercom/service/company.rb +2 -12
  44. data/lib/intercom/service/contact.rb +35 -10
  45. data/lib/intercom/service/conversation.rb +16 -3
  46. data/lib/intercom/service/data_attribute.rb +20 -0
  47. data/lib/intercom/service/export_content.rb +30 -0
  48. data/lib/intercom/service/lead.rb +41 -0
  49. data/lib/intercom/service/note.rb +4 -8
  50. data/lib/intercom/service/phone_call_redirect.rb +15 -0
  51. data/lib/intercom/service/section.rb +7 -0
  52. data/lib/intercom/service/subscription.rb +2 -2
  53. data/lib/intercom/service/subscription_type.rb +18 -0
  54. data/lib/intercom/service/tag.rb +9 -9
  55. data/lib/intercom/service/visitor.rb +17 -8
  56. data/lib/intercom/subscription_type.rb +12 -0
  57. data/lib/intercom/tag.rb +4 -0
  58. data/lib/intercom/traits/api_resource.rb +44 -18
  59. data/lib/intercom/traits/dirty_tracking.rb +8 -1
  60. data/lib/intercom/user.rb +12 -3
  61. data/lib/intercom/utils.rb +19 -3
  62. data/lib/intercom/version.rb +1 -1
  63. data/lib/intercom/visitor.rb +0 -2
  64. data/lib/intercom.rb +39 -22
  65. data/spec/spec_helper.rb +843 -520
  66. data/spec/unit/intercom/admin_spec.rb +2 -2
  67. data/spec/unit/intercom/article_spec.rb +40 -0
  68. data/spec/unit/intercom/base_collection_proxy_spec.rb +52 -0
  69. data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
  70. data/spec/unit/intercom/client_spec.rb +25 -26
  71. data/spec/unit/intercom/collection_spec.rb +32 -0
  72. data/spec/unit/intercom/company_spec.rb +19 -15
  73. data/spec/unit/intercom/contact_spec.rb +402 -33
  74. data/spec/unit/intercom/conversation_spec.rb +60 -7
  75. data/spec/unit/intercom/count_spec.rb +4 -4
  76. data/spec/unit/intercom/data_attribute_spec.rb +40 -0
  77. data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
  78. data/spec/unit/intercom/event_spec.rb +16 -11
  79. data/spec/unit/intercom/export_content_spec.rb +28 -0
  80. data/spec/unit/intercom/job_spec.rb +24 -24
  81. data/spec/unit/intercom/lead_spec.rb +57 -0
  82. data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
  83. data/spec/unit/intercom/message_spec.rb +1 -1
  84. data/spec/unit/intercom/note_spec.rb +4 -10
  85. data/spec/unit/intercom/phone_call_redirect.rb +12 -0
  86. data/spec/unit/intercom/request_spec.rb +14 -1
  87. data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
  88. data/spec/unit/intercom/search_collection_proxy_spec.rb +32 -28
  89. data/spec/unit/intercom/section_spec.rb +32 -0
  90. data/spec/unit/intercom/segment_spec.rb +2 -2
  91. data/spec/unit/intercom/subscription_spec.rb +5 -6
  92. data/spec/unit/intercom/tag_spec.rb +28 -14
  93. data/spec/unit/intercom/team_spec.rb +2 -2
  94. data/spec/unit/intercom/traits/api_resource_spec.rb +107 -52
  95. data/spec/unit/intercom/user_spec.rb +224 -226
  96. data/spec/unit/intercom/visitor_spec.rb +49 -0
  97. data/spec/unit/intercom_spec.rb +5 -3
  98. metadata +44 -8
  99. data/lib/intercom/customer.rb +0 -10
  100. data/lib/intercom/service/customer.rb +0 -14
  101. data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -4,7 +4,7 @@ describe "Intercom::Event" do
4
4
 
5
5
  let(:user) {Intercom::User.new("email" => "jim@example.com", :user_id => "12345", :created_at => Time.now, :name => "Jim Bob")}
6
6
  let(:created_time) {Time.now - 300}
7
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
7
+ let(:client) { Intercom::Client.new(token: 'token') }
8
8
 
9
9
  it 'gets events for a user' do
10
10
  client.expects(:get).with('/events', type: 'user', email: 'joe@example.com').returns(test_event_list)
@@ -12,14 +12,21 @@ describe "Intercom::Event" do
12
12
  end
13
13
 
14
14
  it "has the correct collection proxy class" do
15
- client.events.collection_proxy_class.must_equal Intercom::EventCollectionProxy
15
+ _(client.events.collection_proxy_class).must_equal Intercom::EventCollectionProxy
16
16
  end
17
17
 
18
18
  it "stops iterating if no next link" do
19
19
  client.expects(:get).with("/events", type: 'user', email: 'joe@example.com').returns(page_of_events(false))
20
20
  event_names = []
21
21
  client.events.find_all(type: 'user', email: 'joe@example.com').each { |event| event_names << event.event_name }
22
- event_names.must_equal %W(invited-friend)
22
+ _(event_names).must_equal %W(invited-friend)
23
+ end
24
+
25
+ it "able to fetch event summary" do
26
+ client.expects(:get).with("/events", type: 'user', email: 'joe@example.com', summary: true).returns(page_of_events(false))
27
+ event_names = []
28
+ client.events.find_all(type: 'user', email: 'joe@example.com',summary: true).each { |event| event_names << event.event_name }
29
+ _(event_names).must_equal %W(invited-friend)
23
30
  end
24
31
 
25
32
  it "keeps iterating if next link" do
@@ -27,7 +34,7 @@ describe "Intercom::Event" do
27
34
  client.expects(:get).with("https://api.intercom.io/events?type=user&intercom_user_id=55a3b&before=144474756550", {}).returns(page_of_events(false))
28
35
  event_names = []
29
36
  client.events.find_all(type: 'user', email: 'joe@example.com').each { |event| event_names << event.event_name }
30
- event_names.must_equal %W(invited-friend invited-friend)
37
+ _(event_names).must_equal %W(invited-friend invited-friend)
31
38
  end
32
39
 
33
40
  it "creates an event with metadata" do
@@ -74,15 +81,15 @@ describe "Intercom::Event" do
74
81
  "state"=>"completed"
75
82
  }
76
83
  ]
77
- }
84
+ }
78
85
  }
79
86
  let(:bulk_request) {
80
- {
87
+ {
81
88
  items: [
82
89
  {
83
90
  method: "post",
84
91
  data_type: "event",
85
- data:{
92
+ data: {
86
93
  event_name: "ordered-item",
87
94
  created_at: 1438944980,
88
95
  user_id: "314159",
@@ -95,7 +102,7 @@ describe "Intercom::Event" do
95
102
  {
96
103
  method: "post",
97
104
  data_type: "event",
98
- data:{
105
+ data: {
99
106
  event_name: "invited-friend",
100
107
  created_at: 1438944979,
101
108
  user_id: "314159",
@@ -143,9 +150,7 @@ describe "Intercom::Event" do
143
150
  end
144
151
 
145
152
  it "does not submit delete jobs" do
146
- lambda { client.events.submit_bulk_job(delete_items: events) }.must_raise ArgumentError
153
+ _(lambda { client.events.submit_bulk_job(delete_items: events) }).must_raise ArgumentError
147
154
  end
148
-
149
155
  end
150
-
151
156
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Intercom::ExportContent" do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+ let(:job) {
6
+ {
7
+ job_identifier: "k0e27ohsyvh8ef3m",
8
+ status: "no_data",
9
+ download_url: "",
10
+ download_expires_at: 0
11
+ }
12
+ }
13
+
14
+ it "creates an export job" do
15
+ client.expects(:post).with("/export/content/data", {"created_at_after" => 1667566801, "created_at_before" => 1668085202}).returns(job)
16
+ client.export_content.create({"created_at_after" => 1667566801, "created_at_before" => 1668085202})
17
+ end
18
+
19
+ it "can view an export job" do
20
+ client.expects(:get).with("/export/content/data/#{job[:job_identifier]}", {}).returns(job)
21
+ client.export_content.find(id: job[:job_identifier])
22
+ end
23
+
24
+ it "Cancels a export job redirect" do
25
+ client.expects(:post).with("/export/cancel/#{job[:job_identifier]}", {}).returns(job)
26
+ client.export_content.cancel(job[:job_identifier])
27
+ end
28
+ end
@@ -1,41 +1,41 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "jobs" 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
  let (:job) {
6
6
  {
7
- "app_id"=>"app_id",
8
- "id"=>"super_awesome_job",
9
- "created_at"=>1446033421,
10
- "completed_at"=>1446048736,
11
- "closing_at"=>1446034321,
12
- "updated_at"=>1446048736,
13
- "name"=>"api_bulk_job",
14
- "state"=>"completed",
15
- "links"=>
7
+ "app_id" => "app_id",
8
+ "id" => "super_awesome_job",
9
+ "created_at" => 1446033421,
10
+ "completed_at" => 1446048736,
11
+ "closing_at" => 1446034321,
12
+ "updated_at" => 1446048736,
13
+ "name" => "api_bulk_job",
14
+ "state" => "completed",
15
+ "links" =>
16
16
  {
17
- "error"=>"https://api.intercom.io/jobs/super_awesome_job/error",
18
- "self"=>"https://api.intercom.io/jobs/super_awesome_job"
17
+ "error" => "https://api.intercom.io/jobs/super_awesome_job/error",
18
+ "self" => "https://api.intercom.io/jobs/super_awesome_job"
19
19
  },
20
- "tasks"=>
20
+ "tasks" =>
21
21
  [
22
22
  {
23
- "id"=>"super_awesome_task",
24
- "item_count"=>2,
25
- "created_at"=>1446033421,
26
- "started_at"=>1446033709,
27
- "completed_at"=>1446033709,
28
- "state"=>"completed"
23
+ "id" => "super_awesome_task",
24
+ "item_count" => 2,
25
+ "created_at" => 1446033421,
26
+ "started_at" => 1446033709,
27
+ "completed_at" => 1446033709,
28
+ "state" => "completed"
29
29
  }
30
30
  ]
31
- }
31
+ }
32
32
  }
33
33
  let (:error_feed) {
34
34
  {
35
- "app_id"=>"app_id",
36
- "job_id"=>"super_awesome_job",
37
- "pages"=>{},
38
- "items"=>[]
35
+ "app_id" => "app_id",
36
+ "job_id" => "super_awesome_job",
37
+ "pages" => {},
38
+ "items" => []
39
39
  }
40
40
  }
41
41
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Intercom::Lead' do
6
+ let (:client) { Intercom::Client.new(token: 'token') }
7
+
8
+ it 'should be listable' do
9
+ proxy = client.deprecated__leads.all
10
+ _(proxy.resource_name).must_equal 'contacts'
11
+ _(proxy.resource_class).must_equal Intercom::Lead
12
+ end
13
+
14
+ it 'should not throw ArgumentErrors when there are no parameters' do
15
+ client.expects(:post)
16
+ client.deprecated__leads.create
17
+ end
18
+
19
+ it 'can update a lead with an id' do
20
+ lead = Intercom::Lead.new(id: 'de45ae78gae1289cb')
21
+ client.expects(:put).with('/contacts/de45ae78gae1289cb', 'custom_attributes' => {})
22
+ client.deprecated__leads.save(lead)
23
+ end
24
+
25
+ describe 'converting' do
26
+ let(:lead) { Intercom::Lead.from_api(user_id: 'contact_id') }
27
+ let(:user) { Intercom::User.from_api(id: 'user_id') }
28
+
29
+ it do
30
+ client.expects(:post).with(
31
+ '/contacts/convert',
32
+ contact: { user_id: lead.user_id },
33
+ user: { 'id' => user.id }
34
+ ).returns(test_user)
35
+
36
+ client.deprecated__leads.convert(lead, user)
37
+ end
38
+ end
39
+
40
+ it 'returns a DeprecatedLeadsCollectionProxy for all without making any requests' do
41
+ client.expects(:execute_request).never
42
+ all = client.deprecated__leads.all
43
+ _(all).must_be_instance_of(Intercom::DeprecatedLeadsCollectionProxy)
44
+ end
45
+
46
+ it 'deletes a lead' do
47
+ lead = Intercom::Lead.new('id' => '1')
48
+ client.expects(:delete).with('/contacts/1', {}).returns(lead)
49
+ client.deprecated__leads.delete(lead)
50
+ end
51
+
52
+ it 'sends a request for a hard deletion' do
53
+ lead = Intercom::Lead.new('id' => '1')
54
+ client.expects(:post).with('/user_delete_requests', intercom_user_id: '1').returns(id: lead.id)
55
+ client.deprecated__leads.request_hard_delete(lead)
56
+ end
57
+ end
@@ -1,29 +1,31 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe Intercom::Lib::FlatStore do
4
- it "raises if you try to set or merge in nested hash structures" do
5
- data = Intercom::Lib::FlatStore.new()
6
- proc { data["thing"] = [1] }.must_raise ArgumentError
7
- proc { data["thing"] = {1 => 2} }.must_raise ArgumentError
8
- proc { Intercom::Lib::FlatStore.new({1 => {2 => 3}}) }.must_raise ArgumentError
6
+ it 'raises if you try to set or merge in nested hash structures' do
7
+ data = Intercom::Lib::FlatStore.new
8
+ _(proc { data['thing'] = [1] }).must_raise ArgumentError
9
+ _(proc { data['thing'] = { 1 => 2 } }).must_raise ArgumentError
10
+ _(proc { Intercom::Lib::FlatStore.new(1 => { 2 => 3 }) }).must_raise ArgumentError
9
11
  end
10
12
 
11
- it "raises if you try to use a non string key" do
12
- data =Intercom::Lib::FlatStore.new()
13
- proc { data[1] = "something" }.must_raise ArgumentError
13
+ it 'raises if you try to use a non string key' do
14
+ data = Intercom::Lib::FlatStore.new
15
+ _(proc { data[1] = 'something' }).must_raise ArgumentError
14
16
  end
15
17
 
16
- it "sets and merges valid entries" do
17
- data = Intercom::Lib::FlatStore.new()
18
- data["a"] = 1
18
+ it 'sets and merges valid entries' do
19
+ data = Intercom::Lib::FlatStore.new
20
+ data['a'] = 1
19
21
  data[:b] = 2
20
- data[:a].must_equal 1
21
- data["b"].must_equal 2
22
- data[:b].must_equal 2
23
- data = Intercom::Lib::FlatStore.new({"a" => 1, :b => 2})
24
- data["a"].must_equal 1
25
- data[:a].must_equal 1
26
- data["b"].must_equal 2
27
- data[:b].must_equal 2
22
+ _(data[:a]).must_equal 1
23
+ _(data['b']).must_equal 2
24
+ _(data[:b]).must_equal 2
25
+ data = Intercom::Lib::FlatStore.new('a' => 1, :b => 2)
26
+ _(data['a']).must_equal 1
27
+ _(data[:a]).must_equal 1
28
+ _(data['b']).must_equal 2
29
+ _(data[:b]).must_equal 2
28
30
  end
29
31
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "Intercom::Message" do
4
4
 
5
5
  let (:user) {Intercom::User.new("email" => "jim@example.com", :user_id => "12345", :created_at => Time.now, :name => "Jim Bob")}
6
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
6
+ let(:client) { Intercom::Client.new(token: 'token') }
7
7
 
8
8
  it 'creates an user message with symbol keys' do
9
9
  client.expects(:post).with('/messages', {'from' => { :type => 'user', :email => 'jim@example.com'}, 'body' => 'halp'}).returns(:status => 200)
@@ -1,13 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "notes" do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
5
-
6
- it "creates a note" do
7
- client.expects(:post).with("/notes", {"body" => "Note to leave on user"}).returns({"body" => "<p>Note to leave on user</p>", "created_at" => 1234567890})
8
- note = client.notes.create("body" => "Note to leave on user")
9
- note.body.must_equal "<p>Note to leave on user</p>"
10
- end
4
+ let(:client) { Intercom::Client.new(token: 'token') }
11
5
 
12
6
  it 'gets a note' do
13
7
  client.expects(:get).with("/notes/123", {}).returns({"id" => "123", "body" => "<p>Note to leave on user</p>", "created_at" => 1234567890})
@@ -18,9 +12,9 @@ describe "notes" do
18
12
  params = {"body" => "Note body", "email" => "me@example.com", :user_id => "abc123"}
19
13
  note = Intercom::Note.new(params)
20
14
 
21
- note.to_hash.keys.sort.must_equal params.keys.map(&:to_s).sort
22
- params.keys.each do | key|
23
- note.send(key).must_equal params[key]
15
+ _(note.to_hash.keys.sort).must_equal params.keys.map(&:to_s).sort
16
+ params.keys.each do |key|
17
+ _(note.send(key)).must_equal params[key]
24
18
  end
25
19
  end
26
20
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Intercom::PhoneCallRedirect" do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+
6
+ it "creates a phone redirect" do
7
+
8
+ client.expects(:post).with("/phone_call_redirect", {phone_number: "+353871234567"})
9
+ client.phone_call_redirect.create(phone_number: "+353871234567")
10
+ end
11
+
12
+ end
@@ -9,7 +9,7 @@ describe 'Intercom::Request', '#execute' do
9
9
  let(:default_body) { { data: "test" }.to_json }
10
10
 
11
11
  def execute!
12
- req.execute(uri, username: 'ted', secret: '')
12
+ req.execute(uri, token: 'test-token')
13
13
  end
14
14
 
15
15
  it 'should call sleep for rate limit error three times and raise a rate limit error otherwise' do
@@ -124,6 +124,9 @@ describe 'Intercom::Request', '#execute' do
124
124
  let(:uri) {"https://api.intercom.io/conversations/reply"}
125
125
  let(:req) { Intercom::Request.put(uri, {}) }
126
126
 
127
+ let(:tag_uri) {"https://api.intercom.io/tags/"}
128
+ let(:del_req) { Intercom::Request.delete(tag_uri, {}) }
129
+
127
130
  it 'should raise ResourceNotUniqueError error on resource_conflict code' do
128
131
  stub_request(:put, uri).to_return(
129
132
  status: [409, "Resource Already Exists"],
@@ -153,5 +156,15 @@ describe 'Intercom::Request', '#execute' do
153
156
 
154
157
  expect { execute! }.must_raise(Intercom::ResourceNotFound)
155
158
  end
159
+
160
+ it 'should raise TagHasDependentObjects error on tag_has_dependent_objects code' do
161
+ stub_request(:delete, tag_uri).to_return(
162
+ status: [400, "Bad Request"],
163
+ headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
164
+ body: { type: "error.list", errors: [ code: "tag_has_dependent_objects" ] }.to_json
165
+ )
166
+
167
+ expect { del_req.execute(tag_uri, token: 'test-token') }.must_raise(Intercom::TagHasDependentObjects)
168
+ end
156
169
  end
157
170
  end
@@ -1,56 +1,57 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe Intercom::ScrollCollectionProxy do
4
- let (:client) { Intercom::Client.new(app_id: 'app_id', api_key: 'api_key') }
6
+ let(:client) { Intercom::Client.new(token: 'token') }
5
7
 
6
- it "stops iterating if no users returned" do
7
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(false))
8
- emails = []
9
- client.users.scroll.each { |user| emails << user.email }
10
- emails.must_equal %W()
8
+ it 'stops iterating if no companies returned' do
9
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(false))
10
+ names = []
11
+ client.companies.scroll.each { |company| names << company.name }
12
+ _(names).must_equal %w[]
11
13
  end
12
14
 
13
- it "keeps iterating if users returned" do
14
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
15
- client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(false))
16
- emails = []
17
- client.users.scroll.each { |user| emails << user.email }
15
+ it 'keeps iterating if companies returned' do
16
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
17
+ client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(false))
18
+ names = []
19
+ client.companies.scroll.each { |company| names << company.name }
18
20
  end
19
21
 
20
- it "supports indexed array access" do
21
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
22
- client.users.scroll[0].email.must_equal 'user1@example.com'
22
+ it 'supports indexed array access' do
23
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
24
+ _(client.companies.scroll[0].name).must_equal 'company1'
23
25
  end
24
26
 
25
- it "supports map" do
26
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
27
- client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(false))
28
- emails = client.users.scroll.map { |user| user.email }
29
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
27
+ it 'supports map' do
28
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
29
+ client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(false))
30
+ names = client.companies.scroll.map(&:name)
31
+ _(names).must_equal %w[company1 company2 company3]
30
32
  end
31
33
 
32
- it "returns one page scroll" do
33
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
34
- scroll = client.users.scroll.next
35
- emails = []
36
- scroll.records.each {|usr| emails << usr.email}
37
- emails.must_equal %W(user1@example.com user2@example.com user3@example.com)
34
+ it 'returns one page scroll' do
35
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
36
+ scroll = client.companies.scroll.next
37
+ names = []
38
+ scroll.records.each { |usr| names << usr.name }
39
+ _(names).must_equal %w[company1 company2 company3]
38
40
  end
39
41
 
40
- it "keeps iterating if called with scroll_param" do
41
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(true))
42
- client.expects(:get).with('/users/scroll', {:scroll_param => 'da6bbbac-25f6-4f07-866b-b911082d7'}).returns(users_scroll(true))
43
- scroll = client.users.scroll.next
44
- scroll = client.users.scroll.next('da6bbbac-25f6-4f07-866b-b911082d7')
45
- emails =[]
46
- scroll.records.each {|usr| puts usr.email}
42
+ it 'keeps iterating if called with scroll_param' do
43
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(true))
44
+ client.expects(:get).with('/companies/scroll', scroll_param: 'da6bbbac-25f6-4f07-866b-b911082d7').returns(companies_scroll(true))
45
+ scroll = client.companies.scroll.next
46
+ scroll = client.companies.scroll.next('da6bbbac-25f6-4f07-866b-b911082d7')
47
+ scroll.records.each(&:name)
47
48
  end
48
49
 
49
- it "works with an empty list" do
50
- client.expects(:get).with("/users/scroll", '').returns(users_scroll(false))
51
- scroll = client.users.scroll.next
52
- emails = []
53
- scroll.records.each {|usr| emails << usr.email}
54
- emails.must_equal %W()
50
+ it 'works with an empty list' do
51
+ client.expects(:get).with('/companies/scroll', '').returns(companies_scroll(false))
52
+ scroll = client.companies.scroll.next
53
+ names = []
54
+ scroll.records.each { |usr| names << usr.name }
55
+ _(names).must_equal %w[]
55
56
  end
56
57
  end
@@ -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
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Intercom::Section do
4
+ let(:client) { Intercom::Client.new(token: 'token') }
5
+
6
+ it 'creates a section' do
7
+ client.expects(:post).with('/help_center/sections', { 'name' => 'Section 1', 'parent_id' => '1' }).returns(test_section)
8
+ client.sections.create(:name => 'Section 1', :parent_id => '1')
9
+ end
10
+
11
+ it 'lists sections' do
12
+ client.expects(:get).with('/help_center/sections', {}).returns(test_section_list)
13
+ client.sections.all.each { |t| }
14
+ end
15
+
16
+ it 'finds a section' do
17
+ client.expects(:get).with('/help_center/sections/1', {}).returns(test_section)
18
+ client.sections.find(id: '1')
19
+ end
20
+
21
+ it 'updates a section' do
22
+ section = Intercom::Section.new(id: '12345')
23
+ client.expects(:put).with('/help_center/sections/12345', {})
24
+ client.sections.save(section)
25
+ end
26
+
27
+ it 'deletes a section' do
28
+ section = Intercom::Section.new(id: '12345')
29
+ client.expects(:delete).with('/help_center/sections/12345', {})
30
+ client.sections.delete(section)
31
+ end
32
+ 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