qiniu 6.7.0 → 6.8.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: 1a5c78c8aaf5c3fb151d6513187c163c4e1a6c75
4
- data.tar.gz: d1c98abc2d8a13cc26ffb35e6620473ef9889069
3
+ metadata.gz: de7295d2117d781da3393be2970a1fe47fc805e7
4
+ data.tar.gz: effdc4eeb3869a3cac362d6f23196f3b6a22f20a
5
5
  SHA512:
6
- metadata.gz: d1502137ea8b982085cc93c5552d0ca8b69c6103040a5fa82b78b641aec43acc01b05463d8cf63dba5ee18900e9ce3210d08f3185971ccf6cd0f823011145072
7
- data.tar.gz: bbf7e1a9618044b23b99a0e4747261c6e64416e5d5aa325f2951f88d19c3ed9026b6c8ab57aeb9cb828f6f5ee5cf57eaa85917d0ed5e2106e2d414af17cbeebc
6
+ metadata.gz: d6ffe81579309aa77188ead19e97d422176496b1ecb8b32c4d4455d5dbe0b175a7a55ce73112f8fbb0e2338ee6caa3b25a68ae2e3e038f9a1c23fc945cb6e125
7
+ data.tar.gz: 302e9930d19d6ecf33d69a8a77adc457b16cbcb08e0f6a641efe80405f61a3c6fac674c3e76b7702f1574fd475b96976f6d1f39da40a01ab36f2b87359bfa438
@@ -1,5 +1,9 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### v6.8.0
4
+
5
+ - 支持多存储区域,部分 API 需要额外的 bucket 参数。[https://github.com/qiniu/ruby-sdk/pull/161](https://github.com/qiniu/ruby-sdk/pull/161)
6
+
3
7
  ### v6.7.0
4
8
 
5
9
  - 放弃支持过时的 Ruby 1.9、Ruby 2.0 和 JRuby 1.7。[https://github.com/qiniu/ruby-sdk/pull/149](https://github.com/qiniu/ruby-sdk/pull/149)
data/README.md CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
26
26
 
27
- gem 'qiniu', '>= 6.7.0'
27
+ gem 'qiniu', '>= 6.8.0'
28
28
 
29
29
  然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
30
30
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'qiniu'
4
+
5
+ Qiniu.establish_connection! :access_key => 'xxx',
6
+ :secret_key => 'xxx'
7
+
8
+ #需要fetch操作保存到的空间名
9
+ bucket = 'xxx'
10
+ #fetch过来的url,需要外网可以访问到
11
+ target_url = 'url'
12
+ #保存到空间的fetch操作的文件名
13
+ key = 'xxx'
14
+
15
+ #调用fetch方法
16
+ code, result, response_headers = Qiniu::Storage.fetch(
17
+ bucket,
18
+ target_url,
19
+ key
20
+ )
21
+
22
+ #打印返回的状态码以及信息
23
+ puts code
24
+ puts result
25
+ puts response_headers
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'qiniu'
4
+
5
+ Qiniu.establish_connection! :access_key => 'xxxx',
6
+ :secret_key => 'xxxx'
7
+
8
+ #你要测试的list的空间名
9
+ bucket = 'xxxx'
10
+
11
+ #调用list接口,参数可以参考 http://developer.qiniu.com/code/v6/api/kodo-api/rs/list.html#list-specification
12
+ code, result, response_headers, s, d = Qiniu::Storage.list(Qiniu::Storage::ListPolicy.new(
13
+ bucket, # bucket
14
+ 100, # limit
15
+ 'photo/', # prefix
16
+ '' # delimiter
17
+ ))
18
+ #打印出返回的状态码和信息
19
+ puts code
20
+ puts result
21
+ puts response_headers
@@ -16,6 +16,7 @@ module Qiniu
16
16
  autoload :Storage, 'qiniu/storage'
17
17
  autoload :Fop, 'qiniu/fop'
18
18
  autoload :Misc, 'qiniu/misc'
19
+ autoload :HostManager, 'qiniu/host_manager'
19
20
 
20
21
  class << self
21
22
 
@@ -74,7 +74,9 @@ module Qiniu
74
74
  :fsize_limit => "fsizeLimit" ,
75
75
  :callback_fetch_key => "callbackFetchKey" ,
76
76
  :detect_mime => "detectMime" ,
77
- :mime_limit => "mimeLimit"
77
+ :mime_limit => "mimeLimit" ,
78
+ :uphosts => "uphosts" ,
79
+ :global => "global"
78
80
  } # PARAMS
79
81
 
80
82
  public
@@ -91,6 +93,15 @@ module Qiniu
91
93
  # 覆盖语义,文件已存在则直接覆盖
92
94
  @scope = "#{bucket}:#{key}"
93
95
  end
96
+
97
+ if Config.settings[:multi_region]
98
+ begin
99
+ @uphosts = Config.host_manager.up_hosts(bucket)
100
+ @global = Config.host_manager.global(bucket)
101
+ rescue
102
+ # Do nothing
103
+ end
104
+ end
94
105
  end # scope!
95
106
 
96
107
  def expires_in!(seconds)
@@ -20,12 +20,12 @@ 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
- :fetch_host => "http://iovip.qbox.me",
23
+ :fetch_host => nil,
24
24
  :rsf_host => "http://rsf.qbox.me",
25
- :up_host => "http://up.qiniu.com",
25
+ :up_host => nil,
26
26
  :pub_host => "http://pu.qbox.me:10200",
27
27
  :eu_host => "http://eu.qbox.me",
28
- :iovip_host => "http://iovip.qbox.me",
28
+ :uc_host => "http://uc.qbox.me",
29
29
  :access_key => "",
30
30
  :secret_key => "",
31
31
  :auto_reconnect => true,
@@ -33,12 +33,13 @@ module Qiniu
33
33
  :block_size => 1024*1024*4,
34
34
  :chunk_size => 1024*256,
35
35
  :enable_debug => true,
36
- :tmpdir => Dir.tmpdir + File::SEPARATOR + 'QiniuRuby'
36
+ :tmpdir => Dir.tmpdir + File::SEPARATOR + 'QiniuRuby',
37
+ :multi_region => true
37
38
  }
