Class: Urbanairship::Devices::Email

Inherits:
Object
  • Object
show all
Includes:
Common, Loggable
Defined in:
lib/urbanairship/devices/email.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')) ⇒ Email

Returns a new instance of Email.



25
26
27
# File 'lib/urbanairship/devices/email.rb', line 25

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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#channel_idObject

Returns the value of attribute channel_id.



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

def channel_id
  @channel_id
end

#click_tracking_opted_inObject

Returns the value of attribute click_tracking_opted_in.



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

def click_tracking_opted_in
  @click_tracking_opted_in
end

#click_tracking_opted_outObject

Returns the value of attribute click_tracking_opted_out.



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

def click_tracking_opted_out
  @click_tracking_opted_out
end

#commercial_opted_inObject

Returns the value of attribute commercial_opted_in.



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

def commercial_opted_in
  @commercial_opted_in
end

#commercial_opted_outObject

Returns the value of attribute commercial_opted_out.



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

def commercial_opted_out
  @commercial_opted_out
end

#locale_countryObject

Returns the value of attribute locale_country.



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

def locale_country
  @locale_country
end

#locale_languageObject

Returns the value of attribute locale_language.



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

def locale_language
  @locale_language
end

#open_tracking_opted_inObject

Returns the value of attribute open_tracking_opted_in.



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

def open_tracking_opted_in
  @open_tracking_opted_in
end

#open_tracking_opted_outObject

Returns the value of attribute open_tracking_opted_out.



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

def open_tracking_opted_out
  @open_tracking_opted_out
end

#suppression_stateObject

Returns the value of attribute suppression_state.



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

def suppression_state
  @suppression_state
end

#timezoneObject

Returns the value of attribute timezone.



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

def timezone
  @timezone
end

#transactional_opted_inObject

Returns the value of attribute transactional_opted_in.



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

def transactional_opted_in
  @transactional_opted_in
end

#transactional_opted_outObject

Returns the value of attribute transactional_opted_out.



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

def transactional_opted_out
  @transactional_opted_out
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#lookupObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/urbanairship/devices/email.rb', line 78

def lookup
  fail ArgumentError, 'address must be set to lookup email channel' if @address.nil?

  response = @client.send_request(
    method: 'GET',
    path: channel_path('email/' + address)
  )
  logger.info("Looking up email channel with address #{address}")
  response
end

#registerObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/urbanairship/devices/email.rb', line 29

def register
  fail ArgumentError, 'address must be set to register email channel' if @address.nil?

  payload = {
    'channel': {
      'address': address,
      'click_tracking_opted_in': click_tracking_opted_in,
      'click_tracking_opted_out': click_tracking_opted_out,
      'commercial_opted_in': commercial_opted_in,
      'commercial_opted_out': commercial_opted_out,
      'locale_country': locale_country,
      'locale_language': locale_language,
      'open_tracking_opted_in': open_tracking_opted_in,
      'open_tracking_opted_out': open_tracking_opted_out,
      'suppression_state': suppression_state,
      'timezone': timezone,
      'transactional_opted_in': transactional_opted_in,
      'transactional_opted_out': transactional_opted_out,
      'type': type
    }
  }

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: channel_path('email'),
    content_type: 'application/json'
  )
  logger.info("Registering email channel with address #{address}")
  response
end

#replaceObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/urbanairship/devices/email.rb', line 117

def replace
  fail ArgumentError, 'channel_id must be set to update email channel' if channel_id.nil?
  fail ArgumentError, 'address must be set to update email channel' if address.nil?
  fail ArgumentError, 'type must be set to update email channel' if type.nil?

  channel_data = {
    'address': address,
    'click_tracking_opted_in': click_tracking_opted_in,
    'click_tracking_opted_out': click_tracking_opted_out,
    'commercial_opted_in': commercial_opted_in,
    'commercial_opted_out': commercial_opted_out,
    'locale_country': locale_country,
    'locale_language': locale_language,
    'open_tracking_opted_in': open_tracking_opted_in,
    'open_tracking_opted_out': open_tracking_opted_out,
    'suppression_state': suppression_state,
    'timezone': timezone,
    'transactional_opted_in': transactional_opted_in,
    'transactional_opted_out': transactional_opted_out,
    'type': type
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs

  payload = {'channel': channel_data}

  response = @client.send_request(
    method: 'POST',
    path: channel_path('email/replace/' + channel_id),
    body: JSON.dump(payload),
    content_type: 'application/json'
  )
  logger.info("Replacing email channel with address #{@address}")
  response
end

#uninstallObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/urbanairship/devices/email.rb', line 61

def uninstall
  fail ArgumentError, 'address must be set to register email channel' if @address.nil?

  payload = {
    'email_address': address
  }

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: channel_path('email/uninstall'),
    content_type: 'application/json'
  )
  logger.info("Uninstalling email channel with address #{address}")
  response
end

#updateObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/urbanairship/devices/email.rb', line 89

def update
  fail ArgumentError, 'channel_id must be set to update email channel' if channel_id.nil?

  channel_data =  {
    'address': address,
    'commercial_opted_in': commercial_opted_in,
    'commercial_opted_out': commercial_opted_out,
    'locale_country': locale_country,
    'locale_language': locale_language,
    'timezone': timezone,
    'transactional_opted_in': transactional_opted_in,
    'transactional_opted_out': transactional_opted_out,
    'device_type': type,
    'suppression_state': suppression_state
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs

  payload = {'channel': channel_data}

  response = @client.send_request(
    method: 'PUT',
    path: channel_path('email/' + channel_id),
    body: JSON.dump(payload),
    content_type: 'application/json'
  )
  logger.info("Updating email channel with address #{@address}")
  response
end