oss-ruby 1.0.0.beta

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c5d58f8a8f8af73c7e5a505c7e04e8136023fae
4
+ data.tar.gz: cd3e9e42e90da89c6eacd6ed984df1e42a9769ca
5
+ SHA512:
6
+ metadata.gz: 202bdfbf7dfe629accf744b48c4fef7b11328b6ddf55e848d9ef5eb49a3c99b85d1693af6b5105db86b556cc2809615016ac5e33d94e647c142d7d7bdc8b7984
7
+ data.tar.gz: 568dc2c1bd89f26bc9ce2801966b44a5d821540add10b1a2d0aee47c0e6219150dcb3cc22e56ea038c9264341185f22e2a7cf6b1693e0d5edf9ec81c8a0732b6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easy_ping.gemspec
4
+ gemspec
5
+
6
+ gem 'webmock', '~> 1.22.3'
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oss-ruby (1.0.0.beta)
5
+ faraday (~> 0.9.0)
6
+ mime-types (~> 2.6)
7
+ nokogiri (~> 1.6.6)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.8)
13
+ crack (0.4.2)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.2.5)
16
+ faraday (0.9.2)
17
+ multipart-post (>= 1.2, < 3)
18
+ hashdiff (0.2.3)
19
+ mime-types (2.6.2)
20
+ mini_portile (0.6.2)
21
+ multipart-post (2.0.0)
22
+ nokogiri (1.6.6.2)
23
+ mini_portile (~> 0.6.0)
24
+ rake (10.4.2)
25
+ rspec (3.3.0)
26
+ rspec-core (~> 3.3.0)
27
+ rspec-expectations (~> 3.3.0)
28
+ rspec-mocks (~> 3.3.0)
29
+ rspec-core (3.3.2)
30
+ rspec-support (~> 3.3.0)
31
+ rspec-expectations (3.3.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.3.0)
34
+ rspec-mocks (3.3.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.3.0)
37
+ rspec-support (3.3.0)
38
+ safe_yaml (1.0.4)
39
+ webmock (1.22.3)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+ hashdiff
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.7)
49
+ oss-ruby!
50
+ rake (~> 10.0)
51
+ rspec
52
+ webmock (~> 1.22.3)
53
+
54
+ BUNDLED WITH
55
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright [2015] [Xiaoguang Chen]
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # oss-ruby
2
+
3
+ `oss-ruby` is the Ruby SDK of Aliyun OSS API service. All oss api methods are available through this SDK.
4
+
5
+ What is [Aliyun OSS](http://www.aliyun.com/product/oss)
6
+ Aliyun OSS [API Official Doc](https://docs.aliyun.com/#/pub/oss)
7
+
8
+ **Note**
9
+ It's released on [RubyGems](https://rubygems.org/gems/oss-ruby).
10
+ If something doesn't work, feel free to report a bug or start an issue.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'oss-ruby'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install oss-ruby
27
+
28
+ If you prefer to use the latest code, you can build from source:
29
+
30
+ ```
31
+ gem build oss-ruby.gemspec
32
+ gem install oss-ruby-<VERSION>.gem
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ #### Initialization
38
+ `oss-ruby` requires you to initialize an instance before usage.
39
+
40
+ ```ruby
41
+ # Initialize oss-ruby
42
+ require 'oss'
43
+
44
+ oss = OSS.new({
45
+ endpoint: 'oss-cn-hangzhou.aliyuncs.com',
46
+ access_key_id: 'your_access_key',
47
+ access_key_secret: 'your_access_secret'
48
+ })
49
+ ```
50
+
51
+ #### Call API with SDK
52
+ Using sdk to call oss service is quite straight forward.
53
+
54
+ ```ruby
55
+ # Get Service
56
+ res = oss.get_service
57
+ p res.status # => 200
58
+ ```
59
+
60
+ #### API Response
61
+
62
+ Some of the APIs returns with a xml string as response body.
63
+ `oss-ruby` uses `Nokogiri` to parse the xml document internally.
64
+
65
+ ```ruby
66
+ res = oss.get_service
67
+ p res.status # => 200
68
+ p res.body # => "<?xml version=\"1.0\"..."
69
+ p res.doc.xpath("//ID").text # => "1216909307023357"
70
+ # and it can be shorter
71
+ p res.xpath("//ID").text # => "1216909307023357"
72
+ ```
73
+
74
+ When API responds with an error. `oss-ruby` provide a `error` method in response object to easily parse error messages.
75
+
76
+ ```ruby
77
+ res = oss.get_bucket('non-exist-bucket')
78
+ p res.status # => 404
79
+ p res.body # => "<?xml version=\"1.0\"..."
80
+ p res.error.code #=> "NoSuchBucket"
81
+ p res.error.message #=> "The specified bucket does not exist."
82
+ ```
83
+
84
+ And if network connection fails, `oss-ruby` will raise a `OSS::HTTPClientError` with backtrace and error message.
85
+
86
+ ## Other Documentation
87
+
88
+ * [Quick Start](docs/quick_start.md)
89
+ * [Bucket API](docs/bucket_api.md)
90
+ * [Object API](docs/object_api.md)
91
+ * [Multipart Upload](docs/multipart_upload.md)
92
+ * [Cross-Origin Resource Sharing](docs/cors.md)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,100 @@
1
+ # Bucket API
2
+
3
+ Buckets are the instances with full control of permissions and logs, and they are also the pricing unit in OSS service. Objects must belong to one particular bucket. User can create 10 buckets at most, and space limit of a bucket is 2PB.
4
+
5
+ * Bucket
6
+ * Bucket name conventions
7
+ * Create a bucket
8
+ * List all buckets
9
+ * Delete a bucket
10
+ * Get location of a bucket
11
+ * Manage permissions of a bucket
12
+
13
+ #### Bucket name conventions
14
+
15
+ * Contains only alphanumeric characters, numbers and hyphen.
16
+ * Only lower case is allowed.
17
+ * Must start with alphanumeric character or number.
18
+ * Length between 3-63 bytes.
19
+
20
+ #### Create a bucket
21
+ You can setup the permission of the bucket during creation, default permission is `private`. And you can also choose which [location](https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region) to store the bucket.
22
+
23
+ **Note: bucket once created cannot change its name later.**
24
+
25
+ ```ruby
26
+ # method signature
27
+ put_bucket(name, permission = 'private', location = 'oss-cn-hangzhou')
28
+ ```
29
+ ```ruby
30
+ res = oss.put_bucket('bucket-name')
31
+ p res.status # => 200
32
+ ```
33
+
34
+ #### List all buckets
35
+ You can get the buckets information by simple calling this method without arguments. And 'prefix', 'marker' and 'max-keys' are possible keys to filter results.
36
+ ```ruby
37
+ # method signature
38
+ get_service(params = {})
39
+ ```
40
+
41
+ ```ruby
42
+ res = oss.get_service
43
+ p res.status # => 200
44
+
45
+ # filter
46
+ res = oss.get_service(prefix: 'abc-')
47
+ ```
48
+
49
+ #### Delete a bucket
50
+ Note: only empty bucket can be deleted. If you want to delete a bucket that has objects inside, you have to delete all the objects first.
51
+
52
+ ```ruby
53
+ # method signature
54
+ delete_bucket(name)
55
+ ```
56
+
57
+ ```ruby
58
+ res = oss.delete_bucket('bucket-name')
59
+ p res.status # => 204
60
+ ```
61
+
62
+ #### Get location of a bucket
63
+ You can get the location of a bucket through `get_bucket_location`
64
+
65
+ ```ruby
66
+ # method signature
67
+ get_bucket_location(name)
68
+ ```
69
+
70
+ ```ruby
71
+ res = oss.get_bucket_location('bucket-name')
72
+ p res.status # => 204
73
+ p res.xpath("//LocationConstraint") # => 'oss-cn-hangzhou'
74
+ ```
75
+
76
+ #### Manage permissions of a bucket
77
+ You can change the permission of a bucket after the creation.
78
+
79
+ ```ruby
80
+ # method signature
81
+ put_bucket_acl(name, permission)
82
+ ```
83
+ Acceptable `permission`: 'public-read-write', 'public-read', 'private'.
84
+
85
+ ```ruby
86
+ res = oss.put_bucket_acl('bucket-name', 'public-read-write')
87
+ p res.status # => 200
88
+ ```
89
+
90
+ Get the current permission of a bucket can be done throuth `get_bucket_acl`.
91
+ ```ruby
92
+ # method signature
93
+ get_bucket_acl(name)
94
+ ```
95
+
96
+ ```ruby
97
+ res = oss.get_bucket_acl('bucket-name')
98
+ p res.status # => 200
99
+ p res.xpath("//Grant") # => 'public-read-write'
100
+ ```
data/docs/cors.md ADDED
@@ -0,0 +1,56 @@
1
+ # Cross-Origin Resource Sharing API
2
+
3
+ Cross-Origin Resource Sharing allows Javascript scripts from other origins be able to access resources in a specific bucket.
4
+
5
+ * Cross-Origin Resource Sharing
6
+ * Setup CORS rules of a bucket
7
+ * Get CORS rules of a bucket
8
+ * Delete CORS rules of a bucket
9
+
10
+ #### Setup CORS rules of a bucket
11
+ Rules can be set through `put_bucket_cors`. A bucket can have at most 10 rules.
12
+ See details spec of a rule in [API doc](https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors)
13
+
14
+ ```ruby
15
+ # method signature
16
+ put_bucket_cors(name, rules)
17
+ ```
18
+ ```ruby
19
+ res = oss.put_bucket_cors(
20
+ 'bucket-name',
21
+ [{
22
+ 'AllowedOrigin' => '*',
23
+ 'AllowedMethod' => ['PUT', 'GET'],
24
+ 'AllowedHeader' => 'Authorization'
25
+ }, {
26
+ 'AllowedOrigin' => ['http://www.a.com', 'http://www.b.com'],
27
+ 'AllowedMethod' => 'GET',
28
+ 'AllowedHeader' => 'Authorization',
29
+ 'ExposeHeader' => ['x-oss-test', 'x-oss-test1'],
30
+ 'MaxAgeSeconds' => 100
31
+ }]
32
+ )
33
+ p res.status # => 200
34
+ ```
35
+
36
+ #### Get CORS rules of a bucket
37
+
38
+ ```ruby
39
+ # method signature
40
+ get_bucket_cors(name)
41
+ ```
42
+ ```ruby
43
+ res = oss.get_bucket_cors('bucket-name')
44
+ p res.status # => 200
45
+ ```
46
+
47
+ #### Delete CORS rules of a bucket
48
+
49
+ ```ruby
50
+ # method signature
51
+ delete_bucket_cors(name)
52
+ ```
53
+ ```ruby
54
+ res = oss.delete_bucket_cors('bucket-name')
55
+ p res.status # => 200
56
+ ```
@@ -0,0 +1,116 @@
1
+ # Multipart Upload API
2
+
3
+ OSS service support more than one ways to upload files. Besides `put_object`, user can upload files through 'Multipart Upload'. It supports 'broken-point continuingly-transferring', so it's very suitable in these scenarios:
4
+
5
+ * Needs support of broken-point continuingly-transferring.
6
+ * Large file with size exceeded 100MB.
7
+ * Terrible Networking condition.
8
+ * File size not determined.
9
+
10
+ ---
11
+
12
+ * Multipart Upload
13
+ * Initialize a multipart upload event
14
+ * Upload an object part
15
+ * Copy an object part
16
+ * Complete a multipart upload event
17
+ * Abort a multipart upload event
18
+ * List all multipart upload events in a bucket
19
+ * List parts of an object
20
+
21
+ #### Initialize a multipart upload event
22
+ Before upload parts of the file you need to upload, you have to initialize a multipart upload event.
23
+ ```ruby
24
+ # method signature
25
+ init_multi_upload(bucket, object, headers = {})
26
+ ```
27
+ ```ruby
28
+ res = oss.init_multi_upload('bucket-name', 'object-name')
29
+ p res.status # => 200
30
+ p res.xpath("//UploadId") # => '0004B9894A22E5B1888A1E29F8236E2D'
31
+ ```
32
+
33
+ 'UploadId' is the identifier of the multipart upload event, you'll need it later operations.
34
+
35
+ #### Upload an object part
36
+ ```ruby
37
+ # method signature
38
+ upload_object_part(bucket, object, body, upload_id, part = 1)
39
+ ```
40
+ ```ruby
41
+ res = upload_object_part('bucket-name', 'object-name', 'String Content of Part 1', '0004B9894A22E5B1888A1E29F8236E2D', 1)
42
+ p res.status # => 200
43
+ ```
44
+
45
+ #### Copy an object part
46
+ `upload_object_part_copy` allows user to copy an existed object as a part of the multipart upload object. And objects large than 1GB must be copied through this method.
47
+
48
+ Note:
49
+ * Each part must large than 100KB except the last part.
50
+ * Valid range of part number: 1~10000.
51
+
52
+ ```ruby
53
+ # method signature
54
+ upload_object_part_copy(source_bucket, source_object, target_bucket, target_object, upload_id, part = 1, headers = {})
55
+ ```
56
+ ```ruby
57
+ res = upload_object_part_copy('target-bucket-name', 'target-object-name', 'target-bucket-name', 'target-object-name', '0004B9894A22E5B1888A1E29F8236E2D', 2)
58
+ p res.status # => 200
59
+ ```
60
+
61
+ #### Complete a multipart upload event
62
+ After finishing uploading parts, you have to call `complete_multi_upload` to finish the multipart upload event.
63
+
64
+ ```ruby
65
+ # method signature
66
+ complete_multi_upload(bucket, object, upload_id, parts = [])
67
+ ```
68
+ ```ruby
69
+ res = oss.complete_multi_upload(
70
+ 'bucket-name', 'object-name', '0004B9894A22E5B1888A1E29F8236E2D',
71
+ [{
72
+ part_number: 1,
73
+ etag: "172F5D31191B965FE8CCB5A0F5BECD9A"
74
+ }, {
75
+ part_number: 2,
76
+ etag: "172F5D31191B965FE8CCB5A0F5BECD9A"
77
+ }]
78
+ )
79
+ p res.status # => 200
80
+ ```
81
+
82
+ #### Abort a multipart upload event
83
+ Sometimes you need to abort the upload event, this is where `abort_multi_upload` come into play.
84
+
85
+ ```ruby
86
+ # method signature
87
+ abort_multi_upload(bucket, object, upload_id)
88
+ ```
89
+ ```ruby
90
+ res = oss.abort_multi_upload('bucket-name', 'object-name', '0004B9894A22E5B1888A1E29F8236E2D')
91
+ p res.status # => 204
92
+ ```
93
+
94
+ #### List all multipart upload events in a bucket
95
+ You can get all unfinished multipart upload events through `list_multi_upload`.
96
+
97
+ ```ruby
98
+ # method signature
99
+ list_multi_upload(bucket, headers = {})
100
+ ```
101
+ ```ruby
102
+ res = oss.list_multi_upload('bucket-name')
103
+ p res.status # => 200
104
+ ```
105
+
106
+ #### List parts of an object
107
+ Sometimes you need to view the parts that have been uploaded successfully during a multipart upload event.
108
+
109
+ ```ruby
110
+ # method signature
111
+ list_object_parts(bucket, object, upload_id, headers = {})
112
+ ```
113
+ ```ruby
114
+ res = oss.list_object_parts('bucket-name', 'object-name', '0004B9894A22E5B1888A1E29F8236E2D')
115
+ p res.status # => 200
116
+ ```