Class: Urbanairship::Devices::CreateAndSend
- Inherits:
-
Object
- Object
- Urbanairship::Devices::CreateAndSend
- Defined in:
- lib/urbanairship/devices/create_and_send.rb
Constant Summary
Constants included from Common
Instance Attribute Summary collapse
-
#addresses ⇒ Object
Returns the value of attribute addresses.
-
#campaigns ⇒ Object
Returns the value of attribute campaigns.
-
#device_types ⇒ Object
Returns the value of attribute device_types.
-
#name ⇒ Object
Returns the value of attribute name.
-
#notification ⇒ Object
Returns the value of attribute notification.
-
#scheduled_time ⇒ Object
Returns the value of attribute scheduled_time.
Instance Method Summary collapse
- #create_and_send ⇒ Object
-
#initialize(client: required('client')) ⇒ CreateAndSend
constructor
A new instance of CreateAndSend.
- #payload ⇒ Object
- #schedule ⇒ Object
- #validate ⇒ Object
- #validate_address ⇒ Object
Methods included from Loggable
create_logger, logger, #logger
Methods included from Common
#apid_path, #channel_path, #compact_helper, #create_and_send_path, #custom_events_path, #device_token_path, #experiments_path, #lists_path, #named_users_path, #open_channel_path, #pipelines_path, #push_path, #reports_path, #required, #schedules_path, #segments_path, #tag_lists_path, #try_helper
Constructor Details
#initialize(client: required('client')) ⇒ CreateAndSend
Returns a new instance of CreateAndSend.
16 17 18 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 16 def initialize(client: required('client')) @client = client end |
Instance Attribute Details
#addresses ⇒ Object
Returns the value of attribute addresses.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def addresses @addresses end |
#campaigns ⇒ Object
Returns the value of attribute campaigns.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def campaigns @campaigns end |
#device_types ⇒ Object
Returns the value of attribute device_types.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def device_types @device_types end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def name @name end |
#notification ⇒ Object
Returns the value of attribute notification.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def notification @notification end |
#scheduled_time ⇒ Object
Returns the value of attribute scheduled_time.
9 10 11 |
# File 'lib/urbanairship/devices/create_and_send.rb', line 9 def scheduled_time @scheduled_time end |
Instance Method Details
#create_and_send ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# 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 ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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 ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
20 21 22 23 24 25 26 |
# 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 |