Created
October 6, 2011 15:53
-
-
Save kalinchuk/1267766 to your computer and use it in GitHub Desktop.
Google Voice :: Sending SMS (Code from nasha.molodezh.com, Transfer model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Transfer | |
def self.send_sms(recipients, message, author, google_username, google_password, rnr_se) | |
encoded_msg = CGI::escape(message) | |
responses = [] | |
login_response = self.login_to_google(google_username, google_password) | |
for number in recipients | |
response = self.send_to_google(login_response, number, message, rnr_se) | |
end | |
return true | |
end | |
def self.login_to_google(username, password) | |
login_response = "" | |
url = URI.parse('https://www.google.com/accounts/ClientLogin') | |
login_req = Net::HTTP::Post.new(url.path) | |
login_req.form_data = {'accountType' => 'GOOGLE', 'Email' => username, 'Passwd' => password, 'service' => 'grandcentral', 'source' => 'nasha.molodezh.com'} | |
login_con = Net::HTTP.new(url.host, url.port) | |
login_con.use_ssl = true | |
login_con.start {|http| login_response = http.request(login_req)} | |
return login_response.body | |
end | |
def self.send_to_google(login_response, number, encoded_msg, rnr_se) | |
response = "" | |
url = URI.parse('https://www.google.com/voice/sms/send/') | |
req = Net::HTTP::Post.new(url.path, { 'Content-type' => 'application/x-www-form-urlencoded', 'Authorization' => 'GoogleLogin auth='+login_response.match("Auth\=(.*)")[0].gsub("Auth=", "")}) | |
# We're sending the auth token back to google | |
req.form_data = {'id' => '', 'phoneNumber' => number, 'text' => encoded_msg, '_rnr_se' => rnr_se} | |
con = Net::HTTP.new(url.host, url.port) | |
con.use_ssl = true | |
con.start {|http| response = http.request(req)} | |
return response.body | |
end | |
end | |
google_username = "[email protected]" | |
google_password = "pass" | |
rnr_se = "sdi48df8_3485dfj3&483o5" # comes from the voice.google.com index page. View source and search for "_rnr_se" | |
Transfer.send_sms([5405555555,1234567890], "Sample message", google_username, google_password, rnr_se) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment