easy-drive 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ef7b7a68d2fdf192a48fcc8fd7ef57ec40dc8fb
4
- data.tar.gz: 38e4cec3765eeb827ce6cb359f060aa05ca55e18
3
+ metadata.gz: f5b6ffca9335076250e6fbf2179124c7f279706c
4
+ data.tar.gz: 438bcf874d85eda8f4ed5f776c1bd0f822770af2
5
5
  SHA512:
6
- metadata.gz: 8aaea530069616c738a3b3b8ca7402fbdd8ffc53a3090138b7fd11bd519a9d9a6e328cad9a499fc3c12906ac6fb4b45a6951a168a561e488ee37c0ae77afb2f4
7
- data.tar.gz: fe31e06582048d27be88c05e50a1488ad49b104ac4ee7f6089f2612d4a5273177e2deb0ac83830a3ff3f5de55d15c41a23958a776184d3f569256a8e5a32cf9c
6
+ metadata.gz: 3c3d98461eabab56fdf959c693b5ae2d800ce6ac6aef206854e404e5eee9151a2c21c84d0ac7ae90d8d9769cbefd6b1f7f6f3154dd3526feae45069198e570ae
7
+ data.tar.gz: cd7987b1d9d93aee8dc0834d3cebeb6c15f09414e8fba26c6571ddb8f14f064af8c045783f05f571fc1c104cccbae360ab804302809e8c91970585d0a5a112e4
data/README.md CHANGED
@@ -55,4 +55,21 @@ Insert(Upload) a new file.
55
55
  client.insert('/etc/hello.txt', folder_id, {title: 'This is a new file.'})
56
56
  ```
57
57
 
58
+ Lists the user's all files.
59
+
60
+ ```
61
+ client.list
62
+ ```
63
+
64
+ Search files.
65
+
66
+ ```
67
+ client.list({title: 'TITLE TEXT for searching'})
68
+ ```
69
+
70
+ Search files in a specific folder.
71
+
72
+ ```
73
+ client.list({title: 'TITLE TEXT for searching', folder_id: 'FOLDER_ID'})
74
+ ```
58
75
 
data/easy-drive.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "easy-drive"
6
- spec.version = "0.0.2"
6
+ spec.version = "0.0.3"
7
7
  spec.authors = ["Shinohara Teruki"]
8
8
  spec.email = ["ts_3156@yahoo.co.jp"]
9
9
  spec.description = %q{I just want to copy files on google drive.}
@@ -95,6 +95,74 @@ module EasyDrive
95
95
  puts "An error occurred: #{result.data['error']['message']}"
96
96
  end
97
97
  end
98
+
99
+ # Lists files.
100
+ # @param options [Hash] A customizable set of options.
101
+ # @option options [String] :title The title for searching
102
+ # @option options [String] :folder_id The parent folder ID for searching
103
+ #
104
+ # @return [Array<Google::APIClient::Schema::Drive::V2::File>]
105
+ # List of File resources.
106
+ # @see https://developers.google.com/drive/v2/reference/files
107
+ def list(options = {})
108
+ client = self.client
109
+ drive = self.drive
110
+
111
+ params = {
112
+ "maxResults" => 1000
113
+ }
114
+
115
+ if options.has_key?(:title)
116
+ params['q'] = "title = '#{options[:title]}'"
117
+ end
118
+
119
+ api_method =
120
+ if options.has_key?(:folder_id)
121
+ params['folderId'] = options[:folder_id]
122
+ drive.children.list
123
+ else
124
+ drive.files.list
125
+ end
126
+
127
+ result = []
128
+ page_token = nil
129
+ begin
130
+ if page_token.to_s != ''
131
+ params['pageToken'] = page_token
132
+ end
133
+ api_result = client.execute(
134
+ :api_method => api_method,
135
+ :parameters => params)
136
+
137
+ if api_result.status == 200
138
+ files = api_result.data
139
+ result.concat(files.items)
140
+ page_token = files.next_page_token
141
+ else
142
+ puts "An error occurred: #{result.data['error']['message']}"
143
+ page_token = nil
144
+ end
145
+ end while page_token.to_s != ''
146
+
147
+ if result.size > 0 &&
148
+ result.first.class.name == 'Google::APIClient::Schema::Drive::V2::ChildReference'
149
+
150
+ _result = []
151
+ batch = Google::APIClient::BatchRequest.new
152
+ result.each do |r|
153
+ batch.add(
154
+ :api_method => drive.files.get,
155
+ :parameters => {
156
+ 'fileId' => r.id,
157
+ 'alt' => 'json'}
158
+ ){|api_result| _result.push(api_result.data) }
159
+ end
160
+ client.execute(batch)
161
+ result = _result
162
+ end
163
+
164
+ result
165
+ end
98
166
  end
99
167
  end
100
168
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy-drive
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
  - Shinohara Teruki