Class: GoogleDriver::Document
- Inherits:
-
Object
- Object
- GoogleDriver::Document
- Defined in:
- lib/google_driver/document.rb
Instance Attribute Summary collapse
-
#exports ⇒ Object
Returns the value of attribute exports.
-
#file_id ⇒ Object
Returns the value of attribute file_id.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #download(type) ⇒ Object
- #get_drive_api ⇒ Object
-
#initialize(response, api) ⇒ Document
constructor
A new instance of Document.
- #list ⇒ Object
-
#update ⇒ Object
refresh document information used when we don’t immediate get exportLinks in the response.
Constructor Details
#initialize(response, api) ⇒ Document
Returns a new instance of Document.
5 6 7 8 9 10 11 12 |
# 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 |
Instance Attribute Details
#exports ⇒ Object
Returns the value of attribute exports.
3 4 5 |
# File 'lib/google_driver/document.rb', line 3 def exports @exports end |
#file_id ⇒ Object
Returns the value of attribute file_id.
3 4 5 |
# File 'lib/google_driver/document.rb', line 3 def file_id @file_id end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/google_driver/document.rb', line 3 def response @response end |
Instance Method Details
#download(type) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/google_driver/document.rb', line 30 def get_drive_api @drive = @api.client.discovered_api('drive', 'v2') end |
#list ⇒ Object
26 27 28 |
# File 'lib/google_driver/document.rb', line 26 def list @exports.keys end |
#update ⇒ Object
refresh document information used when we don’t immediate get exportLinks in the response
16 17 18 19 20 21 22 23 24 |
# 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 |