Class: TranslateClient::Auth
- Inherits:
-
Object
- Object
- TranslateClient::Auth
- Defined in:
- lib/translate_client/auth.rb
Instance Method Summary collapse
-
#initialize(api, credentials) ⇒ Auth
constructor
A new instance of Auth.
- #login {|login_info.redirect_url| ... } ⇒ Object
- #logout ⇒ Object
- #viewer ⇒ Object
Constructor Details
#initialize(api, credentials) ⇒ Auth
Returns a new instance of Auth.
5 6 7 8 |
# File 'lib/translate_client/auth.rb', line 5 def initialize(api, credentials) @api = api @credentials = credentials end |
Instance Method Details
#login {|login_info.redirect_url| ... } ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/translate_client/auth.rb', line 10 def login(&block) login_info = @api.request_login @api.auth_token = login_info.auth_token yield(login_info.redirect_url) viewer = Helpers.poll_until(->(viewer) { viewer&.email }) do @api.viewer end @credentials.save!(viewer.email, login_info.auth_token) viewer end |
#logout ⇒ Object
25 26 27 |
# File 'lib/translate_client/auth.rb', line 25 def logout @credentials.delete! end |
#viewer ⇒ Object
29 30 31 |
# File 'lib/translate_client/auth.rb', line 29 def viewer @api.viewer end |