38
39
 
39
- REQUIRED_OPTION_KEYS = [:access_key, :secret_key, :up_host]
40
+ REQUIRED_OPTION_KEYS = [:access_key, :secret_key]
40
41
 
41
- attr_reader :settings, :default_params
42
+ attr_reader :settings, :default_params, :host_manager
42
43
 
43
44
  def load config_file
44
45
  if File.exist?(config_file)
@@ -55,8 +56,17 @@ module Qiniu
55
56
  REQUIRED_OPTION_KEYS.each do |opt|
56
57
  raise MissingArgsError, [opt] unless @settings.has_key?(opt)
57
58
  end
59
+ @host_manager = HostManager.new(@settings)
60
+ nil
58
61
  end
59
62
 
63
+ def up_host(bucket, opts = {})
64
+ @settings[:up_host] || @host_manager.up_host(bucket, opts)
65
+ end
66
+
67
+ def fetch_host(bucket, opts = {})
68
+ @settings[:fetch_host] || @host_manager.fetch_host(bucket, opts)
69
+ end
60
70
  end
61
71
  end # module Config
62
72
  end # module Qiniu
@@ -0,0 +1,104 @@
1
+ require 'thread'
2
+ require 'cgi'
3
+
4
+ module Qiniu
5
+ class BucketIsMissing < RuntimeError; end
6
+
7
+ class HostManager
8
+ def initialize(config)
9
+ @config = config
10
+ @mutex = Mutex.new
11
+ @hosts = {}
12
+ end
13
+
14
+ def up_host(bucket, opts = {})
15
+ if !multi_region_support?
16
+ "#{extract_protocol(opts)}://up.qiniu.com"
17
+ elsif bucket
18
+ hosts(bucket)[extract_protocol(opts)]['up'][0] rescue "#{extract_protocol(opts)}://up.qiniu.com"
19
+ else
20
+ raise BucketIsMissing, 'HostManager#up_host: bucket is required when multi_region is enabled'
21
+ end
22
+ end
23
+
24
+ def fetch_host(bucket, opts = {})
25
+ if !multi_region_support?
26
+ "#{extract_protocol(opts)}://iovip.qbox.me"
27
+ elsif bucket
28
+ hosts(bucket)[extract_protocol(opts)]['io'][0] rescue "#{extract_protocol(opts)}://iovip.qbox.me"
29
+ else
30
+ raise BucketIsMissing, 'HostManager#fetch_host: bucket is required when multi_region is enabled'
31
+ end
32
+ end
33
+
34
+ def up_hosts(bucket, opts = {})
35
+ if multi_region_support?
36
+ hosts(bucket)[extract_protocol(opts)]['up']
37
+ else
38
+ raise 'HostManager#up_hosts: multi_region must be enabled'
39
+ end
40
+ end
41
+
42
+ def global(bucket, opts = {})
43
+ if multi_region_support?
44
+ !!hosts(bucket)['global']
45
+ else
46
+ raise 'HostManager#global: multi_region must be enabled'
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def extract_protocol(opts)
53
+ opts[:protocol] || 'http'
54
+ end
55
+
56
+ def multi_region_support?
57
+ @config[:multi_region]
58
+ end
59
+
60
+ def hosts(bucket)
61
+ host = read_host(bucket)
62
+ if host
63
+ if host_expired?(host)
64
+ delete_host(bucket)
65
+ else
66
+ return host
67
+ end
68
+ end
69
+ url = @config[:uc_host] + '/v1/query?' + HTTP.generate_query_string(ak: @config[:access_key], bucket: bucket)
70
+ status, body = HTTP.api_get(url)
71
+ if HTTP.is_response_ok?(status)
72
+ Utils.debug("Query #{bucket} hosts Success: #{body}")
73
+ host = body.merge(:time => Time.now)
74
+ write_host(bucket, host)
75
+ host
76
+ else
77
+ Utils.debug("Query #{bucket} hosts Error: #{body}")
78
+ raise "Host query is failed"
79
+ end
80
+ end
81
+
82
+ def host_expired?(host)
83
+ host[:time] + host['ttl'] < Time.now
84
+ end
85
+
86
+ def read_host(bucket)
87
+ @mutex.synchronize do
88
+ @hosts[bucket]
89
+ end
90
+ end
91
+
92
+ def write_host(bucket, host)
93
+ @mutex.synchronize do
94
+ @hosts[bucket] = host
95
+ end
96
+ end
97
+
98
+ def delete_host(bucket)
99
+ @mutex.synchronize do
100
+ @hosts.delete(bucket)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -83,7 +83,7 @@ module Qiniu
83
83
  end # delete
