class Urbanairship::Devices::Sms

Attributes

channel_id[RW]
locale_country[RW]
locale_language[RW]
msisdn[RW]
opted_in[RW]
sender[RW]
timezone[RW]

Public Class Methods

new(client: required('client')) click to toggle source
# File lib/urbanairship/devices/sms.rb, line 17
def initialize(client: required('client'))
  @client = client
end

Public Instance Methods

lookup() click to toggle source
# File lib/urbanairship/devices/sms.rb, line 103
def lookup
  fail ArgumentError,'msisdn is required for lookup' if msisdn.nil?
  fail ArgumentError,'sender is required for lookup' if sender.nil?

  response = @client.send_request(
      method: 'GET',
      path: channel_path('sms/' + @msisdn + '/' + @sender)
  )
  logger.info { "Retrieved information for msisdn #{@msisdn}" }
  response
end
opt_out() click to toggle source
# File lib/urbanairship/devices/sms.rb, line 65
def opt_out
  fail ArgumentError, 'sender must be set to opt out sms channel' if sender.nil?
  fail ArgumentError, 'msisdn must be set to opt out sms channel' if msisdn.nil?

  payload = {
    'msisdn': msisdn,
    'sender': sender,
  }

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: channel_path('sms/opt-out'),
    content_type: 'application/json'
  )
  logger.info("Opting Out of SMS messages for #{@msisdn}")
  response
end
register() click to toggle source
# File lib/urbanairship/devices/sms.rb, line 21
def register
  fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
  fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?

  payload = {
    'msisdn': msisdn,
    'sender': sender,
    'opted_in': opted_in
  }

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: channel_path('sms'),
    content_type: 'application/json'
  )
  logger.info("Registering SMS channel with msisdn #{@msisdn}")
  response
end
uninstall() click to toggle source
# File lib/urbanairship/devices/sms.rb, line 84
def uninstall
  fail ArgumentError, 'sender must be set to uninstall sms channel' if sender.nil?
  fail ArgumentError, 'msisdn must be set to uninstall sms channel' if msisdn.nil?

  payload = {
    'msisdn': msisdn,
    'sender': sender,
  }

  response = @client.send_request(
    method: 'POST',
    body: JSON.dump(payload),
    path: channel_path('sms/uninstall'),
    content_type: 'application/json'
  )
  logger.info("Uninstalling SMS channel for #{@msisdn}")
  response
end
update() click to toggle source
# File lib/urbanairship/devices/sms.rb, line 41
def update
  fail ArgumentError, 'sender must be set to update sms channel' if sender.nil?
  fail ArgumentError, 'msisdn must be set to update sms channel' if msisdn.nil?
  fail ArgumentError, 'channel_id must be set to update sms channel' if channel_id.nil?

  payload = {
    'msisdn': msisdn,
    'sender': sender,
    'opted_in': opted_in,
    'locale_country': locale_country,
    'locale_language': locale_language,
    'timezone': timezone
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs

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