Class: TranslateClient::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/translate_client/auth.rb

Instance Method Summary collapse

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

Yields:

  • (login_info.redirect_url)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/translate_client/auth.rb', line 10

def (&block)
   = @api.
  @api.auth_token = .auth_token

  yield(.redirect_url)

  viewer = Helpers.poll_until(->(viewer) { viewer&.email }) do
    @api.viewer
  end

  @credentials.save!(viewer.email, .auth_token)

  viewer
end

#logoutObject



25
26
27
# File 'lib/translate_client/auth.rb', line 25

def logout
  @credentials.delete!
end

#viewerObject



29
30
31
# File 'lib/translate_client/auth.rb', line 29

def viewer
  @api.viewer
end