aliyun-oss-sdk 0.1.2 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +4 -0
- data/README.md +93 -54
- data/aliyun-oss.gemspec +2 -1
- data/lib/aliyun/oss.rb +1 -3
- data/lib/aliyun/oss/api/bucket_objects.rb +28 -9
- data/lib/aliyun/oss/api/buckets.rb +4 -2
- data/lib/aliyun/oss/client.rb +5 -0
- data/lib/aliyun/oss/client/bucket_multiparts.rb +9 -13
- data/lib/aliyun/oss/client/bucket_objects.rb +29 -43
- data/lib/aliyun/oss/client/buckets.rb +12 -10
- data/lib/aliyun/oss/client/clients.rb +9 -0
- data/lib/aliyun/oss/http.rb +2 -1
- data/lib/aliyun/oss/struct/bucket.rb +38 -59
- data/lib/aliyun/oss/struct/directory.rb +8 -6
- data/lib/aliyun/oss/struct/file.rb +12 -0
- data/lib/aliyun/oss/struct/multipart.rb +18 -17
- data/lib/aliyun/oss/struct/object.rb +1 -0
- data/lib/aliyun/oss/utils.rb +15 -0
- data/lib/aliyun/oss/version.rb +1 -1
- data/wiki/error.md +2 -2
- data/wiki/object_based/error.md +2 -2
- metadata +42 -54
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2e96e96c0a7b06bd88f47438253eafed9dc23e0
|
4
|
+
data.tar.gz: 45ea2abaf578d016a75cd6352bd4adb83a080ee4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6281c501347c3a4b596737c259f43716fde2da7b54330534b88fab93d9a898583076b6e2747ba389c47ecfba95a359f8c90f9b4bb5ceacdaa183b9051b0f0ab9
|
7
|
+
data.tar.gz: 98d94648c71197f89b40f5d60c1dae649b27bca725926757dff834c31955e7d1a73d6a06bb1f6564ea7cd3b0012c74b46528f4a4d8ddf3aad4377acfb11f8983
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Aliyun OSS SDK
|
2
2
|
|
3
|
-
[](https://travis-ci.org/zlx/aliyun-oss-ruby-sdk)
|
4
|
+
[](https://coveralls.io/github/zlx/aliyun-oss-ruby-sdk?branch=master)
|
5
|
+
[](http://inch-ci.org/github/zlx/aliyun-oss-ruby-sdk)
|
6
6
|
|
7
7
|
-----
|
8
8
|
|
@@ -19,7 +19,7 @@ It's a Ruby Gem, so you can install it like any Gem:
|
|
19
19
|
|
20
20
|
If you use Gemfile manage your Gems, Add below to your Gemfile.
|
21
21
|
|
22
|
-
gem "aliyun-oss-sdk"
|
22
|
+
gem "aliyun-oss-sdk", require: 'aliyun/oss'
|
23
23
|
|
24
24
|
And run:
|
25
25
|
|
@@ -73,7 +73,7 @@ Here are some more guides for help you. Welcome to advice.
|
|
73
73
|
# Details: https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region#menu2
|
74
74
|
# bucket: your bucket name
|
75
75
|
|
76
|
-
client = Aliyun::
|
76
|
+
client = Aliyun::Oss::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
77
77
|
|
78
78
|
|
79
79
|
# Upload object
|
@@ -96,7 +96,7 @@ Here are some more guides for help you. Welcome to advice.
|
|
96
96
|
# Details: https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region#menu2
|
97
97
|
# bucket: your bucket name
|
98
98
|
|
99
|
-
client = Aliyun::
|
99
|
+
client = Aliyun::Oss::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
100
100
|
|
101
101
|
|
102
102
|
# Upload object
|
@@ -116,12 +116,23 @@ Here are some more guides for help you. Welcome to advice.
|
|
116
116
|
bucket = client.buckets.list.first || Aliyun::Oss::Struct::Bucket.new(name: bucket_name, client: client)
|
117
117
|
multipart = client.bucket_multiparts.list.first || Aliyun::Oss::Struct::Multipart.new(upload_id: upload_id, key: object_key, client: client)
|
118
118
|
bucket_object = client.bucket_objects.list.first || Aliyun::Oss::Struct::Object.new(key: object_key, client: client)
|
119
|
+
file = client.bucket_objects.list.select(&:file?).first || Aliyun::Oss::Struct::File.new(key: object_key, client: client)
|
120
|
+
directory = Client.bucket_objects.list.reject(&:file?) || Aliyun::Oss::Struct::Directory.new(key: object_key, client: client)
|
119
121
|
|
120
122
|
### Share your files
|
121
123
|
|
122
|
-
Sometimes, you want to share some file
|
124
|
+
Sometimes, you want to share some file from your private bucket with your friends , but you donot want to share your AccessKey, thus, Aliyun provide alternative way: [Put signature in URL](https://docs.aliyun.com/#/pub/oss/api-reference/access-control&signature-url)
|
123
125
|
|
124
|
-
We provide a method to
|
126
|
+
We provide a method to get share link for your object:
|
127
|
+
|
128
|
+
# Generate Share link expired in 3600 seconds
|
129
|
+
share_link = client.bucket_get_object_share_link('object-key', 3600)
|
130
|
+
|
131
|
+
# OR
|
132
|
+
file = Aliyun::Oss::Struct::File.new(key: 'object-key', client: client)
|
133
|
+
share_link = file.share_link(3600)
|
134
|
+
|
135
|
+
Besides, if you need more control for temporary signature:
|
125
136
|
|
126
137
|
# Return Singature string
|
127
138
|
Aliyun::Oss::Authorization.get_temporary_signature('SECRET_KEY', Time.now.to_i + 60*60, verb: 'GET', bucket: 'bucket-name', key: 'object-name')
|
@@ -141,6 +152,7 @@ With Post Form, we need Post Policy to restrict permissions, here we provide two
|
|
141
152
|
# Return Signature with policy, can used to fill your form field: Signature
|
142
153
|
client.get_policy_signature(SECRET_KEY, policy)
|
143
154
|
|
155
|
+
Here, we provide a [DEMO](demo/app/views/home/new_post.html.erb).
|
144
156
|
|
145
157
|
### API Mapping
|
146
158
|
|
@@ -151,55 +163,82 @@ Note:
|
|
151
163
|
+ All Function Based API are instance methods of `Aliyun::Oss::Client`
|
152
164
|
+ Object Based API belongs to some other class list below:
|
153
165
|
|
154
|
-
+
|
155
|
-
+
|
156
|
-
+
|
157
|
-
+
|
158
|
-
+
|
159
|
-
+
|
166
|
+
+ Bucket: `Aliyun::Oss::Client::BucketsService`
|
167
|
+
+ BucketObject: `Aliyun::Oss::Client::BucketObjectsService`
|
168
|
+
+ BucketMultipart: `Aliyun::Oss::Client::BucketMultipartsService`
|
169
|
+
+ Bucket: `Aliyun::Oss::Struct::Bucket`
|
170
|
+
+ Multipart: `Aliyun::Oss::Struct::Multipart`
|
171
|
+
+ Object: `Aliyun::Oss::Struct::Object`
|
172
|
+
+ File: `Aliyun::Oss::Struct::File`
|
173
|
+
+ Directory: `Aliyun::Oss::Strcut:Directory`
|
174
|
+
|
175
|
+
|
176
|
+
#### Service
|
177
|
+
|
178
|
+
| Restful API | Function Based | Object Based |
|
179
|
+
| ------------ | --------------- | ------------- |
|
180
|
+
|[GetService (ListBucket)](https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService) |bucket_list |Buckets#list |
|
181
|
+
|
182
|
+
#### Bucket
|
183
|
+
|
184
|
+
| Restful API | Function Based | Object Based |
|
185
|
+
| ------------ | --------------- | ------------- |
|
186
|
+
|[Put Bucket](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucket) |bucket_create | Buckets#create|
|
187
|
+
|[Put Bucket Acl](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketACL) |bucket_set_acl | Bucket#set_acl|
|
188
|
+
|[Put Bucket Logging](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLogging)|bucket_enable_logging | Bucket#enable_logging|
|
189
|
+
|[Put Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite) |bucket_enable_website | Bucket#enable_website|
|
190
|
+
|[Put Bucket Referer](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketReferer) |bucket_set_referer | Bucket#set_referer|
|
191
|
+
|[Put Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLifecycle) | bucket_enable_lifecycle| Bucket#enable_lifecycle|
|
192
|
+
|[Get Bucket (List Object)](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket) | bucket_list_objects| Bucket_objects#list, Directory#list|
|
193
|
+
|[Get Bucket ACL](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketAcl) | bucket_get_acl| Bucket#acl!|
|
194
|
+
|[Get Bucket Location](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLocation)| bucket_get_location| Bucket#location!|
|
195
|
+
|[Get Bucket Logging](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLogging) | bucket_get_logging| Bucket#logging!|
|
196
|
+
|[Get Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketWebsite) | bucket_get_website| Bucket#website!|
|
197
|
+
|[Get Bucket Referer](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketReferer) | bucket_get_referer| Bucket#referer!|
|
198
|
+
|[Get Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLifecycle) | bucket_get_lifecycle| Bucket#lifecycle!|
|
199
|
+
|[Delete Bucket](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucket) | bucket_delete| Buckets#delete|
|
200
|
+
|[Delete Bucket Logging](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLogging) | bucket_disable_logging| Bucket#disable_logging|
|
201
|
+
|[Delete Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketWebsite) | bucket_disable_website| Bucket#disable_website|
|
202
|
+
|[Delete Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLifecycle) | bucket_disable_lifecycle| Bucket#disable_lifecycle|
|
203
|
+
|
204
|
+
|
205
|
+
#### Object
|
206
|
+
|
207
|
+
| Restful API | Function Based | Object Based |
|
208
|
+
| ------------ | --------------- | ------------- |
|
209
|
+
|[Put Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObject)| bucket_create_object| BucketObject#create|
|
210
|
+
|[Copy Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject) | bucket_copy_object| BucketObject#copy|
|
211
|
+
|[Get Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject) | bucket_get_object| BucketObject#get|
|
212
|
+
|[Append Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&AppendObject)| bucket_append_object| BucketObject#append|
|
213
|
+
|[Delete Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject)| bucket_delete_object| BucketObject#delete|
|
214
|
+
|[Delete Multiple Objects](https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects)| bucket_delete_objects| BucketObject#delete_multiple|
|
215
|
+
|[Head Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&HeadObject) | bucket_preflight| Bucket#preflight, Bucket#options|
|
216
|
+
|[Put Object ACL](https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObjectACL) | bucket_set_object_acl| Object#set_acl|
|
217
|
+
|[Get Object ACL](https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObjectACL) | bucket_get_object_acl| Object#acl!|
|
218
|
+
|[Post Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&PostObject) | [DEMO](demo/app/views/home/new_post.html.erb)| [DEMO](demo/app/views/home/new_post.html.erb)|
|
219
|
+
| Share Link | bucket_get_object_share_link | file#share_link |
|
220
|
+
|
221
|
+
|
222
|
+
#### Multipart Upload
|
223
|
+
|
224
|
+
| Restful API | Function Based | Object Based |
|
225
|
+
| ------------ | --------------- | ------------- |
|
226
|
+
|[Initiate Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload) | bucket_init_multipart| BucketMultipart#init|
|
227
|
+
|[Upload Part](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPart) | bucket_multipart_upload| Multipart#upload|
|
228
|
+
|[Upload Part Copy](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPartCopy) | bucket_multipart_copy_upload| Multipart#copy|
|
229
|
+
|[Complete Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&CompleteMultipartUpload) | bucket_complete_multipart| Multipart#complete|
|
230
|
+
|[Abort Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&AbortMultipartUpload) | bucket_abort_multipart| Multipart#abort|
|
231
|
+
|[List Multipart Uploads](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListMultipartUploads) | bucket_list_multiparts| BucketMultipart#list|
|
232
|
+
|[List Parts](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListParts) | bucket_list_parts| Multipart#list_parts|
|
160
233
|
|
234
|
+
#### CORS
|
161
235
|
|
162
236
|
| Restful API | Function Based | Object Based |
|
163
|
-
|
164
|
-
|[
|
165
|
-
|[
|
166
|
-
|[
|
167
|
-
|[
|
168
|
-
|[Put Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketWebsite) |bucket_enable_website | bucket#enable_website|
|
169
|
-
|[Put Bucket Referer](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketReferer) |bucket_set_referer | bucket#set_referer|
|
170
|
-
|[Put Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&PutBucketLifecycle) | bucket_enable_lifecycle| bucket#enable_lifecycle|
|
171
|
-
|[Get Bucket (List Object)](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucket) | bucket_list_objects| bucket_objects#list|
|
172
|
-
|[Get Bucket ACL](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketAcl) | bucket_get_acl| bucket#acl!|
|
173
|
-
|[Get Bucket Location](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLocation)| bucket_get_location| bucket#location!|
|
174
|
-
|[Get Bucket Logging](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLogging) | bucket_get_logging| bucket#logging!|
|
175
|
-
|[Get Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketWebsite) | bucket_get_website| bucket#website!|
|
176
|
-
|[Get Bucket Referer](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketReferer) | bucket_get_referer| bucket#referer!|
|
177
|
-
|[Get Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&GetBucketLifecycle) | bucket_get_lifecycle| bucket#lifecycle!|
|
178
|
-
|[Delete Bucket](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucket) | bucket_delete| buckets#delete|
|
179
|
-
|[Delete Bucket Logging](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLogging) | bucket_disable_logging| bucket#disable_logging|
|
180
|
-
|[Delete Bucket Website](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketWebsite) | bucket_disable_website| bucket#disable_website|
|
181
|
-
|[Delete Bucket Lifecycle](https://docs.aliyun.com/#/pub/oss/api-reference/bucket&DeleteBucketLifecycle) | bucket_disable_lifecycle| bucket#disable_lifecycle|
|
182
|
-
|[Put Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObject)| bucket_create_object| bucket_objects#create|
|
183
|
-
|[Copy Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&CopyObject) | bucket_copy_object| bucket_objects#copy|
|
184
|
-
|[Get Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObject) | bucket_get_object| bucket_objects#get|
|
185
|
-
|[Append Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&AppendObject)| bucket_append_object| bucket_objects#append|
|
186
|
-
|[Delete Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject)| bucket_delete_object| bucket_objects#delete|
|
187
|
-
|[Delete Multiple Objects](https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteMultipleObjects)| bucket_delete_objects| bucket_objects#delete_multiple|
|
188
|
-
|[Head Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&HeadObject) | bucket_preflight| bucket#preflight, bucket#options|
|
189
|
-
|[Put Object ACL](https://docs.aliyun.com/#/pub/oss/api-reference/object&PutObjectACL) | bucket_set_object_acl| object#set_acl|
|
190
|
-
|[Get Object ACL](https://docs.aliyun.com/#/pub/oss/api-reference/object&GetObjectACL) | bucket_get_object_acl| object#acl!|
|
191
|
-
|[Post Object](https://docs.aliyun.com/#/pub/oss/api-reference/object&PostObject) | ...| ...|
|
192
|
-
|[Initiate Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&InitiateMultipartUpload) | bucket_init_multipart| bucket_multiparts#init|
|
193
|
-
|[Upload Part](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPart) | bucket_multipart_upload| multipart#upload|
|
194
|
-
|[Upload Part Copy](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&UploadPartCopy) | bucket_multipart_copy_upload| multipart#copy|
|
195
|
-
|[Complete Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&CompleteMultipartUpload) | bucket_complete_multipart| multipart#complete|
|
196
|
-
|[Abort Multipart Upload](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&AbortMultipartUpload) | bucket_abort_multipart| multipart#abort|
|
197
|
-
|[List Multipart Uploads](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListMultipartUploads) | bucket_list_multiparts| bucket_multiparts#list|
|
198
|
-
|[List Parts](https://docs.aliyun.com/#/pub/oss/api-reference/multipart-upload&ListParts) | bucket_list_parts| multipart#list_parts|
|
199
|
-
|[Put Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors) | bucket_enable_cors| bucket#enable_cors|
|
200
|
-
|[Get Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&GetBucketcors) | bucket_get_cors| bucket#cors!|
|
201
|
-
|[Delete Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&DeleteBucketcors) | bucket_disable_cors| bucket#disable_cors|
|
202
|
-
|[OPTIONS Object](https://docs.aliyun.com/#/pub/oss/api-reference/cors&OptionObject)| bucket_get_meta_object| object#meta!|
|
237
|
+
| ------------ | --------------- | ------------- |
|
238
|
+
|[Put Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors) | bucket_enable_cors| Bucket#enable_cors|
|
239
|
+
|[Get Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&GetBucketcors) | bucket_get_cors| Bucket#cors!|
|
240
|
+
|[Delete Bucket cors](https://docs.aliyun.com/#/pub/oss/api-reference/cors&DeleteBucketcors) | bucket_disable_cors| Bucket#disable_cors|
|
241
|
+
|[OPTIONS Object](https://docs.aliyun.com/#/pub/oss/api-reference/cors&OptionObject)| bucket_get_meta_object| Object#meta!|
|
203
242
|
|
204
243
|
|
205
244
|
## Test
|
data/aliyun-oss.gemspec
CHANGED
@@ -13,12 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = 'Aliyun OSS Ruby SDK'
|
14
14
|
spec.homepage = 'https://github.com/zlx/aliyun-oss-sdk'
|
15
15
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|demo)/}) }
|
17
17
|
spec.bindir = 'exe'
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'httparty'
|
22
|
+
spec.add_dependency 'addressable'
|
22
23
|
spec.add_dependency 'gyoku'
|
23
24
|
|
24
25
|
spec.add_development_dependency 'bundler'
|
data/lib/aliyun/oss.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'aliyun/oss/version'
|
2
|
-
require 'aliyun/oss/client'
|
3
2
|
require 'aliyun/oss/struct'
|
4
3
|
require 'aliyun/oss/error'
|
5
4
|
|
6
5
|
module Aliyun
|
7
6
|
module Oss
|
8
7
|
autoload :Utils, 'aliyun/oss/utils'
|
9
|
-
autoload :
|
8
|
+
autoload :Client, 'aliyun/oss/client'
|
10
9
|
autoload :Authorization, 'aliyun/oss/authorization'
|
11
|
-
autoload :XmlGenerator, 'aliyun/oss/xml_generator'
|
12
10
|
end
|
13
11
|
end
|
@@ -52,15 +52,13 @@ module Aliyun
|
|
52
52
|
# @param source_bucket [String] the source bucket name
|
53
53
|
# @param source_key [String] the source object name
|
54
54
|
# @param [Hash] headers
|
55
|
-
# @option
|
56
|
-
# @option
|
57
|
-
# @option
|
58
|
-
# @option
|
59
|
-
# @option
|
60
|
-
# @option
|
61
|
-
# @option
|
62
|
-
# @option options [String] :x-oss-server-side-encryption supported value: AES256
|
63
|
-
# @option options [String] :x-oss-object-acl supported value: public-read, private, public-read-write
|
55
|
+
# @option headers [String] :x-oss-copy-source-if-match If the specified ETag match the source object ETag, normal transfer and return 200; Otherwise return 412(precondition)
|
56
|
+
# @option headers [String] :x-oss-copy-source-if-none-match If the specified ETag not match the source object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)
|
57
|
+
# @option headers [String] :x-oss-copy-source-if-unmodified-since If the specified time is equal to or later than the source object last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)
|
58
|
+
# @option headers [String] :x-oss-copy-source-if-modified-since If the specified time is earlier than the source object last modification time, normal transfer ans return 200; Otherwise returns 304(not modified)
|
59
|
+
# @option headers [String] :x-oss-metadata-directive ('COPY') supported value: COPY, REPLACE;
|
60
|
+
# @option headers [String] :x-oss-server-side-encryption supported value: AES256
|
61
|
+
# @option headers [String] :x-oss-object-acl supported value: public-read, private, public-read-write
|
64
62
|
#
|
65
63
|
# @raise [RequestError]
|
66
64
|
#
|
@@ -123,6 +121,27 @@ module Aliyun
|
|
123
121
|
http.get("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
|
124
122
|
end
|
125
123
|
|
124
|
+
# Get object share link
|
125
|
+
#
|
126
|
+
# @param key [String] the Object name
|
127
|
+
# @param expired_in_seconds [Integer] expire after specify seconds
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
def bucket_get_object_share_link(key, expired_in_seconds)
|
131
|
+
expire_time = Time.now.to_i + expired_in_seconds
|
132
|
+
|
133
|
+
signature = Authorization.get_temporary_signature(
|
134
|
+
@secret_key,
|
135
|
+
expire_time,
|
136
|
+
verb: 'GET',
|
137
|
+
bucket: bucket,
|
138
|
+
key: key
|
139
|
+
)
|
140
|
+
|
141
|
+
Utils.get_endpoint(bucket, @options[:host]) + "#{key}?" \
|
142
|
+
"OSSAccessKeyId=#{@access_key}&Expires=#{expire_time}&Signature=#{signature}"
|
143
|
+
end
|
144
|
+
|
126
145
|
# Delete object from bucket
|
127
146
|
#
|
128
147
|
# @see https://docs.aliyun.com/#/pub/oss/api-reference/object&DeleteObject Delete Object
|
@@ -4,13 +4,15 @@ module Aliyun
|
|
4
4
|
module Buckets
|
5
5
|
# List buckets
|
6
6
|
#
|
7
|
-
# @see https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService GetService (ListBucket
|
7
|
+
# @see https://docs.aliyun.com/#/pub/oss/api-reference/service&GetService GetService (ListBucket)
|
8
8
|
#
|
9
9
|
# @param options [Hash] options
|
10
10
|
# @option options [String] :prefix Filter buckets with prefix
|
11
11
|
# @option options [String] :marker Bucket name should after marker in alphabetical order
|
12
12
|
# @option options [Integer] :max-keys (100) Limit number of buckets, the maxinum should <= 1000
|
13
13
|
#
|
14
|
+
# @raise [RequestError]
|
15
|
+
#
|
14
16
|
# @return [Response]
|
15
17
|
def list_buckets(options = {})
|
16
18
|
Utils.stringify_keys!(options)
|
@@ -29,7 +31,7 @@ module Aliyun
|
|
29
31
|
# @param location [String] Specify the bucket's data center location, can be one of below:
|
30
32
|
# oss-cn-hangzhou,oss-cn-qingdao,oss-cn-beijing,oss-cn-hongkong,
|
31
33
|
# oss-cn-shenzhen,oss-cn-shanghai,oss-us-west-1 ,oss-ap-southeast-1
|
32
|
-
# @param acl [String] Specify the bucket's access.
|
34
|
+
# @param acl [String] Specify the bucket's access. {Aliyun::Oss::Api::BucketProperty#bucket_set_acl}
|
33
35
|
#
|
34
36
|
# @raise [RequestError]
|
35
37
|
#
|
data/lib/aliyun/oss/client.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'aliyun/oss/xml_generator'
|
2
|
+
# Function Based
|
1
3
|
require 'aliyun/oss/api/buckets'
|
2
4
|
require 'aliyun/oss/api/bucket_property'
|
3
5
|
require 'aliyun/oss/api/bucket_objects'
|
4
6
|
require 'aliyun/oss/api/bucket_multiparts'
|
7
|
+
# Object Based
|
5
8
|
require 'aliyun/oss/client/clients'
|
6
9
|
|
10
|
+
require 'aliyun/oss/http'
|
11
|
+
|
7
12
|
module Aliyun
|
8
13
|
module Oss
|
9
14
|
class Client
|
@@ -4,13 +4,12 @@ module Aliyun
|
|
4
4
|
module BucketMultiparts
|
5
5
|
# Init a Multipart Upload Event
|
6
6
|
#
|
7
|
-
# @
|
7
|
+
# @see Api::BucketMultiparts#bucket_init_multipart
|
8
|
+
# @example (see Api::BucketMultiparts#bucket_init_multipart)
|
9
|
+
# @param (see Api::BucketMultiparts#bucket_init_multipart)
|
10
|
+
# @raise (see Api::BucketMultiparts#bucket_init_multipart)
|
8
11
|
#
|
9
|
-
# @
|
10
|
-
#
|
11
|
-
# @return [Aliyun::Oss::Struct::Multipart]
|
12
|
-
#
|
13
|
-
# @see Client#bucket_init_multipart
|
12
|
+
# @return [Struct::Multipart]
|
14
13
|
def init(*args)
|
15
14
|
result = client.bucket_init_multipart(*args).parsed_response
|
16
15
|
|
@@ -20,15 +19,12 @@ module Aliyun
|
|
20
19
|
|
21
20
|
# List exist Multipart Upload Events of bucket
|
22
21
|
#
|
23
|
-
# @
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
#
|
27
|
-
# @raise [RequestError]
|
22
|
+
# @see Api::BucketMultiparts#bucket_list_multiparts
|
23
|
+
# @example (see Api::BucketMultiparts#bucket_list_multiparts)
|
24
|
+
# @param (see Api::BucketMultiparts#bucket_list_multiparts)
|
25
|
+
# @raise (see Api::BucketMultiparts#bucket_list_multiparts)
|
28
26
|
#
|
29
27
|
# @return [Array<Aliyun::Oss::Struct::Multipart>]
|
30
|
-
#
|
31
|
-
# @see Client#bucket_list_multiparts
|
32
28
|
def list(*args)
|
33
29
|
result = client.bucket_list_multiparts(*args).parsed_response
|
34
30
|
|
@@ -4,14 +4,12 @@ module Aliyun
|
|
4
4
|
module BucketObjects
|
5
5
|
# List objects of bucket
|
6
6
|
#
|
7
|
-
# @
|
8
|
-
# @
|
9
|
-
#
|
10
|
-
# @raise
|
7
|
+
# @see Api::BucketObjects#bucket_list_objects
|
8
|
+
# @example (see Api::BucketObjects#bucket_list_objects)
|
9
|
+
# @param (see Api::BucketObjects#bucket_list_objects)
|
10
|
+
# @raise (see Api::BucketObjects#bucket_list_objects)
|
11
11
|
#
|
12
12
|
# @return [Array<Aliyun::Oss::Struct::Object>]
|
13
|
-
#
|
14
|
-
# @see Client#bucket_list_objects
|
15
13
|
def list(*args)
|
16
14
|
result = client.bucket_list_objects(*args).parsed_response
|
17
15
|
|
@@ -23,84 +21,72 @@ module Aliyun
|
|
23
21
|
|
24
22
|
# create object of bucket
|
25
23
|
#
|
26
|
-
# @
|
27
|
-
#
|
28
|
-
# @
|
24
|
+
# @see Api::BucketObjects#bucket_create_object
|
25
|
+
# @example (see Api::BucketObjects#bucket_create_object)
|
26
|
+
# @param (see Api::BucketObjects#bucket_create_object)
|
27
|
+
# @raise (see Api::BucketObjects#bucket_create_object)
|
29
28
|
#
|
30
29
|
# @return [true]
|
31
|
-
#
|
32
|
-
# @see Client#bucket_create_object
|
33
30
|
def create(*args)
|
34
31
|
!!client.bucket_create_object(*args)
|
35
32
|
end
|
36
33
|
|
37
34
|
# Delete object for bucket
|
38
35
|
#
|
39
|
-
# @
|
40
|
-
#
|
41
|
-
# @
|
36
|
+
# @see Api::BucketObjects#bucket_delete_object
|
37
|
+
# @example (see Api::BucketObjects#bucket_delete_object)
|
38
|
+
# @param (see Api::BucketObjects#bucket_delete_object)
|
39
|
+
# @raise (see Api::BucketObjects#bucket_delete_object)
|
42
40
|
#
|
43
41
|
# @return [true]
|
44
|
-
#
|
45
|
-
# @see Client#bucket_delete_object
|
46
42
|
def delete(*args)
|
47
43
|
!!client.bucket_delete_object(*args)
|
48
44
|
end
|
49
45
|
|
50
46
|
# Delete objects for bucket
|
51
47
|
#
|
52
|
-
# @
|
53
|
-
#
|
54
|
-
# @
|
48
|
+
# @see Api::BucketObjects#bucket_delete_objects
|
49
|
+
# @example (see Api::BucketObjects#bucket_delete_objects)
|
50
|
+
# @param (see Api::BucketObjects#bucket_delete_objects)
|
51
|
+
# @raise (see Api::BucketObjects#bucket_delete_objects)
|
55
52
|
#
|
56
53
|
# @return [true]
|
57
|
-
#
|
58
|
-
# @see Client#bucket_delete_objects
|
59
54
|
def delete_multiple(*args)
|
60
55
|
!!client.bucket_delete_objects(*args)
|
61
56
|
end
|
62
57
|
|
63
58
|
# Copy from existing object
|
64
59
|
#
|
65
|
-
# @
|
66
|
-
#
|
67
|
-
# @
|
68
|
-
#
|
69
|
-
# @raise [RequestError]
|
60
|
+
# @see Api::BucketObjects#bucket_copy_object
|
61
|
+
# @example (see Api::BucketObjects#bucket_copy_object)
|
62
|
+
# @param (see Api::BucketObjects#bucket_copy_object)
|
63
|
+
# @raise (see Api::BucketObjects#bucket_copy_object)
|
70
64
|
#
|
71
65
|
# @return [true]
|
72
|
-
#
|
73
|
-
# @see Client#bucket_copy_object
|
74
66
|
def copy(*args)
|
75
67
|
!!client.bucket_copy_object(*args)
|
76
68
|
end
|
77
69
|
|
78
70
|
# Get Object
|
79
71
|
#
|
80
|
-
# @
|
81
|
-
#
|
82
|
-
# @
|
83
|
-
#
|
84
|
-
# @raise [RequestError]
|
72
|
+
# @see Api::BucketObjects#bucket_get_object
|
73
|
+
# @example (see Api::BucketObjects#bucket_get_object)
|
74
|
+
# @param (see Api::BucketObjects#bucket_get_object)
|
75
|
+
# @raise (see Api::BucketObjects#bucket_get_object)
|
85
76
|
#
|
86
|
-
# @return [
|
87
|
-
#
|
88
|
-
# @see Client#bucekt_get_object
|
77
|
+
# @return [BodyString]
|
89
78
|
def get(*args)
|
90
79
|
client.bucket_get_object(*args).body
|
91
80
|
end
|
92
81
|
|
93
82
|
# Append data to a object, will create Appendable object
|
94
83
|
#
|
95
|
-
# @see
|
96
|
-
#
|
97
|
-
# @param (see #bucket_append_object)
|
98
|
-
#
|
99
|
-
# @raise (see #bucket_append_object)
|
84
|
+
# @see Api::BucketObjects#bucket_append_object
|
85
|
+
# @example (see Api::BucketObjects#bucket_append_object)
|
86
|
+
# @param (see Api::BucketObjects#bucket_append_object)
|
87
|
+
# @raise (see Api::BucketObjects#bucket_append_object)
|
100
88
|
#
|
101
89
|
# @return [HTTParty::Response::Headers]
|
102
|
-
#
|
103
|
-
# @see Client#bucket_append_object
|
104
90
|
def append(*args)
|
105
91
|
client.bucket_append_object(*args).headers
|
106
92
|
end
|
@@ -4,12 +4,12 @@ module Aliyun
|
|
4
4
|
module Buckets
|
5
5
|
# List buckets
|
6
6
|
#
|
7
|
-
# @
|
8
|
-
# @
|
7
|
+
# @see Api::Buckets#list_buckets
|
8
|
+
# @example (see Api::Buckets#list_buckets)
|
9
|
+
# @param (see Api::Buckets#list_buckets)
|
10
|
+
# @raise (see Api::Buckets#list_buckets)
|
9
11
|
#
|
10
12
|
# @return [Array<Aliyun::Oss::Struct::Bucket>]
|
11
|
-
#
|
12
|
-
# @see Client#list_buckets
|
13
13
|
def list(options = {})
|
14
14
|
result = client.list_buckets(options).parsed_response
|
15
15
|
|
@@ -21,22 +21,24 @@ module Aliyun
|
|
21
21
|
|
22
22
|
# Create bucket
|
23
23
|
#
|
24
|
-
# @
|
24
|
+
# @see Api::Buckets#bucket_create
|
25
|
+
# @example (see Api::Buckets#bucket_create)
|
26
|
+
# @param (see Api::Buckets#bucket_create)
|
27
|
+
# @raise (see Api::Buckets#bucket_create)
|
25
28
|
#
|
26
29
|
# @return [true]
|
27
|
-
#
|
28
|
-
# @see Client#bucket_create
|
29
30
|
def create(*args)
|
30
31
|
!!client.bucket_create(*args)
|
31
32
|
end
|
32
33
|
|
33
34
|
# Delete bucket
|
34
35
|
#
|
35
|
-
# @
|
36
|
+
# @see Api::Buckets#bucket_delete
|
37
|
+
# @example (see Api::Buckets#bucket_delete)
|
38
|
+
# @param (see Api::Buckets#bucket_delete)
|
39
|
+
# @raise (see Api::Buckets#bucket_delete)
|
36
40
|
#
|
37
41
|
# @return [true]
|
38
|
-
#
|
39
|
-
# @see Client#bucket_delete
|
40
42
|
def delete(*args)
|
41
43
|
!!client.bucket_delete(*args)
|
42
44
|
end
|
@@ -15,6 +15,10 @@ module Aliyun
|
|
15
15
|
#
|
16
16
|
# client.bucket_multiparts
|
17
17
|
#
|
18
|
+
# current_bucket: get current bucket
|
19
|
+
#
|
20
|
+
# client.current_bucket
|
21
|
+
#
|
18
22
|
#
|
19
23
|
class Client
|
20
24
|
def buckets
|
@@ -30,6 +34,11 @@ module Aliyun
|
|
30
34
|
Client::BucketMultipartsService.new(self)
|
31
35
|
end
|
32
36
|
|
37
|
+
def current_bucket
|
38
|
+
@services[:current_bucket] ||= \
|
39
|
+
Aliyun::Oss::Struct::Bucket.new(name: bucket, client: self)
|
40
|
+
end
|
41
|
+
|
33
42
|
ClientService = ::Struct.new(:client)
|
34
43
|
|
35
44
|
require 'aliyun/oss/client/buckets'
|
data/lib/aliyun/oss/http.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'httparty'
|
2
|
+
require 'addressable/uri'
|
2
3
|
require 'aliyun/oss/error'
|
3
4
|
|
4
5
|
module Aliyun
|
@@ -49,7 +50,7 @@ module Aliyun
|
|
49
50
|
append_headers!(headers, verb, body, options)
|
50
51
|
|
51
52
|
path = api_endpoint(headers['Host']) + resource
|
52
|
-
options = { headers: headers, query: query, body: body }
|
53
|
+
options = { headers: headers, query: query, body: body, uri_adapter: Addressable::URI }
|
53
54
|
|
54
55
|
wrap(HTTParty.__send__(verb.downcase, path, options))
|
55
56
|
end
|
@@ -22,17 +22,18 @@ module Aliyun
|
|
22
22
|
#
|
23
23
|
# @return [String]
|
24
24
|
#
|
25
|
-
# @see
|
25
|
+
# @see Api::BucketProperty#bucket_get_location
|
26
26
|
def location!
|
27
27
|
result = client.bucket_get_location.parsed_response
|
28
|
-
Utils.dig_value(result, 'LocationConstraint', '__content__')
|
28
|
+
Utils.dig_value(result, 'LocationConstraint', '__content__') ||
|
29
|
+
Utils.dig_value(result, 'LocationConstraint')
|
29
30
|
end
|
30
31
|
|
31
32
|
# Get Logging configration for bucket
|
32
33
|
#
|
33
34
|
# return [true]
|
34
35
|
#
|
35
|
-
# @see
|
36
|
+
# @see Api::BucketProperty#bucket_get_logging
|
36
37
|
def logging!
|
37
38
|
result = client.bucket_get_logging.parsed_response
|
38
39
|
Struct::Logging.new(Utils.dig_value(result, 'BucketLoggingStatus'))
|
@@ -40,11 +41,12 @@ module Aliyun
|
|
40
41
|
|
41
42
|
# Used to enable access logging.
|
42
43
|
#
|
43
|
-
# @
|
44
|
+
# @see Api::BucketProperty#bucket_enable_logging
|
45
|
+
# @example (see Api::BucketProperty#bucket_enable_logging)
|
46
|
+
# @param (see Api::BucketProperty#bucket_enable_logging)
|
47
|
+
# @raise (see Api::BucketProperty#bucket_enable_logging)
|
44
48
|
#
|
45
49
|
# @return [true]
|
46
|
-
#
|
47
|
-
# @see Client#bucket_enable_logging
|
48
50
|
def enable_logging(*args)
|
49
51
|
!!client.bucket_enable_logging(*args)
|
50
52
|
end
|
@@ -55,7 +57,7 @@ module Aliyun
|
|
55
57
|
#
|
56
58
|
# @return [true]
|
57
59
|
#
|
58
|
-
# @see
|
60
|
+
# @see Api::BucketProperty#bucket_disable_logging
|
59
61
|
def disable_logging
|
60
62
|
!!client.bucket_disable_logging
|
61
63
|
end
|
@@ -64,7 +66,7 @@ module Aliyun
|
|
64
66
|
#
|
65
67
|
# @return [String]
|
66
68
|
#
|
67
|
-
# @see
|
69
|
+
# @see Api::BucketProperty#bucket_get_acl
|
68
70
|
def acl!
|
69
71
|
result = client.bucket_get_acl.parsed_response
|
70
72
|
acl_keys = %w(AccessControlPolicy AccessControlList Grant)
|
@@ -73,13 +75,12 @@ module Aliyun
|
|
73
75
|
|
74
76
|
# Set ACL for bucket
|
75
77
|
#
|
76
|
-
# @
|
77
|
-
#
|
78
|
-
# @
|
78
|
+
# @see Api::BucketProperty#bucket_set_acl
|
79
|
+
# @example (see Api::BucketProperty#bucket_set_acl)
|
80
|
+
# @param (see Api::BucketProperty#bucket_set_acl)
|
81
|
+
# @raise (see Api::BucketProperty#bucket_set_acl)
|
79
82
|
#
|
80
83
|
# @return [true]
|
81
|
-
#
|
82
|
-
# @see Client#bucket_set_acl
|
83
84
|
def set_acl(*args)
|
84
85
|
!!client.bucket_set_acl(*args)
|
85
86
|
end
|
@@ -88,7 +89,7 @@ module Aliyun
|
|
88
89
|
#
|
89
90
|
# @return [Array<Aliyun::Oss::Struct::Cors>]
|
90
91
|
#
|
91
|
-
# @see
|
92
|
+
# @see Api::BucketProperty#bucket_get_cors
|
92
93
|
def cors!
|
93
94
|
result = client.bucket_get_cors.parsed_response
|
94
95
|
cors_keys = %w(CORSConfiguration CORSRule)
|
@@ -99,28 +100,21 @@ module Aliyun
|
|
99
100
|
|
100
101
|
# Set CORS for bucket
|
101
102
|
#
|
102
|
-
# @see
|
103
|
-
#
|
104
|
-
# @param (see #bucket_enable_cors)
|
105
|
-
#
|
106
|
-
# @raise (see #bucket_enable_cors)
|
103
|
+
# @see Api::BucketProperty#bucket_enable_cors
|
104
|
+
# @example (see Api::BucketProperty#bucket_enable_cors)
|
105
|
+
# @param (see Api::BucketProperty#bucket_enable_cors)
|
106
|
+
# @raise (see Api::BucketProperty#bucket_enable_cors)
|
107
107
|
#
|
108
108
|
# @return [true]
|
109
|
-
#
|
110
|
-
# @see Client#bucket_enable_cors
|
111
109
|
def enable_cors(*args)
|
112
110
|
!!client.bucket_enable_cors(*args)
|
113
111
|
end
|
114
112
|
|
115
113
|
# Disable CORS for bucket
|
116
114
|
#
|
117
|
-
# @see (see #bucket_disable_cors)
|
118
|
-
#
|
119
|
-
# @raise (see #bucket_disable_cors)
|
120
|
-
#
|
121
115
|
# @return [true]
|
122
116
|
#
|
123
|
-
# @see
|
117
|
+
# @see Api::BucketProperty#bucket_disable_cors
|
124
118
|
def disable_cors
|
125
119
|
!!client.bucket_disable_cors
|
126
120
|
end
|
@@ -129,7 +123,7 @@ module Aliyun
|
|
129
123
|
#
|
130
124
|
# @return [Aliyun::Oss::Rule::Website]
|
131
125
|
#
|
132
|
-
# @see
|
126
|
+
# @see Api::BucketProperty#bucket_get_website
|
133
127
|
def website!
|
134
128
|
result = client.bucket_get_website.parsed_response
|
135
129
|
suffix_keys = %w(WebsiteConfiguration IndexDocument Suffix)
|
@@ -142,28 +136,21 @@ module Aliyun
|
|
142
136
|
|
143
137
|
# Used to enable static website hosted mode.
|
144
138
|
#
|
145
|
-
# @see
|
146
|
-
#
|
147
|
-
# @param (see #bucket_enable_website)
|
148
|
-
#
|
149
|
-
# @raise (see #bucket_enable_website)
|
139
|
+
# @see Api::BucketProperty#bucket_enable_website
|
140
|
+
# @example (see Api::BucketProperty#bucket_enable_website)
|
141
|
+
# @param (see Api::BucketProperty#bucket_enable_website)
|
142
|
+
# @raise (see Api::BucketProperty#bucket_enable_website)
|
150
143
|
#
|
151
144
|
# @return [true]
|
152
|
-
#
|
153
|
-
# @see Client#bucket_enable_website
|
154
145
|
def enable_website(*args)
|
155
146
|
!!client.bucket_enable_website(*args)
|
156
147
|
end
|
157
148
|
|
158
149
|
# Used to disable website hostted mode.
|
159
150
|
#
|
160
|
-
# @
|
161
|
-
#
|
162
|
-
# @raise (see #bucket_disable_website)
|
163
|
-
#
|
164
|
-
# @return [Response]
|
151
|
+
# @return [true]
|
165
152
|
#
|
166
|
-
# @see
|
153
|
+
# @see Api::BucketProperty#bucket_disable_website
|
167
154
|
def disable_website
|
168
155
|
!!client.bucket_disable_website
|
169
156
|
end
|
@@ -172,7 +159,7 @@ module Aliyun
|
|
172
159
|
#
|
173
160
|
# @return [Aliyun::Oss::Struct::Referer]
|
174
161
|
#
|
175
|
-
# @see
|
162
|
+
# @see Api::BucketProperty#bucket_get_referer
|
176
163
|
def referer!
|
177
164
|
result = client.bucket_get_referer.parsed_response
|
178
165
|
allow_empty = %w(RefererConfiguration AllowEmptyReferer)
|
@@ -185,15 +172,12 @@ module Aliyun
|
|
185
172
|
|
186
173
|
# Used to set referer for bucket.
|
187
174
|
#
|
188
|
-
# @see
|
189
|
-
#
|
190
|
-
# @param (see #bucket_set_referer)
|
191
|
-
#
|
192
|
-
# @raise (see #bucket_set_referer)
|
175
|
+
# @see Api::BucketProperty#bucket_set_referer
|
176
|
+
# @example (see Api::BucketProperty#bucket_set_referer)
|
177
|
+
# @param (see Api::BucketProperty#bucket_set_referer)
|
178
|
+
# @raise (see Api::BucketProperty#bucket_set_referer)
|
193
179
|
#
|
194
180
|
# @return [true]
|
195
|
-
#
|
196
|
-
# @see Client#set_referer
|
197
181
|
def set_referer(*args)
|
198
182
|
!!client.bucket_set_referer(*args)
|
199
183
|
end
|
@@ -202,7 +186,7 @@ module Aliyun
|
|
202
186
|
#
|
203
187
|
# @return [Array<Aliyun::Oss::Struct::Lifecycle?]
|
204
188
|
#
|
205
|
-
# @see
|
189
|
+
# @see Api::BucketProperty#bucket_get_lifecycle
|
206
190
|
def lifecycle!
|
207
191
|
result = client.bucket_get_lifecycle.parsed_response
|
208
192
|
lifecycle_keys = %w(LifecycleConfiguration Rule)
|
@@ -226,26 +210,21 @@ module Aliyun
|
|
226
210
|
|
227
211
|
# Used to disable lifecycle for bucket
|
228
212
|
#
|
229
|
-
# @raise (see #bucket_disable_lifecycle)
|
230
|
-
#
|
231
213
|
# @return [true]
|
232
214
|
#
|
233
|
-
# @see
|
215
|
+
# @see Api::BucketProperty#bucket_disable_lifecycle
|
234
216
|
def disable_lifecycle
|
235
217
|
!!client.bucket_disable_lifecycle
|
236
218
|
end
|
237
219
|
|
238
220
|
# OPTIONS Object
|
239
221
|
#
|
240
|
-
# @see
|
241
|
-
#
|
242
|
-
# @param (see #bucket_preflight)
|
243
|
-
#
|
244
|
-
# @raise (see #bucket_preflight)
|
222
|
+
# @see Api::BucketProperty#bucket_preflight
|
223
|
+
# @example (see Api::BucketProperty#bucket_preflight)
|
224
|
+
# @param (see Api::BucketProperty#bucket_preflight)
|
225
|
+
# @raise (see Api::BucketProperty#bucket_preflight)
|
245
226
|
#
|
246
227
|
# @return [true]
|
247
|
-
#
|
248
|
-
# @see Client#bucket_preflight
|
249
228
|
def preflight(*args)
|
250
229
|
!!client.bucket_preflight(*args)
|
251
230
|
end
|
@@ -7,18 +7,20 @@ module Aliyun
|
|
7
7
|
|
8
8
|
# List objects under directory
|
9
9
|
#
|
10
|
-
# @see #bucket_list_objects
|
11
|
-
#
|
12
|
-
# @param (see #bucket_list_objects)
|
13
|
-
# @
|
14
|
-
#
|
15
|
-
# @raise [RequestError]
|
10
|
+
# @see Api::BucketObjects#bucket_list_objects
|
11
|
+
# @example (see Api::BucketObjects#bucket_list_objects)
|
12
|
+
# @param (see Api::BucketObjects#bucket_list_objects)
|
13
|
+
# @raise (see Api::BucketObjects#bucket_list_objects)
|
16
14
|
#
|
17
15
|
# @return [Array<Aliyun::Oss::Struct::Object>]
|
18
16
|
def list(options = {})
|
19
17
|
Utils.stringify_keys!(options)
|
20
18
|
client.bucket_objects.list(options.merge('prefix' => key))
|
21
19
|
end
|
20
|
+
|
21
|
+
def file?
|
22
|
+
false
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -2,6 +2,18 @@ module Aliyun
|
|
2
2
|
module Oss
|
3
3
|
module Struct
|
4
4
|
class File < Object
|
5
|
+
def file?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
# Get object share link
|
10
|
+
#
|
11
|
+
# @param expired_in_seconds [Integer] expire after specify seconds
|
12
|
+
#
|
13
|
+
# @return [URL]
|
14
|
+
def share_link(expired_in_seconds)
|
15
|
+
client.bucket_get_object_share_link(key, expired_in_seconds)
|
16
|
+
end
|
5
17
|
end
|
6
18
|
end
|
7
19
|
end
|
@@ -23,11 +23,13 @@ module Aliyun
|
|
23
23
|
|
24
24
|
# Upload part to Multipart Upload Event
|
25
25
|
#
|
26
|
+
# @see Api::BucketMultiparts#bucket_multipart_upload
|
27
|
+
# @example (see Api::BucketMultiparts#bucket_multipart_upload)
|
28
|
+
# @raise (see Api::BucketMultiparts#bucket_multipart_upload)
|
29
|
+
#
|
26
30
|
# @param number [Integer] the part number, Range in 1~10000.
|
27
31
|
# @param file [File, bin data] the upload data
|
28
32
|
#
|
29
|
-
# @raise (see #bucket_multipart_upload)
|
30
|
-
#
|
31
33
|
# @return [HTTParty::Response::Headers]
|
32
34
|
def upload(*args)
|
33
35
|
client.bucket_multipart_upload(*args.unshift(upload_id, key)).headers
|
@@ -37,13 +39,12 @@ module Aliyun
|
|
37
39
|
#
|
38
40
|
# @param number [Integer] the part number, Range in 1~10000.
|
39
41
|
# @param options [Hash] options
|
40
|
-
# @option (see #bucket_multipart_copy_upload)
|
41
42
|
#
|
42
|
-
# @
|
43
|
+
# @see Api::BucketMultiparts#bucket_multipart_copy_upload
|
44
|
+
# @example (see Api::BucketMultiparts#bucket_multipart_copy_upload)
|
45
|
+
# @raise (see Api::BucketMultiparts#bucket_multipart_copy_upload)
|
43
46
|
#
|
44
47
|
# @return [true]
|
45
|
-
#
|
46
|
-
# @see Client#bucket_list_parts
|
47
48
|
def copy(*args)
|
48
49
|
!!client.bucket_multipart_copy_upload(*args.unshift(upload_id, key))
|
49
50
|
end
|
@@ -51,13 +52,12 @@ module Aliyun
|
|
51
52
|
# List uploaded parts for the Multipart Upload Event
|
52
53
|
#
|
53
54
|
# @param options [Hash] options
|
54
|
-
# @option (see #bucket_list_parts)
|
55
55
|
#
|
56
|
-
# @
|
56
|
+
# @see Api::BucketMultiparts#bucket_list_parts
|
57
|
+
# @example (see Api::BucketMultiparts#bucket_list_parts)
|
58
|
+
# @raise (see Api::BucketMultiparts#bucket_list_parts)
|
57
59
|
#
|
58
60
|
# @return [Array<Aliyun::Oss::Struct::Part>]
|
59
|
-
#
|
60
|
-
# @see Client#bucket_list_parts
|
61
61
|
def list_parts(options = {})
|
62
62
|
result = client.bucket_list_parts(upload_id, key, options)
|
63
63
|
.parsed_response
|
@@ -70,13 +70,13 @@ module Aliyun
|
|
70
70
|
|
71
71
|
# Complete Multipart Upload Event
|
72
72
|
#
|
73
|
-
# @param parts [Array<Multipart:Part>] parts
|
73
|
+
# @param parts [Array<Aliyun::Oss::Multipart:Part>] parts
|
74
74
|
#
|
75
|
-
# @
|
75
|
+
# @see Api::BucketMultiparts#bucket_complete_multipart
|
76
|
+
# @example (see Api::BucketMultiparts#bucket_complete_multipart)
|
77
|
+
# @raise (see Api::BucketMultiparts#bucket_complete_multipart)
|
76
78
|
#
|
77
79
|
# @return [Struct::Object]
|
78
|
-
#
|
79
|
-
# @see Client#bucket_complete_multipart
|
80
80
|
def complete(parts = [])
|
81
81
|
resp = client.bucket_complete_multipart(upload_id, key, parts)
|
82
82
|
keys = %w(CompleteMultipartUploadResult)
|
@@ -87,11 +87,12 @@ module Aliyun
|
|
87
87
|
|
88
88
|
# Abort Multipart Upload Event
|
89
89
|
#
|
90
|
-
# @
|
90
|
+
# @see Api::BucketMultiparts#bucket_abort_multipart
|
91
|
+
# @note (see Api::BucketMultiparts#bucket_abort_multipart)
|
92
|
+
# @example (see Api::BucketMultiparts#bucket_abort_multipart)
|
93
|
+
# @raise (see Api::BucketMultiparts#bucket_abort_multipart)
|
91
94
|
#
|
92
95
|
# @return [true]
|
93
|
-
#
|
94
|
-
# @see Client#bucket_abort_multipart
|
95
96
|
def abort
|
96
97
|
!!client.bucket_abort_multipart(upload_id, key)
|
97
98
|
end
|
data/lib/aliyun/oss/utils.rb
CHANGED
@@ -6,6 +6,21 @@ require 'gyoku'
|
|
6
6
|
module Aliyun
|
7
7
|
module Oss
|
8
8
|
class Utils
|
9
|
+
# Get endpoint
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# get_endpoint('bucket-name', 'oss-cn-hangzhou.aliyuncs.com')
|
14
|
+
# # => 'http://bucket-name.oss-cn-hangzhou.aliyuncs.com'
|
15
|
+
#
|
16
|
+
# @param bucket [String] the Bucket name
|
17
|
+
# @param host [String] the host of Bucket
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def self.get_endpoint(bucket, host)
|
21
|
+
"http://#{bucket}.#{host}/"
|
22
|
+
end
|
23
|
+
|
9
24
|
# Calculate content length
|
10
25
|
#
|
11
26
|
# @return [Integer]
|
data/lib/aliyun/oss/version.rb
CHANGED
data/wiki/error.md
CHANGED
@@ -6,7 +6,7 @@ If a error occurs when visit the OSS, the OSS will be return a error code and er
|
|
6
6
|
|
7
7
|
require 'aliyun/oss'
|
8
8
|
|
9
|
-
client = Aliyun::
|
9
|
+
client = Aliyun::Oss::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
10
10
|
|
11
11
|
res = client.bucket_create("invalid_bucket_name")
|
12
12
|
unless res.success?
|
@@ -66,4 +66,4 @@ Here,
|
|
66
66
|
|RequestTimeout |Request Timeout| 400|
|
67
67
|
|RequestIsNotMultiPartContent | Content-Type Invalid| 400|
|
68
68
|
|SignatureDoesNotMatch |Signature Does Not Match|403|
|
69
|
-
|TooManyBuckets |Too Many Buckets| 400|
|
69
|
+
|TooManyBuckets |Too Many Buckets| 400|
|
data/wiki/object_based/error.md
CHANGED
@@ -6,7 +6,7 @@ If a error occurs when visit the OSS, the OSS will be return a error code and er
|
|
6
6
|
|
7
7
|
require 'aliyun/oss'
|
8
8
|
|
9
|
-
client = Aliyun::
|
9
|
+
client = Aliyun::Oss::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
10
10
|
|
11
11
|
begin
|
12
12
|
client.buckets.create("invalid_bucket_name")
|
@@ -67,4 +67,4 @@ Here,
|
|
67
67
|
|RequestTimeout |Request Timeout| 400|
|
68
68
|
|RequestIsNotMultiPartContent | Content-Type Invalid| 400|
|
69
69
|
|SignatureDoesNotMatch |Signature Does Not Match|403|
|
70
|
-
|TooManyBuckets |Too Many Buckets| 400|
|
70
|
+
|TooManyBuckets |Too Many Buckets| 400|
|
metadata
CHANGED
@@ -1,158 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-oss-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Newell Zhu
|
9
8
|
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2015-
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: httparty
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: gyoku
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - ">="
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :runtime
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ">="
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: bundler
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - ">="
|
52
60
|
- !ruby/object:Gem::Version
|
53
61
|
version: '0'
|
54
62
|
type: :development
|
55
63
|
prerelease: false
|
56
64
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
65
|
requirements:
|
59
|
-
- -
|
66
|
+
- - ">="
|
60
67
|
- !ruby/object:Gem::Version
|
61
68
|
version: '0'
|
62
69
|
- !ruby/object:Gem::Dependency
|
63
70
|
name: rake
|
64
71
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
72
|
requirements:
|
67
|
-
- -
|
73
|
+
- - ">="
|
68
74
|
- !ruby/object:Gem::Version
|
69
75
|
version: '0'
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
78
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
79
|
requirements:
|
75
|
-
- -
|
80
|
+
- - ">="
|
76
81
|
- !ruby/object:Gem::Version
|
77
82
|
version: '0'
|
78
83
|
- !ruby/object:Gem::Dependency
|
79
84
|
name: minitest
|
80
85
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
86
|
requirements:
|
83
|
-
- -
|
87
|
+
- - ">="
|
84
88
|
- !ruby/object:Gem::Version
|
85
89
|
version: '0'
|
86
90
|
type: :development
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
93
|
requirements:
|
91
|
-
- -
|
94
|
+
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
- !ruby/object:Gem::Dependency
|
95
98
|
name: mocha
|
96
99
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
100
|
requirements:
|
99
|
-
- -
|
101
|
+
- - ">="
|
100
102
|
- !ruby/object:Gem::Version
|
101
103
|
version: '0'
|
102
104
|
type: :development
|
103
105
|
prerelease: false
|
104
106
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
107
|
requirements:
|
107
|
-
- -
|
108
|
+
- - ">="
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
- !ruby/object:Gem::Dependency
|
111
112
|
name: webmock
|
112
113
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
121
|
requirements:
|
123
|
-
- -
|
122
|
+
- - ">="
|
124
123
|
- !ruby/object:Gem::Version
|
125
124
|
version: '0'
|
126
125
|
- !ruby/object:Gem::Dependency
|
127
126
|
name: timecop
|
128
127
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
128
|
requirements:
|
131
|
-
- -
|
129
|
+
- - ">="
|
132
130
|
- !ruby/object:Gem::Version
|
133
131
|
version: '0'
|
134
132
|
type: :development
|
135
133
|
prerelease: false
|
136
134
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
135
|
requirements:
|
139
|
-
- -
|
136
|
+
- - ">="
|
140
137
|
- !ruby/object:Gem::Version
|
141
138
|
version: '0'
|
142
139
|
- !ruby/object:Gem::Dependency
|
143
140
|
name: rubocop
|
144
141
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
142
|
requirements:
|
147
|
-
- -
|
143
|
+
- - ">="
|
148
144
|
- !ruby/object:Gem::Version
|
149
145
|
version: '0'
|
150
146
|
type: :development
|
151
147
|
prerelease: false
|
152
148
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
149
|
requirements:
|
155
|
-
- -
|
150
|
+
- - ">="
|
156
151
|
- !ruby/object:Gem::Version
|
157
152
|
version: '0'
|
158
153
|
description: Aliyun OSS Ruby SDK
|
@@ -162,9 +157,9 @@ executables: []
|
|
162
157
|
extensions: []
|
163
158
|
extra_rdoc_files: []
|
164
159
|
files:
|
165
|
-
- .gitignore
|
166
|
-
- .rubocop.yml
|
167
|
-
- .travis.yml
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rubocop.yml"
|
162
|
+
- ".travis.yml"
|
168
163
|
- Gemfile
|
169
164
|
- LICENSE
|
170
165
|
- README.md
|
@@ -219,32 +214,25 @@ files:
|
|
219
214
|
- wiki/object_based/object.md
|
220
215
|
homepage: https://github.com/zlx/aliyun-oss-sdk
|
221
216
|
licenses: []
|
217
|
+
metadata: {}
|
222
218
|
post_install_message:
|
223
219
|
rdoc_options: []
|
224
220
|
require_paths:
|
225
221
|
- lib
|
226
222
|
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
-
none: false
|
228
223
|
requirements:
|
229
|
-
- -
|
224
|
+
- - ">="
|
230
225
|
- !ruby/object:Gem::Version
|
231
226
|
version: '0'
|
232
|
-
segments:
|
233
|
-
- 0
|
234
|
-
hash: 314123667821853469
|
235
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
|
-
none: false
|
237
228
|
requirements:
|
238
|
-
- -
|
229
|
+
- - ">="
|
239
230
|
- !ruby/object:Gem::Version
|
240
231
|
version: '0'
|
241
|
-
segments:
|
242
|
-
- 0
|
243
|
-
hash: 314123667821853469
|
244
232
|
requirements: []
|
245
233
|
rubyforge_project:
|
246
|
-
rubygems_version:
|
234
|
+
rubygems_version: 2.2.0
|
247
235
|
signing_key:
|
248
|
-
specification_version:
|
236
|
+
specification_version: 4
|
249
237
|
summary: Aliyun OSS Ruby SDK
|
250
238
|
test_files: []
|