carrierwave-aliyun 0.1.4 → 0.1.5

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: 88fa0eb30adeceb86f58ba51613ede7fd5ad252d
4
- data.tar.gz: 37bcfc260f4213ba2db3e19aa193d0d1bd998e5e
3
+ metadata.gz: 66ec3f177151654773bc1eddd296f93c79832fab
4
+ data.tar.gz: c9f0a7b23e521a236139992f8b0c08034335a80b
5
5
  SHA512:
6
- metadata.gz: fa0bf265b62fb7c081c9266a8868965b310d8dffd0d743e132b1b077368b54c981741ad314ae3b9da519e64e8e10392687145bd7162b51c79ca544e73be6d05f
7
- data.tar.gz: 91434a7ce71d32805b88bd12397c0730948ea3ef695323e03b8438204aae266cac242490a2b7f8d3b9246f85749e04313f3fb75940722232008e739b950df343
6
+ metadata.gz: 2b0e87655cc012e33a7c5741ac6a30207bc950ebc201135eb2df49e7f0f419bc290665a7c99c08ee65de70c418a727dff2b7eb1b35e4ddb261b37e6ea495f0c4
7
+ data.tar.gz: 2be951bd4e828cecd28650a31b08950ea7d2b84b77ac430c7b6b7f66a8363f3563196b0fef69d48b1e6ce968a06e3ff6d35fb207c9a9be9991f0c5129e745fa0
data/Changelogs.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.5
2
+
3
+ * 自定义域名支持
4
+
1
5
  ## 0.1.3
2
6
 
3
7
  * delete 接口加入。
data/README.md CHANGED
@@ -28,6 +28,9 @@ CarrierWave.configure do |config|
28
28
  config.aliyun_bucket = "simple"
29
29
  # 是否使用内部连接,true - 使用 Aliyun 局域网的方式访问 false - 外部网络访问
30
30
  config.aliyun_internal = true
31
+ # 使用自定义域名,设定此项,carrierwave 返回的 URL 将会用自定义域名
32
+ # 自定于域名请 CNAME 到 you_bucket_name.oss.aliyuncs.com (you_bucket_name 是你的 bucket 的名称)
33
+ config.aliyun_host = "foo.bar.com"
31
34
  end
32
35
  ```
33
36
 
@@ -7,6 +7,7 @@ module CarrierWave
7
7
  add_config :aliyun_access_key
8
8
  add_config :aliyun_bucket
9
9
  add_config :aliyun_internal
10
+ add_config :aliyun_host
10
11
  end
11
12
  end
12
13
 
@@ -1,7 +1,7 @@
1
1
  module CarrierWave
2
2
  module Aliyun
3
3
  class Version
4
- MAJOR, MINOR, PATCH = 0, 1, 4
4
+ MAJOR, MINOR, PATCH = 0, 1, 5
5
5
 
6
6
  ##
7
7
  # Returns the major version ( big release based off of multiple minor releases )
@@ -13,9 +13,10 @@ module CarrierWave
13
13
  @aliyun_access_id = options[:aliyun_access_id]
14
14
  @aliyun_access_key = options[:aliyun_access_key]
15
15
  @aliyun_bucket = options[:aliyun_bucket]
16
- @aliyun_host = "oss.aliyuncs.com"
16
+ @aliyun_upload_host = "oss.aliyuncs.com"
17
+ @aliyun_host = options[:aliyun_host] || @aliyun_upload_host
17
18
  if options[:aliyun_internal] == true
18
- @aliyun_host = "oss-internal.aliyuncs.com"
19
+ @aliyun_upload_host = "oss-internal.aliyuncs.com"
19
20
  end
20
21
  end
21
22
 
@@ -31,24 +32,24 @@ module CarrierWave
31
32
  "Content-Type" => content_type,
32
33
  "Content-Length" => file_data.length,
33
34
  "Date" => date,
34
- "Host" => @aliyun_host,
35
+ "Host" => @aliyun_upload_host,
35
36
  "Expect" => "100-Continue"
36
37
  }
37
38
  response = RestClient.put(url, file_data, headers)
38
- return url
39
+ return path_to_url(path, :get => true)
39
40
  end
40
41
 
41
42
  def delete(path)
42
43
  path = format_path(path)
43
44
  date = gmtdate
44
45
  headers = {
45
- "Host" => @aliyun_host,
46
+ "Host" => @aliyun_upload_host,
46
47
  "Date" => date,
47
48
  "Authorization" => sign("DELETE", path, "", "" ,date)
48
49
  }
49
50
  url = path_to_url(path)
50
51
  RestClient.delete(url, headers)
51
- return url
52
+ return path_to_url(path, :get => true)
52
53
  end
53
54
 
54
55
  def gmtdate
@@ -61,8 +62,10 @@ module CarrierWave
61
62
  [@aliyun_bucket, path].join("/")
62
63
  end
63
64
 
64
- def path_to_url(path)
65
- "http://#{@aliyun_host}/#{path}"
65
+ def path_to_url(path, opts = {})
66
+ host = @aliyun_upload_host
67
+ host = @aliyun_host if opts[:get]
68
+ "http://#{host}/#{path}"
66
69
  end
67
70
 
68
71
  private
@@ -122,7 +125,7 @@ module CarrierWave
122
125
  end
123
126
 
124
127
  def url
125
- "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
128
+ "http://#{@uploader.aliyun_host}/#{@uploader.aliyun_bucket}/#{@path}"
126
129
  end
127
130
 
128
131
  def store(data, opts = {})
data/spec/aliyun_spec.rb CHANGED
@@ -4,26 +4,38 @@ require "net/http"
4
4
 
5
5
  describe "Aliyun" do
6
6
  before(:all) do
7
- opts = {
7
+ @opts = {
8
8
  :aliyun_access_id => ALIYUN_ACCESS_ID,
9
9
  :aliyun_access_key => ALIYUN_ACCESS_KEY,
10
10
  :aliyun_bucket => ALIYUN_BUCKET
11
11
  }
12
- @connection = CarrierWave::Storage::Aliyun::Connection.new(opts)
12
+ @connection = CarrierWave::Storage::Aliyun::Connection.new(@opts)
13
13
  end
14
-
14
+
15
15
  it "should put" do
16
16
  url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
17
17
  Net::HTTP.get_response(URI.parse(url)).code.should == "200"
18
18
  end
19
-
19
+
20
20
  it "should put with / prefix" do
21
21
  url = @connection.put("/a/a.jpg",load_file("foo.jpg").read)
22
22
  Net::HTTP.get_response(URI.parse(url)).code.should == "200"
23
23
  end
24
-
24
+
25
25
  it "should delete" do
26
26
  url = @connection.delete("/a/a.jpg")
27
27
  Net::HTTP.get_response(URI.parse(url)).code.should == "404"
28
28
  end
29
+
30
+ it "should use default domain" do
31
+ url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
32
+ url.should == "http://oss.aliyuncs.com/#{ALIYUN_BUCKET}/a/a.jpg"
33
+ end
34
+
35
+ it "should support custom domain" do
36
+ @opts[:aliyun_host] = "foo.bar.com"
37
+ @connection = CarrierWave::Storage::Aliyun::Connection.new(@opts)
38
+ url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
39
+ url.should == "http://foo.bar.com/#{ALIYUN_BUCKET}/a/a.jpg"
40
+ end
29
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-12 00:00:00.000000000 Z
11
+ date: 2013-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 2.0.2
84
+ rubygems_version: 2.0.0
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: Aliyun OSS support for Carrierwave