84
84
 
85
85
  def fetch(bucket, target_url, key)
86
- url = Config.settings[:fetch_host] + '/fetch/' + Utils.urlsafe_base64_encode(target_url) + '/to/' + encode_entry_uri(bucket, key)
86
+ url = Config.fetch_host(bucket) + '/fetch/' + Utils.urlsafe_base64_encode(target_url) + '/to/' + encode_entry_uri(bucket, key)
87
87
  return HTTP.management_post(url)
88
88
  end # fetch
89
89
 
@@ -149,11 +149,6 @@ module Qiniu
149
149
  return resp_code, resp_body, resp_headers, has_more, new_list_policy
150
150
  end # list
151
151
 
152
- def fetch(url, bucket, key)
153
- api_url = Config.settings[:iovip_host] + '/fetch/' + Utils.urlsafe_base64_encode(url) + '/to/' + Utils.urlsafe_base64_encode("#{bucket}:#{key}")
154
- return HTTP.management_post(api_url)
155
- end # fetch
156
-
157
152
  private
158
153
 
159
154
  def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
@@ -103,7 +103,7 @@ module Qiniu
103
103
  }
104
104
  }
105
105
  if !content_type.nil? && !content_type.empty? then
106
- options[:headers][:content_type] = content_type
106
+ options[:headers][:content_type] = content_type
107
107
  end
108
108
 
109
109
  code, data, raw_headers = HTTP.api_post(url, data, options)
@@ -116,8 +116,8 @@ module Qiniu
116
116
  return code, data, raw_headers
117
117
  end # _call_binary_with_token
118
118
 
119
- def _mkblock(uptoken, block_size, body)
120
- url = Config.settings[:up_host] + "/mkblk/#{block_size}"
119
+ def _mkblock(bucket, uptoken, block_size, body)
120
+ url = Config.up_host(bucket) + "/mkblk/#{block_size}"
121
121
  _call_binary_with_token(uptoken, url, body)
122
122
  end # _mkblock
123
123
 
@@ -126,7 +126,8 @@ module Qiniu
126
126
  _call_binary_with_token(uptoken, url, body)
127
127
  end # _putblock
128
128
 
