easy-drive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6082c3845efc2b0052073af3ad16eb5e362e391a
4
+ data.tar.gz: 300bf0996858b8182c2b2f81cf409a5fc9dd6a71
5
+ SHA512:
6
+ metadata.gz: f25172eeff47aba22ea552a6daeb35945e8a83b10fa294da9553e651f3455a06b56ca25750be4d07a06ea2f8b9893afcda897eec9ea74edfbf96c175504860e9
7
+ data.tar.gz: 4612a631c7dc35e363455c44697c78fcaece5a4b331db4641af01ce93b5eb465b4d50ca3cd7a400c26adcf77f411a0a472aa8773ed0075164bfc76aac4333008
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /.bundle
3
+ /pkg
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
8
+
9
+ group :test do
10
+ end
11
+
12
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2014- Shinohara Teruki
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "easy-drive"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Shinohara Teruki"]
8
+ spec.email = ["ts_3156@yahoo.co.jp"]
9
+ spec.description = %q{A thin wrapper for google-api-ruby-client}
10
+ spec.summary = %q{A thin wrapper for google-api-ruby-client}
11
+ spec.license = "Apache 2.0"
12
+ spec.homepage = "https://github.com/ts-3156/easy-drive"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_runtime_dependency "google-api-client", '= 0.7.1'
21
+ end
@@ -0,0 +1,87 @@
1
+ require 'easy_drive/files'
2
+ require 'easy_drive/version'
3
+
4
+ module EasyDrive
5
+ class Client
6
+ include EasyDrive::Files
7
+
8
+ API_VERSION = 'v2'
9
+ CACHED_API_FILE = "easy_drive-#{API_VERSION}.cache"
10
+ CREDENTIAL_STORE_FILE = "easy_drive-oauth2.json"
11
+
12
+ attr_accessor :application_name
13
+ attr_reader :client, :drive
14
+
15
+ # Initializes a new Client object
16
+ #
17
+ # @param options [Hash]
18
+ # @return [EasyDrive::Client]
19
+ def initialize(options = {})
20
+ options.each do |key, value|
21
+ instance_variable_set("@#{key}", value)
22
+ end
23
+ yield(self) if block_given?
24
+ end
25
+
26
+ # @note refresh_token bug fix
27
+ # @see https://github.com/google/google-api-ruby-client/issues/90
28
+ def file_format_bug_fix(credential_store_file)
29
+ return if !File.exists?(credential_store_file)
30
+ temp = nil
31
+ File.open(credential_store_file, "r") do |f|
32
+ temp = JSON.load(f)
33
+ if temp["authorization_uri"].class != String
34
+ temp["authorization_uri"] =
35
+ "https://accounts.google.com/o/oauth2/auth"
36
+ end
37
+ if temp["token_credential_uri"].class != String
38
+ temp["token_credential_uri"] =
39
+ "https://accounts.google.com/o/oauth2/token"
40
+ end
41
+ end
42
+ File.open(credential_store_file, "w") do |f|
43
+ f.write(temp.to_json)
44
+ end
45
+ end
46
+
47
+ def setup()
48
+ client = Google::APIClient.new(:application_name => @application_name,
49
+ :application_version => '1.0.0')
50
+
51
+ file_storage = Google::APIClient::FileStorage.new(CREDENTIAL_STORE_FILE)
52
+ if file_storage.authorization.nil?
53
+ client_secrets = Google::APIClient::ClientSecrets.load
54
+ flow = Google::APIClient::InstalledAppFlow.new(
55
+ :client_id => client_secrets.client_id,
56
+ :client_secret => client_secrets.client_secret,
57
+ :scope => ['https://www.googleapis.com/auth/drive']
58
+ )
59
+ client.authorization = flow.authorize(file_storage)
60
+ else
61
+ client.authorization = file_storage.authorization
62
+ end
63
+
64
+ drive = nil
65
+ if File.exists? CACHED_API_FILE
66
+ File.open(CACHED_API_FILE) do |file|
67
+ drive = Marshal.load(file)
68
+ end
69
+ else
70
+ drive = client.discovered_api('drive', API_VERSION)
71
+ File.open(CACHED_API_FILE, 'w') do |file|
72
+ Marshal.dump(drive, file)
73
+ end
74
+ end
75
+
76
+ @client = client
77
+ @drive = drive
78
+
79
+ return client, drive
80
+ end
81
+
82
+ # @return [String]
83
+ def version
84
+ "#{Twitter::Version}"
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,23 @@
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
+
@@ -0,0 +1,16 @@
1
+ module EasyDrive
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+ PRE = nil
7
+
8
+ class << self
9
+ # @return [String]
10
+ def to_s
11
+ [MAJOR, MINOR, PATCH, PRE].compact.join('.')
12
+ end
13
+ end
14
+ end
15
+ end
16
+
data/lib/easy_drive.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-drive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shinohara Teruki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: google-api-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.1
41
+ description: A thin wrapper for google-api-ruby-client
42
+ email:
43
+ - ts_3156@yahoo.co.jp
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - easy-drive.gemspec
54
+ - lib/easy_drive.rb
55
+ - lib/easy_drive/client.rb
56
+ - lib/easy_drive/files/copy.rb
57
+ - lib/easy_drive/version.rb
58
+ homepage: https://github.com/ts-3156/easy-drive
59
+ licenses:
60
+ - Apache 2.0
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A thin wrapper for google-api-ruby-client
82
+ test_files: []