Project

oss-ruby

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby SDK for Aliyun OSS.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
>= 0

Runtime

~> 0.9.0
~> 1.6.6
 Project Readme

oss-ruby

oss-ruby is the Ruby SDK of Aliyun OSS API service. All oss api methods are available through this SDK.

What is Aliyun OSS
Aliyun OSS API Official Doc

Note It's released on RubyGems. If something doesn't work, feel free to report a bug or start an issue.

Installation

Add this line to your application's Gemfile:

gem 'oss-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install oss-ruby

If you prefer to use the latest code, you can build from source:

gem build oss-ruby.gemspec
gem install oss-ruby-<VERSION>.gem

Usage

Initialization

oss-ruby requires you to initialize an instance before usage.

# Initialize oss-ruby
require 'oss'

oss = OSS.new({
  endpoint: 'oss-cn-hangzhou.aliyuncs.com',
  access_key_id: 'your_access_key',
  access_key_secret: 'your_access_secret'
})

Call API with SDK

Using sdk to call oss service is quite straight forward.

# Get Service
res = oss.get_service
p res.status # => 200

API Response

Some of the APIs returns with a xml string as response body. oss-ruby uses Nokogiri to parse the xml document internally.

res = oss.get_service
p res.status # => 200
p res.body # => "<?xml version=\"1.0\"..."
p res.doc.xpath("//ID").text # => "1216909307023357"
# and it can be shorter
p res.xpath("//ID").text # => "1216909307023357"

When API responds with an error. oss-ruby provide a error method in response object to easily parse error messages.

res = oss.get_bucket('non-exist-bucket')
p res.status # => 404
p res.body # => "<?xml version=\"1.0\"..."
p res.error.code #=> "NoSuchBucket"
p res.error.message #=> "The specified bucket does not exist."

And if network connection fails, oss-ruby will raise a OSS::HTTPClientError with backtrace and error message.

Other Documentation