Class: SendSms
- Inherits:
-
Object
- Object
- SendSms
- Defined in:
- lib/sendsms.rb
Overview
The class which handles sending sms with way2sms
Constant Summary collapse
- URL =
The way2sms root url
'http://site6.way2sms.com'
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username, password, auto_logout = true) ⇒ SendSms
constructor
Initiate Sendsms class with way2sms username and password.
-
#login ⇒ json
Login to way2sms.com.
-
#logout ⇒ json
To logout the way2sms session.
-
#send(msisdns, message) ⇒ json
To send Individual and Group SMS This method support Group SMS from version 0.0.5.
-
#send_to_many(msisdns, message) ⇒ json
deprecated
Deprecated.
Use #send instead of this method
Constructor Details
#initialize(username, password, auto_logout = true) ⇒ SendSms
Initiate Sendsms class with way2sms username and password
46 47 48 49 50 51 52 53 54 |
# File 'lib/sendsms.rb', line 46 def initialize(username , password ,auto_logout = true) @username = username @password = password @uri = URI.parse URL @cookie = @action = nil @referer = URL @auto_logout = auto_logout @http = Net::HTTP.new(@uri.host,@uri.port) end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
31 32 33 |
# File 'lib/sendsms.rb', line 31 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
31 32 33 |
# File 'lib/sendsms.rb', line 31 def username @username end |
Instance Method Details
#login ⇒ json
Login to way2sms.com
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sendsms.rb', line 65 def login data = "username=#{@username}&password=#{@password}" headers = set_header @cookie, @referer response = @http.post("/Login1.action",data,headers.delete_if {|i,j| j.nil? }) case response.code when /3\d{2}/ if response['location'].include?("Main.action") @cookie ||= response['set-cookie'] @referer ||= response['referer'] @action = getAction return {:success => true,:message => "Login successfully"} end return {:success => false,:message => "Login failed"} else return {:success => false,:message => "Http Error"} end end |
#logout ⇒ json
To logout the way2sms session
184 185 186 187 188 189 190 191 192 193 |
# File 'lib/sendsms.rb', line 184 def logout response = @http.get("/jsp/logout.jsp"); @cookie = nil case response.code when /2\d{2}/ return {:success => true,:message => "Logout successfully"} else return {:success => false,:message => "Logout failed"} end end |
#send(msisdns, message) ⇒ json
To send Individual and Group SMS This method support Group SMS from version 0.0.5
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sendsms.rb', line 113 def send msisdns, if @cookie.nil? login_res = login return {:success => false,:message => "Login failed"} if !login_res[:success] end if msisdns.kind_of?(String) && !msisdns.include?(";") response = send_sms msisdns, logout if @auto_logout return response else if msisdns.kind_of?(String) && msisdns.include?(";") msisdns = msisdns.split(';') end response = {} msisdns.each do | key, msisdn | msisdn = key if msisdn.nil? response[msisdn] = send_sms msisdn, end logout if @auto_logout return response end end |
#send_to_many(msisdns, message) ⇒ json
Deprecated.
Use #send instead of this method
To send Group SMS
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/sendsms.rb', line 158 def send_to_many msisdns, @auto_logout = false if @cookie.nil? login_res = login return {:success => false,:message => "Login failed"} if !login_res[:success] end msisdns = msisdns.split(';') response = {} msisdns.each do | msisdn | response[msisdn] = send msisdn, end return response end |