upyun-rb 0.0.17 → 0.0.18

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: c996a66c6930c4daa33dbb9ec0ea018a4206de9e
4
- data.tar.gz: b4a07ad4c4e4f78a5050701728071009c186006c
3
+ metadata.gz: 2635ae3a9f18e342a3e09ab3d30064733b359c78
4
+ data.tar.gz: 355c81c11444068839fde3a601b59c1bf3813c10
5
5
  SHA512:
6
- metadata.gz: 56358ab06793ce64e67bd7dc130e4e4f6d5e01eef000d70a9d1870944eb1bb3aaf94d5ed10091bb8ab7584a1dd975fd0b6477744f8179602bd90fbe26df8ecc3
7
- data.tar.gz: 4692f1f31c41763e6bac355d9dda7687b1db208da5577c9d85b9dc3c96d43b90c2fd5e0ed8a4321903b3c486bbc18d4a8d1c6a555b2650cff56ea03ed198575c
6
+ metadata.gz: 365393dda78bdb64b91294b64908cdc0b78d7c6c27df6334cc85df1eef65e5f88022bd1cd65b460f29e0f0fb1413e483ccf71092d91414645010f1a0d78447c7
7
+ data.tar.gz: 4563c501c4619052e1d1f4cb6885ead158d5d935258dd229edd8bafa913a117cafb2642044d804133a48da04817cdd8608bf15f8986341d72ce0316e10056f31
@@ -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
- @connection = Faraday.new(:url => upyun_host) do |faraday|
11
- faraday.request :url_encoded # form-encode POST params
12
- faraday.response :logger # log requests to STDOUT
13
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
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
- @connection.head do |req|
23
- req.url uri
24
- req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
25
- req.headers['Date'] = date
26
- req.headers['Expect'] = ''
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
- @connection.put do |req|
38
- req.url uri
39
- req.body = Faraday::UploadIO.new(file, mime_type)
40
- req.headers['Mkdir'] = 'true'
41
- req.headers['Content-Type'] = mime_type
42
- req.headers['Content-Length'] = file_size.to_s
43
- req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
44
- req.headers['Date'] = date
45
- req.headers['Expect'] = ''
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
- @connection.delete do |req|
55
- req.url uri
56
- req.headers['Authorization'] = "UpYun #{@operator}:#{sign}"
57
- req.headers['Date'] = date
58
- req.headers['Expect'] = ''
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
@@ -1,3 +1,3 @@
1
1
  module Upyun
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
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.17
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: 2014-04-26 00:00:00.000000000 Z
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