129
- def _resumable_put_block(uptoken,
129
+ def _resumable_put_block(bucket,
130
+ uptoken,
130
131
  fh,
131
132
  block_index,
132
133
  block_size,
@@ -151,7 +152,7 @@ module Qiniu
151
152
  raise FileSeekReadError.new(fpath, block_index, seek_pos, body_length, result_length)
152
153
  end
153
154
 
154
- code, data, raw_headers = _mkblock(uptoken, block_size, body)
155
+ code, data, raw_headers = _mkblock(bucket, uptoken, block_size, body)
155
156
  Utils.debug "Mkblk : #{code.inspect} #{data.inspect} #{raw_headers.inspect}"
156
157
 
157
158
  body_crc32 = Zlib.crc32(body)
@@ -214,7 +215,8 @@ module Qiniu
214
215
  ((fsize + Config.settings[:block_size] - 1) / Config.settings[:block_size]).to_i
215
216
  end # _block_count
216
217
 
217
- def _resumable_put(uptoken,
218
+ def _resumable_put(bucket,
219
+ uptoken,
218
220
  fh,
219
221
  checksums,
220
222
  progresses,
@@ -239,7 +241,7 @@ module Qiniu
239
241
  end
240
242
  #code, data = _resumable_put_block(uptoken, fh, block_index, block_size, Config.settings[:chunk_size], progresses[block_index], Config.settings[:max_retry_times], chunk_notifier)
241
243
  # Put the whole block as a chunk
242
- code, data = _resumable_put_block(uptoken, fh, block_index, block_size, block_size, progresses[block_index], Config.settings[:max_retry_times], chunk_notifier)
244
+ code, data = _resumable_put_block(bucket, uptoken, fh, block_index, block_size, block_size, progresses[block_index], Config.settings[:max_retry_times], chunk_notifier)
243
245
  if HTTP.is_response_ok?(code)
244
246
  #checksums[block_index] = data["checksum"]
245
247
  checksums[block_index] = data["ctx"]
@@ -299,7 +301,7 @@ module Qiniu
299
301
  checksums = []
300
302
  block_count.times{checksums << ''}
301
303
 
302
- code, data, raw_headers = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
304
+ code, data, raw_headers = _resumable_put(bucket, uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
303
305
 
304
306
  if HTTP.is_response_ok?(code)
305
307
  uphost = data["host"]
@@ -32,7 +32,7 @@ module Qiniu
32
32
  end
33
33
  callback_query_string = HTTP.generate_query_string(callback_params)
34
34
 
35
- url = Config.settings[:up_host] + '/upload'
35
+ url = Config.up_host(bucket) + '/upload'
36
36
  post_data = {
37
37
  :params => callback_query_string,
38
38
  :action => action_params,
@@ -52,7 +52,7 @@ module Qiniu
52
52
  x_vars = nil,
53
53
  opts = {})
54
54
  ### 构造URL
55
- url = Config.settings[:up_host]
55
+ url = Config.up_host(opts[:bucket])
56
56
  url[/\/*$/] = ''
57
57
  url += '/'
58
58
 
@@ -80,6 +80,8 @@ module Qiniu
80
80
 
81
81
  ### 发送请求
82
82
  HTTP.api_post(url, post_data)
83
+ rescue BucketIsMissing
84
+ raise 'upload_with_token_2 requires :bucket option when multi_region is enabled'
83
85
  end # upload_with_token_2
84
86
 
85
87
  def upload_buffer_with_token(uptoken,
@@ -88,7 +90,7 @@ module Qiniu
88
90
  x_vars = nil,
89
91
  opts = {})
90
92
  ### 构造 URL
91
- url = Config.settings[:up_host]
93
+ url = Config.up_host(opts[:bucket])
92
94
  url[/\/*$/] = ''
93
95
  url += '/'
94
96
 
@@ -125,6 +127,8 @@ module Qiniu
125
127
 
126
128
  ### 发送请求
127
129
  HTTP.api_post(url, post_data)
130
+ rescue BucketIsMissing
131
+ raise 'upload_buffer_with_token requires :bucket option when multi_region is enabled'
128
132
  end # upload_with_token_2
129
133
 
130
134
  ### 授权举例
@@ -147,6 +151,8 @@ module Qiniu
147
151
  end
148
152
 
149
153
  return upload_with_token_2(uptoken, local_file, key, x_vars, opts)
154
+ rescue BucketIsMissing
155
+ raise 'upload_with_put_policy requires :bucket option when multi_region is enabled'
150
156
  end # upload_with_put_policy
151
157
 
152
158
  def upload_buffer_with_put_policy(put_policy,
@@ -160,6 +166,8 @@ module Qiniu
160
166
  end
161
167
 
162
168
  return upload_buffer_with_token(uptoken, buf, key, x_vars, opts)
169
+ rescue BucketIsMissing
170
+ raise 'upload_buffer_with_put_policy requires :bucket option when multi_region is enabled'
163
171
  end # upload_buffer_with_put_policy
164
172
 
165
173
  private
@@ -3,7 +3,7 @@
3
3
  module Qiniu
4
4
  module Version
5
5
  MAJOR = 6
6
- MINOR = 7
6
+ MINOR = 8
7
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
  #
@@ -29,7 +29,10 @@ module Qiniu
29
29
  pp = Auth::PutPolicy.new(@bucket, key)
30
30
  code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
31
31
  pp,
32
- __FILE__
32
+ __FILE__,
33
+ nil,
34
+ nil,
35
+ bucket: @bucket
33
36
  )
34
37
  code.should == 200
35
38
  puts data.inspect
@@ -68,6 +71,24 @@ module Qiniu
68
71
  code.should == 200
69
72
  puts data.inspect
70
73
  end
74
+
75
+ it "should generate uphosts and global for multi_region" do
76
+ origin_multi_region = Config.settings[:multi_region]
77
+ begin
78
+ Config.settings[:multi_region] = true
79
+ ### 生成Key
80
+ key = 'a_private_file'
81
+ key = make_unique_key_in_bucket(key)
82
+ puts "key=#{key}"
83
+
84
+ ### 生成 PutPolicy
85
+ pp = Auth::PutPolicy.new(@bucket, key)
86
+ expect(pp.instance_variable_get(:@uphosts)).to eq ["http://up.qiniu.com", "http://upload.qiniu.com", "-H up.qiniu.com http://183.136.139.16"]
87
+ expect(pp.instance_variable_get(:@global)).to be false
88
+ ensure
89
+ Config.settings[:multi_region] = origin_multi_region
90
+ end
91
+ end
71
92
  end
72
93
  end
73
94
 
@@ -9,31 +9,22 @@ require 'qiniu'
9
9
 
10
10
  module Qiniu
11
11
  module Storage
12
- describe Storage do
13
-
12
+ shared_examples "Management Specs" do
14
13
  before :all do
15
- @bucket = 'rubysdk'
16
-
17
14
  @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
18
15
  @key = make_unique_key_in_bucket(@key)
19
16
 
20
17
  @key2 = @key + rand(100).to_s
21
- end
22
18
 
23
- after :all do
24
- end
25
-
26
- ### 准备数据
27
- context ".prepare_file" do
28
- it "should works" do
29
- pp = Auth::PutPolicy.new(@bucket, @key)
30
- code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
31
- pp,
32
- __FILE__
33
- )
34
- code.should == 200
35
- puts data.inspect
36
- end
19
+ pp = Auth::PutPolicy.new(@bucket, @key)
20
+ code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
21
+ pp,
22
+ __FILE__,
23
+ nil,
24
+ nil,
25
+ bucket: @bucket
26
+ )
27
+ code.should == 200
37
28
  end
38
29
 
39
30
  ### 列举Bucket
@@ -48,103 +39,136 @@ module Qiniu
48
39
  context ".stat" do
49
40
  it "should works" do
50
41
  code, data = Storage.stat(@bucket, @key)
51
- code.should == 200
52
42
  puts data.inspect
43
+ code.should == 200
53
44
  end
54
45
  end
55
46
 
56
47
  context ".get" do
57
48
  it "should works" do
58
49
  code, data = Storage.get(@bucket, @key)
59
- code.should == 200
60
50
  puts data.inspect
51
+ code.should == 200
61
52
  end
62
53
  end
63
54
 
64
55
  context ".batch" do
65
56
  it "should works" do
66
57
  code, data = Storage.batch("stat", @bucket, [@key])
67
- code.should == 200
68
58
  puts data.inspect
59
+ code.should == 200
69
60
  end
70
61
  end
71
62
 
72
63
  context ".batch_stat" do
73
64
  it "should works" do
74
65
  code, data = Storage.batch_stat(@bucket, [@key])
75
- code.should == 200
76
66
  puts data.inspect
67
+ code.should == 200
77
68
  end
78
69
  end
79
70
 
80
71
  context ".batch_get" do
81
72
  it "should works" do
82
73
  code, data = Storage.batch_get(@bucket, [@key])
83
- code.should == 200
84
74
  puts data.inspect
75
+ code.should == 200
85
76
  end
86
77
  end
87
78
 
88
79
  context ".batch_copy" do
89
80
  it "should works" do
90
81
  code, data = Storage.batch_copy @bucket, @key, @bucket, @key2
91
- code.should == 200
92
82
  puts data.inspect
83
+ code.should == 200
93
84
 
94
85
  code, data = Storage.delete @bucket, @key2
95
- code.should == 200
96
86
  puts data.inspect
87
+ code.should == 200
97
88
  end
98
89
  end
99
90
 
100
91
  context ".batch_move" do
101
92
  it "should works" do
102
93
  code, data = Storage.batch_move [@bucket, @key, @bucket, @key2]
103
- code.should == 200
104
94
  puts data.inspect
95
+ code.should == 200
105
96
 
106
97
  code3, data3 = Storage.batch_move [@bucket, @key2, @bucket, @key]
107
- code3.should == 200
108
98
  puts data3.inspect
99
+ code3.should == 200
109
100
  end
110
101
  end
111
102
 
112
103
  context ".move" do
113
104
  it "should works" do
114
105
  code, data = Storage.move(@bucket, @key, @bucket, @key2)
115
- code.should == 200
116
106
  puts data.inspect
107
+ code.should == 200
117
108
 
118
109
  code2, data2 = Storage.stat(@bucket, @key2)
119
- code2.should == 200
120
110
  puts data2.inspect
111
+ code2.should == 200
121
112
 
122
113
  code3, data3 = Storage.move(@bucket, @key2, @bucket, @key)
123
- code3.should == 200
124
114
  puts data3.inspect
115
+ code3.should == 200
125
116
  end
126
117
  end
127
118
 
128
119
  context ".copy" do
129
120
  it "should works" do
130
121
  code, data = Storage.copy(@bucket, @key, @bucket, @key2)
131
- code.should == 200
132
122
  puts data.inspect
123
+ code.should == 200
133
124
 
134
125
  code, data = Storage.delete(@bucket, @key2)
135
- code.should == 200
136
126
  puts data.inspect
127
+ code.should == 200
137
128
  end
138
129
  end
139
130
 
140
131
  context ".delete" do
141
132
  it "should works" do
142
133
  code, data = Storage.delete(@bucket, @key)
134
+ puts data.inspect
135
+ code.should == 200
136
+ end
137
+ end
138
+
139
+ context ".fetch" do
140
+ it "should works" do
141
+ code, data = Qiniu::Storage.fetch(@bucket, "https://www.baidu.com/robots.txt", @key)
143
142
  code.should == 200
144
143
  puts data.inspect
145
144
  end
146
145
  end
146
+ end
147
147
 
148
+ describe 'When multi_region is disabled' do
149
+ before :all do
150
+ Config.settings[:multi_region] = false
151
+ @bucket = 'rubysdk'
152
+ end
153
+ include_examples 'Management Specs'
154
+ end
155
+
156
+ describe 'When multi_region is enabled' do
157
+ describe 'for z0 bucket' do
158
+ before :all do
159
+ Config.settings[:multi_region] = true
160
+ @bucket = 'rubysdk'
161
+ end
162
+ include_examples 'Management Specs'
163
+ end
164
+
165
+ describe 'for z1 bucket' do
166
+ before :all do
167
+ Config.settings[:multi_region] = true
168
+ @bucket = 'rubysdk-bc'
169
+ end
170
+ include_examples 'Management Specs'
171
+ end
148
172
  end
149
173
  end # module Storage
150
174
  end # module Qiniu
@@ -8,11 +8,8 @@ require 'digest/sha1'
8
8
 
9
9
  module Qiniu
10
10
  module Storage
11
- describe Storage do
12
-
11
+ shared_examples "Upload Specs" do
13
12
  before :all do
14
- @bucket = 'rubysdk'
15
-
16
13
  @key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
17
14
  @key = make_unique_key_in_bucket(@key)
18
15
  puts "key=#{@key}"
@@ -52,6 +49,12 @@ module Qiniu
52
49
 
53
50
  ### 测试单文件直传
54
51
  context ".upload_with_token" do
52
+ after do
53
+ code, data = Qiniu::Storage.delete(@bucket, @key)
54
+ puts data.inspect
55
+ code.should == 200
56
+ end
57
+
55
58
  it "should works" do
56
59
  upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
57
60
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -68,26 +71,20 @@ module Qiniu
68
71
  code.should == 200
69
72
  puts data.inspect
70
73
  puts raw_headers.inspect
71
- end
72
- end
73
74
 
74
- context ".stat" do
75
- it "should exists" do
76
75
  code, data = Qiniu::Storage.stat(@bucket, @key)
77
76
  puts data.inspect
78
77
  code.should == 200
79
78
  end
80
79
  end
81
80
 
82
- context ".delete" do
83
- it "should works" do
81
+ context ".upload_with_token_2" do
82
+ after do
84
83
  code, data = Qiniu::Storage.delete(@bucket, @key)
85
84
  puts data.inspect
86
85
  code.should == 200
87
86
  end
88
- end
89
87
 
90
- context ".upload_with_token_2" do
91
88
  it "should works" do
92
89
  upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
93
90
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -95,32 +92,28 @@ module Qiniu
95
92
  code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
96
93
  uptoken,
97
94
  __FILE__,
98
- @key
95
+ @key,
96
+ nil,
97
+ bucket: @bucket
99
98
  )
100
99
 
101
100
  code.should == 200
102
101
  puts data.inspect
103
102
  puts raw_headers.inspect
104
- end
105
- end # .upload_with_token_2
106
103
 
107
- context ".stat" do
108
- it "should exists" do
109
104
  code, data = Qiniu::Storage.stat(@bucket, @key)
110
105
  puts data.inspect
111
106
  code.should == 200
112
107
  end
113
- end
108
+ end # .upload_with_token_2
114
109
 
115
- context ".delete" do
116
- it "should works" do
110
+ context ".upload_with_put_policy" do
111
+ after do
117
112
  code, data = Qiniu::Storage.delete(@bucket, @key)
118
113
  puts data.inspect
119
114
  code.should == 200
120
115
  end
121
- end
122
116
 
123
- context ".upload_with_put_policy" do
124
117
  it "should works" do
125
118
  pp = Qiniu::Auth::PutPolicy.new(@bucket, @key)
126
119
  pp.end_user = "why404@gmail.com"
@@ -129,7 +122,9 @@ module Qiniu
129
122
  code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
130
123
  pp,
131
124
  __FILE__,
132
- @key + '-not-equal'
125
+ @key + '-not-equal',
126
+ nil,
127
+ bucket: @bucket
133
128
  )
134
129
  code.should_not == 200
135
130
  puts data.inspect
@@ -138,16 +133,28 @@ module Qiniu
138
133
  code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
139
134
  pp,
140
135
  __FILE__,
141
- @key
136
+ @key,
137
+ nil,
138
+ bucket: @bucket
142
139
  )
143
140
 
144
141
  code.should == 200
145
142
  puts data.inspect
146
143
  puts raw_headers.inspect
144
+
145
+ code, data = Qiniu::Storage.stat(@bucket, @key)
146
+ puts data.inspect
147
+ code.should == 200
147
148
  end
148
149
  end # .upload_with_put_policy
149
150
 
150
151
  context ".upload_buffer_with_put_policy" do
152
+ after do
153
+ code, data = Qiniu::Storage.delete(@bucket, @key)
154
+ puts data.inspect
155
+ code.should == 200
156
+ end
157
+
151
158
  it "should works" do
152
159
  pp = Qiniu::Auth::PutPolicy.new(@bucket, @key)
153
160
  pp.end_user = "amethyst.black@gmail.com"
@@ -157,32 +164,28 @@ module Qiniu
157
164
  code, data, raw_headers = Qiniu::Storage.upload_buffer_with_put_policy(
158
165
  pp,
159
166
  test_line,
160
- @key
167
+ @key,
168
+ nil,
169
+ bucket: @bucket
161
170
  )
162
171
  code.should == 200
163
172
  puts data.inspect
164
173
  puts raw_headers.inspect
165
- end
166
- end # .upload_buffer_with_put_policy
167
174
 
168
- context ".stat" do
169
- it "should exists" do
170
175
  code, data = Qiniu::Storage.stat(@bucket, @key)
171
176
  puts data.inspect
172
177
  code.should == 200
173
178
  end
174
- end
179
+ end # .upload_buffer_with_put_policy
175
180
 
176
- context ".delete" do
177
- it "should works" do
178
- code, data = Qiniu::Storage.delete(@bucket, @key)
181
+ ### 测试断点续上传
182
+ context ".resumable_upload_with_token" do
183
+ after do
184
+ code, data = Qiniu::Storage.delete(@bucket, @key_5m)
179
185
  puts data.inspect
180
186
  code.should == 200
181
187
  end
182
- end
183
188
 
184
- ### 测试断点续上传
185
- context ".resumable_upload_with_token" do
186
189
  it "should works" do
187
190
  upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
188
191
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -196,26 +199,20 @@ module Qiniu
196
199
  puts data.inspect
197
200
  puts raw_headers.inspect
198
201
  puts "key_5m=#{@key_5m}"
199
- end
200
- end
201
202
 
202
- context ".stat" do
203
- it "should exists" do
204
203
  code, data = Qiniu::Storage.stat(@bucket, @key_5m)
205
204
  puts data.inspect
206
205
  code.should == 200
207
206
  end
208
207
  end
209
208
 
210
- context ".delete" do
211
- it "should works" do
212
- code, data = Qiniu::Storage.delete(@bucket, @key_5m)
209
+ context ".resumable_upload_with_token2" do
210
+ after do
211
+ code, data = Qiniu::Storage.delete(@bucket, @key_4m)
213
212
  puts data.inspect
214
213
  code.should == 200
215
214
  end
216
- end
217
215
 
218
- context ".resumable_upload_with_token2" do
219
216
  it "should works" do
220
217
  upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
221
218
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -229,26 +226,20 @@ module Qiniu
229
226
  puts data.inspect
230
227
  puts raw_headers.inspect
231
228
  puts "key_4m=#{@key_4m}"
232
- end
233
- end
234
229
 
235
- context ".stat" do
236
- it "should exists" do
237
230
  code, data = Qiniu::Storage.stat(@bucket, @key_4m)
238
231
  puts data.inspect
239
232
  code.should == 200
240
233
  end
241
234
  end
242
235
 
243
- context ".delete" do
244
- it "should works" do
245
- code, data = Qiniu::Storage.delete(@bucket, @key_4m)
236
+ context ".resumable_upload_with_token3" do
237
+ after do
238
+ code, data = Qiniu::Storage.delete(@bucket, @key_8m)
246
239
  puts data.inspect
247
240
  code.should == 200
248
241
  end
249
- end
250
242
 
251
- context ".resumable_upload_with_token3" do
252
243
  it "should works" do
253
244
  upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
254
245
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -262,26 +253,20 @@ module Qiniu
262
253
  puts data.inspect
263
254
  puts raw_headers.inspect
264
255
  puts "key_8m=#{@key_8m}"
265
- end
266
- end
267
256
 
268
- context ".stat" do
269
- it "should exists" do
270
257
  code, data = Qiniu::Storage.stat(@bucket, @key_8m)
271
258
  puts data.inspect
272
259
  code.should == 200
273
260
  end
274
261
  end
275
262
 
276
- context ".delete" do
277
- it "should works" do
278
- code, data = Qiniu::Storage.delete(@bucket, @key_8m)
263
+ context ".resumable_upload_with_token4" do
264
+ after do
265
+ code, data = Qiniu::Storage.delete(@bucket, @key_1m)
279
266
  puts data.inspect
280
267
  code.should == 200
281
268
  end
282
- end
283
269
 
284
- context ".resumable_upload_with_token4" do
285
270
  it "should works" do
286
271
  upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
287
272
  uptoken = Qiniu.generate_upload_token(upopts)
@@ -295,25 +280,51 @@ module Qiniu
295
280
  puts data.inspect
296
281
  puts raw_headers.inspect
297
282
  puts "key_1m=#{@key_1m}"
298
- end
299
- end
300
283
 
301
- context ".stat" do
302
- it "should exists" do
303
284
  code, data = Qiniu::Storage.stat(@bucket, @key_1m)
304
285
  puts data.inspect
305
286
  code.should == 200
306
287
  end
307
288
  end
289
+ end
308
290
 
309
- context ".delete" do
310
- it "should works" do
311
- code, data = Qiniu::Storage.delete(@bucket, @key_1m)
312
- puts data.inspect
313
- code.should == 200
291
+ describe 'When multi_region is disabled' do
292
+ before :all do
293
+ Config.settings[:multi_region] = false
294
+ @bucket = 'rubysdk'
295
+ end
296
+ include_examples 'Upload Specs'
297
+ end
298
+
299
+ describe 'When multi_region is enabled' do
300
+ describe 'for z0 bucket' do
301
+ before :all do
302
+ Config.settings[:multi_region] = true
303
+ @bucket = 'rubysdk'
314
304
  end
305
+ include_examples 'Upload Specs'
315
306
  end
316
307
 
308
+ describe 'for z1 bucket' do
309
+ before :all do
310
+ Config.settings[:multi_region] = true
311
+ @bucket = 'rubysdk-bc'
312
+ end
313
+ include_examples 'Upload Specs'
314
+
315
+ it 'should raise BucketIsMissing error' do
316
+ upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
317
+ uptoken = Qiniu.generate_upload_token(upopts)
318
+
319
+ expect do
320
+ Qiniu::Storage.upload_with_token_2(
321
+ uptoken,
322
+ __FILE__,
323
+ @key,
324
+ )
325
+ end.to raise_error('upload_with_token_2 requires :bucket option when multi_region is enabled')
326
+ end
327
+ end
317
328
  end
318
329
  end # module Storage
319
330
  end # module Qiniu
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.7.0
4
+ version: 6.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - why404
@@ -9,104 +9,104 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-19 00:00:00.000000000 Z
12
+ date: 2016-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0.9'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.9'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '2.11'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.11'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: fakeweb
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.3'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: json
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1.8'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.8'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rest-client
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.8.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.8.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: mime-types
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: 2.4.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: 2.4.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: ruby-hmac
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ~>
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0.4'
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ~>
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.4'
112
112
  description: 'Qiniu Resource (Cloud) Storage SDK for Ruby. See: http://developer.qiniu.com/docs/v6/sdk/ruby-sdk.html'
@@ -116,9 +116,9 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - .gitignore
120
- - .rspec
121
- - .travis.yml
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
122
  - CHANGELOG.md
123
123
  - Gemfile
124
124
  - LICENSE
@@ -128,7 +128,9 @@ files:
128
128
  - examples/copy.rb
129
129
  - examples/delete.rb
130
130
  - examples/download.rb
131
+ - examples/fetch.rb
131
132
  - examples/fops.rb
133
+ - examples/list.rb
132
134
  - examples/move.rb
133
135
  - examples/stat.rb
134
136
  - examples/upload.rb
@@ -142,6 +144,7 @@ files:
142
144
  - lib/qiniu/config.rb
143
145
  - lib/qiniu/exceptions.rb
144
146
  - lib/qiniu/fop.rb
147
+ - lib/qiniu/host_manager.rb
145
148
  - lib/qiniu/http.rb
146
149
  - lib/qiniu/image.rb
147
150
  - lib/qiniu/log.rb
@@ -183,17 +186,17 @@ require_paths:
183
186
  - lib
184
187
  required_ruby_version: !ruby/object:Gem::Requirement
185
188
  requirements:
186
- - - '>='
189
+ - - ">="
187
190
  - !ruby/object:Gem::Version
188
191
  version: '0'
189
192
  required_rubygems_version: !ruby/object:Gem::Requirement
190
193
  requirements:
191
- - - '>='
194
+ - - ">="
192
195
  - !ruby/object:Gem::Version
193
196
  version: '0'
194
197
  requirements: []
195
198
  rubyforge_project:
196
- rubygems_version: 2.0.14.1
199
+ rubygems_version: 2.5.1
197
200
  signing_key:
198
201
  specification_version: 4
199
202
  summary: Qiniu Resource (Cloud) Storage SDK for Ruby