Class: Truesenses::SMSGateway
- Inherits:
-
Object
- Object
- Truesenses::SMSGateway
- Includes:
- HTTParty
- Defined in:
- lib/truesenses/sms_gateway.rb
Constant Summary collapse
- RESPONSE_FORMAT =
/(\d{2}) (.*)/
- SUCCESS =
1
- HTTP_BASE =
'http://truesenses.com/cgi-bin/smsgateway.cgi'
- HTTPS_BASE =
'https://secure.simmcomm.ch/cgi-bin/smsgateway.cgi'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #credits_left ⇒ Object
-
#initialize(config) ⇒ SMSGateway
constructor
A new instance of SMSGateway.
-
#send_text_message(message, receipient, options = {}) ⇒ Object
Send a text message.
Constructor Details
#initialize(config) ⇒ SMSGateway
Returns a new instance of SMSGateway.
13 14 15 |
# File 'lib/truesenses/sms_gateway.rb', line 13 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/truesenses/sms_gateway.rb', line 9 def config @config end |
Instance Method Details
#credits_left ⇒ Object
18 19 20 |
# File 'lib/truesenses/sms_gateway.rb', line 18 def credits_left post_request('CHECKCREDITS').to_i end |
#send_text_message(message, receipient, options = {}) ⇒ Object
Send a text message
Available options are: :origin: if nil, do not transmit origin even if specified in config :flash: true|false (defaults to false) :test: true|false (defaults to false)
returns the ID of the message in the YYMMDDHHMMSS format (strange, i know…)
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/truesenses/sms_gateway.rb', line 30 def (, receipient, = {}) params = {'NUMBER' => receipient, 'MESSAGE' => } if .has_key?(:origin) && [:origin].nil? # ignore origin, even if it's in config elsif [:origin] || self.config.origin # set origin override config is specified in options params['ORIGIN'] = [:origin] || self.config.origin end params['FLASH'] = 'ON' if [:flash] params['TEST'] = 'ON' if [:test] || (self.config.deliver == false) post_request('SENDMESSAGE', params) end |