easy-drive 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 +4 -4
- data/README.md +17 -0
- data/easy-drive.gemspec +1 -1
- data/lib/easy_drive/files.rb +68 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5b6ffca9335076250e6fbf2179124c7f279706c
|
4
|
+
data.tar.gz: 438bcf874d85eda8f4ed5f776c1bd0f822770af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.}
|
data/lib/easy_drive/files.rb
CHANGED
@@ -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
|
|