class GoogleDrive::OAuth

Constants

REDIRECT_URL

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/google_drive_oauth.rb, line 8
def initialize(options)
  @options = options
end

Public Instance Methods

auth_url() click to toggle source
# 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]) click to toggle source
# 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.login_with_oauth(access_token.token)
end
get_token(authorization_code) click to toggle source
# 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

Private Instance Methods

client() click to toggle source
# File lib/google_drive_oauth.rb, line 40
def client
  @client ||= OAuth2::Client.new(
    options[:client_id], options[:client_secret],
    :site => "https://accounts.google.com",
    :token_url => "/o/oauth2/token",
    :authorize_url => "/o/oauth2/auth")
end
load_token(refresh_token) click to toggle source
# File lib/google_drive_oauth.rb, line 36
def load_token(refresh_token)
  OAuth2::AccessToken.from_hash(client, {refresh_token: refresh_token})
end