Class: GoogleAuth
- Inherits:
-
Object
show all
- Defined in:
- lib/google_auth.rb
Defined Under Namespace
Classes: AuthenticationFailedError, NotLoggedInError
Constant Summary
collapse
- GA_SOURCE =
'beforefilter.blogspot.com-rubypost'
- GA_GOOGLE =
'www.google.com'
- GA_SERVICE =
'/accounts/ClientLogin'
Class Method Summary
collapse
-
.authenticate(username, password, print_debug = false) ⇒ Object
-
.default_headers(token) ⇒ Object
-
.delete(path, token, etag = nil) ⇒ Object
-
.get(path, token, etag = nil) ⇒ Object
-
.post(path, data, token) ⇒ Object
-
.put(path, data, token, etag = nil) ⇒ Object
Class Method Details
.authenticate(username, password, print_debug = false) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/google_auth.rb', line 12
def self.authenticate(username, password, print_debug = false)
http = Net::HTTP.new(GA_GOOGLE, 443)
http.use_ssl = true
login_url = GA_SERVICE
data = 'Email=' + username +'&Passwd=' + password + '&source=' + GA_SOURCE + '&service=blogger'
= { 'Content-Type' => 'application/x-www-form-urlencoded' }
response, data = http.post(login_url, data, )
pp response.inspect if print_debug
pp data.inspect if print_debug
unless response.code.eql? '200'
raise AuthenticationFailedError.new("Error during authentication: #{resp.message}")
else
data.split("\n").map {|l| l.split("=")}.assoc("Auth")[1]
end
end
|
32
33
34
35
36
37
38
|
# File 'lib/google_auth.rb', line 32
def self.(token)
{
'Authorization' => 'GoogleLogin auth=' + token,
'Content-Type' => 'application/atom+xml',
'GData-Version' => '2'
}
end
|
.delete(path, token, etag = nil) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/google_auth.rb', line 50
def self.delete(path, token, etag = nil)
= self.(token)
http = Net::HTTP.new('www.blogger.com')
req = Net::HTTP::Delete.new(path, )
http.request(req)
end
|
.get(path, token, etag = nil) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/google_auth.rb', line 40
def self.get(path, token, etag = nil)
= self.(token)
.merge!('If-None-Match' => "#{etag}") if etag
http = Net::HTTP.new('www.blogger.com')
http.get(path, )
end
|
.post(path, data, token) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/google_auth.rb', line 66
def self.post(path, data, token)
= self.(token)
http = Net::HTTP.new('www.blogger.com')
http.post(path, data, )
end
|
.put(path, data, token, etag = nil) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/google_auth.rb', line 58
def self.put(path, data, token, etag = nil)
= self.(token)
http = Net::HTTP.new('www.blogger.com')
req = Net::HTTP::Put.new(path, )
http.request(req, data)
end
|