class Urbanairship::Devices::CreateAndSend
Attributes
addresses[RW]
campaigns[RW]
device_types[RW]
name[RW]
notification[RW]
scheduled_time[RW]
Public Class Methods
new(client: required('client'))
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 16 def initialize(client: required('client')) @client = client end
Public Instance Methods
create_and_send()
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 51 def create_and_send response = @client.send_request( method: 'POST', body: JSON.dump(payload), path: create_and_send_path, content_type: 'application/json' ) logger.info("Running create and send for addresses #{@addresses}") response end
payload()
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 28 def payload fail ArgumentError, 'addresses must be set for defining payload' if @addresses.nil? fail ArgumentError, 'device type array must be set for defining payload' if @device_types.nil? fail ArgumentError, 'notification object must be set for defining payload' if @notification.nil? validate_address full_payload = { 'audience': { 'create_and_send': addresses }, 'device_types': device_types, 'notification': notification, } if campaigns campaign_object = {'categories': campaigns} full_payload[:campaigns] = campaign_object end full_payload end
schedule()
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 73 def schedule fail ArgumentError, 'scheduled time must be set to run an operation' if @scheduled_time.nil? scheduled_payload = { "schedule": { "scheduled_time": scheduled_time }, "name": name, "push": payload } response = @client.send_request( method: 'POST', body: JSON.dump(scheduled_payload), path: schedules_path('create-and-send'), content_type: 'application/json' ) logger.info("Scheduling create and send operation with name #{@name}") response end
validate()
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 62 def validate response = @client.send_request( method: 'POST', body: JSON.dump(payload), path: create_and_send_path('validate'), content_type: 'application/json' ) logger.info("Validating payload for create and send") response end
validate_address()
click to toggle source
# File lib/urbanairship/devices/create_and_send.rb, line 20 def validate_address @addresses.each do |address| unless address.include?(:ua_address) or address.include?(:ua_msisdn && :ua_opted_in && :ua_sender) fail ArgumentError, 'Missing a component in address portion of the object' end end end