Class: Knock
- Inherits:
-
Object
- Object
- Knock
- Defined in:
- lib/knock.rb
Constant Summary collapse
- GOOGLE =
"https://www.google.com:443/accounts/ClientLogin"- APP_NAME =
"Knock-Knock Ruby Gem"
Class Method Summary collapse
- .connect(user, password, serv) ⇒ Object
- .get(url, params) ⇒ Object
-
.header ⇒ Object
ClientLogin Authentication requires the Auth property not the SID or LSID ones.
- .login ⇒ Object
- .token ⇒ Object
Class Method Details
.connect(user, password, serv) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/knock.rb', line 11 def self.connect user,password,serv @confs = { 'accountType' => 'GOOGLE', 'Email' => user, 'Passwd' => password, 'service' => serv, 'source' => APP_NAME } @@token = login end |
.get(url, params) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/knock.rb', line 44 def self.get url,params uri = URI.parse(url) res = Net::HTTP::Get.new(uri.request_uri,header) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true result = http.start() { |conn| conn.request(res) } result.body end |
.header ⇒ Object
ClientLogin Authentication requires the Auth property not the SID or LSID ones. Along with the Content-Lenght(that must exists!) goes the Auth on the header of every request the library does to Google.
34 35 36 37 38 |
# File 'lib/knock.rb', line 34 def self.header {'Cookie' => "Name=#{@@token};Auth=#{@@token};Domain=.google.com;Path=/;Expires=160000000000", 'Content-length' => '0', 'Authorization' => "GoogleLogin auth=#{@@token}"} end |
.login ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/knock.rb', line 21 def self.login url = URI.parse(GOOGLE) req = Net::HTTP::Post.new(url.path) req.set_form_data(@confs) res = Net::HTTP.new(url.host, url.port) res.use_ssl = true body = res.start {|http| http.request(req) } body.body.split("\n").last.gsub("Auth=",'') end |
.token ⇒ Object
40 41 42 |
# File 'lib/knock.rb', line 40 def self.token @@token end |