added buckets

This commit is contained in:
404
2012-07-30 15:37:52 +08:00
parent b2b5b8b92d
commit da3bdd362e
5 changed files with 51 additions and 2 deletions
+10
View File
@@ -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
+8
View File
@@ -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
+14 -2
View File
@@ -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)
+11
View File
@@ -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)
+8
View File
@@ -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