Class: Truesenses::SMSGateway

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#configObject (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_leftObject



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 send_text_message(message, receipient, options = {})
  params = {'NUMBER' => receipient, 'MESSAGE' => message}
  if options.has_key?(:origin) && options[:origin].nil?
    # ignore origin, even if it's in config
  elsif options[:origin] || self.config.origin
    # set origin override config is specified in options
    params['ORIGIN'] = options[:origin] || self.config.origin
  end
  params['FLASH'] = 'ON' if options[:flash]
  params['TEST'] = 'ON' if options[:test] || (self.config.deliver == false)
  post_request('SENDMESSAGE', params)
end