Class: VoipfoneClient::SMS

Inherits:
Client
  • Object
show all
Defined in:
lib/voipfone_client/sms.rb

Instance Attribute Summary collapse

Attributes inherited from Client

#browser

Instance Method Summary collapse

Methods inherited from Client

#account_balance, #account_details, #parse_response, #phone_numbers, #voicemail

Constructor Details

#initialize(to: nil, from: nil, message: nil) ⇒ SMS

Constructor to create an SMS - optionally pass in to, from and message

Parameters:

  • to (String) (defaults to: nil)

    the phone number to send the SMS to, as a string. Spaces will be stripped; + symbol allowed.

  • from (String) (defaults to: nil)

    the phone number to send the SMS from, as a string. Spaces will be stripped; + symbol allowed.

  • message (String) (defaults to: nil)

    the message to send. The first 160 characters only will be sent.



9
10
11
12
13
14
# File 'lib/voipfone_client/sms.rb', line 9

def initialize(to: nil, from: nil, message: nil)
  @to = to
  @from = from
  @message = message
  super()
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/voipfone_client/sms.rb', line 3

def from
  @from
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/voipfone_client/sms.rb', line 3

def message
  @message
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/voipfone_client/sms.rb', line 3

def to
  @to
end

Instance Method Details

#sendObject

Send an sms from your account.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/voipfone_client/sms.rb', line 17

def send
  if @to.nil? || @from.nil? || @message.nil?
    raise ArgumentError, "You need to include 'to' and 'from' numbers and a message to send an SMS"
  end
  to = @to.gsub(" ","")
  from = @from.gsub(" ","")
  parameters = {
    "sms-send-to" => to,
    "sms-send-from" => from,
    "sms-message" => @message[0..159]
  }
  request = @browser.post("#{VoipfoneClient::API_POST_URL}?smsSend", parameters)
  response = parse_response(request)
  if response == "ok"
    return true
  else
    raise VoipfoneAPIError, response
  end
end