module Twizo::Sms

Constants

RESULT_TYPE_CALLBACK

Bitmasks of which type of result type to send

RESULT_TYPE_POLL

Attributes

params[R]

Getter for params

Public Instance Methods

poll() click to toggle source

@return [Object]

# File lib/twizo/modules/sms.rb, line 79
def poll

  response = send_api_call(Entity::ACTION_RETRIEVE, 'sms/poll')

  raise response if response.kind_of?(TwizoError)

  @batch_id = response['batchId'] unless response['batchId'].nil?

  unless @batch_id == ''
    send_api_call(Entity::ACTION_REMOVE, 'sms/poll/' + @batch_id)
  end

  response_to_array(response, 'messages')
end
send() click to toggle source

Send message to the server and return response

@return [Object]

# File lib/twizo/modules/sms.rb, line 61
def send
  # set @dcs to 0 if dcs is not set
  @params.dcs ||= 0

  @params.body = bin_to_hex(@params.body).upcase if is_binary?

  post_params = @params.to_json send_advanced: true

  response = send_api_call(Entity::ACTION_CREATE, location, post_params)

  raise response if response.kind_of?(TwizoError)

  response_to_array(response, 'items')
end
send_simple() click to toggle source

Send message to the server and return response

@return [Object]

# File lib/twizo/modules/sms.rb, line 46
def send_simple
  post_params = @params.to_json

  response = send_api_call(Entity::ACTION_CREATE, 'sms/submitsimple', post_params)

  raise response if response.kind_of?(TwizoError)

  response_to_array(response, 'items')
end
set(body, recipients, sender) click to toggle source

@param [String] body @param [Array] recipients @param [String] sender

# File lib/twizo/modules/sms.rb, line 34
def set(body, recipients, sender)
  @params = SmsParams.new
  @params.body = body
  @params.recipients = recipients
  @params.sender = sender
end

Private Instance Methods

bin_to_hex(binary_string) click to toggle source

@param [Binary] binary_string

@return [Hex]

# File lib/twizo/modules/sms.rb, line 123
def bin_to_hex(binary_string)
  binary_string.unpack('H*').first
end
is_binary?() click to toggle source

@return [Boolean]

# File lib/twizo/modules/sms.rb, line 106
def is_binary?
  binary = false

  if (@params.dcs & 200) === 0
    binary = ((@params.dcs & 4) > 0)
  elsif (@params.dcs & 4) > 0
    binary = ((@params.dcs & 4) > 0)
  end

  binary
end
location() click to toggle source

@return [String]

# File lib/twizo/modules/sms.rb, line 99
def location
  'sms/submit'
end