qiniu 6.3.2 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0490995fd65a7c080576f274603413605c3fad33
4
- data.tar.gz: 2c9cfb656b7f522af8f12b6de04b11e7cbc12ce9
3
+ metadata.gz: 904dd3defbe758fc4ee3e823983e417179a91ee8
4
+ data.tar.gz: 5bb0b1ce13cca8bd025424d01a9b13f162d2c391
5
5
  SHA512:
6
- metadata.gz: f7ee45929fd260b772ff70f9629c27bf4e1beb22c323e0c3d3859910397857a2a2773e8ef1835f2e0b9e1b6ccd7aa5ee379f596f52828572057cd1703f33d130
7
- data.tar.gz: 60e62061df61c91562f6be6242df8c15b011a71392fbdc6c1fd7635f60794d901d276cf028b3790e84bca79f2a4d736c83b1727798831ce4246b7bc43a903d2b
6
+ metadata.gz: 2a26f6c5a2ed13eb534e0d43bb0a0ce90be118564143f235b3f9d5c7b55659dba211a596e59a76d85fa07651b2f2cd7eaba9c554fe8fdd21b19e2b1f43ff2eaf
7
+ data.tar.gz: 2e22236452c242c657b2a726eda091fc9a564210b9f52ea2111470b2422bc2a223e561c3548993c430fde0d24791cba6377bf625b1515513ebd309f25a4657dd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v6.4.0
4
+
5
+ - 为 put_with_put_policy() 添加 opts 参数,允许使用 :content_type 键指定上传文件的 mime type。 [https://github.com/qiniu/ruby-sdk/pull/111](https://github.com/qiniu/ruby-sdk/pull/111)
6
+
3
7
  ### v6.3.2
4
8
 
5
9
  - 调整上传host。 [https://github.com/qiniu/ruby-sdk/pull/103](https://github.com/qiniu/ruby-sdk/pull/103)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiniu (6.3.1)
4
+ qiniu (6.4.0)
5
5
  json (~> 1.7)
6
6
  mime-types (~> 1.19)
7
7
  rest-client (~> 1.6)
data/lib/qiniu/config.rb CHANGED
@@ -20,7 +20,8 @@ module Qiniu
20
20
  :content_type => 'application/x-www-form-urlencoded',
21
21
  :auth_url => "https://acc.qbox.me/oauth2/token",
22
22
  :rs_host => "http://rs.qiniu.com",
23
- :up_host => "http://upload.qiniu.com",
23
+ :rsf_host => "http://rsf.qbox.me",
24
+ :up_host => "http://up.qiniu.com",
24
25
  :pub_host => "http://pu.qbox.me:10200",
25
26
  :eu_host => "http://eu.qbox.me",
26
27
  :access_key => "",
@@ -1,10 +1,48 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # vim: sw=2 ts=2
3
3
 
4
+ require 'qiniu/adt'
4
5
  require 'qiniu/http'
5
6
 
6
7
  module Qiniu
7
8
  module Storage
9
+ class ListPolicy
10
+ include ADT::Policy
11
+
12
+ private
13
+ def initialize(bucket,
14
+ limit = 1000,
15
+ prefix = '',
16
+ delimiter = '')
17
+ @bucket = bucket
18
+ @limit = limit
19
+ @prefix = prefix
20
+ @delimiter = delimiter
21
+ end # initialize
22
+
23
+ public
24
+ PARAMS = {
25
+ # 字符串类型参数
26
+ :bucket => "bucket",
27
+ :prefix => "prefix",
28
+ :delimiter => "delimiter",
29
+ :marker => "marker",
30
+
31
+ # 数值类型参数
32
+ :limit => "limit"
33
+ } # PARAMS
34
+
35
+ PARAMS.each_pair do |key, fld|
36
+ attr_accessor key
37
+ end
38
+
39
+ def params
40
+ return PARAMS
41
+ end # params
42
+
43
+ alias :to_s :to_query_string
44
+ end # class ListPolicy
45
+
8
46
  class << self
9
47
  include Utils
10
48
 
@@ -86,6 +124,26 @@ module Qiniu
86
124
  save_as(bucket, key, source_image_url, mogrify_params_string)
87
125
  end # image_mogrify_save_as
88
126
 
127
+ def list(list_policy)
128
+ url = Config.settings[:rsf_host] + '/list?' + list_policy.to_query_string()
129
+
130
+ resp_code, resp_body, resp_headers = HTTP.management_post(url)
131
+ if resp_code == 0 || resp_code > 299 then
132
+ has_more = false
133
+ return resp_code, resp_body, resp_headers, has_more, list_policy
134
+ end
135
+
136
+ has_more = (resp_body['marker'].is_a?(String) && resp_body['marker'] != '')
137
+ if has_more then
138
+ new_list_policy = list_policy.clone()
139
+ new_list_policy.marker = resp_body['marker']
140
+ else
141
+ new_list_policy = list_policy
142
+ end
143
+
144
+ return resp_code, resp_body, resp_headers, has_more, new_list_policy
145
+ end # list
146
+
89
147
  private
90
148
 
91
149
  def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
@@ -102,6 +160,7 @@ module Qiniu
102
160
  url = Config.settings[:rs_host] + "/batch"
103
161
  return HTTP.management_post(url, execs.join("&"))
104
162
  end # _batch_cp_or_mv
105
- end
163
+
164
+ end # class << self
106
165
  end # module Storage
107
166
  end # module Qiniu
data/lib/qiniu/upload.rb CHANGED
@@ -47,15 +47,23 @@ module Qiniu
47
47
  def upload_with_token_2(uptoken,
48
48
  local_file,
49
49
  key = nil,
50
- x_vars = nil)
50
+ x_vars = nil,
51
+ opts = {})
51
52
  ### 构造URL
52
53
  url = Config.settings[:up_host]
53
54
  url[/\/*$/] = ''
54
55
  url += '/'
55
56
 
56
57
  ### 构造HTTP Body
58
+ file = File.new(local_file, 'rb')
59
+ if not opts[:content_type].nil?
60
+ file.define_singleton_method("content_type") do
61
+ opts[:content_type]
62
+ end
63
+ end
64
+
57
65
  post_data = {
58
- :file => File.new(local_file, 'rb'),
66
+ :file => file,
59
67
  :multipart => true,
60
68
  }
61
69
  if not uptoken.nil?
@@ -84,13 +92,14 @@ module Qiniu
84
92
  def upload_with_put_policy(put_policy,
85
93
  local_file,
86
94
  key = nil,
87
- x_vars = nil)
95
+ x_vars = nil,
96
+ opts = {})
88
97
  uptoken = Auth.generate_uptoken(put_policy)
89
98
  if key.nil? then
90
99
  key = put_policy.key
91
100
  end
92
101
 
93
- return upload_with_token_2(uptoken, local_file, key, x_vars)
102
+ return upload_with_token_2(uptoken, local_file, key, x_vars, opts)
94
103
  end # upload_with_put_policy
95
104
 
96
105
  private
data/lib/qiniu/version.rb CHANGED
@@ -3,8 +3,8 @@
3
3
  module Qiniu
4
4
  module Version
5
5
  MAJOR = 6
6
- MINOR = 3
7
- PATCH = 2
6
+ MINOR = 4
7
+ PATCH = 0
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
9
9
  #
10
10
  # Example
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.2
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - why404
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-24 00:00:00.000000000 Z
12
+ date: 2014-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake