oss-ruby-sdk 0.1.0

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: 6806a4db8e8e3bb883eb090109ae0b7d1261a1d6
4
+ data.tar.gz: 33d14eb0bef98859334d249e6699fd1c485a559d
5
+ SHA512:
6
+ metadata.gz: 862edf3f58355d5626bfc6e5af0c01eb8117d2c63f3388c6c32dd3431eab95b8042a5b388a128a3891fe81027fa576eb29f2690b13524a13a8db577350f7731b
7
+ data.tar.gz: acd82d4c9739197d8abcb649531e90f25040a88046d357365b257f628c7490d5295bcefa0efa387e98f5dad63089f99ebbcaaad2b4d72d3e69f42c215a47deef
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
11
+ .DS_Store
12
+ Thumbs.db
13
+ .cache
14
+ .project
15
+ .settings
16
+ .tmproj
17
+ *.esproj
18
+ nbproject
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # dependencies in oss-ruby-sdk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 1999-2015 RaymondChou
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,41 @@
1
+ # OSS Ruby SDK
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/oss/ruby/sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'oss-ruby-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install oss-ruby-sdk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/oss-ruby-sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "oss"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/oss.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'oss/version'
2
+ require 'oss/api'
3
+ require 'oss/client'
4
+ require 'oss/service'
5
+ require 'oss/bucket'
6
+ require 'oss/object'
7
+ require 'oss/multipart'
8
+ require 'oss/cors'
9
+
10
+ module Oss
11
+
12
+ attr_reader :config
13
+
14
+ # load configs for Rails app
15
+ def self.config
16
+ @config ||= begin
17
+ if defined? Rails
18
+ config_file = Rails.root.join('config/oss.yml')
19
+ config = YAML.load(ERB.new(File.new(config_file).read).result)[Rails.env] if File.exist?(config_file)
20
+ end
21
+
22
+ config ||= config_from_environment
23
+ config.symbolize_keys!
24
+ config[:endpoint] ||= 'oss-cn-hangzhou.aliyuncs.com'
25
+ OpenStruct.new(config)
26
+ end
27
+ end
28
+
29
+ def self.api
30
+ @api ||= Api.new(config.endpoint, config.access_key_id, config.access_key_secret, config.bucket)
31
+ end
32
+
33
+ # load configs from environment
34
+ def self.config_from_environment
35
+ {
36
+ access_key_id: ENV['OSS_ID'],
37
+ access_key_secret: ENV['OSS_SECRET'],
38
+ endpoint: ENV['ENDPOINT'],
39
+ bucket: ENV['BUCKET'],
40
+ }
41
+ end
42
+
43
+ end
data/lib/oss/api.rb ADDED
@@ -0,0 +1,342 @@
1
+ require 'oss/service'
2
+ require 'oss/bucket'
3
+ require 'oss/object'
4
+ require 'oss/multipart'
5
+ require 'oss/cors'
6
+
7
+ module Oss
8
+
9
+ class Api
10
+
11
+ attr_accessor :client, :bucket
12
+
13
+ def initialize(endpoint, access_key_id, access_key_secret, bucket = nil)
14
+ @bucket = bucket
15
+ @client = Client.new(endpoint, access_key_id, access_key_secret)
16
+ end
17
+
18
+
19
+ #######################
20
+ # Service
21
+ #######################
22
+
23
+ # params:
24
+ # - options:
25
+ # - prefix
26
+ # - marker
27
+ # - max_keys
28
+ def get_service(options = {})
29
+ Service.new(@client).get_service(options)
30
+ end
31
+
32
+ alias_method :list_bucket, :get_service
33
+
34
+
35
+ #######################
36
+ # Bucket
37
+ #######################
38
+
39
+ # params:
40
+ # - bucket_name
41
+ # - acl
42
+ def put_bucket(bucket_name, acl)
43
+ Bucket.new(@client).put_bucket(bucket_name, acl)
44
+ end
45
+
46
+ # params:
47
+ # - bucket_name
48
+ # - acl
49
+ def put_bucket_acl(bucket_name, acl)
50
+ Bucket.new(@client).put_bucket_acl(bucket_name, acl)
51
+ end
52
+
53
+ # params:
54
+ # - bucket_name
55
+ # - target_bucket
56
+ # - enable
57
+ # - target_prefix
58
+ def put_bucket_logging(bucket_name, target_bucket, enable = true, target_prefix = nil)
59
+ Bucket.new(@client).put_bucket_logging(bucket_name, target_bucket, enable, target_prefix)
60
+ end
61
+
62
+ # params:
63
+ # - bucket_name
64
+ # - index_doc
65
+ # - error_doc
66
+ def put_bucket_website(bucket_name, index_doc, error_doc)
67
+ Bucket.new(@client).put_bucket_website(bucket_name, index_doc, error_doc)
68
+ end
69
+
70
+ # params:
71
+ # - bucket_name
72
+ # - allow_empty
73
+ # - referer_list
74
+ def put_bucket_referer(bucket_name, allow_empty, referer_list = [])
75
+ Bucket.new(@client).put_bucket_referer(bucket_name, allow_empty, referer_list)
76
+ end
77
+
78
+ # params:
79
+ # - bucket_name
80
+ # - allow_empty
81
+ # - referer_list
82
+ def put_bucket_lifecycle(bucket_name, rules = [])
83
+ Bucket.new(@client).put_bucket_lifecycle(bucket_name, rules)
84
+ end
85
+
86
+ # params:
87
+ # - bucket_name
88
+ # - options:
89
+ # - delimiter
90
+ # - prefix
91
+ # - marker
92
+ # - max_keys
93
+ # - encoding_type
94
+ def get_bucket(bucket_name, options = {})
95
+ Bucket.new(@client).get_bucket(bucket_name, options)
96
+ end
97
+
98
+ # params:
99
+ # - bucket_name
100
+ def get_bucket_acl(bucket_name)
101
+ Bucket.new(@client).get_bucket_acl(bucket_name)
102
+ end
103
+
104
+ # params:
105
+ # - bucket_name
106
+ def get_bucket_location(bucket_name)
107
+ Bucket.new(@client).get_bucket_location(bucket_name)
108
+ end
109
+
110
+ # params:
111
+ # - bucket_name
112
+ def get_bucket_logging(bucket_name)
113
+ Bucket.new(@client).get_bucket_logging(bucket_name)
114
+ end
115
+
116
+ # params:
117
+ # - bucket_name
118
+ def get_bucket_website(bucket_name)
119
+ Bucket.new(@client).get_bucket_website(bucket_name)
120
+ end
121
+
122
+ # params:
123
+ # - bucket_name
124
+ def get_bucket_referer(bucket_name)
125
+ Bucket.new(@client).get_bucket_referer(bucket_name)
126
+ end
127
+
128
+ # params:
129
+ # - bucket_name
130
+ def get_bucket_lifecycle(bucket_name)
131
+ Bucket.new(@client).get_bucket_lifecycle(bucket_name)
132
+ end
133
+
134
+ # params:
135
+ # - bucket_name
136
+ def delete_bucket(bucket_name)
137
+ Bucket.new(@client).delete_bucket(bucket_name)
138
+ end
139
+
140
+ # params:
141
+ # - bucket_name
142
+ def delete_bucket_logging(bucket_name)
143
+ Bucket.new(@client).delete_bucket_logging(bucket_name)
144
+ end
145
+
146
+ # params:
147
+ # - bucket_name
148
+ def delete_bucket_website(bucket_name)
149
+ Bucket.new(@client).delete_bucket_website(bucket_name)
150
+ end
151
+
152
+ # params:
153
+ # - bucket_name
154
+ def delete_bucket_lifecycle(bucket_name)
155
+ Bucket.new(@client).delete_bucket_lifecycle(bucket_name)
156
+ end
157
+
158
+
159
+ #######################
160
+ # Object
161
+ #######################
162
+
163
+ # params:
164
+ # - bucket_name
165
+ # - object_name
166
+ # - file
167
+ # - options
168
+ def put_object(bucket_name, object_name, file, options = {})
169
+ Object.new(@client).put_object(bucket_name, object_name, file, options)
170
+ end
171
+
172
+ # params:
173
+ # - bucket_name
174
+ # - object_name
175
+ # - file
176
+ # - options
177
+ def copy_object(bucket_name, object, old_bucket, old_object, options = {})
178
+ Object.new(@client).copy_object(bucket_name, object, old_bucket, old_object, options)
179
+ end
180
+
181
+ # params:
182
+ # - bucket_name
183
+ # - object
184
+ # - options
185
+ def get_object(bucket_name, object, options = {})
186
+ Object.new(@client).get_object(bucket_name, object, options)
187
+ end
188
+
189
+ # params:
190
+ # - bucket_name
191
+ # - object_name
192
+ # - file
193
+ # - options
194
+ def append_object(bucket_name, object_name, file, position, options = {})
195
+ Object.new(@client).append_object(bucket_name, object_name, file, position, options)
196
+ end
197
+
198
+ # params:
199
+ # - bucket_name
200
+ # - object_name
201
+ def delete_object(bucket_name, object_name)
202
+ Object.new(@client).delete_object(bucket_name, object_name)
203
+ end
204
+
205
+ # params:
206
+ # - bucket_name
207
+ # - objects
208
+ def delete_multiple_objects(bucket_name, objects)
209
+ Object.new(@client).delete_multiple_objects(bucket_name, objects)
210
+ end
211
+
212
+ # params:
213
+ # - bucket_name
214
+ # - object_name
215
+ # - options
216
+ def head_object(bucket_name, object_name)
217
+ Object.new(@client).head_object(bucket_name, object_name)
218
+ end
219
+
220
+ # params:
221
+ # - bucket_name
222
+ # - object_name
223
+ # - acl
224
+ def put_object_acl(bucket_name, object_name, acl)
225
+ Object.new(@client).put_object_acl(bucket_name, object_name, acl)
226
+ end
227
+
228
+ # params:
229
+ # - bucket_name
230
+ # - object_name
231
+ # - acl
232
+ def post_object(bucket_name, key, options = {})
233
+ Object.new(@client).post_object(bucket_name, key, options)
234
+ end
235
+
236
+
237
+ #######################
238
+ # Multipart
239
+ #######################
240
+
241
+ # params:
242
+ # - bucket_name
243
+ # - object_name
244
+ # - options
245
+ def initiate_multipart_upload(bucket_name, object_name, options = {})
246
+ Multipart.new(@client).initiate_multipart_upload(bucket_name, object_name, options)
247
+ end
248
+
249
+ # params:
250
+ # - bucket_name
251
+ # - object_name
252
+ # - upload_id
253
+ # - file
254
+ # - part_number
255
+ # - options
256
+ def upload_part(bucket_name, object_name, upload_id, file, part_number = 1, options = {})
257
+ Multipart.new(@client).upload_part(bucket_name, object_name, upload_id, file, part_number, options)
258
+ end
259
+
260
+ # params:
261
+ # - bucket_name
262
+ # - object_name
263
+ # - upload_id
264
+ # - old_bucket
265
+ # - old_object
266
+ # - part_number
267
+ # - options
268
+ def upload_part_copy(bucket_name, object_name, upload_id, old_bucket, old_object, part_number = 1, options = {})
269
+ Multipart.new(@client).upload_part_copy(bucket_name, object_name, upload_id, old_bucket, old_object, part_number, options)
270
+ end
271
+
272
+ # params:
273
+ # - bucket_name
274
+ # - object_name
275
+ # - upload_id
276
+ # - parts
277
+ def complete_multipart_upload(bucket_name, object_name, upload_id, parts)
278
+ Multipart.new(@client).complete_multipart_upload(bucket_name, object_name, upload_id, parts)
279
+ end
280
+
281
+ # params:
282
+ # - bucket_name
283
+ # - object_name
284
+ # - upload_id
285
+ def abort_multipart_upload(bucket_name, object_name, upload_id)
286
+ Multipart.new(@client).abort_multipart_upload(bucket_name, object_name, upload_id)
287
+ end
288
+
289
+ # params:
290
+ # - bucket_name
291
+ # - options
292
+ def list_multipart_upload(bucket_name, options = {})
293
+ Multipart.new(@client).list_multipart_upload(bucket_name, options)
294
+ end
295
+
296
+ # params:
297
+ # - bucket_name
298
+ # - object_name
299
+ # - options
300
+ def list_parts(bucket_name, object_name, options = {})
301
+ Multipart.new(@client).list_parts(bucket_name, object_name, options)
302
+ end
303
+
304
+
305
+ #######################
306
+ # Cors
307
+ #######################
308
+
309
+ # params:
310
+ # - bucket_name
311
+ # - rules
312
+ def put_bucket_cors(bucket_name, rules)
313
+ Cors.new(@client).put_bucket_cors(bucket_name, rules)
314
+ end
315
+
316
+ # params:
317
+ # - bucket_name
318
+ # - rules
319
+ def get_bucket_cors(bucket_name)
320
+ Cors.new(@client).get_bucket_cors(bucket_name)
321
+ end
322
+
323
+ # params:
324
+ # - bucket_name
325
+ # - rules
326
+ def delete_bucket_cors(bucket_name)
327
+ Cors.new(@client).delete_bucket_cors(bucket_name)
328
+ end
329
+
330
+ # params:
331
+ # - bucket_name
332
+ # - object_name
333
+ # - origin
334
+ # - request_method
335
+ # - request_headers
336
+ def option_object(bucket_name, object_name, origin, request_method, request_headers)
337
+ Cors.new(@client).option_object(bucket_name, object_name, origin, request_method, request_headers)
338
+ end
339
+
340
+ end
341
+
342
+ end