carrierwave-webdav 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave-dropbox.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Qinix
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Carrierwave::WebDAV
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'carrierwave-webdav'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install carrierwave-webdav
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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave/webdav/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "carrierwave-webdav"
8
+ gem.version = Carrierwave::WebDAV::VERSION
9
+ gem.authors = ["Qinix"]
10
+ gem.email = ["i@qinix.com"]
11
+ gem.description = %q{WebDAV support for CarrierWave}
12
+ gem.summary = %q{WebDAV support for CarrierWave}
13
+ gem.homepage = "https://github.com/qinix/carrierwave-webdav"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'carrierwave'
21
+ gem.add_dependency 'httparty'
22
+
23
+ end
@@ -0,0 +1,28 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'httparty'
4
+
5
+ # Monkey patch for HTTParty
6
+ # Add MKCOL method
7
+ module HTTParty
8
+
9
+ class Request
10
+ SupportedHTTPMethods << Net::HTTP::Mkcol
11
+ end
12
+
13
+ module ClassMethods
14
+ # Perform a MKCOL request to a path
15
+ def mkcol(path, options = {}, &block)
16
+ perform_request Net::HTTP::Mkcol, path, options, &block
17
+ end
18
+ end
19
+
20
+ class Basement
21
+ include HTTParty
22
+ end
23
+
24
+ def self.mkcol(*args, &block)
25
+ Basement.mkcol(*args, &block)
26
+ end
27
+ end # HTTParty
28
+
Binary file
@@ -0,0 +1,97 @@
1
+ require 'carrierwave/httparty_monkey'
2
+
3
+ module CarrierWave
4
+ module Storage
5
+ class WebDAV < Abstract
6
+
7
+ # Store the file in WebDAV
8
+ #
9
+ # === Parameters
10
+ #
11
+ # [ file (CarrierWave::SanitizedFile) ] the file to store
12
+ #
13
+ # === Returns
14
+ #
15
+ # [ CarrierWave::SanitizedFile ] a sanitized file
16
+ #
17
+ def store!(file)
18
+ stored = CarrierWave::Storage::WebDAV::File.new(uploader, uploader.store_path)
19
+ stored.write(file.read)
20
+ stored
21
+ end
22
+
23
+ # Retrieve the file from WebDAV
24
+ #
25
+ # === Parameters
26
+ #
27
+ # [ identifier (String) ] the filename of the file
28
+ #
29
+ # === Returns
30
+ #
31
+ # [ CarrierWave::Store::WebDAV::File ] a sanitized file
32
+ #
33
+ def retrieve!(identifier)
34
+ CarrierWave::Storage::WebDAV::File.new(uploader, uploader.store_path(identifier))
35
+ end
36
+
37
+ class File
38
+ attr_reader :path
39
+ attr_reader :uploader
40
+ attr_reader :options
41
+ attr_reader :server # Like 'https://www.WebDAV.com/dav'
42
+
43
+ def initialize(uploader, path)
44
+ @path = path
45
+ @path.sub! /^\//, ''
46
+ @uploader = uploader
47
+ @server = uploader.webdav_server
48
+ @server.sub! /\/$/, ''
49
+ @username = uploader.webdav_username
50
+ @password = uploader.webdav_password || ''
51
+ if @username
52
+ @options = { basic_auth: { username: @username, password: @password }}
53
+ else
54
+ @options = {}
55
+ end
56
+ end
57
+
58
+ def read
59
+ HTTParty.get(fullurl, options).body
60
+ end
61
+
62
+ def write(file)
63
+ mkcol
64
+ HTTParty.put(fullurl, options.merge({ body: file }))
65
+ end
66
+
67
+ def length
68
+ end
69
+
70
+ def delete
71
+ end
72
+
73
+ def content_type
74
+ end
75
+
76
+ alias :content_length :length
77
+ alias :file_length :length
78
+ alias :size :length
79
+
80
+ private
81
+ def fullurl
82
+ "#{server}/#{path}"
83
+ end
84
+
85
+ def mkcol
86
+ dirs = []
87
+ path.split('/')[0...-1].each do |dir|
88
+ dirs << "#{dirs[-1]}/#{dir}"
89
+ end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c']
90
+ dirs.each do |dir|
91
+ HTTParty.mkcol("#{server}#{dir}", options)
92
+ end # Make collections recursively
93
+ end
94
+ end # File
95
+ end # WebDAV
96
+ end # Storage
97
+ end # CarrierWave
@@ -0,0 +1,15 @@
1
+ require 'carrierwave'
2
+ require 'carrierwave/store/webdav'
3
+
4
+ CarrierWave::Storage.autoload :WebDAV, 'carrierwave/store/webdav'
5
+
6
+ class CarrierWave::Uploader::Base
7
+ add_config :webdav_username
8
+ add_config :webdav_password
9
+ add_config :webdav_server
10
+
11
+ configure do |config|
12
+ config.storage_engines[:webdav] = 'CarrierWave::Storage::WebDAV'
13
+ end
14
+ end
15
+
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module WebDAV
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave-webdav
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Qinix
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ name: carrierwave
30
+ - !ruby/object:Gem::Dependency
31
+ type: :runtime
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ name: httparty
46
+ description: WebDAV support for CarrierWave
47
+ email:
48
+ - i@qinix.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - carrierwave-webdav.gemspec
59
+ - lib/carrierwave/httparty_monkey.rb
60
+ - lib/carrierwave/store/.box.rb.swp
61
+ - lib/carrierwave/store/webdav.rb
62
+ - lib/carrierwave/webdav.rb
63
+ - lib/carrierwave/webdav/version.rb
64
+ homepage: https://github.com/qinix/carrierwave-webdav
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: WebDAV support for CarrierWave
88
+ test_files: []