Segments\uf0c1

Segment Listing\uf0c1

Segment lists are fetched by instantiating an iterator object using SegmentList. For more information, see the API documentation

require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key: 'application_key', secret: 'master_secret')
segment_list = UA::SegmentList.new(client: airship)

segment_list.each do |segment|
   puts(segment['display_name'])
end

Creating a Segment\uf0c1

Create a segment for the application. See the segment creation API documentation for more information.

require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key: 'application_key', secret: 'master_secret')
segment = UA::Segment.new(client: airship)
segment.display_name = 'Display Name'
segment.criteria = { 'tag' => 'existing_tag' }
segment.create

Modifying a Segment\uf0c1

Change the display name and/or criteria of a segment. For more information, see the segment update API documentation.

require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key: 'application_key', secret: 'master_secret')
segment = UA::Segment.new(client: airship)
segment.from_id(id: 'segment_id')
segment.display_name = 'Updated Display Name'
segment.criteria = { 'tag' => 'updated_tag' }
segment.update

Deleting a Segment\uf0c1

Delete a segment. For more information, see the segment deletion API documentation.

require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key: 'application_key', secret: 'master_secret')
segment = UA::Segment.new(client: airship)
segment.from_id(id: 'segment_id')
segment.delete

Segment Lookup\uf0c1

Fetch a particular segment’s display name and criteria. See the individual segment lookup API documentation for more information.

require 'urbanairship'
UA = Urbanairship
airship = UA::Client.new(key: 'application_key', secret: 'master_secret')
segment = UA::Segment.new(client: airship)
segment.from_id(id: 'segment_id')

Note

Calling segment.from_id(id: 'segment_id') automatically sets the display_name and criteria attributes of segment.