Class: Way2sms
- Inherits:
-
Object
- Object
- Way2sms
- Defined in:
- lib/way2sms.rb
Instance Method Summary collapse
-
#initialize(uname, pwd) ⇒ Way2sms
constructor
A new instance of Way2sms.
- #send_sms(to, message) ⇒ Object
Constructor Details
#initialize(uname, pwd) ⇒ Way2sms
Returns a new instance of Way2sms.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/way2sms.rb', line 5 def initialize(uname, pwd) puts "way2sms gem initialized" login_url = 'http://site25.way2sms.com/Login1.action' params = "username=" + uname + "&password=" + pwd uri = URI.parse(login_url) http = Net::HTTP.new(uri.host, uri.port) response = http.post(uri.request_uri, params) @cookie = response['Set-Cookie'].split(';').first end |
Instance Method Details
#send_sms(to, message) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/way2sms.rb', line 16 def send_sms(to, ) = @cookie puts token = .split('~').last sms_url = "http://site25.way2sms.com/smstoss.action" ref = "http://site25.way2sms.com/sendSMS?Token=" + token uri = URI.parse(sms_url) mess = "ssaction=ss&Token=" + token + "&mobile=" + to.to_s + "&message=" + CGI.escape() http = Net::HTTP.new(uri.host, uri.port) ct = "application/x-www-form-urlencoded" ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" head = {"Cookie" => , "Referer" => ref, "Content-Type" => ct, "User-Agent" => ua} http.post(uri.request_uri, mess, head) puts "SMS sent succesfully" end |