Class: Urbanairship::Devices::EmailNotification

Inherits:
Object
  • Object
show all
Includes:
Common, Loggable
Defined in:
lib/urbanairship/devices/email_notification.rb

Constant Summary

Constants included from Common

Common::CONTENT_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

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')) ⇒ EmailNotification

Returns a new instance of EmailNotification.



23
24
25
# File 'lib/urbanairship/devices/email_notification.rb', line 23

def initialize(client: required('client'))
  @client = client
end

Instance Attribute Details

#bccObject

Returns the value of attribute bcc.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def bcc
  @bcc
end

#bypass_opt_in_levelObject

Returns the value of attribute bypass_opt_in_level.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def bypass_opt_in_level
  @bypass_opt_in_level
end

#click_trackingObject

Returns the value of attribute click_tracking.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def click_tracking
  @click_tracking
end

#html_bodyObject

Returns the value of attribute html_body.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def html_body
  @html_body
end

#message_typeObject

Returns the value of attribute message_type.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def message_type
  @message_type
end

#open_trackingObject

Returns the value of attribute open_tracking.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def open_tracking
  @open_tracking
end

#plaintext_bodyObject

Returns the value of attribute plaintext_body.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def plaintext_body
  @plaintext_body
end

#reply_toObject

Returns the value of attribute reply_to.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def reply_to
  @reply_to
end

#sender_addressObject

Returns the value of attribute sender_address.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def sender_address
  @sender_address
end

#sender_nameObject

Returns the value of attribute sender_name.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def sender_name
  @sender_name
end

#subjectObject

Returns the value of attribute subject.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def subject
  @subject
end

#template_idObject

Returns the value of attribute template_id.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def template_id
  @template_id
end

#variable_detailsObject

Returns the value of attribute variable_details.



9
10
11
# File 'lib/urbanairship/devices/email_notification.rb', line 9

def variable_details
  @variable_details
end

Instance Method Details

#define_fieldsObject



81
82
83
84
85
86
87
88
# File 'lib/urbanairship/devices/email_notification.rb', line 81

def define_fields
  if subject && plaintext_body
    {
      subject: subject,
      plaintext_body: plaintext_body
    }
  end
end

#define_template_objectObject



72
73
74
75
76
77
78
79
# File 'lib/urbanairship/devices/email_notification.rb', line 72

def define_template_object
  fail ArgumentError, 'Must choose between template_id or fields object' if template_id && plaintext_body && subject
  template_portion = {
    template_id: template_id,
    fields: define_fields,
    variable_details: variable_details
  }.delete_if {|key, value| value.nil?}
end

#email_overrideObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/urbanairship/devices/email_notification.rb', line 27

def email_override
  fail ArgumentError, 'message_type is needed for email override' if @message_type.nil?
  fail ArgumentError, 'plaintext_body is needed for email override' if @plaintext_body.nil?
  fail ArgumentError, 'reply_to is needed for email override' if @reply_to.nil?
  fail ArgumentError, 'sender_address is needed for email override' if @sender_address.nil?
  fail ArgumentError, 'sender_name is needed for email override' if @sender_name.nil?
  fail ArgumentError, 'subject is needed for email override' if @subject.nil?

  override = {
    bcc: bcc,
    bypass_opt_in_level: bypass_opt_in_level,
    click_tracking: click_tracking,
    html_body: html_body,
    message_type: message_type,
    open_tracking: open_tracking, 
    plaintext_body: plaintext_body,
    reply_to: reply_to,
    sender_address: sender_address,
    sender_name: sender_name,
    subject: subject
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs

  {'email': override}
end

#email_with_inline_templateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/urbanairship/devices/email_notification.rb', line 52

def email_with_inline_template
  fail ArgumentError, 'message_type is needed for email with inline template' if @message_type.nil?
  fail ArgumentError, 'reply_to is needed for email with inline template' if @reply_to.nil?
  fail ArgumentError, 'sender_address is needed for email with inline template' if @sender_address.nil?
  fail ArgumentError, 'sender_name is needed for email with inline template' if @sender_name.nil?

  inline_template = {
    bcc: bcc,
    click_tracking: click_tracking,
    message_type: message_type,
    open_tracking: open_tracking,
    reply_to: reply_to,
    sender_address: sender_address,
    sender_name: sender_name,
    template: define_template_object
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs      

  {'email': inline_template}
end