Class: InteltechSms

Inherits:
Object
  • Object
show all
Defined in:
lib/inteltech_sms.rb

Direct Known Subclasses

DummyInteltechSms

Defined Under Namespace

Classes: BadRequest, Duplicate, Error, Failure, FakeHTTPSuccess, NoCredit, Response, Success, Unauthorized

Constant Summary collapse

SUCCESS_RESPONSE_CODE =
'0000'
UNAUTHORIZED_RESPONSE_CODE =
'2006'
ACCOUNT_NOT_ACTIVATED_RESPONSE_CODE =
'2007'
INVALID_NUMBER_RESPONSE_CODE =
'2015'
DUPLICATE_RESPONSE_CODE =
'2016'
NO_CREDIT_RESPONSE_CODE =
'2018'
UNAUTHORIZED_KEY_RESPONSE_CODE =
'2022'
EMPTY_MESSAGE_RESPONSE_CODE =
'2051'
TOO_MANY_RECIPIENTS_RESPONSE_CODE =
'2052'
INVALID_SENDER_RESPONSE_CODE =

General failures

'2017'

Instance Method Summary collapse

Constructor Details

#initialize(username, secret_key) ⇒ InteltechSms

Returns a new instance of InteltechSms.



107
108
109
110
# File 'lib/inteltech_sms.rb', line 107

def initialize(username, secret_key)
  @username = username
  @secret_key = secret_key
end

Instance Method Details

#get_creditObject



112
113
114
115
116
# File 'lib/inteltech_sms.rb', line 112

def get_credit
  uri = URI('http://inteltech.com.au/secure-api/credit.php')
  res = Net::HTTP.post_form(uri, 'username' => @username, 'key' => @secret_key, 'method' => 'ruby')
  process_get_credit_response(res)
end

#send_multiple_sms(sms, message, options = { }) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/inteltech_sms.rb', line 125

def send_multiple_sms(sms, message, options = { })
  uri = URI('http://inteltech.com.au/secure-api/send.php')
  sms_string = sms.respond_to?(:join) ? sms.join(',') : sms.to_s
  args = { :username => @username, :key => @secret_key, :sms => sms_string, :message => message, :method => 'ruby' }.merge(options)
  res = Net::HTTP.post_form(uri, args)
  process_send_multiple_sms_response(res)
end

#send_sms(sms, message, options = { }) ⇒ Object



118
119
120
121
122
123
# File 'lib/inteltech_sms.rb', line 118

def send_sms(sms, message, options = { })
  uri = URI('http://inteltech.com.au/secure-api/send.single.php')
  args = { :username => @username, :key => @secret_key, :sms => sms, :message => message, :method => 'ruby' }.merge(options)
  res = Net::HTTP.post_form(uri, args)
  process_send_sms_response(res, sms)
end