carrierwave-qiniu 0.1.8 → 0.1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ccbd315d40ee92225c01233111bb7fe0dba63bf6
4
- data.tar.gz: f971548c853f9e1969e7c2154bcdd772f01ffc94
3
+ metadata.gz: ce0788a33edf4b269a2f351ee329b23ff8447f10
4
+ data.tar.gz: 78414ebcc9b2bfee47ba3a92a8e33118b561f81c
5
5
  SHA512:
6
- metadata.gz: 3eef04296696a3088e96ea06e0cb2b813c4f7235a6b9d64ba89164c4a386a61c21fc96c027a6d148320fb856010c9b9b3e2887718531098c34e8b96e99224893
7
- data.tar.gz: ce454ab4c3af772794e92703576a167df5c1a802e2d0e67cf34164262e6372663ffecf35010cd8af101b67dd80826c028994ef82f8de0670dd46d6c8ae172ae3
6
+ metadata.gz: cf2a596f92ffca378a6f60ef023dbc358775c35f6cb4695fc1df66706159d7ec6e8c265bcb849e289517a8217c30073bf37fb9bfe0c93a5b27b88ec894269ee5
7
+ data.tar.gz: d8372b8f85ba30d4c650492e3e4ec2d425b0e3dd9c8f50f3f01e6970e5a634e74d2356bc583cb7ae98f2083c5a08f70f59bdf11038055f0f92b74e9bae6575b8
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .env
7
+ .env.*
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
@@ -16,4 +18,3 @@ test/tmp
16
18
  test/version_tmp
17
19
  tmp
18
20
  uploads/
19
-
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
 
2
2
  ## CHANGE LOG
3
3
 
4
+ ### v0.1.8.1
5
+
6
+ https://github.com/huobazi/carrierwave-qiniu/pull/36
7
+
8
+ https://github.com/huobazi/carrierwave-qiniu/pull/38
9
+
4
10
  ### v0.1.7
5
11
 
6
12
  - 添加从云端读取(下载)文件 。 [https://github.com/huobazi/carrierwave-qiniu/pull/27](https://github.com/huobazi/carrierwave-qiniu/pull/27)
7
13
 
8
14
  - 增加获取有时效性url链接地址的方法 。 [https://github.com/huobazi/carrierwave-qiniu/issues/25](https://github.com/huobazi/carrierwave-qiniu/issues/25)
15
+
16
+ - 升级七牛 SDK 至 6.4.2
data/Gemfile CHANGED
@@ -12,4 +12,5 @@ group :test do
12
12
  gem 'qiniu'
13
13
  gem 'rspec', '~> 2.11'
14
14
  gem 'mocha', '>=0.10.0'
15
+ gem 'dotenv'
15
16
  end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carrierwave::Qiniu
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png)](http://badge.fury.io/rb/carrierwave-qiniu)
3
+ [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?20150410001)](http://badge.fury.io/rb/carrierwave-qiniu)
4
4
 
5
5
  This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
6
6
  example: https://github.com/huobazi/carrierwave-qiniu-example
@@ -36,7 +36,7 @@ module CarrierWave
36
36
  )
37
37
  put_policy.persistent_ops = @qiniu_async_ops
38
38
 
