From da3bdd362ee0715f7a88c9ac30d362694f659b2e Mon Sep 17 00:00:00 2001 From: 404 Date: Mon, 30 Jul 2012 15:37:52 +0800 Subject: [PATCH] added buckets --- lib/qiniu/rs.rb | 10 ++++++++++ lib/qiniu/rs/rs.rb | 8 ++++++++ spec/qiniu/rs/rs_spec.rb | 16 ++++++++++++++-- spec/qiniu/rs_spec.rb | 11 +++++++++++ spec/spec_helper.rb | 8 ++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index d02e824..16250a9 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -29,6 +29,16 @@ module Qiniu code == StatusOK end + def buckets + code, data = RS.buckets + code == StatusOK ? data : false + end + + def mkbucket(bucket_name) + code, data = RS.mkbuckets(bucket_name) + code == StatusOK + end + def put_auth(expires_in = nil, callback_url = nil) code, data = IO.put_auth(expires_in, callback_url) code == StatusOK ? data["url"] : false diff --git a/lib/qiniu/rs/rs.rb b/lib/qiniu/rs/rs.rb index 3d75c3b..3e4903d 100755 --- a/lib/qiniu/rs/rs.rb +++ b/lib/qiniu/rs/rs.rb @@ -6,6 +6,14 @@ module Qiniu class << self include Utils + def buckets + Auth.request Config.settings[:rs_host] + '/buckets' + end + + def mkbucket(bucket_name) + Auth.request Config.settings[:rs_host] + '/mkbucket/' + bucket_name + end + def stat(bucket, key) Auth.request Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key) end diff --git a/spec/qiniu/rs/rs_spec.rb b/spec/qiniu/rs/rs_spec.rb index 6d2af22..1478828 100755 --- a/spec/qiniu/rs/rs_spec.rb +++ b/spec/qiniu/rs/rs_spec.rb @@ -26,11 +26,15 @@ module Qiniu data2["url"].should_not be_empty data2["expiresIn"].should_not be_zero puts data2.inspect - @put_url = data2["url"] + @bucket = "test" @key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s - @domain = 'cdn.example.com' + @domain = 'iovip.qbox.me/test' + + code3, data3 = Qiniu::RS::RS.mkbucket(@bucket) + code3.should == 200 + puts data3.inspect end context "IO.upload_file" do @@ -41,6 +45,14 @@ module Qiniu end end + context ".buckets" do + it "should works" do + code, data = Qiniu::RS::RS.buckets + code.should == 200 + puts data.inspect + end + end + context ".stat" do it "should works" do code, data = Qiniu::RS::RS.stat(@bucket, @key) diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index 5af44a4..471c72f 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -13,6 +13,9 @@ module Qiniu @test_image_bucket = 'test_images_12345' @test_image_key = 'image_logo_for_test.png' + + result = Qiniu::RS.mkbucket(@bucket) + result.should_not be_false end =begin @@ -24,6 +27,14 @@ module Qiniu end =end + context ".buckets" do + it "should works" do + result = Qiniu::RS.buckets + result.should_not be_false + puts result.inspect + end + end + context ".put_auth" do it "should works" do result = Qiniu::RS.put_auth(10) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4161bd4..f4cc93b 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,5 +8,13 @@ RSpec.configure do |config| config.before :all do Qiniu::RS.establish_connection! :access_key => "3fPHl_SLkPXdioqI_A8_NGngPWVJhlDk2ktRjogH", :secret_key => "bXTPMDJrVYRJUiSDRFtFYwycVD_mjXxYWrCYlDHy" + +=begin + Qiniu::RS.establish_connection! :access_key => "bE21M6FW9V7zAFrBY5psgKOKJQLiBj12qMWTpc57", + :secret_key => "uMo7Nyq_eDK_CuQ8_FYCxoTHQZqjiaPh-cbiKO7L", + :auth_url => "http://m1.qbox.me:13001/oauth2/token", + :rs_host => "http://m1.qbox.me:13003", + :io_host => "http://m1.qbox.me:13004" +=end end end