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.



20
21
22
# File 'lib/urbanairship/devices/email.rb', line 20

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

#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

#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



68
69
70
71
72
73
74
75
76
77
# File 'lib/urbanairship/devices/email.rb', line 68

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



24
25
26
27
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/email.rb', line 24

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

  payload = {
    'channel': {
      '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,
      '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

#uninstallObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/urbanairship/devices/email.rb', line 51

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/urbanairship/devices/email.rb', line 79

def update
  fail ArgumentError, 'address 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,
    'localte_country': locale_country,
    'locale_language': locale_language,
    '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: '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