39
- code, result, response_headers = ::Qiniu::Storage.upload_with_put_policy(
39
+ ::Qiniu::Storage.upload_with_put_policy(
40
40
  put_policy,
41
41
  file.path,
42
42
  key
@@ -45,29 +45,27 @@ module CarrierWave
45
45
  end
46
46
 
47
47
  def delete(key)
48
- begin
49
- ::Qiniu::Storage.delete(@qiniu_bucket, key)
50
- rescue Exception
51
- nil
52
- end
48
+ ::Qiniu::Storage.delete(@qiniu_bucket, key) rescue nil
53
49
  end
54
50
 
55
51
  def stat(key)
56
- code, result, response_headers = ::Qiniu::Storage.stat(@qiniu_bucket, key)
52
+ code, result, _ = ::Qiniu::Storage.stat(@qiniu_bucket, key)
57
53
  code == 200 ? result : {}
58
54
  end
59
55
 
60
56
  def get(path)
61
- code, result, response_headers = ::Qiniu::HTTP.get( download_url(path) )
57
+ code, result, _ = ::Qiniu::HTTP.get( download_url(path) )
62
58
  code == 200 ? result : nil
63
59
  end
64
60
 
65
61
  def download_url(path)
66
- private_url_args = {}
67
- encode_path = URI.escape(path, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) #fix chinese file name, same as encodeURIComponent in js
62
+ encode_path = URI.escape(path) #fix chinese file name, same as encodeURIComponent in js but preserve slash '/'
68
63
  primitive_url = "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{encode_path}"
69
- private_url_args.merge!(expires_in: @qiniu_private_url_expires_in) if @qiniu_bucket_private
70
- @qiniu_bucket_private ? ::Qiniu::Auth.authorize_download_url(primitive_url, private_url_args) : primitive_url
64
+ @qiniu_bucket_private ? \
65
+ ::Qiniu::Auth.authorize_download_url(primitive_url, :expires_in => @qiniu_private_url_expires_in) \
66
+ : \
67
+ primitive_url
68
+
71
69
  end
72
70
 
73
71
  private
@@ -76,14 +74,16 @@ module CarrierWave
76
74
  init_qiniu_rs_connection
77
75
  end
78
76
 
77
+ UserAgent = "CarrierWave-Qiniu/#{Carrierwave::Qiniu::VERSION} (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}".freeze
78
+
79
79
  def init_qiniu_rs_connection
80
80
  options = {
81
81
  :access_key => @qiniu_access_key,
82
82
  :secret_key => @qiniu_secret_key,
83
- :user_agent => 'CarrierWave-Qiniu/' + Carrierwave::Qiniu::VERSION + ' ('+RUBY_PLATFORM+')' + ' Ruby/'+ RUBY_VERSION
83
+ :user_agent => UserAgent
84
84
  }
85
- options.merge(:block_size => @qiniu_block_size) if @qiniu_block_size
86
- options.merge(:up_host => @qiniu_up_host) if @qiniu_up_host
85
+ options[:block_size] = @qiniu_block_size if @qiniu_block_size
86
+ options[:up_host] = @qiniu_up_host if @qiniu_up_host
87
87
 
88
88
  ::Qiniu.establish_connection! options
89
89
 
@@ -125,7 +125,7 @@ module CarrierWave
125
125
  end
126
126
 
127
127
  def content_type
128
- file_info['mimeType'] || 'application/octet-stream'
128
+ file_info['mimeType'] || 'application/octet-stream'.freeze
129
129
  end
130
130
 
131
131
  def size
@@ -135,9 +135,7 @@ module CarrierWave
135
135
  private
136
136
 
137
137
  def qiniu_connection
138
- if @qiniu_connection
139
- @qiniu_connection
140
- else
138
+ @qiniu_connection ||= begin
141
139
  config = {
142
140
  :qiniu_access_key => @uploader.qiniu_access_key,
143
141
  :qiniu_secret_key => @uploader.qiniu_secret_key,
@@ -151,23 +149,10 @@ module CarrierWave
151
149
  :qiniu_private_url_expires_in => @uploader.qiniu_private_url_expires_in
152
150
  }
153
151
 
154
- if @uploader.respond_to?(:qiniu_async_ops) and !@uploader.qiniu_async_ops.nil? and @uploader.qiniu_async_ops.size > 0
155
- if @uploader.qiniu_async_ops.is_a?(Array)
156
- config.merge!(:qiniu_async_ops => @uploader.qiniu_async_ops.join(';'))
157
- else
158
- config.merge!(:qiniu_async_ops => @uploader.qiniu_async_ops)
159
- end
160
- end
161
-
162
- if @uploader.respond_to?(:qiniu_can_overwrite) and !@uploader.qiniu_can_overwrite.nil?
163
- if @uploader.qiniu_can_overwrite.is_a?(TrueClass) or @uploader.is_a?(FalseClass)
164
- config.merge!(:qiniu_can_overwrite => @uploader.qiniu_can_overwrite)
165
- else
166
- config.merge!(:qiniu_can_overwrite => false)
167
- end
168
- end
169
-
170
- @qiniu_connection ||= Connection.new config
152
+ config[:qiniu_async_ops] = Array(@uploader.qiniu_async_ops).join(';') rescue ''
153
+ config[:qiniu_can_overwrite] = @uploader.try :qiniu_can_overwrite rescue false
154
+
155
+ Connection.new config
171
156
  end
172
157
  end
173
158
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.8.1"
5
5
  end
6
6
  end
@@ -4,7 +4,7 @@ require "carrierwave/qiniu/configuration"
4
4
  require "carrierwave-qiniu/version"
5
5
 
6
6
  ::CarrierWave.configure do |config|
7
- config.storage_engines.merge!({:qiniu => "::CarrierWave::Storage::Qiniu"})
7
+ config.storage_engines[:qiniu] = "::CarrierWave::Storage::Qiniu".freeze
8
8
  end
9
9
 
10
10
  ::CarrierWave::Uploader::Base.send(:include, ::CarrierWave::Qiniu::Configuration)
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ require "rails"
6
6
  require "active_record"
7
7
  require "carrierwave"
8
8
  require "carrierwave/orm/activerecord"
9
+ require 'dotenv'
9
10
 
10
11
  $LOAD_PATH.unshift(File.dirname(__FILE__))
11
12
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","lib"))
@@ -20,16 +21,19 @@ module Rails
20
21
  end
21
22
  end
22
23
 
24
+ Dotenv.load
25
+
23
26
  ActiveRecord::Migration.verbose = false
24
27
 
25
- # 测试的时候需要修改这个地方
28
+ # 测试的时候载入环境变量
29
+ # 或者在根目录下新建 `.env` 文件,包含 <key>=<value>
26
30
  ::CarrierWave.configure do |config|
27
31
  config.storage = :qiniu
28
- config.qiniu_access_key = "xxx"
29
- config.qiniu_secret_key = "xxx"
32
+ config.qiniu_access_key = ENV['qiniu_access_key']
33
+ config.qiniu_secret_key = ENV['qiniu_secret_key']
30
34
 
31
- config.qiniu_bucket = "xxx"
32
- config.qiniu_bucket_domain = "xxx"
35
+ config.qiniu_bucket = ENV['qiniu_bucket']
36
+ config.qiniu_bucket_domain = ENV['qiniu_bucket_domain']
33
37
 
34
38
  config.qiniu_block_size = 4*1024*1024
35
39
  config.qiniu_protocol = "http"
data/spec/upload_spec.rb CHANGED
@@ -75,7 +75,7 @@ describe "CarrierWave Qiniu" do
75
75
 
76
76
  puts ""
77
77
  puts 'The image was uploaded to:'
78
- puts ""
78
+ puts photo.image.url
79
79
 
80
80
  open(photo.image.url).should_not be_nil
81
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave