Class: Smscentral

Inherits:
Object
  • Object
show all
Defined in:
lib/smscentral.rb,
lib/smscentral/version.rb,
lib/smscentral/api_version.rb

Overview

Smscentral REST client

Constant Summary collapse

VERSION =
'0.1.0'
API_VERSION =
'v3.2'

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Smscentral

Returns a new instance of Smscentral.

Parameters:

  • username (String)
  • password (String)


12
13
14
15
16
# File 'lib/smscentral.rb', line 12

def initialize(username, password)
  @username = username
  @password = password
  @uri = "https://my.smscentral.com.au/api/#{API_VERSION}"
end

Instance Method Details

#send(originator, recipient, message_text) ⇒ Hash

special values ‘shared’ or ‘dedicated’. See the documentation at: www.smscentral.com.au/sms-api/rest-api/ international format (ie - 61412341234) 160 characters will be split into multiple messages.

Parameters:

  • originator (String)

    may be a phone number, alphanumeric, or the

  • recipeient (String)

    must be a phone number, recommended to use

  • message_text (String)

    is the text body. Messages longer than

Returns:

  • (Hash)

    contains a response :code [Int] and :message [String]

Raises:

  • (IOError)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/smscentral.rb', line 27

def send(originator, recipient, message_text)
  response = RestClient.post(@uri, {
    :USERNAME => @username,
    :PASSWORD => @password,
    :ACTION => 'send',
    :ORIGINATOR => originator,
    :RECIPIENT => recipient,
    :MESSAGE_TEXT => message_text,
  })
  if response.body == '0'
    return {
      :code => 0,
      :message => 'Success',
    }
  end
  result = RESPONSE_REGEXP.match(response.body)
  raise IOError, "Unprocessable response from SMS Central: #{response}" if result.nil?
  return {
    :code => result[:code].to_i,
    :message => result[:message],
  }
end