class GoogleDriver::Document

Attributes

exports[RW]
file_id[RW]
response[RW]

Public Class Methods

new(response, api) click to toggle source
# File lib/google_driver/document.rb, line 5
def initialize(response, api)
  @api = api
  @drive = get_drive_api

  @response = response
  @file_id = response.data.to_hash['id']
  @exports = response.data.to_hash['exportLinks']
end

Public Instance Methods

download(type) click to toggle source
# File lib/google_driver/document.rb, line 34
def download(type)
  loops = 0
  while loops < 5 do
    self.update()
    if @exports and @exports.keys.include?(type)
      return @api.client.execute(uri: @exports[type]).body
    else
      loops+=1
      sleep(5*loops) # Wait an increasing amount of time between loops
    end
  end
end
get_drive_api() click to toggle source
# File lib/google_driver/document.rb, line 30
def get_drive_api
  @drive = @api.client.discovered_api('drive', 'v2')
end
list() click to toggle source
# File lib/google_driver/document.rb, line 26
def list
  @exports.keys
end
update() click to toggle source

refresh document information used when we don’t immediate get exportLinks in the response

# File lib/google_driver/document.rb, line 16
def update
  response = @api.client.execute(
      api_method: @drive.files.get,
      :parameters => { 'fileId' => @file_id }
      )
  @response = response
  @file_id = response.data.to_hash['id']
  @exports = response.data.to_hash['exportLinks']
end