Compare commits

..
27 Commits
Author SHA1 Message Date
Bai Long 5332645665 Merge pull request #114 from liluo/dev
updated runtime dependency mime-types version
2014-12-14 23:08:09 +08:00
liluo 946442f782 updated runtime dependency mime-types version 2014-12-14 16:39:17 +08:00
Bai Long 8e4805cf68 [ci skip] 2014-12-11 23:40:07 +08:00
Bai Long 78147d76f8 Merge pull request #113 from BluntBlade/master
将 mime-types 依赖版本升级至 2.4.3 。
2014-12-11 23:36:53 +08:00
Liang Tao 2bb0514df4 更新 README 说明,将版本号提到最新。 2014-12-11 23:08:17 +08:00
Liang Tao 0bca27457a 将 mime-types 依赖版本升级到 2.4.3 。 2014-12-11 23:05:25 +08:00
Bai Long b21833779e Merge pull request #112 from dekexu/master
七牛up_host的修改
2014-12-11 22:47:05 +08:00
xudeke a64fb3a63e real merge 2014-12-10 14:42:34 +08:00
deco 0d2f2f23dd usage added 2014-12-10 10:12:50 +08:00
xudeke d0b4fb7412 ok 2014-12-09 21:18:27 +08:00
xudeke 40bf2cfbbb string keys to symbol 2014-12-09 21:17:17 +08:00
deco 4e80a5ec98 Update README.md 2014-12-09 20:30:16 +08:00
xudeke 4fbfdbf472 允许海外服务器高速上传 2014-12-09 14:18:30 +08:00
xudeke d14fe23e45 ok 2014-12-09 14:16:59 +08:00
deco 3d0578cb88 Update README.md 2014-12-09 13:18:12 +08:00
deco 09b8921d20 七牛海外服务器上传 2014-12-09 13:12:44 +08:00
Bai Long 7d65b22e2e [ci skip] 2014-11-28 18:02:00 +08:00
Bai Long 8b000c0a98 Merge pull request #111 from BluntBlade/master
更新接口代码
2014-11-28 18:00:35 +08:00
Liang Tao f93e50c838 更新 ChangeLog 。 2014-11-28 16:38:47 +08:00
Liang Tao b8f43a1ded 为 upload 的最新版本接口添加 content-type/mimeType 设置方法。 2014-11-28 16:22:58 +08:00
Liang Tao 804fa4d5b6 添加rsf_host。 2014-08-01 17:08:05 +08:00
Liang Tao 0f2466d4c2 Merge branch 'master' of github.com:qiniu/ruby-sdk into list
Conflicts:
	lib/qiniu/config.rb
