upyun-purge 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +11 -0
- data/lib/upyun/purge.rb +37 -0
- data/lib/upyun/purge/base_extend.rb +53 -0
- data/lib/upyun/purge/client.rb +48 -0
- data/lib/upyun/purge/version.rb +5 -0
- data/test/purge_test.rb +23 -0
- data/test/test_helper.rb +28 -0
- data/upyun-purge.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a68306a260f897f14087197e19f97e50615a2abe
|
4
|
+
data.tar.gz: e19708549c7114c372e4baa3e14128af7f75a104
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 47ce72b1cc0a1fab7729bad306da96ce6ea037306222c696c34d66ea5bf4f5b31127dc4f3c82d5034d3f7dc80bf20134bb0baf91c223f8bb384687ba534f57db
|
7
|
+
data.tar.gz: 9a07b789e6d5ea208c3970f3e3a6d3ff5692ac8b31fc328edd2e241b5754a6806ea71d351a21cd4a0d1b365e2c24510de61f019444c3ccb1188acb691c266530
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Lester Zhao
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Upyun::Purge
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'upyun-purge'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install upyun-purge
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
|
26
|
+
upyun = Upyun::Purge.new(bucket_name: "xxxx", operator_name: "xxxxx", operator_password: "xxxxxx")
|
27
|
+
|
28
|
+
upyun.purge("http://xx.xxxx.com/xxx.jpg")
|
29
|
+
|
30
|
+
upyun.purge(["http://xx.xxxx.com/xxx.jpg","http://bb.bbb.com/bbb.jpg"])
|
31
|
+
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
|
38
|
+
Upyun::Purge.setup do |config|
|
39
|
+
|
40
|
+
# bucket name
|
41
|
+
config.bucket_name = "testid"
|
42
|
+
|
43
|
+
# operator name
|
44
|
+
config.operator_name = "testsecret"
|
45
|
+
|
46
|
+
# operator password
|
47
|
+
config.operator_password = "password"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
upyun = Upyun::Purge.new
|
52
|
+
result = upyun.purge("http://xx.xxxx.com/xxx.jpg")
|
53
|
+
result = upyun.purge(["http://xx.xxxx.com/xxx.jpg","http://bb.bbb.com/bbb.jpg"])
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/[my-github-username]/upyun-purge/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/upyun/purge.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "upyun/purge/version"
|
2
|
+
require "upyun/purge/base_extend"
|
3
|
+
require "upyun/purge/client"
|
4
|
+
|
5
|
+
module Upyun
|
6
|
+
module Purge
|
7
|
+
extend BaseExtend
|
8
|
+
|
9
|
+
# bucket_name
|
10
|
+
define_attribute :bucket_name
|
11
|
+
@@bucket_name = nil
|
12
|
+
|
13
|
+
# operator_name
|
14
|
+
define_attribute :operator_name
|
15
|
+
@@operator_name = nil
|
16
|
+
|
17
|
+
# operator_password
|
18
|
+
define_attribute :operator_password
|
19
|
+
@@operator_password = nil
|
20
|
+
|
21
|
+
# api server
|
22
|
+
define_attribute :api_server
|
23
|
+
@@api_server = "http://purge.upyun.com/purge/"
|
24
|
+
|
25
|
+
# setup upyun base info
|
26
|
+
def self.setup
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
def self.new
|
33
|
+
Client.new
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Upyun
|
2
|
+
module Purge
|
3
|
+
module BaseExtend
|
4
|
+
def define_attribute( attr_name )
|
5
|
+
|
6
|
+
# define read mehtod for class and instance
|
7
|
+
class_eval(" @@#{attr_name} = nil unless defined? @@#{attr_name}
|
8
|
+
|
9
|
+
def self.#{attr_name}
|
10
|
+
@@#{attr_name}
|
11
|
+
end
|
12
|
+
", __FILE__, __LINE__ + 1)
|
13
|
+
|
14
|
+
class_eval(" def #{attr_name}
|
15
|
+
@@#{attr_name}
|
16
|
+
end
|
17
|
+
", __FILE__, __LINE__ + 1)
|
18
|
+
|
19
|
+
# define write mehtod for class and instance
|
20
|
+
class_eval(" @@#{attr_name} = nil unless defined? @@#{attr_name}
|
21
|
+
|
22
|
+
def self.#{attr_name}=(obj)
|
23
|
+
@@#{attr_name} = obj
|
24
|
+
end
|
25
|
+
", __FILE__, __LINE__ + 1)
|
26
|
+
|
27
|
+
class_eval(" def #{attr_name}=(obj)
|
28
|
+
@@#{attr_name} = obj
|
29
|
+
end
|
30
|
+
", __FILE__, __LINE__ + 1)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
def random_string( len = 20 )
|
37
|
+
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
38
|
+
newpass = ""
|
39
|
+
1.upto(len) { |i| newpass << chars[Kernel.rand(chars.size-1)] }
|
40
|
+
newpass
|
41
|
+
end
|
42
|
+
|
43
|
+
def random_number( len = 20 )
|
44
|
+
chars = ("0".."9").to_a
|
45
|
+
newpass = ""
|
46
|
+
1.upto(len) { |i| newpass << chars[Kernel.rand(chars.size-1)] }
|
47
|
+
newpass
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Upyun
|
2
|
+
module Purge
|
3
|
+
class Client
|
4
|
+
|
5
|
+
attr_accessor :urls
|
6
|
+
|
7
|
+
def purge( urls = nil)
|
8
|
+
@urls = urls.is_a?(Array) ? urls : [urls]
|
9
|
+
@urls = @urls.compact
|
10
|
+
|
11
|
+
uri = URI(Upyun::Purge.api_server)
|
12
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
13
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
14
|
+
request.set_form_data( purge: @urls.join("\n") )
|
15
|
+
request['Authorization'] = auth_header
|
16
|
+
request['Date'] = Time.now
|
17
|
+
response = http.request(request)
|
18
|
+
case response
|
19
|
+
when Net::HTTPSuccess
|
20
|
+
return response.body
|
21
|
+
else
|
22
|
+
raise Exception.new "Request uri:#{uri.request_uri} \nResponse code: #{response.code} \nMessage: #{response.body}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
def make_signature
|
31
|
+
_urls = @urls.join("\n")
|
32
|
+
datetime = Time.now
|
33
|
+
second_str = [_urls,Upyun::Purge.bucket_name, datetime, md5(Upyun::Purge.operator_password)].join("&")
|
34
|
+
sign = md5(second_str)
|
35
|
+
sign
|
36
|
+
end
|
37
|
+
|
38
|
+
def auth_header
|
39
|
+
"UpYun #{Upyun::Purge.bucket_name}:#{Upyun::Purge.operator_name}:#{make_signature}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def md5( str )
|
43
|
+
Digest::MD5.hexdigest str
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/test/purge_test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class PurgeTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@upyun = Upyun::Purge.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_purge
|
9
|
+
result = @upyun.purge("http://xx.xxxx.com/xxx.jpg")
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def test_purge_mult
|
14
|
+
result = @upyun.purge(["http://xx.xxxx.com/xxx.jpg","http://bb.bbb.com/bbb.jpg"])
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def test_md5
|
20
|
+
assert_equal("5f4dcc3b5aa765d61d8327deb882cf99", @upyun.md5("password"))
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/pride'
|
3
|
+
|
4
|
+
require 'upyun/purge'
|
5
|
+
|
6
|
+
|
7
|
+
# setup global config
|
8
|
+
|
9
|
+
Upyun::Purge.setup do |config|
|
10
|
+
|
11
|
+
# bucket name
|
12
|
+
config.bucket_name = "bucket_name"
|
13
|
+
|
14
|
+
# operator name
|
15
|
+
config.operator_name = "operator_name"
|
16
|
+
|
17
|
+
# operator password
|
18
|
+
config.operator_password = "password"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
# If real_account.rb exist in the test folder the config of upyun can rewrite by it.
|
23
|
+
# It's usefull by when you want to test the real upyun.
|
24
|
+
begin
|
25
|
+
require "real_account"
|
26
|
+
rescue LoadError
|
27
|
+
print "\nPlease notice: You haven't config infor of upyun account. \n\n"
|
28
|
+
end
|
data/upyun-purge.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'upyun/purge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "upyun-purge"
|
8
|
+
spec.version = Upyun::Purge::VERSION
|
9
|
+
spec.authors = ["Lester Zhao"]
|
10
|
+
spec.email = ["zm.backer@gmail.com"]
|
11
|
+
spec.summary = %q{Help you purge the cache on upyun.}
|
12
|
+
spec.description = %q{Help you purge the cache on upyun.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: upyun-purge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lester Zhao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Help you purge the cache on upyun.
|
42
|
+
email:
|
43
|
+
- zm.backer@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/upyun/purge.rb
|
54
|
+
- lib/upyun/purge/base_extend.rb
|
55
|
+
- lib/upyun/purge/client.rb
|
56
|
+
- lib/upyun/purge/version.rb
|
57
|
+
- test/purge_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
- upyun-purge.gemspec
|
60
|
+
homepage: ''
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Help you purge the cache on upyun.
|
84
|
+
test_files:
|
85
|
+
- test/purge_test.rb
|
86
|
+
- test/test_helper.rb
|