Module: Magti

Defined in:
lib/magti.rb,
lib/magti/sms.rb,
lib/magti/config.rb,
lib/magti/version.rb

Defined Under Namespace

Classes: Config, Response

Constant Summary collapse

SMS_SEND_URL =

URL for sending SMS.

'http://81.95.160.47/mt/oneway'
SMS_TRACK_URL =

URL for tracking SMS status.

'http://81.95.160.47/bi/track.php'
MAX_SIZE =

Maximum size of individual SMS message.

160
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.config(params = {}) ⇒ Object



35
36
37
38
39
40
# File 'lib/magti/config.rb', line 35

def self.config(params = {})
  params.each do |k, v|
    Magti::Config.instance.send "#{k}=".to_sym, v
  end
  Magti::Config.instance
end

.send_sms(mobile, text) ⇒ Object

Sending SMS.

Parameters:

  • mobile

    mobile number

  • text

    text to be sent

Returns:

  • Response object with response code and message ID



30
31
32
33
34
35
36
37
38
# File 'lib/magti/sms.rb', line 30

def self.send_sms(mobile, text)
  options = Magti.config.security_options
  Magti.validate_security_options(options)
  options = options.merge(:to => "995#{mobile}", :text => text, :coding => 2)
  http_resp = HTTParty.post(Magti::SMS_SEND_URL, {:body => options}).body
  resp = Response.new
  resp.code, resp.id = http_resp.split(' - ')
  resp
end

.track_sms(msg_id) ⇒ Object

Tracking SMS.



41
42
43
44
45
46
47
# File 'lib/magti/sms.rb', line 41

def self.track_sms(msg_id)
  options = Magti.config.security_options
  Magti.validate_security_options(options)
  options = options.merge(:message_id => msg_id)
  http_resp = HTTParty.get(Magti::SMS_TRACK_URL, {:query => options}).body
  http_resp.to_i
end