google_driver 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Zjk4NzA1ZjZhODgyNGI5ZTgwMmRlMjA4YjBhYjgxMzUyM2VhMTBhMQ==
4
+ YTJkMmVkZjRlZjQzOGE1YzJkYjFkNjMxMDVkOWEzYzIwNGY4ZTliMQ==
5
5
  data.tar.gz: !binary |-
6
- ZjM2NDkyZDY1MTljNmEwODYyZTY0NjFmOTQzYjlmODljZGMxOTMxNw==
6
+ M2Y3MWE4MTVlNmMyYWE0ZDZhMDhlZjgyNjE4ZThjMmFjZmY0ZmU5YQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDVjYjJkY2E1ODM3NWNiYTFkNGU2OWJjMTlmNDllNzI1ZWJmNTQyOTA3Zjc2
10
- M2FlOWMyMjVlNWQzMzVmMDZiNmI3ZjRiZmU4YTcxZGY2MjI2NDVkYjQwNmE1
11
- ZTU4ZTFiYWY3YTI2M2IzM2I4ZjhjMmY0OTA0ZDQzNjIzZTgwOTA=
9
+ NmZhNzZhNjY5ODdlZWVlOTAxNjM0MmE1NjNiZTkyNjBhMjU3MjM0NzdhYzNm
10
+ MzdhNjA2NDkwZTBmNTYwZTRhYWZlNzVmNjAzMDliMDFjMzg4MDU0MDQyNTVk
11
+ YWQ1ZjM2ZTUyNDg1OGM2ODM5MGQzZjJmOWViMmQ0MjRjM2MwYzE=
12
12
  data.tar.gz: !binary |-
13
- ZGMyNTkwN2Q3NzdkNDE0ZjdlYjExNDk5YjMxNDczMjczNWVmNGQ2ZTM1MTMz
14
- MWNmNWJkMzMyMjc2YjA3MmIyYTUyYjE3YWJhNWMwZGQ5NGJmZTA4YmE3YjBj
15
- YzExY2M5Y2E1OTliZjAwYmRiMjVmNDYzZGMzNTlmNDNjYTFkYWM=
13
+ YjEyZWFhOWNmNDFmNmVjYTBhZTE5ODllZDhjYTJlMzMwYjMyYjVkYzMyOGM5
14
+ YjYxYjExMzNkODYzMjJmNTBjYTk0ZjQ4M2VkZmZlMjgxZjc2ZmZhNjBhZmYz
15
+ ZTliNzBjNGQ3NjcyYWE2YzUwYWNhY2Q2NzdkMWYzZjAyNDUyYzI=
@@ -1,38 +1,46 @@
1
1
  module GoogleDriver
2
2
  class Document
3
- attr_accessor :exports, :response
3
+ attr_accessor :exports, :response, :file_id
4
4
 
5
5
  def initialize(response, api)
6
+ @api = api
7
+ @drive = get_drive_api
8
+
6
9
  @response = response
10
+ @file_id = response.data.to_hash['id']
7
11
  @exports = response.data.to_hash['exportLinks']
8
- @api = api
9
12
  end
10
13
 
11
- # Do we want mimetypes as getters?
12
- # doc.application/pdf doesn't sound like a good getter to me
13
- def make_getters(*links)
14
- class << self
15
- links.each do |link|
16
- attr_reader link.intern
17
- end
18
- end
14
+ # refresh document information
15
+ # used when we don't immediate get exportLinks in the response
16
+ def update
17
+ response = @api.client.execute(
18
+ api_method: @drive.files.get,
19
+ :parameters => { 'fileId' => @file_id }
20
+ )
21
+ @response = response
22
+ @file_id = response.data.to_hash['id']
23
+ @exports = response.data.to_hash['exportLinks']
19
24
  end
20
25
 
21
26
  def list
22
27
  @exports.keys
23
28
  end
24
29
 
30
+ def get_drive_api
31
+ @drive = @api.client.discovered_api('drive', 'v2')
32
+ end
33
+
25
34
  def download(type)
26
35
  loops = 0
27
- if @exports and @exports.keys.include? type
28
- @api.client.execute(uri: @exports[type]).body
29
- else
30
- if loops > 5
31
- break
36
+ while loops < 5 do
37
+ self.update()
38
+ if @exports and @exports.keys.include?(type)
39
+ return @api.client.execute(uri: @exports[type]).body
40
+ else
41
+ loops+=1
42
+ sleep(5*loops) # Wait an increasing amount of time between loops
32
43
  end
33
- loops+=1
34
- sleep(5)
35
- self.download(type)
36
44
  end
37
45
  end
38
46
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleDriver
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Wolfwood
@@ -124,3 +124,4 @@ test_files:
124
124
  - spec/google_driver_api_spec.rb
125
125
  - spec/google_driver_document_spec.rb
126
126
  - spec/spec_helper.rb
127
+ has_rdoc: