Skip to content

Commit bab09db

Browse files
authored
Add support for listing contact segments (#557)
1 parent c62d700 commit bab09db

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ contact.create_note(body: "<p>Text for the note</p>")
125125
# List notes for a contact
126126
contact.notes.each {|n| p n.body}
127127

128+
# List segments for a contact
129+
contact.segments.each {|segment| p segment.name}
130+
128131
# Add a contact to a company
129132
company = intercom.companies.find(id: "123")
130133
contact.add_company(id: company.id)

lib/intercom/contact.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Contact
1313
nested_resource_methods :tag, operations: %i[add delete list]
1414
nested_resource_methods :note, operations: %i[create list]
1515
nested_resource_methods :company, operations: %i[add delete list]
16+
nested_resource_methods :segment, operations: %i[list]
1617

1718
def self.collection_proxy_class
1819
Intercom::BaseCollectionProxy

lib/intercom/segment.rb

+4
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
module Intercom
44
class Segment
55
include Traits::ApiResource
6+
7+
def self.collection_proxy_class
8+
Intercom::BaseCollectionProxy
9+
end
610
end
711
end

spec/unit/intercom/contact_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@
285285
_(proxy.resource_class).must_equal Intercom::Note
286286
end
287287

288+
it 'returns a collection proxy for listing segments' do
289+
proxy = contact.segments
290+
_(proxy.resource_name).must_equal 'segments'
291+
_(proxy.url).must_equal '/contacts/1/segments'
292+
_(proxy.resource_class).must_equal Intercom::Segment
293+
end
294+
288295
it 'returns a collection proxy for listing tags' do
289296
proxy = contact.tags
290297
_(proxy.resource_name).must_equal 'tags'

0 commit comments

Comments
 (0)