upyun-rainbow 0.1.2
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.
- data/.document +5 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +20 -0
- data/README +1 -0
- data/README.rdoc +62 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/generators/templates/upyun_settings.rb +7 -0
- data/lib/generators/upyun_configuration_generator.rb +13 -0
- data/lib/upyun-rainbow.rb +5 -0
- data/lib/upyun-rainbow/railtie.rb +12 -0
- data/lib/upyun-rainbow/upyun-rainbow.rb +75 -0
- data/test/helper.rb +18 -0
- data/test/test_upyun-rainbow.rb +7 -0
- metadata +143 -0
data/.document
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
source 'http://ruby.taobao.org/'
|
|
2
|
+
# Add dependencies required to use your gem here.
|
|
3
|
+
# Example:
|
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
|
5
|
+
|
|
6
|
+
# Add dependencies to develop your gem here.
|
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
|
8
|
+
group :development do
|
|
9
|
+
gem "shoulda", ">= 0"
|
|
10
|
+
gem "bundler", "~> 1.0.0"
|
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
|
12
|
+
gem "rcov", ">= 0"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
gem "rest-client", "~> 1.6.7"
|
|
16
|
+
|
|
17
|
+
gem "configatron"
|
|
18
|
+
|
|
19
|
+
gem "domainatrix"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://ruby.taobao.org/
|
|
3
|
+
specs:
|
|
4
|
+
addressable (2.2.6)
|
|
5
|
+
configatron (2.9.0)
|
|
6
|
+
yamler (>= 0.1.0)
|
|
7
|
+
domainatrix (0.0.10)
|
|
8
|
+
addressable
|
|
9
|
+
git (1.2.5)
|
|
10
|
+
jeweler (1.6.4)
|
|
11
|
+
bundler (~> 1.0)
|
|
12
|
+
git (>= 1.2.5)
|
|
13
|
+
rake
|
|
14
|
+
mime-types (1.17.2)
|
|
15
|
+
rake (0.9.2.2)
|
|
16
|
+
rcov (0.9.11)
|
|
17
|
+
rest-client (1.6.7)
|
|
18
|
+
mime-types (>= 1.16)
|
|
19
|
+
shoulda (2.11.3)
|
|
20
|
+
yamler (0.1.0)
|
|
21
|
+
|
|
22
|
+
PLATFORMS
|
|
23
|
+
ruby
|
|
24
|
+
|
|
25
|
+
DEPENDENCIES
|
|
26
|
+
bundler (~> 1.0.0)
|
|
27
|
+
configatron
|
|
28
|
+
domainatrix
|
|
29
|
+
jeweler (~> 1.6.4)
|
|
30
|
+
rcov
|
|
31
|
+
rest-client (~> 1.6.7)
|
|
32
|
+
shoulda
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 tim.rubist
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Will come soon
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
= UpyunRainbow -- simple util for migrating existing files to http://upyun.com
|
|
2
|
+
|
|
3
|
+
A simple REST client for Ruby, inspired by the rest-client style
|
|
4
|
+
of specifying actions: get, put, post, delete.
|
|
5
|
+
|
|
6
|
+
== Installation:
|
|
7
|
+
|
|
8
|
+
in your Gemfile:
|
|
9
|
+
|
|
10
|
+
gem "upyun-rainbow"
|
|
11
|
+
|
|
12
|
+
== Usage:
|
|
13
|
+
|
|
14
|
+
require 'upyun-rainbow'
|
|
15
|
+
|
|
16
|
+
$ util = UpyunRainbow::Util.new "your_bucket_name", "upyun_operator", "password"
|
|
17
|
+
|
|
18
|
+
By default, the upyun api host is http://v0.api.upyun.com, if you want to pick someone else you can do it like this:
|
|
19
|
+
|
|
20
|
+
$ util = UpyunRainbow::Util.new "your_bucket_name", "upyun_operator", "password", "http://some/other/api/host"
|
|
21
|
+
|
|
22
|
+
After initialize, to upload a file:
|
|
23
|
+
|
|
24
|
+
$ util.post "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
|
|
25
|
+
# => [:ok, 200]
|
|
26
|
+
|
|
27
|
+
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.
|
|
28
|
+
|
|
29
|
+
To remove a file:
|
|
30
|
+
|
|
31
|
+
$ util.delete "http://your-bind-domain.com/file/to/remove.txt"
|
|
32
|
+
# => [:ok, 200]
|
|
33
|
+
|
|
34
|
+
To update an existing file:
|
|
35
|
+
|
|
36
|
+
$ util.put "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
|
|
37
|
+
# => [:ok, 200]
|
|
38
|
+
|
|
39
|
+
To determine a file existance:
|
|
40
|
+
$ util.get "http://your-bind-domain.com/file/if/exists.txt"
|
|
41
|
+
# => [:error, 404]
|
|
42
|
+
|
|
43
|
+
== Global Setting
|
|
44
|
+
|
|
45
|
+
To follow the DRY principle, initialize an UpyunRainbow object no need to specify bucket name, operator and password.
|
|
46
|
+
|
|
47
|
+
rails-app$ rails g upyun_configuration generate_configatrion
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
$ util = UpyunRainbow::Util.new #this will use the system wide bucket info you specified in the initializer
|
|
52
|
+
|
|
53
|
+
$ util.post "http://your-bind-domain.com/some/relative/path/pic.jpg", File.read("/Users/tim/Desktop/a.jpg")
|
|
54
|
+
# => [:ok, 200]
|
|
55
|
+
|
|
56
|
+
$ util = UpyunRainbow::Util.new "some-other-bucket", "not-default-operator", "password" #use an customize bucket etc
|
|
57
|
+
$ util.delete "some http resource"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
== Copyright
|
|
61
|
+
|
|
62
|
+
Copyright © 2011 tim.teng. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
+
gem.name = "upyun-rainbow"
|
|
18
|
+
gem.homepage = "http://github.com/tteng/upyun-rainbow"
|
|
19
|
+
gem.license = "MIT"
|
|
20
|
+
gem.summary = %Q{upaiyun ruby driver}
|
|
21
|
+
gem.description = %Q{upaiyun ruby driver}
|
|
22
|
+
gem.email = "tim.rubist@gmail.com"
|
|
23
|
+
gem.authors = ["tim.rubist"]
|
|
24
|
+
# dependencies defined in Gemfile
|
|
25
|
+
end
|
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
+
|
|
28
|
+
require 'rake/testtask'
|
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
|
30
|
+
test.libs << 'lib' << 'test'
|
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
|
32
|
+
test.verbose = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
require 'rcov/rcovtask'
|
|
36
|
+
Rcov::RcovTask.new do |test|
|
|
37
|
+
test.libs << 'test'
|
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
|
39
|
+
test.verbose = true
|
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
task :default => :test
|
|
44
|
+
|
|
45
|
+
require 'rake/rdoctask'
|
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
48
|
+
|
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
50
|
+
rdoc.title = "upyun-rainbow #{version}"
|
|
51
|
+
rdoc.rdoc_files.include('README*')
|
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
53
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.2
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#coding: utf-8
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'rails/generators'
|
|
4
|
+
|
|
5
|
+
class UpyunConfigurationGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
8
|
+
|
|
9
|
+
def generate_configuration
|
|
10
|
+
copy_file "upyun_settings.rb", "config/initializers/upyun_settings.rb"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#coding: utf-8
|
|
2
|
+
require 'configatron'
|
|
3
|
+
require 'rest-client'
|
|
4
|
+
require 'domainatrix'
|
|
5
|
+
require 'uri'
|
|
6
|
+
|
|
7
|
+
module UpyunRainbow
|
|
8
|
+
|
|
9
|
+
class Util
|
|
10
|
+
|
|
11
|
+
def initialize bucket=nil, user=nil, pwd=nil, api_host="http://v0.api.upyun.com"
|
|
12
|
+
@api_host = api_host || configatron.upaiyun.api_host
|
|
13
|
+
@bucket = bucket || configatron.upaiyun.bucket_name
|
|
14
|
+
@user = user || configatron.upaiyun.user_name
|
|
15
|
+
@password = pwd || configatron.upaiyun.password
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get url, options={}
|
|
19
|
+
relative_path = get_relative_path url
|
|
20
|
+
result = process :get, relative_path, options
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def put url, data, options={}
|
|
24
|
+
relative_path = get_relative_path url
|
|
25
|
+
result = process :put, relative_path, data, options
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def post url, data, options={}
|
|
29
|
+
relative_path = get_relative_path url
|
|
30
|
+
result = process :post, relative_path, data, {'Expect' => '', 'Mkdir' => 'true'}.merge(options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def delete url, options={}
|
|
34
|
+
relative_path = get_relative_path url
|
|
35
|
+
result = process :delete, relative_path, options
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def resource
|
|
40
|
+
@resource ||= RestClient::Resource.new(
|
|
41
|
+
"#{@api_host}/#{@bucket}",
|
|
42
|
+
:user => @user,
|
|
43
|
+
:password => @password
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def escaped_path url
|
|
48
|
+
URI.encode url
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get_relative_path url
|
|
52
|
+
begin
|
|
53
|
+
relative_path = Domainatrix.parse(escaped_path(url)).path
|
|
54
|
+
rescue
|
|
55
|
+
raise "Not a regular http path to process, the url should looks like http://yourdomain.com/file/to/process.jpg|txt"
|
|
56
|
+
end
|
|
57
|
+
raise "Oh, Which file to process?" if relative_path.blank?
|
|
58
|
+
relative_path
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def process meth, url, data=nil, options={}
|
|
62
|
+
proc = Proc.new do |response, request, result|
|
|
63
|
+
case response.code
|
|
64
|
+
when 200
|
|
65
|
+
[:ok, 200]
|
|
66
|
+
else
|
|
67
|
+
[:error, response.code]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
result = [:post, :put].include?(meth) ? resource[url].send(meth, data, options, &proc) : resource[url].send(meth, options, &proc)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'bundler'
|
|
3
|
+
begin
|
|
4
|
+
Bundler.setup(:default, :development)
|
|
5
|
+
rescue Bundler::BundlerError => e
|
|
6
|
+
$stderr.puts e.message
|
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
8
|
+
exit e.status_code
|
|
9
|
+
end
|
|
10
|
+
require 'test/unit'
|
|
11
|
+
require 'shoulda'
|
|
12
|
+
|
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
15
|
+
require 'upyun-rainbow'
|
|
16
|
+
|
|
17
|
+
class Test::Unit::TestCase
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: upyun-rainbow
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- tim.rubist
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-01-18 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rest-client
|
|
16
|
+
requirement: &70126047570020 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 1.6.7
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70126047570020
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: configatron
|
|
27
|
+
requirement: &70126047569540 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70126047569540
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: domainatrix
|
|
38
|
+
requirement: &70126047569060 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ! '>='
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
type: :runtime
|
|
45
|
+
prerelease: false
|
|
46
|
+
version_requirements: *70126047569060
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: shoulda
|
|
49
|
+
requirement: &70126047568580 !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *70126047568580
|
|
58
|
+
- !ruby/object:Gem::Dependency
|
|
59
|
+
name: bundler
|
|
60
|
+
requirement: &70126047568100 !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
62
|
+
requirements:
|
|
63
|
+
- - ~>
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: 1.0.0
|
|
66
|
+
type: :development
|
|
67
|
+
prerelease: false
|
|
68
|
+
version_requirements: *70126047568100
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: jeweler
|
|
71
|
+
requirement: &70126047567620 !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ~>
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: 1.6.4
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: *70126047567620
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: rcov
|
|
82
|
+
requirement: &70126047567140 !ruby/object:Gem::Requirement
|
|
83
|
+
none: false
|
|
84
|
+
requirements:
|
|
85
|
+
- - ! '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: *70126047567140
|
|
91
|
+
description: upaiyun ruby driver
|
|
92
|
+
email: tim.rubist@gmail.com
|
|
93
|
+
executables: []
|
|
94
|
+
extensions: []
|
|
95
|
+
extra_rdoc_files:
|
|
96
|
+
- LICENSE.txt
|
|
97
|
+
- README
|
|
98
|
+
- README.rdoc
|
|
99
|
+
files:
|
|
100
|
+
- .document
|
|
101
|
+
- Gemfile
|
|
102
|
+
- Gemfile.lock
|
|
103
|
+
- LICENSE.txt
|
|
104
|
+
- README
|
|
105
|
+
- README.rdoc
|
|
106
|
+
- Rakefile
|
|
107
|
+
- VERSION
|
|
108
|
+
- lib/generators/templates/upyun_settings.rb
|
|
109
|
+
- lib/generators/upyun_configuration_generator.rb
|
|
110
|
+
- lib/upyun-rainbow.rb
|
|
111
|
+
- lib/upyun-rainbow/railtie.rb
|
|
112
|
+
- lib/upyun-rainbow/upyun-rainbow.rb
|
|
113
|
+
- test/helper.rb
|
|
114
|
+
- test/test_upyun-rainbow.rb
|
|
115
|
+
homepage: http://github.com/tteng/upyun-rainbow
|
|
116
|
+
licenses:
|
|
117
|
+
- MIT
|
|
118
|
+
post_install_message:
|
|
119
|
+
rdoc_options: []
|
|
120
|
+
require_paths:
|
|
121
|
+
- lib
|
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
|
+
none: false
|
|
124
|
+
requirements:
|
|
125
|
+
- - ! '>='
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: '0'
|
|
128
|
+
segments:
|
|
129
|
+
- 0
|
|
130
|
+
hash: 2884429431946913101
|
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
|
+
none: false
|
|
133
|
+
requirements:
|
|
134
|
+
- - ! '>='
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
requirements: []
|
|
138
|
+
rubyforge_project:
|
|
139
|
+
rubygems_version: 1.8.10
|
|
140
|
+
signing_key:
|
|
141
|
+
specification_version: 3
|
|
142
|
+
summary: upaiyun ruby driver
|
|
143
|
+
test_files: []
|