aliyun-sdk 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+ require 'yaml'
5
+ require 'nokogiri'
6
+
7
+ module Aliyun
8
+ module OSS
9
+
10
+ describe "Service" do
11
+ before :all do
12
+ @endpoint = 'oss.aliyuncs.com'
13
+ @protocol = Protocol.new(
14
+ Config.new(:endpoint => @endpoint,
15
+ :access_key_id => 'xxx', :access_key_secret => 'yyy'))
16
+
17
+ @all_buckets = []
18
+ (1..10).each do |i|
19
+ name = "rubysdk-bucket-#{i.to_s.rjust(3, '0')}"
20
+ @all_buckets << Bucket.new(
21
+ :name => name,
22
+ :location => 'oss-cn-hangzhou',
23
+ :creation_time => Time.now)
24
+ end
25
+ end
26
+
27
+ # 生成list_buckets返回的响应,包含bucket列表和more信息
28
+ def mock_response(buckets, more)
29
+ builder = Nokogiri::XML::Builder.new do |xml|
30
+ xml.ListAllMyBucketsResult {
31
+ xml.Owner {
32
+ xml.ID 'owner_id'
33
+ xml.DisplayName 'owner_name'
34
+ }
35
+ xml.Buckets {
36
+ buckets.each do |b|
37
+ xml.Bucket {
38
+ xml.Location b.location
39
+ xml.Name b.name
40
+ xml.CreationDate b.creation_time.to_s
41
+ }
42
+ end
43
+ }
44
+
45
+ unless more.empty?
46
+ xml.Prefix more[:prefix]
47
+ xml.Marker more[:marker]
48
+ xml.MaxKeys more[:limit].to_s
49
+ xml.NextMarker more[:next_marker]
50
+ xml.IsTruncated more[:truncated]
51
+ end
52
+ }
53
+ end
54
+
55
+ builder.to_xml
56
+ end
57
+
58
+ context "List all buckets" do
59
+ # 测试list_buckets正确地发送了HTTP请求
60
+ it "should send correct request" do
61
+ stub_request(:get, @endpoint)
62
+
63
+ @protocol.list_buckets
64
+
65
+ expect(WebMock).to have_requested(:get, @endpoint).
66
+ with(:body => nil, :query => {})
67
+ end
68
+
69
+ # 测试list_buckets正确地解析了list_buckets的返回
70
+ it "should correctly parse response" do
71
+ stub_request(:get, @endpoint).to_return(
72
+ {:body => mock_response(@all_buckets, {})})
73
+
74
+ buckets, more = @protocol.list_buckets
75
+ bucket_names = buckets.map {|b| b.name}
76
+
77
+ all_bucket_names = @all_buckets.map {|b| b.name}
78
+ expect(bucket_names).to match_array(all_bucket_names)
79
+
80
+ expect(more).to be_empty
81
+ end
82
+ end
83
+
84
+ context "Paging buckets" do
85
+ # 测试list_buckets的请求中包含prefix/marker/maxkeys等信息
86
+ it "should set prefix/max-keys param" do
87
+ prefix = 'rubysdk-bucket-00'
88
+ marker = 'rubysdk-bucket-002'
89
+ limit = 5
90
+
91
+ stub_request(:get, @endpoint).with(
92
+ :query => {'prefix' => prefix, 'marker' => marker, 'max-keys' => limit})
93
+
94
+ @protocol.list_buckets(
95
+ :prefix => prefix, :limit => limit, :marker => marker)
96
+
97
+ expect(WebMock).to have_requested(:get, @endpoint).
98
+ with(:body => nil,
99
+ :query => {'prefix' => prefix,
100
+ 'marker' => marker,
101
+ 'max-keys' => limit})
102
+ end
103
+
104
+ # 测试list_buckets正确地解析了HTTP响应,包含more信息
105
+ it "should parse next marker" do
106
+ prefix = 'rubysdk-bucket-00'
107
+ marker = 'rubysdk-bucket-002'
108
+ limit = 5
109
+ # returns ['rubysdk-bucket-003', ..., 'rubysdk-bucket-007']
110
+ return_buckets = @all_buckets[2, 5]
111
+ next_marker = 'rubysdk-bucket-007'
112
+
113
+ more = {:prefix => prefix, :marker => marker, :limit => limit,
114
+ :next_marker => next_marker, :truncated => true}
115
+
116
+ stub_request(:get, @endpoint).with(
117
+ :query => {'prefix' => prefix, 'marker' => marker, 'max-keys' => limit}
118
+ ).to_return(
119
+ {:body => mock_response(return_buckets, more)})
120
+
121
+ buckets, more = @protocol.list_buckets(
122
+ :prefix => prefix,
123
+ :limit => limit,
124
+ :marker => marker)
125
+
126
+ bucket_names = buckets.map {|b| b.name}
127
+ return_bucket_names = return_buckets.map {|b| b.name}
128
+ expect(bucket_names).to match_array(return_bucket_names)
129
+
130
+ expect(more).to eq({
131
+ :prefix => prefix,
132
+ :marker => marker,
133
+ :limit => limit,
134
+ :next_marker => next_marker,
135
+ :truncated => true})
136
+ end
137
+
138
+ end
139
+
140
+ end # Bucket
141
+ end # OSS
142
+ end # Aliyun
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'spec_helper'
4
+
5
+ module Aliyun
6
+ module OSS
7
+
8
+ describe Util do
9
+ # 测试对body content的md5编码是否正确
10
+ it "should get correct content md5" do
11
+ content = ""
12
+
13
+ md5 = Util.get_content_md5(content)
14
+ expect(md5).to eq("1B2M2Y8AsgTpgAmY7PhCfg==")
15
+
16
+ content = "hello world"
17
+ md5 = Util.get_content_md5(content)
18
+ expect(md5).to eq("XrY7u+Ae7tCTyyK7j1rNww==")
19
+ end
20
+
21
+ # 测试签名是否正确
22
+ it "should get correct signature" do
23
+ key = 'helloworld'
24
+ date = 'Fri, 30 Oct 2015 07:21:00 GMT'
25
+
26
+ signature = Util.get_signature(key, 'GET', {'Date' => date}, {})
27
+ expect(signature).to eq("u8QKAAj/axKX4JhHXa5DYfYSPxE=")
28
+
29
+ signature = Util.get_signature(
30
+ key, 'PUT', {'Date' => date}, {:path => '/bucket'})
31
+ expect(signature).to eq("lMKrMCJIuGygd8UsdMA+S0QOAsQ=")
32
+
33
+ signature = Util.get_signature(
34
+ key, 'PUT',
35
+ {'Date' => date, 'x-oss-copy-source' => '/bucket/object-old'},
36
+ {:path => '/bucket/object-new'})
37
+ expect(signature).to eq("McYUmBaErN//yvE9voWRhCgvsIc=")
38
+
39
+ signature = Util.get_signature(
40
+ key, 'PUT',
41
+ {'Date' => date},
42
+ {:path => '/bucket/object-new',
43
+ :sub_res => {'append' => nil, 'position' => 0}})
44
+ expect(signature).to eq("7Oh2wobzeg6dw/cWYbF/2m6s6qc=")
45
+ end
46
+
47
+ end # Util
48
+
49
+ end # OSS
50
+ end # Aliyun
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tianlong Wu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.22'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.10'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.10'
111
+ description: A Ruby program to facilitate accessing Aliyun Object Storage Service
112
+ email:
113
+ - tianlong.wtl@alibaba-inc.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files:
117
+ - README.md
118
+ files:
119
+ - README.md
120
+ - lib/aliyun/oss.rb
121
+ - lib/aliyun/oss/bucket.rb
122
+ - lib/aliyun/oss/client.rb
123
+ - lib/aliyun/oss/config.rb
124
+ - lib/aliyun/oss/download.rb
125
+ - lib/aliyun/oss/exception.rb
126
+ - lib/aliyun/oss/http.rb
127
+ - lib/aliyun/oss/iterator.rb
128
+ - lib/aliyun/oss/logging.rb
129
+ - lib/aliyun/oss/multipart.rb
130
+ - lib/aliyun/oss/object.rb
131
+ - lib/aliyun/oss/protocol.rb
132
+ - lib/aliyun/oss/struct.rb
133
+ - lib/aliyun/oss/upload.rb
134
+ - lib/aliyun/oss/util.rb
135
+ - lib/aliyun/oss/version.rb
136
+ - spec/aliyun/oss/bucket_spec.rb
137
+ - spec/aliyun/oss/client/bucket_spec.rb
138
+ - spec/aliyun/oss/client/client_spec.rb
139
+ - spec/aliyun/oss/client/resumable_download_spec.rb
140
+ - spec/aliyun/oss/client/resumable_upload_spec.rb
141
+ - spec/aliyun/oss/http_spec.rb
142
+ - spec/aliyun/oss/multipart_spec.rb
143
+ - spec/aliyun/oss/object_spec.rb
144
+ - spec/aliyun/oss/service_spec.rb
145
+ - spec/aliyun/oss/util_spec.rb
146
+ homepage: https://gitlab.alibaba-inc.com/oss/ruby-sdk
147
+ licenses:
148
+ - MIT
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - '>='
157
+ - !ruby/object:Gem::Version
158
+ version: 1.9.2
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.0
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Aliyun OSS SDK for Ruby
170
+ test_files:
171
+ - spec/aliyun/oss/bucket_spec.rb
172
+ - spec/aliyun/oss/client/bucket_spec.rb
173
+ - spec/aliyun/oss/client/client_spec.rb
174
+ - spec/aliyun/oss/client/resumable_download_spec.rb
175
+ - spec/aliyun/oss/client/resumable_upload_spec.rb
176
+ - spec/aliyun/oss/http_spec.rb
177
+ - spec/aliyun/oss/multipart_spec.rb
178
+ - spec/aliyun/oss/object_spec.rb
179
+ - spec/aliyun/oss/service_spec.rb
180
+ - spec/aliyun/oss/util_spec.rb
181
+ has_rdoc: