qiniu 6.5.1 → 6.6.0

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: 4183bac23fa834f48579fbc1b8d05a8218ada08b
4
- data.tar.gz: 62ff9f7fb37c1acb45d03b37c72c13d6c5073d67
3
+ metadata.gz: 6156890d8118959d78f316edf9c7de45fd66affe
4
+ data.tar.gz: b4750d7adf8b61b924af905c4fe91757e468cf97
5
5
  SHA512:
6
- metadata.gz: c417b92d7a4a06508a9db2be71a9049843fdcb4730854e3e47b0bddccc0c246c4301504bc5acc7745402f07e5452f5639d9d4d8604a45e8e54e2e8d156fa29a6
7
- data.tar.gz: b30fde59f5ff8711b0f8c76c5ee1b8db8539798ac5da75907fc77302a0cdc49a8accbb779ed46fa050711fde471d81a95709a512c7c53a6d22072ed237517661
6
+ metadata.gz: 49ce22e5fdc92699eb5eed74f9c6c19db50896370c2704251bfb4aa8dd8dd65a575d6c64fe8dbcddbe37560cc29f7b8ba44697f5d531412767c5fec1c119acae
7
+ data.tar.gz: 5d2df9eb2a1533d9fbf07cc16339779699b9f24f6a00c9a0a2b598206082d9ec742b2eacaa42cb268380f22dd4b064201c9067c2c825588a1c73d41375862e6e
@@ -1,5 +1,13 @@
1
1
  ## CHANGE LOG
2
2
 
