Module: Twizo::Sms

Defined in:
lib/twizo/modules/sms.rb

Constant Summary collapse

RESULT_TYPE_CALLBACK =

Bitmasks of which type of result type to send

1
RESULT_TYPE_POLL =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject (readonly)

Getter for params



21
22
23
# File 'lib/twizo/modules/sms.rb', line 21

def params
  @params
end

Instance Method Details

#pollObject

Returns:

  • (Object)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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

#sendObject

Send message to the server and return response

Returns:

  • (Object)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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_simpleObject

Send message to the server and return response

Returns:

  • (Object)


46
47
48
49
50
51
52
53
54
# 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) ⇒ Object

Parameters:

  • body (String)
  • recipients (Array)
  • sender (String)


34
35
36
37
38
39
# 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