class FileConvert::Client

Constants

APP_OPTIONS

Attributes

drive[R]

Public Class Methods

new() click to toggle source

Inherits from Google::APIClient Basically wraps authentiation for simple configuration

@return [FileConvert::Client] (inherits from Google::APIClient)

Calls superclass method
# File lib/file_convert/client.rb, line 20
def initialize
  gaccount = FileConvert.config['google_service_account']
  gaccount['auth_url'] ||= 'https://www.googleapis.com/auth/drive'

  key = load_key gaccount['pkcs12_file_path'], 'notasecret'
  options = APP_OPTIONS.merge(authorization: get_authorization(
    gaccount['email'], gaccount['auth_url'], key
  ))

  super(options).tap do |client|
    client.authorization.fetch_access_token!
    @drive = client.discovered_api 'drive', 'v2'
  end
end

Private Instance Methods

get_authorization(email, auth_url, key) click to toggle source
# File lib/file_convert/client.rb, line 41
def get_authorization(email, auth_url, key)
  Signet::OAuth2::Client.new(
    token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
    audience: 'https://accounts.google.com/o/oauth2/token',
    scope: auth_url,
    issuer: email,
    signing_key: key
  )
end
load_key(path, secret) click to toggle source
# File lib/file_convert/client.rb, line 37
def load_key(path, secret)
  Google::APIClient::PKCS12.load_key(path, secret)
end