easy-drive 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/Gemfile +1 -0
- data/README.md +58 -0
- data/easy-drive.gemspec +3 -3
- data/lib/easy_drive.rb +1 -0
- data/lib/easy_drive/client.rb +8 -3
- data/lib/easy_drive/files.rb +100 -0
- data/spec/easy_drive/client_spec.rb +4 -0
- data/spec/easy_drive/files_spec.rb +11 -0
- data/spec/spec_helper.rb +8 -0
- metadata +13 -6
- data/lib/easy_drive/files/copy.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ef7b7a68d2fdf192a48fcc8fd7ef57ec40dc8fb
|
4
|
+
data.tar.gz: 38e4cec3765eeb827ce6cb359f060aa05ca55e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aaea530069616c738a3b3b8ca7402fbdd8ffc53a3090138b7fd11bd519a9d9a6e328cad9a499fc3c12906ac6fb4b45a6951a168a561e488ee37c0ae77afb2f4
|
7
|
+
data.tar.gz: fe31e06582048d27be88c05e50a1488ad49b104ac4ee7f6089f2612d4a5273177e2deb0ac83830a3ff3f5de55d15c41a23958a776184d3f569256a8e5a32cf9c
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
EasyDrive
|
2
|
+
----
|
3
|
+
|
4
|
+
I just want to copy files on google drive! (^^)
|
5
|
+
|
6
|
+
Installation
|
7
|
+
----
|
8
|
+
|
9
|
+
Add EasyDrive to your `Gemfile`.
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'easy_drive'
|
13
|
+
```
|
14
|
+
|
15
|
+
Initial Setup
|
16
|
+
----
|
17
|
+
|
18
|
+
1. You need to enable the Drive API for your app and download `client_secrets.json` to your project root directory.
|
19
|
+
|
20
|
+
You can do this in your app's API project in the [Google APIs Console](https://code.google.com/apis/console/).
|
21
|
+
|
22
|
+
See further information on [google-api-ruby-client-samples](https://github.com/google/google-api-ruby-client-samples/tree/master/drive)
|
23
|
+
|
24
|
+
2. Call `setup`, and both `easy_drive-oauth2.json` and `easy_drive-v2.cache` are created in project root directory.
|
25
|
+
|
26
|
+
```
|
27
|
+
client = EasyDrive::Client.new
|
28
|
+
client.setup # generate above 2 files.
|
29
|
+
```
|
30
|
+
|
31
|
+
Usage
|
32
|
+
----
|
33
|
+
|
34
|
+
```
|
35
|
+
client = EasyDrive::Client.new
|
36
|
+
client.copy(source_file_id, dest_folder_id, {title: 'new file name'})
|
37
|
+
```
|
38
|
+
|
39
|
+
That's all. Feel free to copy! (^^)
|
40
|
+
|
41
|
+
Advanced Usage
|
42
|
+
----
|
43
|
+
|
44
|
+
EasyDrive implements other Google Drive APIs.
|
45
|
+
|
46
|
+
Gets a file's metadata by ID.
|
47
|
+
|
48
|
+
```
|
49
|
+
client.get(file_id)
|
50
|
+
```
|
51
|
+
|
52
|
+
Insert(Upload) a new file.
|
53
|
+
|
54
|
+
```
|
55
|
+
client.insert('/etc/hello.txt', folder_id, {title: 'This is a new file.'})
|
56
|
+
```
|
57
|
+
|
58
|
+
|
data/easy-drive.gemspec
CHANGED
@@ -3,11 +3,11 @@ $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.2"
|
7
7
|
spec.authors = ["Shinohara Teruki"]
|
8
8
|
spec.email = ["ts_3156@yahoo.co.jp"]
|
9
|
-
spec.description = %q{
|
10
|
-
spec.summary = %q{
|
9
|
+
spec.description = %q{I just want to copy files on google drive.}
|
10
|
+
spec.summary = %q{I just want to copy files on google drive.}
|
11
11
|
spec.license = "Apache 2.0"
|
12
12
|
spec.homepage = "https://github.com/ts-3156/easy-drive"
|
13
13
|
|
data/lib/easy_drive.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'easy_drive/client'
|
data/lib/easy_drive/client.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'easy_drive/files'
|
2
2
|
require 'easy_drive/version'
|
3
3
|
|
4
|
+
require 'google/api_client'
|
5
|
+
require 'google/api_client/client_secrets'
|
6
|
+
require 'google/api_client/auth/file_storage'
|
7
|
+
require 'google/api_client/auth/installed_app'
|
8
|
+
|
4
9
|
module EasyDrive
|
5
10
|
class Client
|
6
11
|
include EasyDrive::Files
|
@@ -45,8 +50,8 @@ module EasyDrive
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def setup()
|
48
|
-
client = Google::APIClient.new(:application_name =>
|
49
|
-
:application_version =>
|
53
|
+
client = Google::APIClient.new(:application_name => self.class.to_s,
|
54
|
+
:application_version => version)
|
50
55
|
|
51
56
|
file_storage = Google::APIClient::FileStorage.new(CREDENTIAL_STORE_FILE)
|
52
57
|
if file_storage.authorization.nil?
|
@@ -81,7 +86,7 @@ module EasyDrive
|
|
81
86
|
|
82
87
|
# @return [String]
|
83
88
|
def version
|
84
|
-
"#{
|
89
|
+
"#{EasyDrive::Version}"
|
85
90
|
end
|
86
91
|
end
|
87
92
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module EasyDrive
|
2
|
+
module Files
|
3
|
+
# Gets a file's metadata by ID
|
4
|
+
# @param file_id [String]
|
5
|
+
# ID of the file to get
|
6
|
+
# @return [Google::APIClient::Schema::Drive::V2::File]
|
7
|
+
# The got file if successful, nil otherwise
|
8
|
+
# @see https://developers.google.com/drive/v2/reference/files
|
9
|
+
def get(file_id)
|
10
|
+
client = self.client
|
11
|
+
drive = self.drive
|
12
|
+
|
13
|
+
result = client.execute(
|
14
|
+
:api_method => drive.files.get,
|
15
|
+
:parameters => {
|
16
|
+
'fileId' => file_id,
|
17
|
+
'alt' => 'json'})
|
18
|
+
|
19
|
+
if result.status == 200
|
20
|
+
result.data
|
21
|
+
else
|
22
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Insert(Upload) a new file
|
27
|
+
# @param file_name [String]
|
28
|
+
# Name of file to upload
|
29
|
+
# @param folder_id [String]
|
30
|
+
# ID of the destination folder which contains this file
|
31
|
+
# @param options [Hash] A customizable set of options.
|
32
|
+
# @option options [String] :title The title of this file
|
33
|
+
# @option options [String] :description The description of this file
|
34
|
+
# @option options [String] :mine_type The mine type of this file
|
35
|
+
# @return [Google::APIClient::Schema::Drive::V2::File]
|
36
|
+
# The uploaded file if successful, nil otherwise
|
37
|
+
# @see https://developers.google.com/drive/v2/reference/files
|
38
|
+
def insert(file_name, folder_id, options = {})
|
39
|
+
client = self.client
|
40
|
+
drive = self.drive
|
41
|
+
|
42
|
+
file = drive.files.insert.request_schema.new({
|
43
|
+
'title' => options[:title],
|
44
|
+
'description' => options[:description],
|
45
|
+
'mimeType' => options[:mime_type],
|
46
|
+
'parents' => [{:id => folder_id}]
|
47
|
+
})
|
48
|
+
|
49
|
+
media = Google::APIClient::UploadIO.new(file_name, options[:mime_type])
|
50
|
+
result = client.execute(
|
51
|
+
:api_method => drive.files.insert,
|
52
|
+
:body_object => file,
|
53
|
+
:media => media,
|
54
|
+
:parameters => {
|
55
|
+
'uploadType' => 'multipart',
|
56
|
+
'alt' => 'json'})
|
57
|
+
|
58
|
+
if result.status == 200
|
59
|
+
return result.data
|
60
|
+
else
|
61
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias_method :upload, :insert
|
65
|
+
|
66
|
+
# Creates a copy of the specified file
|
67
|
+
# @param file_id [String]
|
68
|
+
# ID of the origin file to copy
|
69
|
+
# @param folder_id [String]
|
70
|
+
# ID of the destination folder which contains this file
|
71
|
+
# @param options [Hash] A customizable set of options.
|
72
|
+
# @option options [String] :title The title of this file
|
73
|
+
# @return [Google::APIClient::Schema::Drive::V2::File]
|
74
|
+
# The copied file if successful, nil otherwise
|
75
|
+
# @see https://developers.google.com/drive/v2/reference/files
|
76
|
+
def copy(file_id, folder_id, options = {})
|
77
|
+
client = self.client
|
78
|
+
drive = self.drive
|
79
|
+
|
80
|
+
file = drive.files.copy.request_schema.new({
|
81
|
+
'title' => options[:title],
|
82
|
+
'parents' => [{:id => folder_id}]
|
83
|
+
})
|
84
|
+
|
85
|
+
result = client.execute(
|
86
|
+
:api_method => drive.files.copy,
|
87
|
+
:body_object => file,
|
88
|
+
:parameters => {
|
89
|
+
'fileId' => file_id,
|
90
|
+
'alt' => 'json'})
|
91
|
+
|
92
|
+
if result.status == 200
|
93
|
+
result.data
|
94
|
+
else
|
95
|
+
puts "An error occurred: #{result.data['error']['message']}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-drive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinohara Teruki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.7.1
|
41
|
-
description:
|
41
|
+
description: I just want to copy files on google drive.
|
42
42
|
email:
|
43
43
|
- ts_3156@yahoo.co.jp
|
44
44
|
executables: []
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
|
+
- .rspec
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
@@ -53,8 +54,11 @@ files:
|
|
53
54
|
- easy-drive.gemspec
|
54
55
|
- lib/easy_drive.rb
|
55
56
|
- lib/easy_drive/client.rb
|
56
|
-
- lib/easy_drive/files
|
57
|
+
- lib/easy_drive/files.rb
|
57
58
|
- lib/easy_drive/version.rb
|
59
|
+
- spec/easy_drive/client_spec.rb
|
60
|
+
- spec/easy_drive/files_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
58
62
|
homepage: https://github.com/ts-3156/easy-drive
|
59
63
|
licenses:
|
60
64
|
- Apache 2.0
|
@@ -78,5 +82,8 @@ rubyforge_project:
|
|
78
82
|
rubygems_version: 2.0.3
|
79
83
|
signing_key:
|
80
84
|
specification_version: 4
|
81
|
-
summary:
|
82
|
-
test_files:
|
85
|
+
summary: I just want to copy files on google drive.
|
86
|
+
test_files:
|
87
|
+
- spec/easy_drive/client_spec.rb
|
88
|
+
- spec/easy_drive/files_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module EasyDrive
|
2
|
-
module Files
|
3
|
-
def copy(client, drive, file_id, folder_id, options = {})
|
4
|
-
client = self.client
|
5
|
-
drive = self.drive
|
6
|
-
|
7
|
-
file = drive.files.insert.request_schema.new({
|
8
|
-
'title' => options[:title],
|
9
|
-
'parents' => [{:id => folder_id}]
|
10
|
-
})
|
11
|
-
|
12
|
-
result = client.execute(
|
13
|
-
:api_method => drive.files.copy,
|
14
|
-
:body_object => file,
|
15
|
-
:parameters => {
|
16
|
-
'fileId' => file_id,
|
17
|
-
'alt' => 'json'})
|
18
|
-
|
19
|
-
result.data
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|