Class: FileConvert::Client

Inherits:
Google::APIClient
  • Object
show all
Defined in:
lib/file_convert/client.rb

Constant Summary collapse

APP_OPTIONS =
{
  application_name: 'file-convert',
  application_version: FileConvert::Version::STRING,
  # Retry request **once** in case authorization failed
  retries: 1
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileConvert::Client

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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

Instance Attribute Details

#driveObject (readonly)

Returns the value of attribute drive.



13
14
15
# File 'lib/file_convert/client.rb', line 13

def drive
  @drive
end