0.0
No commit activity in last 3 years
No release in over 3 years
upaiyun ruby driver
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.6.4
>= 0

Runtime

 Project Readme

UpyunRainbow – simple util for migrating existing files to upyun.com¶ ↑

A simple REST client for Ruby, inspired by the rest-client style of specifying actions: get, put, post, delete.

Installation:¶ ↑

in your Gemfile: 

gem "upyun-rainbow"

Usage: ¶ ↑

require 'upyun-rainbow'

$ util = UpyunRainbow::Util.new "your_bucket_name", "upyun_operator", "password"

By default, the upyun api host is v0.api.upyun.com, if you want to pick someone else you can do it like this:

$ util = UpyunRainbow::Util.new "your_bucket_name", "upyun_operator", "password", "http://some/other/api/host"

After initialize, to upload a file:

$ util.post "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
# => [:ok, 200]

Rainbow will return an two elements arry as result, the first of which determines the process result; the second is a http status code, which helps to debug if any unexpected error occurs.

To remove a file:

$ util.delete "http://your-bind-domain.com/file/to/remove.txt"
# => [:ok, 200]

To update an existing file:

$ util.put "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
# => [:ok, 200]

To determine a file existance:

$ util.get "http://your-bind-domain.com/file/if/exists.txt"
# => [:error, 404]

Global Setting¶ ↑

To follow the DRY principle, initialize an UpyunRainbow object no need to specify bucket name, operator and password.

rails-app$ rails g upyun_configuration generate_configuration

This will copy an upyun settings file to the initializers directory, modify that file, fill in your details and the initialize will be more elegant.

$ util = UpyunRainbow::Util.new #this will use the system wide bucket info you specified in the initializer

$ util.post "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
# => [:ok, 200]

$ util = UpyunRainbow::Util.new "some-other-bucket", "not-default-operator", "password" #use an customize bucket etc
$ util.delete "some http resource"

Copyright © 2011 tim.teng. See LICENSE for details.