Class: Dewey::ClientAuth
- Inherits:
-
Object
- Object
- Dewey::ClientAuth
- Defined in:
- lib/dewey/client_auth.rb
Instance Attribute Summary collapse
-
#authentications ⇒ Object
readonly
Returns the value of attribute authentications.
Instance Method Summary collapse
- #authenticate!(service = nil) ⇒ Object
- #authenticated?(service = nil) ⇒ Boolean
-
#initialize(email, password) ⇒ ClientAuth
constructor
A new instance of ClientAuth.
- #token(service = nil) ⇒ Object
Constructor Details
#initialize(email, password) ⇒ ClientAuth
5 6 7 8 9 |
# File 'lib/dewey/client_auth.rb', line 5 def initialize(email, password) @email = email @password = password @authentications = {} end |
Instance Attribute Details
#authentications ⇒ Object (readonly)
Returns the value of attribute authentications.
3 4 5 |
# File 'lib/dewey/client_auth.rb', line 3 def authentications @authentications end |
Instance Method Details
#authenticate!(service = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dewey/client_auth.rb', line 19 def authenticate!(service = nil) service ||= :writely params = { 'accountType' => 'HOSTED_OR_GOOGLE', 'Email' => @email, 'Passwd' => @password, 'service' => service.to_s } url = URI.parse(Dewey::GOOGLE_LOGIN_URL) response = Net::HTTPS.post_form(url, params) case response when Net::HTTPSuccess @authentications[service] = response.body.split('=').last true when Net::HTTPForbidden false else raise DeweyError, "Unexpected response: #{response}" end end |
#authenticated?(service = nil) ⇒ Boolean
11 12 13 14 15 16 17 |
# File 'lib/dewey/client_auth.rb', line 11 def authenticated?(service = nil) if service @authentications.has_key?(service) else @authentications.any? end end |
#token(service = nil) ⇒ Object
43 44 45 46 47 |
# File 'lib/dewey/client_auth.rb', line 43 def token(service = nil) service = guard(service) authenticate!(service) unless authenticated?(service) @authentications[service] end |