carrierwave-google_drive 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/*
19
+ .rspec
20
+ .rbenv-*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-google_drive.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Maxim
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Carrierwave::GoogleDrive
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'carrierwave-google_drive'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install carrierwave-google_drive
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave-google_drive/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "carrierwave-google_drive"
8
+ gem.version = Carrierwave::GoogleDrive::VERSION
9
+ gem.authors = ["Maxim Pechnikov"]
10
+ gem.email = ["parallel588@gmail.com"]
11
+ gem.description = %q{This gem provides a simple way to upload files from Rails application to Google Drive service.}
12
+ gem.summary = %q{Google Drive storage for CarrierWave gem}
13
+ gem.homepage = ""
14
+
15
+ gem.add_dependency('carrierwave', '>= 0.7.1')
16
+ gem.add_dependency('parallel588_google_drive', '= 0.3.4')
17
+ gem.add_development_dependency "rake"
18
+ gem.add_development_dependency "rspec", "~> 2.11.0"
19
+ gem.add_development_dependency('simplecov')
20
+ gem.add_development_dependency('webmock')
21
+
22
+ gem.files = `git ls-files`.split($/)
23
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
25
+ gem.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,18 @@
1
+ require "carrierwave-google_drive/version"
2
+ require "carrierwave/storage/google_drive"
3
+
4
+ module Carrierwave
5
+ module GoogleDrive
6
+ # Your code goes here...
7
+ end
8
+ end
9
+
10
+ CarrierWave::Uploader::Base.add_config :google_login
11
+ CarrierWave::Uploader::Base.add_config :google_password
12
+
13
+ CarrierWave.configure do |config|
14
+ config.storage_engines.merge!({:google_drive => "CarrierWave::Storage::GoogleDrive"})
15
+ end
16
+
17
+
18
+ require "carrierwave/uploader/google_drive"
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module GoogleDrive
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ require "google_drive"
3
+
4
+ module CarrierWave
5
+ module Storage
6
+
7
+ class GoogleDrive < Abstract
8
+
9
+ def connection
10
+ @connection ||= ::GoogleDrive.login( uploader.google_login, uploader.google_password )
11
+ end
12
+
13
+ def store!(file)
14
+ f = CarrierWave::Storage::GoogleDrive::File.new(uploader, self)
15
+ f.store(file)
16
+ f
17
+ end
18
+
19
+ def retrieve!(resource_id)
20
+ CarrierWave::Storage::GoogleDrive::File.new(uploader, self, resource_id)
21
+ end
22
+
23
+ class File
24
+
25
+ def initialize(uploader, storage, resource_id = nil)
26
+ @uploader = uploader
27
+ @storage = storage
28
+ @version_name = (uploader.version_name||'default').to_sym
29
+ @resource_id = YAML.load(resource_id.to_s)[@version_name] rescue ""
30
+ end
31
+
32
+ def store(file)
33
+ @remote_file = connection.upload_from_file(file.path, nil, :convert => false)
34
+ @remote_file.acl.push( {:scope_type => "default", :role => "reader"})
35
+ @resource_id = @remote_file.resource_id.split(':').last
36
+ @uploader.key = @remote_file.resource_id.split(':').last
37
+ @resource_id
38
+ end
39
+
40
+ def delete
41
+ if @resource_id.present?
42
+ file.delete
43
+ end
44
+ end
45
+
46
+ def connection
47
+ @storage.connection
48
+ end
49
+
50
+ def content_type
51
+ @content_type ||= file.available_content_types.first
52
+ @content_type
53
+ end
54
+ def extension
55
+ content_type.to_s
56
+ end
57
+
58
+ def url(options = { })
59
+ "https://docs.google.com/uc?&id=#{@resource_id}"
60
+ end
61
+
62
+ private
63
+ def file
64
+ @file || begin
65
+ doc = connection.request(:get, "https://docs.google.com/feeds/default/private/full/#{@resource_id}?v=3", :auth => :writely)
66
+ @file = connection.entry_element_to_file(doc)
67
+ end
68
+ @file
69
+ end
70
+
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,61 @@
1
+ require 'carrierwave'
2
+
3
+ module CarrierWave
4
+ module Uploader
5
+ class GoogleDrive < Base
6
+
7
+ attr_accessor :key
8
+
9
+ storage :google_drive
10
+
11
+ after :store, :updatemodel
12
+
13
+ def updatemodel(file)
14
+ model.update_column("#{self.mounted_as}".to_sym, build_version_hash(self.key).to_yaml)
15
+ end
16
+
17
+ def build_version_hash(google_reource_id)
18
+ load_version_hash.merge({ (version_name.blank? ? :default : version_name.to_sym) => google_reource_id })
19
+ end
20
+
21
+ def load_version_hash
22
+ _data = YAML.load(model.read_attribute("#{self.mounted_as}".to_sym))
23
+ _data.is_a?(Hash) ? _data : { }
24
+ rescue
25
+ { }
26
+ end
27
+
28
+ private
29
+
30
+ def build_versioned_key(key, version_name)
31
+ key
32
+ end
33
+
34
+ def store_versions!(new_file)
35
+ active_versions.each { |name, v|
36
+ v.key = build_versioned_key(key, name)
37
+ v.store!(new_file)
38
+ }
39
+ end
40
+
41
+ def remove_versions!
42
+ versions.each { |name, v|
43
+ v.key = build_versioned_key(key, name)
44
+ v.remove!
45
+ }
46
+ end
47
+
48
+ def retrieve_versions_from_cache!(cache_name)
49
+ versions.each { |name, v|
50
+ v.key = build_versioned_key(key, name)
51
+ v.retrieve_from_cache!(cache_name)
52
+ }
53
+ end
54
+
55
+ def retrieve_versions_from_store!(identifier)
56
+ versions.each { |name, v|
57
+ v.retrieve_from_store!(build_versioned_key(identifier, name)) }
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-google_drive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Maxim Pechnikov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: carrierwave
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: parallel588_google_drive
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.3.4
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.3.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.11.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.11.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: This gem provides a simple way to upload files from Rails application
111
+ to Google Drive service.
112
+ email:
113
+ - parallel588@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - carrierwave-google_drive.gemspec
124
+ - lib/carrierwave-google_drive.rb
125
+ - lib/carrierwave-google_drive/version.rb
126
+ - lib/carrierwave/storage/google_drive.rb
127
+ - lib/carrierwave/uploader/google_drive.rb
128
+ homepage: ''
129
+ licenses: []
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ none: false
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 1.8.24
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Google Drive storage for CarrierWave gem
152
+ test_files: []
153
+ has_rdoc: