Class: Clian::Authorizer

Inherits:
Object
  • Object
show all
Defined in:
lib/clian/authorizer.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, scope, token_store_path) ⇒ Authorizer

Returns a new instance of Authorizer.



13
14
15
16
17
18
19
# File 'lib/clian/authorizer.rb', line 13

def initialize(client_id, client_secret, scope, token_store_path)
  @authorizer = Google::Auth::UserAuthorizer.new(
    Google::Auth::ClientId.new(client_id, client_secret),
    scope,
    Google::Auth::Stores::FileTokenStore.new(file: token_store_path)
  )
end

Instance Method Details

#auth_interactively(user_id = "default", shell = Thor.new.shell) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/clian/authorizer.rb', line 25

def auth_interactively(user_id = "default", shell = Thor.new.shell)
  oob_uri = "urn:ietf:wg:oauth:2.0:oob"

  url = @authorizer.get_authorization_url(base_url: oob_uri)
  begin
    Launchy.open(url)
  rescue
    puts "Open URL in your browser:\n #{url}"
  end

  code = shell.ask "Enter the resulting code:"

  @authorizer.get_and_store_credentials_from_code(
    user_id:  user_id,
    code:     code,
    base_url: oob_uri
  )
end

#credentials(user_id = "default") ⇒ Object



21
22
23
# File 'lib/clian/authorizer.rb', line 21

def credentials(user_id = "default")
  @authorizer.get_credentials(user_id)
end