Module: Urbanairship::CustomEvents::Payload
- Includes:
- Urbanairship::Common
- Included in:
- Urbanairship
- Defined in:
- lib/urbanairship/custom_events/payload.rb
Constant Summary collapse
- NAME_REGEX =
Validators
/^[a-z0-9_\-]+$/
Constants included from Urbanairship::Common
Urbanairship::Common::CONTENT_TYPE
Instance Method Summary collapse
- #custom_events(body: required('body'), occurred: required('occurred'), user: required('user')) ⇒ Object
-
#custom_events_body(interaction_id: nil, interaction_type: nil, name: required('name'), properties: nil, session_id: nil, transaction: nil, value: nil) ⇒ Object
Body specific portion of CustomEvent Object.
-
#custom_events_user(amazon_channel: nil, android_channel: nil, channel: nil, ios_channel: nil, named_user_id: nil, web_channel: nil) ⇒ Object
User specific portion of CustomEvent Object.
-
#format_timestamp(timestamp) ⇒ Object
Formatters ————————————————————————.
- #validates_name_format(name) ⇒ Object
- #validates_value_format(value) ⇒ Object
Methods included from Urbanairship::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
Instance Method Details
#custom_events(body: required('body'), occurred: required('occurred'), user: required('user')) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/urbanairship/custom_events/payload.rb', line 9 def custom_events( body: required('body'), occurred: required('occurred'), user: required('user') ) compact_helper({ body: body, occurred: (occurred), user: user }) end |
#custom_events_body(interaction_id: nil, interaction_type: nil, name: required('name'), properties: nil, session_id: nil, transaction: nil, value: nil) ⇒ Object
Body specific portion of CustomEvent Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/urbanairship/custom_events/payload.rb', line 22 def custom_events_body( interaction_id: nil, interaction_type: nil, name: required('name'), properties: nil, session_id: nil, transaction: nil, value: nil ) validates_name_format(name) validates_value_format(value) compact_helper({ interaction_id: interaction_id, interaction_type: interaction_type, name: name, properties: properties, session_id: session_id, transaction: transaction, value: value }) end |
#custom_events_user(amazon_channel: nil, android_channel: nil, channel: nil, ios_channel: nil, named_user_id: nil, web_channel: nil) ⇒ Object
User specific portion of CustomEvent Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/urbanairship/custom_events/payload.rb', line 42 def custom_events_user( amazon_channel: nil, android_channel: nil, channel: nil, ios_channel: nil, named_user_id: nil, web_channel: nil ) res = compact_helper({ amazon_channel: amazon_channel, android_channel: android_channel, channel: channel, ios_channel: ios_channel, named_user_id: named_user_id, web_channel: web_channel, }) fail ArgumentError, 'at least one user identifier must be defined' if res.empty? res end |
#format_timestamp(timestamp) ⇒ Object
Formatters
64 65 66 67 68 |
# File 'lib/urbanairship/custom_events/payload.rb', line 64 def () return if .is_a?(String) .strftime('%Y-%m-%dT%H:%M:%S') end |
#validates_name_format(name) ⇒ Object
75 76 77 78 79 |
# File 'lib/urbanairship/custom_events/payload.rb', line 75 def validates_name_format(name) return if name =~ NAME_REGEX fail ArgumentError, 'invalid "name": it must follows this pattern /^[a-z0-9_\-]+$/' end |
#validates_value_format(value) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/urbanairship/custom_events/payload.rb', line 81 def validates_value_format(value) return if value.nil? return if value.is_a?(Numeric) fail ArgumentError, 'invalid "value": must be a number' end |