Class: Smscentral
- Inherits:
-
Object
- Object
- Smscentral
- 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
-
#initialize(username, password) ⇒ Smscentral
constructor
A new instance of Smscentral.
-
#send(originator, recipient, message_text) ⇒ Hash
special values ‘shared’ or ‘dedicated’.
Constructor Details
#initialize(username, password) ⇒ Smscentral
Returns a new instance of Smscentral.
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.
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, ) response = RestClient.post(@uri, { :USERNAME => @username, :PASSWORD => @password, :ACTION => 'send', :ORIGINATOR => originator, :RECIPIENT => recipient, :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 |