upyun-rb 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/upyun-rb/bucket.rb +36 -25
- data/lib/upyun-rb/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2635ae3a9f18e342a3e09ab3d30064733b359c78
|
4
|
+
data.tar.gz: 355c81c11444068839fde3a601b59c1bf3813c10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365393dda78bdb64b91294b64908cdc0b78d7c6c27df6334cc85df1eef65e5f88022bd1cd65b460f29e0f0fb1413e483ccf71092d91414645010f1a0d78447c7
|
7
|
+
data.tar.gz: 4563c501c4619052e1d1f4cb6885ead158d5d935258dd229edd8bafa913a117cafb2642044d804133a48da04817cdd8608bf15f8986341d72ce0316e10056f31
|
data/lib/upyun-rb/bucket.rb
CHANGED
@@ -3,14 +3,19 @@ module Upyun
|
|
3
3
|
def initialize(bucket, operator, password, options={})
|
4
4
|
upyun_host = options[:upyun_host] || "http://v0.api.upyun.com"
|
5
5
|
|
6
|
+
pool = options[:pool] || 2
|
7
|
+
timeout = options[:timeout] || 10
|
8
|
+
|
6
9
|
@bucket = bucket
|
7
10
|
@operator = operator
|
8
11
|
@signed_password = Digest::MD5.hexdigest(password)
|
9
12
|
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
@pool = ConnectionPool.new(size: pool, timeout: timeout) do
|
14
|
+
Faraday.new(:url => upyun_host) do |faraday|
|
15
|
+
faraday.request :url_encoded # form-encode POST params
|
16
|
+
faraday.response :logger # log requests to STDOUT
|
17
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
@@ -19,11 +24,13 @@ module Upyun
|
|
19
24
|
date = Upyun::Util.current_date
|
20
25
|
sign = Digest::MD5.hexdigest("HEAD&#{uri}&#{date}&0&#{@signed_password}")
|
21
26
|
|
22
|
-
@
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
@pool.with do |conn|
|
28
|
+
conn.head do |req|
|
29
|
+
req.url uri
|
30
|
+
req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
|
31
|
+
req.headers['Date'] = date
|
32
|
+
req.headers['Expect'] = ''
|
33
|
+
end
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
@@ -31,18 +38,20 @@ module Upyun
|
|
31
38
|
uri = "/#{@bucket}/#{path}"
|
32
39
|
date = Upyun::Util.current_date
|
33
40
|
mime_type = `file -b --mime #{file}`.gsub(/\n/,"").split(';')[0]
|
34
|
-
file_size = file.nil? ? 0 : File.size(file)
|
41
|
+
file_size = file.nil? ? 0 : File.size(file)
|
35
42
|
sign = Digest::MD5.hexdigest("PUT&#{uri}&#{date}&#{file_size}&#{@signed_password}")
|
36
43
|
|
37
|
-
@
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
@pool.with do |conn|
|
45
|
+
conn.put do |req|
|
46
|
+
req.url uri
|
47
|
+
req.body = Faraday::UploadIO.new(file, mime_type)
|
48
|
+
req.headers['Mkdir'] = 'true'
|
49
|
+
req.headers['Content-Type'] = mime_type
|
50
|
+
req.headers['Content-Length'] = file_size.to_s
|
51
|
+
req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
|
52
|
+
req.headers['Date'] = date
|
53
|
+
req.headers['Expect'] = ''
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
@@ -50,12 +59,14 @@ module Upyun
|
|
50
59
|
uri = "/#{@bucket}/#{path}"
|
51
60
|
date = Upyun::Util.current_date
|
52
61
|
sign = Digest::MD5.hexdigest("DELETE&#{uri}&#{date}&0&#{@signed_password}")
|
53
|
-
|
54
|
-
@
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
|
63
|
+
@pool.with do |conn|
|
64
|
+
conn.delete do |req|
|
65
|
+
req.url uri
|
66
|
+
req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
|
67
|
+
req.headers['Date'] = date
|
68
|
+
req.headers['Expect'] = ''
|
69
|
+
end
|
59
70
|
end
|
60
71
|
end
|
61
72
|
end
|
data/lib/upyun-rb/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upyun-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: connection_pool
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|