module Urbanairship::Push::Audience

Constants

DATE_TERMS
DEVICE_TOKEN_PATTERN
UUID_PATTERN

Public Instance Methods

absolute_date(resolution: required('resolution'), start: required('start'), the_end: required('the_end')) click to toggle source

Select an absolute date range for a location selector.

@param resolution [Symbol] Time resolution specifier, one of

:minutes :hours :days :weeks :months :years

@param start [String] UTC start time in ISO 8601 format. @param the_end [String] UTC end time in ISO 8601 format.

@example

absolute_date(resolution: :months, start: '2013-01', the_end: '2013-06')
#=> {months: {end: '2013-06', start: '2013-01'}}

absolute_date(resolution: :minutes, start: '2012-01-01 12:00',
              the_end: '2012-01-01 12:45')
#=> {minutes: {end: '2012-01-01 12:45', start: '2012-01-01 12:00'}}
# File lib/urbanairship/push/audience.rb, line 111
def absolute_date(resolution: required('resolution'), start: required('start'), the_end: required('the_end'))
  unless DATE_TERMS.include?(resolution)
    fail ArgumentError, "#{resolution} not in #{DATE_TERMS}"
  end
  { resolution => { start: start, end: the_end } }
end
alias(an_alias) click to toggle source

Select a single alias

# File lib/urbanairship/push/audience.rb, line 40
def alias(an_alias)
  { alias: an_alias }
end
and(*children) click to toggle source

Select devices that match all of the given selectors.

@example

and(tag('sports'), tag('business')) # ==>
  {and: [{tag: 'sports'}, {tag: 'business'}]}
# File lib/urbanairship/push/audience.rb, line 68
def and(*children)
  { and: children }
end
device_token(token) click to toggle source

Select a single iOS device token

# File lib/urbanairship/push/audience.rb, line 27
def device_token(token)
  Util.validate(token, 'device_token', DEVICE_TOKEN_PATTERN)
  { device_token: token.upcase.strip }
end
location(date: required('date'), **params) click to toggle source

Select a location expression.

Location selectors are made up of either an id or an alias and a date period specifier. Use a date specification function to generate the time period specifier.

@example ID location

location(id: '4oFkxX7RcUdirjtaenEQIV', date: recent_date(days: 4))
#=> {location: {date: {recent: {days: 4}},
    id: '4oFkxX7RcUdirjtaenEQIV'}}

@example Alias location

location(us_zip: '94103', date: absolute_date(
         resolution: 'days', start: '2012-01-01', end: '2012-01-15'))
#=> {location: {date: {days: {end: '2012-01-15',
    start: '2012-01-01'}}, us_zip: '94103'}}
# File lib/urbanairship/push/audience.rb, line 134
def location(date: required('date'), **params)
  unless params.size == 1
    fail ArgumentError, 'One location specifier required'
  end
  params[:date] = date
  { location: params }
end
named_user(named_user) click to toggle source

Select a single named user

# File lib/urbanairship/push/audience.rb, line 50
def named_user(named_user)
  { named_user: named_user }
end
not(child) click to toggle source

Select devices that do not match the given selectors.

@example

not(and_(tag('sports'), tag('business'))) # ==>
  {not: {and: [{tag: 'sports'}, {tag: 'business'}]}}
# File lib/urbanairship/push/audience.rb, line 77
def not(child)
  { not: child }
end
or(*children) click to toggle source

Select devices that match at least one of the given selectors.

@example

or(tag('sports'), tag('business')) # ==>
  {or: [{tag: 'sports'}, {tag: 'business'}]}
# File lib/urbanairship/push/audience.rb, line 59
def or(*children)
  { or: children }
end
recent_date(**params) click to toggle source

Select a recent date range for a location selector. Valid selectors are:

:minutes :hours :days :weeks :months :years

@example

recent_date(months: 6)  # => { recent: { months: 6 }}
recent_date(weeks: 3)  # => { recent: { weeks: 3 }}
# File lib/urbanairship/push/audience.rb, line 88
def recent_date(**params)
  fail ArgumentError, 'Only one range allowed' if params.size != 1
  k, v = params.first
  unless DATE_TERMS.include?(k)
    fail ArgumentError, "#{k} not in #{DATE_TERMS}"
  end
  { recent: { k => v } }
end
segment(segment) click to toggle source

Select a single segment using segment_id

# File lib/urbanairship/push/audience.rb, line 45
def segment(segment)
  { segment: segment }
end
tag(tag, group: nil) click to toggle source

Select a single tag

# File lib/urbanairship/push/audience.rb, line 33
def tag(tag, group: nil)
  tag_params = { tag: tag }
  tag_params[:group] = group unless group.nil?
  tag_params
end

Private Instance Methods

cleanup(uuid) click to toggle source

Clean up a UUID for use in the library

# File lib/urbanairship/push/audience.rb, line 145
def cleanup(uuid)
  Util.validate(uuid, 'UUID', UUID_PATTERN)
  uuid.downcase.strip
end