2014-07-29 10:20:02 +08:00
Bai Long 93c3cb8dea update version [ci skip] 2014-07-24 21:27:48 +08:00
Bai Long 3cccf69b61 update log [ci skip] 2014-07-24 21:26:35 +08:00
Bai Long b98cec1433 Merge pull request #103 from longbai/update_dependency
update test
2014-07-24 17:23:44 +08:00
longbai a29cfe5a71 update test 2014-07-24 14:38:59 +08:00
Liang Tao a70b6f5313 添加list接口。 2014-05-05 20:55:23 +08:00
17 changed files with 111 additions and 100 deletions
+2 -2
View File
@@ -5,5 +5,5 @@ rvm:
- 2.1.1
- jruby-19mode
before_script:
- export QINIU_ACCESS_KEY=LGRqJsjX7LAvtdtX6hhyxs861lS57HwnOQmJsOuX
- export QINIU_SECRET_KEY=g_OxhuN5iJ1O7BoA6YdXyF6zSszk34UZFKDfdIIW
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
+12
View File
@@ -1,5 +1,17 @@
## CHANGE LOG
### v6.4.1
- 将 mime-types 的依赖版本升级到 2.4.3 。 [https://github.com/qiniu/ruby-sdk/pull/113](https://github.com/qiniu/ruby-sdk/pull/113)
### v6.4.0
- 为 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)
### v6.3.2
- 调整上传host。 [https://github.com/qiniu/ruby-sdk/pull/103](https://github.com/qiniu/ruby-sdk/pull/103)
### v6.3.1
- 为过期方法添加说明。 [https://github.com/qiniu/ruby-sdk/pull/98](https://github.com/qiniu/ruby-sdk/pull/98)
+2 -2
View File
@@ -1,9 +1,9 @@
PATH
remote: .
specs:
qiniu (6.3.1)
qiniu (6.4.1)
json (~> 1.7)
mime-types (~> 1.19)
mime-types (~> 2.4.3)
rest-client (~> 1.6)
ruby-hmac (~> 0.4)
+1 -1
View File
@@ -15,7 +15,7 @@
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
gem 'qiniu', '~> 6.3.1'
gem 'qiniu', '~> 6.4.1'
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
+5 -3
View File
@@ -20,7 +20,8 @@ module Qiniu
:content_type => 'application/x-www-form-urlencoded',
:auth_url => "https://acc.qbox.me/oauth2/token",
:rs_host => "http://rs.qiniu.com",
:up_host => "http://upload.qiniu.com",
:rsf_host => "http://rsf.qbox.me",
:up_host => "http://up.qiniu.com",
:pub_host => "http://pu.qbox.me:10200",
:eu_host => "http://eu.qbox.me",
:access_key => "",
@@ -33,13 +34,14 @@ module Qiniu
:tmpdir => Dir.tmpdir + File::SEPARATOR + 'QiniuRuby'
}
REQUIRED_OPTION_KEYS = [:access_key, :secret_key]
REQUIRED_OPTION_KEYS = [:access_key, :secret_key, :up_host]
attr_reader :settings, :default_params
def load config_file
if File.exist?(config_file)
config_options = YAML.load_file(config_file)
config_options.symbolize_keys!
initialize_connect(config_options)
else
raise MissingConfError, config_file
@@ -47,7 +49,7 @@ module Qiniu
end
def initialize_connect options = {}
@settings = DEFAULT_OPTIONS.merge(options)
@settings = DEFAULT_OPTIONS.merge!(options)
REQUIRED_OPTION_KEYS.each do |opt|
raise MissingArgsError, [opt] unless @settings.has_key?(opt)
end
+62 -24
View File
@@ -1,10 +1,48 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'qiniu/adt'
require 'qiniu/http'
module Qiniu
module Storage
class ListPolicy
include ADT::Policy
private
def initialize(bucket,
limit = 1000,
prefix = '',
delimiter = '')
@bucket = bucket
@limit = limit
@prefix = prefix
@delimiter = delimiter
end # initialize
public
PARAMS = {
# 字符串类型参数
:bucket => "bucket",
:prefix => "prefix",
:delimiter => "delimiter",
:marker => "marker",
# 数值类型参数
:limit => "limit"
} # PARAMS
PARAMS.each_pair do |key, fld|
attr_accessor key
end
def params
return PARAMS
end # params
alias :to_s :to_query_string
end # class ListPolicy
class << self
include Utils
@@ -14,22 +52,6 @@ module Qiniu
return HTTP.management_post(url)
end # buckets
PRIVATE_BUCKET = 0
PUBLIC_BUCKET = 1
def mkbucket(bucket_name, is_public = PUBLIC_BUCKET)
url = Config.settings[:rs_host] + '/mkbucket2/' + bucket_name + '/public/' + is_public.to_s
return HTTP.management_post(url)
end # mkbucket
def make_a_private_bucket(bucket_name)
return mkbucket(bucket_name, PRIVATE_BUCKET)
end # make_a_private_bucket
def make_a_public_bucket(bucket_name)
return mkbucket(bucket_name, PUBLIC_BUCKET)
end # make_a_public_bucket
def stat(bucket, key)
url = Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key)
return HTTP.management_post(url)
@@ -60,11 +82,6 @@ module Qiniu
return HTTP.management_post(url)
end # delete
def drop(bucket)
url = Config.settings[:rs_host] + "/drop/#{bucket}"
return HTTP.management_post(url)
end # drop
def batch(command, bucket, keys)
execs = []
keys.each do |key|
@@ -107,6 +124,26 @@ module Qiniu
save_as(bucket, key, source_image_url, mogrify_params_string)
end # image_mogrify_save_as
def list(list_policy)
url = Config.settings[:rsf_host] + '/list?' + list_policy.to_query_string()
resp_code, resp_body, resp_headers = HTTP.management_post(url)
if resp_code == 0 || resp_code > 299 then
has_more = false
return resp_code, resp_body, resp_headers, has_more, list_policy
end
has_more = (resp_body['marker'].is_a?(String) && resp_body['marker'] != '')
if has_more then
new_list_policy = list_policy.clone()
new_list_policy.marker = resp_body['marker']
else
new_list_policy = list_policy
end
return resp_code, resp_body, resp_headers, has_more, new_list_policy
end # list
private
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
@@ -117,12 +154,13 @@ module Qiniu
def _batch_cp_or_mv(command, *op_args)
execs = []
op_args.each do |e|
op_args.each do |e|
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
end
end
url = Config.settings[:rs_host] + "/batch"
return HTTP.management_post(url, execs.join("&"))
end # _batch_cp_or_mv
end
end # class << self
end # module Storage
end # module Qiniu
Executable → Regular
+13 -4
View File
@@ -47,15 +47,23 @@ module Qiniu
def upload_with_token_2(uptoken,
local_file,
key = nil,
x_vars = nil)
x_vars = nil,
opts = {})
### 构造URL
url = Config.settings[:up_host]
url[/\/*$/] = ''
url += '/'
### 构造HTTP Body
file = File.new(local_file, 'rb')
if not opts[:content_type].nil?
file.define_singleton_method("content_type") do
opts[:content_type]
end
end
post_data = {
:file => File.new(local_file, 'rb'),
:file => file,
:multipart => true,
}
if not uptoken.nil?
@@ -84,13 +92,14 @@ module Qiniu
def upload_with_put_policy(put_policy,
local_file,
key = nil,
x_vars = nil)
x_vars = nil,
opts = {})
uptoken = Auth.generate_uptoken(put_policy)
if key.nil? then
key = put_policy.key
end
return upload_with_token_2(uptoken, local_file, key, x_vars)
return upload_with_token_2(uptoken, local_file, key, x_vars, opts)
end # upload_with_put_policy
private
+1 -1
View File
@@ -3,7 +3,7 @@
module Qiniu
module Version
MAJOR = 6
MINOR = 3
MINOR = 4
PATCH = 1
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
#
+1 -1
View File
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "fakeweb", "~> 1.3"
gem.add_runtime_dependency "json", "~> 1.7"
gem.add_runtime_dependency "rest-client", "~> 1.6"
gem.add_runtime_dependency "mime-types", "~> 1.19"
gem.add_runtime_dependency "mime-types", "~> 2.4.3"
gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
end
+2 -9
View File
@@ -7,20 +7,13 @@ require 'qiniu/storage'
require 'digest/sha1'
module Qiniu
module Auth
module Auth
describe Auth do
before :all do
@bucket = 'RubySDK-Test-Private'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu::Storage.make_a_private_bucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
end
after :all do
### 不删除Bucket以备下次使用
end
### 测试私有资源下载
+1 -10
View File
@@ -10,15 +10,7 @@ module Qiniu
describe Fop do
before :all do
### 复用RubySDK-Test-Storage空间
@bucket = 'RubySDK-Test-Storage'
@bucket = make_unique_bucket(@bucket)
### 尝试创建空间
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
pic_fname = "image_logo_for_test.png"
@key = make_unique_key_in_bucket(pic_fname)
@@ -57,7 +49,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
context ".info" do
+1 -7
View File
@@ -12,12 +12,7 @@ module Qiniu
describe Storage do
before :all do
@bucket = 'RubySDK-Test-Management'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
@key = make_unique_key_in_bucket(@key)
@@ -26,7 +21,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
### 准备数据
+1 -7
View File
@@ -10,16 +10,10 @@ module Qiniu
describe Misc do
before :all do
### 复用RubySDK-Test-Management空间
@bucket = 'RubySDK-Test-Management'
@bucket = make_unique_bucket(@bucket)
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
end
after :all do
### 不删除Bucket以备下次使用
end
context ".set_protected" do
+1 -10
View File
@@ -12,15 +12,7 @@ module Qiniu
describe Persistance do
before :all do
### 复用RubySDK-Test-Storage空间
@bucket = 'RubySDK-Test-Storage'
@bucket = make_unique_bucket(@bucket)
### 尝试创建空间
code, data, headers = Qiniu::Storage.make_a_public_bucket(@bucket)
puts code.inspect
puts data.inspect
puts headers.inspect
@bucket = 'rubysdk'
pic_fname = "image_logo_for_test.png"
@key = make_unique_key_in_bucket(pic_fname)
@@ -44,7 +36,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
context ".pfop" do
+1 -7
View File
@@ -9,15 +9,10 @@ module Qiniu
describe Qiniu do
before :all do
@bucket = 'RubySDK-Test'
@bucket = make_unique_bucket(@bucket)
@bucket = 'rubysdk'
@test_image_bucket = @bucket
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@key = Digest::SHA1.hexdigest Time.now.to_s
@key = make_unique_key_in_bucket(@key)
@@ -34,7 +29,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
context ".buckets" do
+1 -8
View File
@@ -11,12 +11,7 @@ module Qiniu
describe Storage do
before :all do
@bucket = 'RubySDK-Test-Storage'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
@key = make_unique_key_in_bucket(@key)
@@ -53,8 +48,6 @@ module Qiniu
File.unlink(@localfile_4m) if File.exists?(@localfile_4m)
File.unlink(@localfile_8m) if File.exists?(@localfile_8m)
File.unlink(@localfile_1m) if File.exists?(@localfile_1m)
### 不删除Bucket以备下次使用
end
### 测试单文件直传
+4 -4
View File
@@ -26,8 +26,8 @@ module Qiniu
context ".send_request_with" do
it "should works" do
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json)
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :body => {:abc => 123}.to_json)
res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get
res.should == [200, {"abc" => 123}, {}]
end
@@ -35,9 +35,9 @@ module Qiniu
context "upstream return http #{code}" do
it "should raise RestClient::RequestFailed" do
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :status => code)
FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :status => code)
lambda {
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get
}.should raise_error RestClient::RequestFailed
end
end