paperclip-upyun 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/README.md +4 -0
- data/lib/paperclip/storage/upyun.rb +117 -0
- data/lib/paperclip/upyun.rb +4 -0
- data/lib/paperclip/upyun/exceptions.rb +10 -0
- data/lib/paperclip/upyun/response.rb +18 -0
- data/lib/paperclip/upyun/version.rb +5 -0
- data/paperclip-upyun.gemspec +26 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e27aa163e3b59f69f837b9ebbd4428603c59e82d
|
4
|
+
data.tar.gz: 7fa1ee32084126404cca6e5d7dc3777a2ab2ee9d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cee84342f50cc3f3cbe7941d4d0b34ad4cce3187a13b0c550e9d4ddcba79c4c3ad00f3c4a68f504d3f54b02d72cc65053507dd829f6ebf46bc31e50fb8005afb
|
7
|
+
data.tar.gz: 9c777305a3f9ee0e1a8b1a623e41d9016fad78fdf36c8b7131f463ca5131b6a6b725308f511d8bdd0439140e39e09e1beef513897de3ff6497344729b3832f40
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# require_relative '../../paperclip-upyun/exceptions'
|
2
|
+
# require_relative '../../paperclip-upyun/response'
|
3
|
+
|
4
|
+
module Paperclip
|
5
|
+
module Storage
|
6
|
+
module Upyun
|
7
|
+
def self.extended base
|
8
|
+
begin
|
9
|
+
require 'upyun'
|
10
|
+
rescue LoadError => e
|
11
|
+
e.message << " (You may need to install the upyun gem)"
|
12
|
+
raise e
|
13
|
+
end unless defined?(::Upyun)
|
14
|
+
|
15
|
+
base.instance_eval do
|
16
|
+
@bucket = @options[:bucket]
|
17
|
+
@operator = @options[:operator]
|
18
|
+
@password = @options[:password]
|
19
|
+
|
20
|
+
raise Paperclip::Upyun::Exceptions::OptionsError '(You should set upyun_host)' unless @host = @options[:upyun_host]
|
21
|
+
# @options = @options[:options]
|
22
|
+
# @endpoint = @options[:endpoint]
|
23
|
+
@options[:interval] = "!"
|
24
|
+
|
25
|
+
@upyun = ::Upyun::Rest.new(@bucket, @operator, @password)
|
26
|
+
log("@options[:path]: #{@options[:path]}")
|
27
|
+
log("@options[:url]: #{@options[:url]}")
|
28
|
+
@options[:path] = @options[:path].gsub(/:url/, @options[:url])
|
29
|
+
log("@options[:path]: #{@options[:path]}")
|
30
|
+
@options[:url] = ':upyun_public_url'
|
31
|
+
|
32
|
+
Paperclip.interpolates(:version) do |attachment, style|
|
33
|
+
attachment.version(style)
|
34
|
+
end unless Paperclip::Interpolations.respond_to? :version
|
35
|
+
|
36
|
+
Paperclip.interpolates(:upyun_public_url) do |attachment, style|
|
37
|
+
attachment.public_url(style)
|
38
|
+
end unless Paperclip::Interpolations.respond_to? :upyun_public_url
|
39
|
+
|
40
|
+
Paperclip.interpolates :upyun_host do |attachment, style|
|
41
|
+
attachment.upyun_host(style)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def exists?(style = default_style)
|
49
|
+
puts "enter exists? #{style}"
|
50
|
+
resp = @upyun.getinfo(path(style))
|
51
|
+
begin
|
52
|
+
Paperclip::Upyun::Response.parse(resp)
|
53
|
+
rescue => err
|
54
|
+
log("UPYUN<ERROR>: #{err}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def flush_writes
|
59
|
+
for style, file in @queued_for_write do
|
60
|
+
log("saving #{path(style)}")
|
61
|
+
retried = false
|
62
|
+
begin
|
63
|
+
upload(file, path(style))
|
64
|
+
ensure
|
65
|
+
file.rewind
|
66
|
+
end
|
67
|
+
end
|
68
|
+
after_flush_writes # allows attachment to clean up temp files
|
69
|
+
@queued_for_write = {}
|
70
|
+
end
|
71
|
+
|
72
|
+
def flush_deletes
|
73
|
+
for path in @queued_for_delete do
|
74
|
+
log("deleting: #{path}")
|
75
|
+
delete(path)
|
76
|
+
end
|
77
|
+
@queued_for_delete = []
|
78
|
+
end
|
79
|
+
|
80
|
+
def public_url(style = default_style)
|
81
|
+
log("url:path=>#{path(style)}")
|
82
|
+
url = "#{@options[:upyun_host]}/#{path(style)}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def version(style = default_style)
|
86
|
+
url = ''
|
87
|
+
url += @options[:interval] unless style == default_style
|
88
|
+
url += style.to_s unless style == default_style
|
89
|
+
url
|
90
|
+
end
|
91
|
+
|
92
|
+
def upyun_host(style = default_style)
|
93
|
+
"#{@options[:upyun_host]}" || raise('upyun_host is nil')
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def upload(file, path)
|
99
|
+
res = @upyun.put(path, File.new(file.path,"rb"))
|
100
|
+
begin
|
101
|
+
Paperclip::Upyun::Response.parse(res)
|
102
|
+
rescue => err
|
103
|
+
log("UPYUN<ERROR>: #{err}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def delete(path)
|
108
|
+
res = @upyun.delete(path)
|
109
|
+
begin
|
110
|
+
Paperclip::Upyun::Response.parse(res)
|
111
|
+
rescue => err
|
112
|
+
log("UPYUN<ERROR>: #{err}")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Paperclip
|
2
|
+
module Upyun
|
3
|
+
class Response
|
4
|
+
|
5
|
+
def self.parse(res)
|
6
|
+
return true if res.is_a?(TrueClass)
|
7
|
+
raise TypeError, "Upyun Response type: #{res.class}" unless res.is_a?(Hash)
|
8
|
+
self.error(res) if res.has_key?(:error) || res.has_key?("error")
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.error(res)
|
13
|
+
raise Paperclip::Upyun::Exceptions::ResponseError, "#{res.to_s}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'paperclip/upyun/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "paperclip-upyun"
|
8
|
+
spec.version = Paperclip::Upyun::VERSION
|
9
|
+
spec.author = "Edison-Hsu"
|
10
|
+
spec.email = ["edison.hsu.sh@gmail.com"]
|
11
|
+
spec.summary = "UPYUN API SDK for Paperclip Storage Plugin"
|
12
|
+
spec.description = <<-EOF
|
13
|
+
UPYUN API SDK for Paperclip Storage Plugin. Use Upyun SDK to upload file.
|
14
|
+
EOF
|
15
|
+
spec.homepage = "https://github.com/Edison-Hsu/paperclip-upyun"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "upyun", "~> 1.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.6"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paperclip-upyun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edison-Hsu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: upyun
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
41
|
+
description: |2
|
42
|
+
UPYUN API SDK for Paperclip Storage Plugin. Use Upyun SDK to upload file.
|
43
|
+
email:
|
44
|
+
- edison.hsu.sh@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- README.md
|
51
|
+
- lib/paperclip/storage/upyun.rb
|
52
|
+
- lib/paperclip/upyun.rb
|
53
|
+
- lib/paperclip/upyun/exceptions.rb
|
54
|
+
- lib/paperclip/upyun/response.rb
|
55
|
+
- lib/paperclip/upyun/version.rb
|
56
|
+
- paperclip-upyun.gemspec
|
57
|
+
homepage: https://github.com/Edison-Hsu/paperclip-upyun
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.8
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: UPYUN API SDK for Paperclip Storage Plugin
|
81
|
+
test_files: []
|