The official QingStor SDK for Ruby programming language.
This Gem uses Ruby's keyword arguments feature, thus Ruby v2.1.5 or higher is required. See this article for more details about keyword arguments.
Notice: If you are using Ruby v1.9.x, please checkout the compatible branch.
$ gem install qingstor-sdk
Specify qingstor-sdk
as dependency in your application's Gemfile:
gem 'qingstor-sdk'
Ensure qingstor-sdk
is installed as dependency with bundle-install
:
$ bundle install
Get code from GitHub:
$ git clone [email protected]:yunify/qingstor-sdk-ruby.git
Build and install with bundler:
$ cd qingstor-sdk-ruby
$ bundle install
$ bundle exec rake install
$ gem uninstall qingstor-sdk
Before using the SDK, please make sure you already have QingCloud API access key, apply one from QingCloud Console otherwise.
API Access Key Example:
access_key_id: 'ACCESS_KEY_ID_EXAMPLE'
secret_access_key: 'SECRET_ACCESS_KEY_EXAMPLE'
require 'qingstor/sdk'
require 'digest/md5'
# Create a config object with access_key_id and secret_access_key defined as
# environment variables.
config = QingStor::SDK::Config.init ENV['ENV_ACCESS_KEY_ID'],
ENV['ENV_SECRET_ACCESS_KEY']
# Initialize QingStor service with the config object.
qs_service = QingStor::SDK::Service.new config
# List buckets
result = qs_service.list_buckets
# Print HTTP status code
puts result[:status_code]
# Print bucket count
puts result[:buckets].length
# Print the first bucket name
puts result[:buckets][0][:name]
# Initialize a QingStor bucket
bucket = qs_service.bucket 'test-bucket', 'pek3a'
# List objects
result = bucket.list_objects
# Print HTTP status code
puts result[:status_code]
# Print keys count
puts result[:keys].length
# Upload an object
file_path = File.expand_path '~/Desktop/Screenshot.jpg'
md5_string = Digest::MD5.file(file_path).to_s
result = bucket.put_object 'Screenshot.jpg',
content_md5: md5_string,
body: File.open(file_path)
# Print HTTP status code.
puts result[:status_code]
Except access_key_id and secret_access_key, you can also configure the API server (in case of QingStor is deployed in private environment, thus has different endpoint with public QingStor) either in the config file, or in the program dynamically.
Code Example:
require 'qingstor/sdk'
# Load default configuration
config = QingStor::SDK::Config.new.load_default_config
# Create with default value
config = QingStor::SDK::Config.new({
host: 'qingstor.dev',
log_level: 'debug',
})
# Create a configuration from AccessKeyID and SecretAccessKey
config = QingStor::SDK::Config.init ENV['ENV_ACCESS_KEY_ID'],
ENV['ENV_SECRET_ACCESS_KEY']
# Load configuration from config file
config = QingStor::SDK::Config.new
config = config.load_config_from_file '~/qingstor/config.yaml'
# Change API server
config.update({host: 'test.qingstor.com'})
Default Configuration File:
# QingStor services configuration
access_key_id: 'ACCESS_KEY_ID'
secret_access_key: 'SECRET_ACCESS_KEY'
host: 'qingstor.com'
port: 443
protocol: 'https'
connection_retries: 3
# Valid log levels are "debug", "info", "warn", "error", and "fatal".
log_level: 'warn'
All notable changes to QingStor SDK for Ruby will be documented here.
v2.1.1 - 2017-01-16
- Fix signer bug.
v2.1.0 - 2016-12-24
- Fix signer bug.
- Add more parameters to sign.
- Add request parameters for GET Object.
- Add IP address conditions for bucket policy.
v2.0.1 - 2016-12-16
- Improve the implementation of deleting multiple objects.
- QingStor SDK for the Ruby programming language.
- Fork it ( https://github.com/yunify/qingstor-sdk-ruby/fork )
- Create your feature branch (
git checkout -b new-feature
) - Commit your changes (
git commit -asm 'Add some feature'
) - Push to the branch (
git push origin new-feature
) - Create a new Pull Request
The Apache License (Version 2.0, January 2004).