qiniu-s3 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'fakeweb'
5
+ require 'qiniu/s3/utils'
6
+
7
+ module Qiniu
8
+ module S3
9
+ describe Utils do
10
+ before :all do
11
+ Struct.new("Response", :code, :body)
12
+ end
13
+
14
+ after :each do
15
+ FakeWeb.clean_registry
16
+ FakeWeb.allow_net_connect = true
17
+ end
18
+
19
+ context "safe_json_parse" do
20
+ it "should works" do
21
+ Utils.safe_json_parse('{"foo": "bar"}').should == {"foo" => "bar"}
22
+ Utils.safe_json_parse('{}').should == {}
23
+ end
24
+ end
25
+
26
+ context ".send_request_with" do
27
+ it "should works" do
28
+ FakeWeb.allow_net_connect = false
29
+ FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json)
30
+ res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
31
+ res.should == [200, {"abc" => 123}]
32
+ end
33
+
34
+ [400, 500].each do |code|
35
+ context "upstream return http #{code}" do
36
+ it "should raise RestClient::RequestFailed" do
37
+ FakeWeb.allow_net_connect = false
38
+ FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :status => code)
39
+ lambda {
40
+ res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
41
+ }.should raise_error RestClient::RequestFailed
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'qiniu/s3/version'
5
+
6
+ describe Qiniu::S3 do
7
+ it "should has a VERSION" do
8
+ Qiniu::S3::VERSION.should =~ /^\d+\.\d+\.\d+?$/
9
+ end
10
+ end
@@ -0,0 +1,147 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'qiniu/s3'
5
+
6
+ module Qiniu
7
+ describe S3 do
8
+
9
+ before :all do
10
+ @bucket = 'qiniu_s3_test'
11
+ @key = Digest::SHA1.hexdigest Time.now.to_s
12
+ @domain = 'cdn.example.com'
13
+ end
14
+
15
+ context ".login!" do
16
+ it "should works" do
17
+ result = Qiniu::S3.login!("test@qbox.net", "test")
18
+ result.should be_true
19
+ end
20
+ end
21
+
22
+ context ".put_auth" do
23
+ it "should works" do
24
+ result = Qiniu::S3.put_auth(10)
25
+ result.should_not be_false
26
+ result.should_not be_empty
27
+ puts result.inspect
28
+ end
29
+ end
30
+
31
+ context ".upload" do
32
+ it "should works" do
33
+ put_url = Qiniu::S3.put_auth(10)
34
+ put_url.should_not be_false
35
+ put_url.should_not be_empty
36
+ puts put_url.inspect
37
+ result = Qiniu::S3.upload(put_url, __FILE__, @bucket, @key)
38
+ result.should be_true
39
+ end
40
+ end
41
+
42
+ context ".stat" do
43
+ it "should works" do
44
+ result = Qiniu::S3.stat(@bucket, @key)
45
+ result.should_not be_false
46
+ result.should_not be_empty
47
+ puts result.inspect
48
+ end
49
+ end
50
+
51
+ context ".get" do
52
+ it "should works" do
53
+ result = Qiniu::S3.get(@bucket, @key, "s3_spec.rb", 10)
54
+ result.should_not be_false
55
+ result.should_not be_empty
56
+ puts result.inspect
57
+ end
58
+ end
59
+
60
+ context ".download" do
61
+ it "should works" do
62
+ result = Qiniu::S3.download(@bucket, @key, "s3_spec.rb", 10)
63
+ result.should_not be_false
64
+ result.should_not be_empty
65
+ puts result.inspect
66
+ end
67
+ end
68
+
69
+ context ".batch" do
70
+ it "should works" do
71
+ result = Qiniu::S3.batch("stat", @bucket, [@key])
72
+ result.should_not be_false
73
+ result.should_not be_empty
74
+ puts result.inspect
75
+ end
76
+ end
77
+
78
+ context ".batch_stat" do
79
+ it "should works" do
80
+ result = Qiniu::S3.batch_stat(@bucket, [@key])
81
+ result.should_not be_false
82
+ result.should_not be_empty
83
+ puts result.inspect
84
+ end
85
+ end
86
+
87
+ context ".batch_get" do
88
+ it "should works" do
89
+ result = Qiniu::S3.batch_get(@bucket, [@key])
90
+ result.should_not be_false
91
+ result.should_not be_empty
92
+ puts result.inspect
93
+ end
94
+ end
95
+
96
+ context ".batch_download" do
97
+ it "should works" do
98
+ result = Qiniu::S3.batch_download(@bucket, [@key])
99
+ result.should_not be_false
100
+ result.should_not be_empty
101
+ puts result.inspect
102
+ end
103
+ end
104
+
105
+ context ".publish" do
106
+ it "should works" do
107
+ result = Qiniu::S3.publish(@domain, @bucket)
108
+ result.should_not be_false
109
+ end
110
+ end
111
+
112
+ context ".unpublish" do
113
+ it "should works" do
114
+ result = Qiniu::S3.unpublish(@domain)
115
+ result.should_not be_false
116
+ end
117
+ end
118
+
119
+ context ".delete" do
120
+ it "should works" do
121
+ result = Qiniu::S3.delete(@bucket, @key)
122
+ result.should_not be_false
123
+ end
124
+ end
125
+
126
+ context ".drop" do
127
+ it "should works" do
128
+ result = Qiniu::S3.drop(@bucket)
129
+ result.should_not be_false
130
+ end
131
+ end
132
+
133
+ context ".image_info" do
134
+ it "should works" do
135
+ data = Qiniu::S3.get("test_images", "test_image.jpg")
136
+ data.should_not be_false
137
+ data.should_not be_empty
138
+ puts data.inspect
139
+ result = Qiniu::S3.image_info(data["url"])
140
+ result.should_not be_false
141
+ result.should_not be_empty
142
+ puts result.inspect
143
+ end
144
+ end
145
+
146
+ end
147
+ end
@@ -0,0 +1,12 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'bundler/setup'
4
+ require 'qiniu/s3'
5
+ require 'rspec'
6
+
7
+ RSpec.configure do |config|
8
+ config.before :all do
9
+ Qiniu::S3.establish_connection! :client_id => "abcd0c7edcdf914228ed8aa7c6cee2f2bc6155e2",
10
+ :client_secret => "fc9ef8b171a74e197b17f85ba23799860ddf3b9c"
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qiniu-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - why404
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakeweb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mime-types
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! 'Qiniu Cloud Storage SDK for Ruby. See: http://docs.qiniutek.com/v1/sdk/ruby/'
79
+ email:
80
+ - why404@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - lib/qiniu-s3.rb
92
+ - lib/qiniu/s3.rb
93
+ - lib/qiniu/s3/auth.rb
94
+ - lib/qiniu/s3/config.rb
95
+ - lib/qiniu/s3/exceptions.rb
96
+ - lib/qiniu/s3/image.rb
97
+ - lib/qiniu/s3/io.rb
98
+ - lib/qiniu/s3/log.rb
99
+ - lib/qiniu/s3/rs.rb
100
+ - lib/qiniu/s3/utils.rb
101
+ - lib/qiniu/s3/version.rb
102
+ - qiniu-s3.gemspec
103
+ - spec/qiniu/s3/auth_spec.rb
104
+ - spec/qiniu/s3/image_spec.rb
105
+ - spec/qiniu/s3/io_spec.rb
106
+ - spec/qiniu/s3/rs_spec.rb
107
+ - spec/qiniu/s3/utils_spec.rb
108
+ - spec/qiniu/s3/version_spec.rb
109
+ - spec/qiniu/s3_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/why404/qiniu-s3-sdk-for-ruby
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 1.8.24
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Qiniu Cloud Storage SDK for Ruby
135
+ test_files:
136
+ - spec/qiniu/s3/auth_spec.rb
137
+ - spec/qiniu/s3/image_spec.rb
138
+ - spec/qiniu/s3/io_spec.rb
139
+ - spec/qiniu/s3/rs_spec.rb
140
+ - spec/qiniu/s3/utils_spec.rb
141
+ - spec/qiniu/s3/version_spec.rb
142
+ - spec/qiniu/s3_spec.rb
143
+ - spec/spec_helper.rb