paperclip-qiniu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paperclip-qiniu.gemspec
4
+ gemspec
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paperclip-qiniu (0.0.1)
5
+ paperclip
6
+ qiniu-rs
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (3.2.6)
12
+ activesupport (= 3.2.6)
13
+ builder (~> 3.0.0)
14
+ activerecord (3.2.6)
15
+ activemodel (= 3.2.6)
16
+ activesupport (= 3.2.6)
17
+ arel (~> 3.0.2)
18
+ tzinfo (~> 0.3.29)
19
+ activesupport (3.2.6)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ arel (3.0.2)
23
+ builder (3.0.0)
24
+ cocaine (0.2.1)
25
+ i18n (0.6.0)
26
+ json (1.7.3)
27
+ mime-types (1.19)
28
+ multi_json (1.3.6)
29
+ paperclip (3.1.2)
30
+ activemodel (>= 3.0.0)
31
+ activerecord (>= 3.0.0)
32
+ activesupport (>= 3.0.0)
33
+ cocaine (>= 0.0.2)
34
+ mime-types
35
+ qiniu-rs (2.1.2)
36
+ json (~> 1.7.3)
37
+ mime-types (~> 1.19)
38
+ rest-client (~> 1.6.7)
39
+ ruby-hmac (~> 0.4.0)
40
+ rest-client (1.6.7)
41
+ mime-types (>= 1.16)
42
+ ruby-hmac (0.4.0)
43
+ tzinfo (0.3.33)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ paperclip-qiniu!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 LI Daobing
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,50 @@
1
+ # Paperclip::Qiniu
2
+
3
+ storage paperclip attachments to http://qiniutek.com
4
+
5
+ ## Usage
6
+
7
+ 0. confirm you are working on a rails app
8
+
9
+ 1. add following line to `Gemfile`
10
+
11
+ ```
12
+ gem 'paperclip'
13
+ gem 'paperclip-qiniu'
14
+ ```
15
+
16
+ 2. edit your `config/application.rb`
17
+
18
+ ```
19
+ module PaperclipQiniuExample
20
+ class Application < Rails::Application
21
+ # ....
22
+ config.paperclip_defaults = {:storage => :qiniu,
23
+ :qiniu_credentials => {
24
+ :access_key => ENV['QINIU_ACCESS_KEY'] || raise("set env QINIU_ACCESS_KEY"),
25
+ :secret_key => ENV['QINIU_SECRET_KEY'] || raise("set env QINIU_SECRET_KEY")
26
+ },
27
+ :bucket => "paperclip-qiniu-example",
28
+ :use_timestamp => false
29
+ }
30
+ end
31
+ end
32
+ ```
33
+
34
+ 3. add a model like this
35
+
36
+ ```
37
+ class Image < ActiveRecord::Base
38
+ attr_accessible :file
39
+ has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }
40
+ validates :file, :attachment_presence => true
41
+ end
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "paperclip-qiniu/version"
2
+ require 'paperclip/storage/qiniu'
@@ -0,0 +1,5 @@
1
+ module Paperclip
2
+ module Qiniu
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,86 @@
1
+ module Paperclip
2
+ module Storage
3
+ module Qiniu
4
+ def self.extended base
5
+ begin
6
+ require 'qiniu-rs'
7
+ rescue LoadError => e
8
+ e.message << " (You may need to install the qiniu-rs gem)"
9
+ raise e
10
+ end unless defined?(::Qiniu)
11
+
12
+ base.instance_eval do
13
+ unless @options[:url].to_s.match(/^:fog.*url$/)
14
+ @options[:path] = @options[:path].gsub(/:url/, @options[:url])
15
+ @options[:url] = ':qiniu_public_url'
16
+ end
17
+ Paperclip.interpolates(:qiniu_public_url) do |attachment, style|
18
+ attachment.public_url(style)
19
+ end unless Paperclip::Interpolations.respond_to? :qiniu_public_url
20
+ end
21
+
22
+ end
23
+
24
+ def exists?(style = default_style)
25
+ init
26
+ !!::Qiniu::RS.stat(bucket, path(style))
27
+ end
28
+
29
+ def flush_writes
30
+ init
31
+ for style, file in @queued_for_write do
32
+ log("saving #{path(style)}")
33
+ retried = false
34
+ begin
35
+ upload(file, path(style))
36
+ ensure
37
+ file.rewind
38
+ end
39
+ end
40
+
41
+ after_flush_writes # allows attachment to clean up temp files
42
+
43
+ @queued_for_write = {}
44
+ end
45
+
46
+ def flush_deletes
47
+ init
48
+ for path in @queued_for_delete do
49
+ ::Qiniu::RS.delete(bucket, path)
50
+ end
51
+ @queued_for_delete = []
52
+ end
53
+
54
+ def public_url(style = default_style)
55
+ init
56
+ res = ::Qiniu::RS.get(bucket, path(style))
57
+ return res["url"] if res
58
+ nil
59
+ end
60
+
61
+ private
62
+
63
+ def init
64
+ return if @inited
65
+ ::Qiniu::RS.establish_connection! @options[:qiniu_credentials]
66
+ inited = true
67
+ end
68
+
69
+ def upload(file, path)
70
+ remote_upload_url = ::Qiniu::RS.put_auth
71
+ opts = {:url => remote_upload_url,
72
+ :file => file.path,
73
+ :key => path,
74
+ :bucket => bucket,
75
+ :mime_type => file.content_type,
76
+ :enable_crc32_check => true}
77
+ ::Qiniu::RS.upload opts
78
+ log ::Qiniu::RS.get(bucket, path)
79
+ end
80
+
81
+ def bucket
82
+ @options[:bucket] || raise("bucket is nil")
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/paperclip-qiniu/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["LI Daobing"]
6
+ gem.email = ["lidaobing@gmail.com"]
7
+ gem.description = %q{paperclip plugin for qiniu}
8
+ gem.summary = %q{paperclip plugin for qiniu}
9
+ gem.homepage = "https://github.com/lidaobing/paperclip-qiniu"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "paperclip-qiniu"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Paperclip::Qiniu::VERSION
17
+ gem.add_dependency 'paperclip'
18
+ gem.add_dependency 'qiniu-rs'
19
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip-qiniu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - LI Daobing
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paperclip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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'
30
+ - !ruby/object:Gem::Dependency
31
+ name: qiniu-rs
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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'
46
+ description: paperclip plugin for qiniu
47
+ email:
48
+ - lidaobing@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/paperclip-qiniu.rb
60
+ - lib/paperclip-qiniu/version.rb
61
+ - lib/paperclip/storage/qiniu.rb
62
+ - paperclip-qiniu.gemspec
63
+ homepage: https://github.com/lidaobing/paperclip-qiniu
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.23
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: paperclip plugin for qiniu
87
+ test_files: []
88
+ has_rdoc: