Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
/ aliyunoss Public archive

Ruby gem for accessing Aliyun Open Storage Service.

License

Notifications You must be signed in to change notification settings

dannyxu2015/aliyunoss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aliyun::Oss

Ruby gem for Aliyun Open Storage Service (OSS). This gem implemented API from references of Aliyun OSS-API.

Installation

Add this line to your application's Gemfile:

gem 'aliyunoss'

And then execute:

$ bundle

Or install it yourself as:

$ gem install aliyunoss

Usage

This gem provides high level interfaces which are built around class Bucket and low level interfaces which are wrappers for OSS API.

Load Access Key ID and Access Key Secret

Specify you access key and access secret before calling methods provided in this gem:

Aliyun::Oss::configure(:access_key_id => 'access key id from aliyun', :access_key_secret => 'access secret from aliyun')

Low Level Interfaces

Low level interfaces are simple wrappers for OSS API, you send requests with specified parameters and receive responses with a Net::HTTPResponse object. All parameters listed in OSS API are needed for every request, and context info between requests is maintained by yourself. In order to tell whether a a request is success, check code and body of returned Net::HTTPResponse object.

All OSS API listed are implemented except Post Object and CORS APIs.

List all the buckets:

Aliyun::Oss::API.list_bucket

Upload data to specified bucket:

bucket = Aliyun::Oss::Bucket.new(:name => 'bucket-name', :location => 'oss-cn-beijing')
path = '/test.dat'
data = Random.new.bytes(1024 * rand(100..300))
Aliyun::Oss::API.put_object(bucket, path, data)

Download data from specified bucket:

bucket = Bucket.new(:name => 'bucket-name', :location => 'oss-cn-beijing')
path = '/test.dat'
Aliyun::Oss::API.get_object(bucket, path)

For more usage, see API documentation generated by rdoc.

High Level Interfaces

High level interface are built around class Bucket. You create a new bucket, and upload, download or delete files in it. When needed, responses are parsed to array, hash or object etc, thus more meaningful. Exceptions will be raised when request failed.

# Create a bucket in OSS server
bucket = Aliyun::Oss::Bucket.create('aliyun-oss-gem-api-test','oss-cn-hangzhou')

# Upload a file
filename = '/some/file'
bucket.upload( IO.read(filename) )

# List all files in this bucket, returns a Hash array containing files info
files = bucket.list_files

# Download a file, returns raw data
data = bucket.download( '/some/path' )

For more usage, see API documentation generated by rdoc.

Testing

This gem use rspec for testing. Most of testing needs a valid access key id and access key secret, you should get these info from Aliyun.

Create a file named aliyun-config.yml in path rspec/aliyun/oss, fill in valid access key id and access key secret and cotinue to test.

Contributing

  1. Fork it ( https://github.com/yijiecc/aliyunoss/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Ruby gem for accessing Aliyun Open Storage Service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages