Class: GoogleDrive::OAuth

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

Constant Summary collapse

REDIRECT_URL =
"urn:ietf:wg:oauth:2.0:oob"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ OAuth

Returns a new instance of OAuth.



8
9
10
# File 'lib/google_drive_oauth.rb', line 8

def initialize(options)
  @options = options
end

Instance Method Details

#auth_urlObject



12
13
14
15
16
17
18
# File 'lib/google_drive_oauth.rb', line 12

def auth_url
  client.auth_code.authorize_url(
    :redirect_uri => REDIRECT_URL,
    :scope => "https://www.googleapis.com/auth/drive " +
      "https://spreadsheets.google.com/feeds/"
  )
end

#drive_session(access_token: nil, refresh_token: options[:refresh_token]) ⇒ Object



26
27
28
29
30
# File 'lib/google_drive_oauth.rb', line 26

def drive_session(access_token: nil, refresh_token: options[:refresh_token])
  access_token = load_token(refresh_token) if access_token.nil?
  access_token = access_token.refresh! if access_token.token.empty? or access_token.expired?
  GoogleDrive.(access_token.token)
end

#get_token(authorization_code) ⇒ Object



20
21
22
23
24
# File 'lib/google_drive_oauth.rb', line 20

def get_token(authorization_code)
  client.auth_code.get_token(
    authorization_code,
    :redirect_uri => REDIRECT_URL)
end