3
+ ### V6.6.0
4
+
5
+ - 添加 upload_buffer_with_put_policy() 方法,直接上传一块数据作为文件内容。[https://github.com/qiniu/ruby-sdk/pull/146](https://github.com/qiniu/ruby-sdk/pull/146)
6
+
7
+ ### V6.5.2
8
+
9
+ - 修正无法触发加载异常类的问题;修正 batch_move 参数未正确打包的问题。[https://github.com/qiniu/ruby-sdk/pull/142](https://github.com/qiniu/ruby-sdk/pull/142)
10
+
3
11
  ### V6.5.1
4
12
 
5
13
  - 为 Qiniu::Auth 添加验证七牛回调请求签名合法性的函数。[https://github.com/qiniu/ruby-sdk/pull/133](https://github.com/qiniu/ruby-sdk/pull/133)
@@ -4,7 +4,7 @@ PATH
4
4
  qiniu (6.5.1)
5
5
  json (~> 1.8)
6
6
  mime-types (~> 1.19)
7
- rest-client (~> 1.7.3)
7
+ rest-client (~> 1.8.0)
8
8
  ruby-hmac (~> 0.4)
9
9
 
10
10
  GEM
@@ -16,7 +16,8 @@ GEM
16
16
  mime-types (1.25.1)
17
17
  netrc (0.10.3)
18
18
  rake (10.4.2)
19
- rest-client (1.7.3)
19
+ rest-client (1.8.0)
20
+ http-cookie (>= 1.0.2, < 2.0)
20
21
  mime-types (>= 1.16, < 3.0)
21
22
  netrc (~> 0.7)
22
23
  rspec (3.2.0)
data/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
17
17
 
18
- gem 'qiniu', '~> 6.4.1'
18
+ gem 'qiniu', '=> 6.4.1', '<= 6.6.0'
19
19
 
20
20
  然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
21
21
 
@@ -25,6 +25,14 @@
25
25
 
26
26
  $ gem install qiniu
27
27
 
28
+ ## Rails 4 项目安装
29
+
30
+ 在 Rails 4 项目的 `Gemfile` 里添加 `qiniu` 后执行 `bundle` 命令可能会失败,这是因为 Rails 4 项目默认会使用 `mime-types` 3.x 版本。需要使用以下命令将 `mime-types` 降级为满足 Qiniu Ruby SDK 的 2.6.x 版本。
31
+
32
+ bundle update mime-types
33
+
34
+ 由于 `mime-types` 3.0 要求的最低 Ruby 版本是 2.0,而 Qiniu Ruby SDK 支持 Ruby 1.9,因此我们不能通过简单修改对 `mime-types` 的版本依赖来解决此问题。
35
+
28
36
  ## 使用
29
37
 
30
38
  参考文档:[七牛云存储 Ruby SDK 使用指南](http://developer.qiniu.com/docs/v6/sdk/ruby-sdk.html)
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require 'qiniu/exceptions'
4
+
3
5
  module Qiniu
4
6
  autoload :Version, 'qiniu/version'
5
7
  autoload :Utils, 'qiniu/utils'
6
8
  autoload :Auth, 'qiniu/auth'
7
9
  autoload :Config, 'qiniu/config'
8
10
  autoload :Log, 'qiniu/log'
9
- autoload :Exception, 'qiniu/exceptions'
10
11
  autoload :AccessToken, 'qiniu/tokens/access_token'
11
12
  autoload :QboxToken, 'qiniu/tokens/qbox_token'
12
13
  autoload :UploadToken, 'qiniu/tokens/upload_token'
@@ -117,6 +118,11 @@ module Qiniu
117
118
  code == StatusOK
118
119
  end
119
120
 
121
+ def fetch(bucket, target_url, key)
122
+ code, data = Storage.fetch(bucket, target_url, key)
123
+ code == StatusOK
124
+ end
125
+
120
126
  def batch(command, bucket, keys)
121
127
  code, data = Storage.batch(command, bucket, keys)
122
128
  code == StatusOK ? data : false
@@ -20,10 +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
24
  :rsf_host => "http://rsf.qbox.me",
24
25
  :up_host => "http://up.qiniu.com",
25
26
  :pub_host => "http://pu.qbox.me:10200",
26
27
  :eu_host => "http://eu.qbox.me",
28
+ :iovip_host => "http://iovip.qbox.me",
27
29
  :access_key => "",
28
30
  :secret_key => "",
29
31
  :auto_reconnect => true,
@@ -82,6 +82,11 @@ module Qiniu
82
82
  return HTTP.management_post(url)
83
83
  end # delete
84
84
 
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)
87
+ return HTTP.management_post(url)
88
+ end # fetch
89
+
85
90
  def batch(command, bucket, keys)
86
91
  execs = []
87
92
  keys.each do |key|
@@ -105,7 +110,7 @@ module Qiniu
105
110
  end # batch_copy
106
111
 
107
112
  def batch_move(*args)
108
- _batch_cp_or_mv('move', args)
113
+ _batch_cp_or_mv('move', *args)
109
114
  end # batch_move
110
115
 
111
116
  def batch_delete(bucket, keys)
@@ -144,6 +149,11 @@ module Qiniu
144
149
  return resp_code, resp_body, resp_headers, has_more, new_list_policy
145
150
  end # list
146
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
+
147
157
  private
148
158
 
149
159
  def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
@@ -1,6 +1,8 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # vim: sw=2 ts=2
3
3
 
4
+ require 'stringio'
5
+
4
6
  module Qiniu
5
7
  module Storage
6
8
  class << self
@@ -80,6 +82,51 @@ module Qiniu
80
82
  HTTP.api_post(url, post_data)
81
83
  end # upload_with_token_2
82
84
 
85
+ def upload_buffer_with_token(uptoken,
86
+ buf,
87
+ key = nil,
88
+ x_vars = nil,
89
+ opts = {})
90
+ ### 构造 URL
91
+ url = Config.settings[:up_host]
92
+ url[/\/*$/] = ''
93
+ url += '/'
94
+
95
+ ### 构造 HTTP Body
96
+ if buf.is_a?(String)
97
+ data = StringIO.new(buf)
98
+ elsif buf.respond_to?(:read)
99
+ data = buf
100
+ end
101
+
102
+ data.define_singleton_method("path") do
103
+ 'NO-PATH'
104
+ end
105
+ data.define_singleton_method("original_filename") do
106
+ 'A-MASS-OF-DATA'
107
+ end
108
+ data.define_singleton_method("content_type") do
109
+ (opts[:content_type].nil? || opts[:content_type].empty?) ? 'application/octet-stream' : opts[:content_type]
110
+ end
111
+
112
+ post_data = {
113
+ :file => data,
114
+ :multipart => true,
115
+ }
116
+ if not uptoken.nil?
117
+ post_data[:token] = uptoken
118
+ end
119
+ if not key.nil?
120
+ post_data[:key] = key
121
+ end
122
+ if x_vars.is_a?(Hash)
123
+ post_data.merge!(x_vars)
124
+ end
125
+
126
+ ### 发送请求
127
+ HTTP.api_post(url, post_data)
128
+ end # upload_with_token_2
129
+
83
130
  ### 授权举例
84
131
  # put_policy.bucket | put_policy.key | key | 语义 | 授权
85
132
  # :---------------- | :------------- | :------ | :--- | :---
@@ -102,6 +149,19 @@ module Qiniu
102
149
  return upload_with_token_2(uptoken, local_file, key, x_vars, opts)
103
150
  end # upload_with_put_policy
104
151
 
152
+ def upload_buffer_with_put_policy(put_policy,
153
+ buf,
154
+ key = nil,
155
+ x_vars = nil,
156
+ opts = {})
157
+ uptoken = Auth.generate_uptoken(put_policy)
158
+ if key.nil? then
159
+ key = put_policy.key
160
+ end
161
+
162
+ return upload_buffer_with_token(uptoken, buf, key, x_vars, opts)
163
+ end # upload_buffer_with_put_policy
164
+
105
165
  private
106
166
  def _generate_action_params(local_file,
107
167
  bucket,
@@ -3,8 +3,8 @@
3
3
  module Qiniu
4
4
  module Version
5
5
  MAJOR = 6
6
- MINOR = 5
7
- PATCH = 1
6
+ MINOR = 6
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
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency "rspec", ">= 2.11"
23
23
  gem.add_development_dependency "fakeweb", "~> 1.3"
24
24
  gem.add_runtime_dependency "json", "~> 1.8"
25
- gem.add_runtime_dependency "rest-client", "~> 1.7.3"
25
+ gem.add_runtime_dependency "rest-client", "~> 1.8.0"
26
26
  gem.add_runtime_dependency "mime-types", "~> 2.4.3"
27
27
  gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
28
28
  gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency "rspec", ">= 2.11"
23
23
  gem.add_development_dependency "fakeweb", "~> 1.3"
24
24
  gem.add_runtime_dependency "json", "~> 1.8"
25
- gem.add_runtime_dependency "rest-client", "~> 1.7.3"
25
+ gem.add_runtime_dependency "rest-client", "~> 1.8.0"
26
26
  gem.add_runtime_dependency "mime-types", "~> 1.19"
27
27
  gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
28
28
  gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
@@ -99,11 +99,11 @@ module Qiniu
99
99
 
100
100
  context ".batch_move" do
101
101
  it "should works" do
102
- code, data = Storage.batch_move @bucket, @key, @bucket, @key2
102
+ code, data = Storage.batch_move [@bucket, @key, @bucket, @key2]
103
103
  code.should == 200
104
104
  puts data.inspect
105
105
 
106
- code3, data3 = Storage.batch_move @bucket, @key2, @bucket, @key
106
+ code3, data3 = Storage.batch_move [@bucket, @key2, @bucket, @key]
107
107
  code3.should == 200
108
108
  puts data3.inspect
109
109
  end
@@ -147,6 +147,24 @@ module Qiniu
147
147
  end
148
148
  end # .upload_with_put_policy
149
149
 
150
+ context ".upload_buffer_with_put_policy" do
151
+ it "should works" do
152
+ pp = Qiniu::Auth::PutPolicy.new(@bucket, @key)
153
+ pp.end_user = "amethyst.black@gmail.com"
154
+ puts 'put_policy=' + pp.to_json
155
+
156
+ test_line = 'This is a test line for testing put_buffer function.'
157
+ code, data, raw_headers = Qiniu::Storage.upload_buffer_with_put_policy(
158
+ pp,
159
+ test_line,
160
+ @key
161
+ )
162
+ code.should == 200
163
+ puts data.inspect
164
+ puts raw_headers.inspect
165
+ end
166
+ end # .upload_buffer_with_put_policy
167
+
150
168
  context ".stat" do
151
169
  it "should exists" do
152
170
  code, data = Qiniu::Storage.stat(@bucket, @key)
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.5.1
4
+ version: 6.6.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: 2015-09-24 00:00:00.000000000 Z
12
+ date: 2016-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- version: 1.7.3
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
- version: 1.7.3
83
+ version: 1.8.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: mime-types
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  version: '0'
186
186
  requirements: []
187
187
  rubyforge_project:
188
- rubygems_version: 2.0.14
188
+ rubygems_version: 2.0.14.1
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: Qiniu Resource (Cloud) Storage SDK for Ruby