intercom 3.5.10 → 4.1.2
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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +35 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +5 -0
- data/Gemfile +1 -4
- data/README.md +418 -216
- data/RELEASING.md +9 -0
- data/Rakefile +1 -1
- data/changes.txt +141 -0
- data/intercom.gemspec +1 -2
- data/lib/intercom.rb +34 -19
- data/lib/intercom/api_operations/archive.rb +16 -0
- data/lib/intercom/api_operations/delete.rb +4 -1
- data/lib/intercom/api_operations/find.rb +5 -2
- data/lib/intercom/api_operations/find_all.rb +4 -3
- data/lib/intercom/api_operations/list.rb +4 -1
- data/lib/intercom/api_operations/load.rb +4 -2
- data/lib/intercom/api_operations/nested_resource.rb +70 -0
- data/lib/intercom/api_operations/request_hard_delete.rb +12 -0
- data/lib/intercom/api_operations/save.rb +6 -4
- data/lib/intercom/api_operations/scroll.rb +4 -5
- data/lib/intercom/api_operations/search.rb +18 -0
- data/lib/intercom/article.rb +7 -0
- data/lib/intercom/base_collection_proxy.rb +72 -0
- data/lib/intercom/client.rb +66 -18
- data/lib/intercom/client_collection_proxy.rb +17 -39
- data/lib/intercom/collection.rb +7 -0
- data/lib/intercom/company.rb +8 -0
- data/lib/intercom/contact.rb +22 -3
- data/lib/intercom/conversation.rb +5 -0
- data/lib/intercom/data_attribute.rb +7 -0
- data/lib/intercom/deprecated_leads_collection_proxy.rb +22 -0
- data/lib/intercom/deprecated_resources.rb +13 -0
- data/lib/intercom/errors.rb +44 -4
- data/lib/intercom/extended_api_operations/segments.rb +3 -1
- data/lib/intercom/extended_api_operations/tags.rb +3 -1
- data/lib/intercom/lead.rb +21 -0
- data/lib/intercom/lib/typed_json_deserializer.rb +42 -37
- data/lib/intercom/note.rb +4 -0
- data/lib/intercom/request.rb +162 -95
- data/lib/intercom/scroll_collection_proxy.rb +38 -42
- data/lib/intercom/search_collection_proxy.rb +47 -0
- data/lib/intercom/section.rb +23 -0
- data/lib/intercom/segment.rb +4 -0
- data/lib/intercom/service/article.rb +20 -0
- data/lib/intercom/service/base_service.rb +13 -0
- data/lib/intercom/service/collection.rb +24 -0
- data/lib/intercom/service/company.rb +4 -2
- data/lib/intercom/service/contact.rb +29 -6
- data/lib/intercom/service/conversation.rb +23 -2
- data/lib/intercom/service/data_attribute.rb +20 -0
- data/lib/intercom/service/event.rb +12 -0
- data/lib/intercom/service/lead.rb +41 -0
- data/lib/intercom/service/note.rb +4 -8
- data/lib/intercom/service/section.rb +7 -0
- data/lib/intercom/service/tag.rb +8 -8
- data/lib/intercom/service/team.rb +17 -0
- data/lib/intercom/service/user.rb +4 -2
- data/lib/intercom/service/visitor.rb +15 -6
- data/lib/intercom/tag.rb +4 -0
- data/lib/intercom/team.rb +7 -0
- data/lib/intercom/traits/api_resource.rb +48 -27
- data/lib/intercom/traits/dirty_tracking.rb +8 -1
- data/lib/intercom/user.rb +12 -3
- data/lib/intercom/utils.rb +13 -2
- data/lib/intercom/version.rb +1 -1
- data/lib/intercom/visitor.rb +0 -2
- data/spec/spec_helper.rb +881 -436
- data/spec/unit/intercom/admin_spec.rb +2 -2
- data/spec/unit/intercom/article_spec.rb +40 -0
- data/spec/unit/intercom/base_collection_proxy_spec.rb +30 -0
- data/spec/unit/intercom/client_collection_proxy_spec.rb +41 -41
- data/spec/unit/intercom/client_spec.rb +76 -9
- data/spec/unit/intercom/collection_spec.rb +32 -0
- data/spec/unit/intercom/company_spec.rb +29 -21
- data/spec/unit/intercom/contact_spec.rb +365 -29
- data/spec/unit/intercom/conversation_spec.rb +70 -7
- data/spec/unit/intercom/count_spec.rb +4 -4
- data/spec/unit/intercom/data_attribute_spec.rb +40 -0
- data/spec/unit/intercom/deprecated_leads_collection_proxy_spec.rb +17 -0
- data/spec/unit/intercom/event_spec.rb +25 -8
- data/spec/unit/intercom/job_spec.rb +24 -24
- data/spec/unit/intercom/lead_spec.rb +57 -0
- data/spec/unit/intercom/lib/flat_store_spec.rb +22 -20
- data/spec/unit/intercom/message_spec.rb +1 -1
- data/spec/unit/intercom/note_spec.rb +4 -10
- data/spec/unit/intercom/request_spec.rb +150 -9
- data/spec/unit/intercom/scroll_collection_proxy_spec.rb +40 -39
- data/spec/unit/intercom/search_collection_proxy_spec.rb +60 -0
- data/spec/unit/intercom/section_spec.rb +32 -0
- data/spec/unit/intercom/segment_spec.rb +2 -2
- data/spec/unit/intercom/subscription_spec.rb +5 -6
- data/spec/unit/intercom/tag_spec.rb +22 -14
- data/spec/unit/intercom/team_spec.rb +21 -0
- data/spec/unit/intercom/traits/api_resource_spec.rb +129 -47
- data/spec/unit/intercom/user_spec.rb +227 -217
- data/spec/unit/intercom/visitor_spec.rb +49 -0
- data/spec/unit/intercom_spec.rb +5 -3
- metadata +63 -26
- data/.travis.yml +0 -6
- data/lib/intercom/extended_api_operations/users.rb +0 -16
- data/spec/unit/intercom/visitors_spec.rb +0 -61
@@ -1,13 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "notes" do
|
4
|
-
let
|
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 |
|
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
|
@@ -1,16 +1,157 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
WebMock.enable!
|
5
|
+
|
6
|
+
describe 'Intercom::Request', '#execute' do
|
7
|
+
let(:uri) {"https://api.intercom.io/users"}
|
8
|
+
let(:req) { Intercom::Request.get(uri, {}) }
|
9
|
+
let(:default_body) { { data: "test" }.to_json }
|
10
|
+
|
11
|
+
def execute!
|
12
|
+
req.execute(uri, token: 'test-token')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should call sleep for rate limit error three times and raise a rate limit error otherwise' do
|
16
|
+
stub_request(:any, uri).to_return(
|
17
|
+
status: [429, "Too Many Requests"],
|
18
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
19
|
+
body: default_body
|
20
|
+
)
|
21
|
+
|
22
|
+
req.handle_rate_limit=true
|
23
|
+
|
24
|
+
req.expects(:sleep).times(3).with(any_parameters)
|
25
|
+
|
26
|
+
expect { execute! }.must_raise(Intercom::RateLimitExceeded)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should not call sleep for rate limit error' do
|
30
|
+
stub_request(:any, uri).to_return(
|
31
|
+
status: [200, "OK"],
|
32
|
+
headers: { 'X-RateLimit-Reset' => Time.now.utc + 10 },
|
33
|
+
body: default_body
|
34
|
+
)
|
35
|
+
|
36
|
+
req.handle_rate_limit=true
|
37
|
+
req.expects(:sleep).never.with(any_parameters)
|
38
|
+
|
39
|
+
execute!
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should call sleep for rate limit error just once' do
|
43
|
+
stub_request(:any, uri).to_return(
|
44
|
+
status: [429, "Too Many Requests"],
|
45
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
46
|
+
).then.to_return(status: [200, "OK"], body: default_body)
|
47
|
+
|
48
|
+
req.handle_rate_limit=true
|
49
|
+
req.expects(:sleep).with(any_parameters)
|
50
|
+
|
51
|
+
execute!
|
9
52
|
end
|
10
53
|
|
11
|
-
it '
|
12
|
-
|
13
|
-
|
14
|
-
|
54
|
+
it 'should not sleep if rate limit reset time has passed' do
|
55
|
+
stub_request(:any, uri).to_return(
|
56
|
+
status: [429, "Too Many Requests"],
|
57
|
+
headers: { 'X-RateLimit-Reset' => Time.parse("February 25 2010").utc.to_i.to_s },
|
58
|
+
body: default_body
|
59
|
+
).then.to_return(status: [200, "OK"], body: default_body)
|
60
|
+
|
61
|
+
req.handle_rate_limit=true
|
62
|
+
req.expects(:sleep).never.with(any_parameters)
|
63
|
+
|
64
|
+
execute!
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'handles an empty body gracefully' do
|
68
|
+
stub_request(:any, uri).to_return(
|
69
|
+
status: 200,
|
70
|
+
body: nil
|
71
|
+
)
|
72
|
+
|
73
|
+
assert_nil(execute!)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'HTTP error handling' do
|
77
|
+
it 'raises an error when the response is successful but the body is not JSON' do
|
78
|
+
stub_request(:any, uri).to_return(
|
79
|
+
status: 200,
|
80
|
+
body: '<html>something</html>'
|
81
|
+
)
|
82
|
+
|
83
|
+
expect { execute! }.must_raise(Intercom::UnexpectedResponseError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'raises an error when an html error page rendered' do
|
87
|
+
stub_request(:any, uri).to_return(
|
88
|
+
status: 500,
|
89
|
+
body: '<html>something</html>'
|
90
|
+
)
|
91
|
+
|
92
|
+
expect { execute! }.must_raise(Intercom::ServerError)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises an error if the decoded_body is "null"' do
|
96
|
+
stub_request(:any, uri).to_return(
|
97
|
+
status: 500,
|
98
|
+
body: 'null'
|
99
|
+
)
|
100
|
+
|
101
|
+
expect { execute! }.must_raise(Intercom::ServerError)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'raises a RateLimitExceeded error when the response code is 429' do
|
105
|
+
stub_request(:any, uri).to_return(
|
106
|
+
status: 429,
|
107
|
+
body: 'null'
|
108
|
+
)
|
109
|
+
|
110
|
+
expect { execute! }.must_raise(Intercom::RateLimitExceeded)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'raises a GatewayTimeoutError error when the response code is 504' do
|
114
|
+
stub_request(:any, uri).to_return(
|
115
|
+
status: 504,
|
116
|
+
body: '<html> <head><title>504 Gateway Time-out</title></head> <body bgcolor="white"> <center><h1>504 Gateway Time-out</h1></center> </body> </html>'
|
117
|
+
)
|
118
|
+
|
119
|
+
expect { execute! }.must_raise(Intercom::GatewayTimeoutError)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "application error handling" do
|
124
|
+
let(:uri) {"https://api.intercom.io/conversations/reply"}
|
125
|
+
let(:req) { Intercom::Request.put(uri, {}) }
|
126
|
+
|
127
|
+
it 'should raise ResourceNotUniqueError error on resource_conflict code' do
|
128
|
+
stub_request(:put, uri).to_return(
|
129
|
+
status: [409, "Resource Already Exists"],
|
130
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
131
|
+
body: { type: "error.list", errors: [ code: "resource_conflict" ] }.to_json
|
132
|
+
)
|
133
|
+
|
134
|
+
expect { execute! }.must_raise(Intercom::ResourceNotUniqueError)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should raise ApiVersionInvalid error on intercom_version_invalid code' do
|
138
|
+
stub_request(:put, uri).to_return(
|
139
|
+
status: [400, "Bad Request"],
|
140
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
141
|
+
body: { type: "error.list", errors: [ code: "intercom_version_invalid" ] }.to_json
|
142
|
+
)
|
143
|
+
|
144
|
+
expect { execute! }.must_raise(Intercom::ApiVersionInvalid)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should raise ResourceNotFound error on company_not_found code' do
|
148
|
+
stub_request(:put, uri).to_return(
|
149
|
+
status: [404, "Not Found"],
|
150
|
+
headers: { 'X-RateLimit-Reset' => (Time.now.utc + 10).to_i.to_s },
|
151
|
+
body: { type: "error.list", errors: [ code: "company_not_found" ] }.to_json
|
152
|
+
)
|
153
|
+
|
154
|
+
expect { execute! }.must_raise(Intercom::ResourceNotFound)
|
155
|
+
end
|
15
156
|
end
|
16
157
|
end
|
@@ -1,56 +1,57 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Intercom::ScrollCollectionProxy do
|
4
|
-
let
|
6
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
7
|
|
6
|
-
it
|
7
|
-
client.expects(:get).with(
|
8
|
-
|
9
|
-
client.
|
10
|
-
|
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
|
14
|
-
client.expects(:get).with(
|
15
|
-
client.expects(:get).with('/
|
16
|
-
|
17
|
-
client.
|
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
|
21
|
-
client.expects(:get).with(
|
22
|
-
client.
|
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
|
26
|
-
client.expects(:get).with(
|
27
|
-
client.expects(:get).with('/
|
28
|
-
|
29
|
-
|
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
|
33
|
-
client.expects(:get).with(
|
34
|
-
scroll = client.
|
35
|
-
|
36
|
-
scroll.records.each {|usr|
|
37
|
-
|
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
|
41
|
-
client.expects(:get).with(
|
42
|
-
client.expects(:get).with('/
|
43
|
-
scroll = client.
|
44
|
-
scroll = client.
|
45
|
-
|
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
|
50
|
-
client.expects(:get).with(
|
51
|
-
scroll = client.
|
52
|
-
|
53
|
-
scroll.records.each {|usr|
|
54
|
-
|
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
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Intercom::SearchCollectionProxy do
|
4
|
+
let(:client) { Intercom::Client.new(token: 'token') }
|
5
|
+
|
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
|
+
end
|
10
|
+
|
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
|
+
end
|
15
|
+
|
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
|
+
end
|
20
|
+
|
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
|
+
end
|
25
|
+
|
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
|
34
|
+
end
|
35
|
+
|
36
|
+
it "stops iterating if no starting_after value" do
|
37
|
+
client.expects(:post).with("/contacts/search", { query: {} }).returns(page_of_contacts(false))
|
38
|
+
emails = []
|
39
|
+
client.contacts.search(query: {}).each { |contact| emails << contact.email }
|
40
|
+
_(emails).must_equal %w[test1@example.com test2@example.com test3@example.com]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "keeps iterating if starting_after value" do
|
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))
|
46
|
+
emails = []
|
47
|
+
client.contacts.search(query: {}).each { |contact| emails << contact.email }
|
48
|
+
end
|
49
|
+
|
50
|
+
it "supports indexed array access" do
|
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'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "supports map" do
|
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]
|
59
|
+
end
|
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
|
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
|
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
|
4
|
-
let
|
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
|
7
|
-
client.expects(:
|
8
|
-
tag = client.tags.
|
9
|
-
tag.name.must_equal
|
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
|
13
|
-
client.expects(:post).with(
|
14
|
-
tag = client.tags.tag(:
|
15
|
-
tag.name.must_equal
|
16
|
-
tag.
|
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
|
20
|
-
client.expects(:post).with(
|
21
|
-
client.tags.untag(:
|
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
|