upyun-purge 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/upyun/purge/client.rb +12 -18
- data/lib/upyun/purge/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9b8bf1a641cd4c58f0d6129f264b788adbd93e3
|
4
|
+
data.tar.gz: f2da9ecd1720d0325221daaa568604ac370e3f30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f4b0a4ca4704077b0b19774a8a251365cdc37abc012adeb60d9b87b5d2ef29d3e4a639788bc9ec2410ffc84e3df767c4a1ed45efc27f442d3369bcc32612c08
|
7
|
+
data.tar.gz: 02788c16e1b31986f1619a418d320ad326a01e58d579765177a1899245d304c1ae1a5b0fbe8f8f10b11628cf5b7dd6b13f7b2688946a7a4379de6956bd1f0bd7
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Upyun::Purge
|
2
2
|
|
3
|
-
|
3
|
+
Help you purge the cache on upyun.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -59,7 +59,7 @@ result = upyun.purge(["http://xx.xxxx.com/xxx.jpg","http://bb.bbb.com/bbb.jpg"])
|
|
59
59
|
|
60
60
|
## Contributing
|
61
61
|
|
62
|
-
1. Fork it ( https://github.com/
|
62
|
+
1. Fork it ( https://github.com/zmbacker/upyun-purge/fork )
|
63
63
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
64
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
65
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/upyun/purge/client.rb
CHANGED
@@ -1,56 +1,50 @@
|
|
1
1
|
module Upyun
|
2
2
|
module Purge
|
3
3
|
class Client
|
4
|
-
|
5
4
|
attr_accessor :urls
|
6
5
|
|
7
6
|
attr_accessor :bucket_name, :operator_name, :operator_password
|
8
7
|
|
9
|
-
def initialize(
|
8
|
+
def initialize(option = {})
|
10
9
|
@bucket_name = option[:bucket_name] || Upyun::Purge.bucket_name
|
11
10
|
@operator_name = option[:operator_name] || Upyun::Purge.operator_name
|
12
11
|
@operator_password = option[:operator_password] || Upyun::Purge.operator_password
|
13
12
|
end
|
14
13
|
|
15
|
-
def purge(
|
14
|
+
def purge(urls = nil)
|
16
15
|
@urls = urls.is_a?(Array) ? urls : [urls]
|
17
16
|
@urls = @urls.compact
|
18
17
|
|
19
18
|
uri = URI(Upyun::Purge.api_server)
|
20
19
|
http = Net::HTTP.new(uri.host, uri.port)
|
20
|
+
datetime = Time.now.gmtime.httpdate
|
21
21
|
request = Net::HTTP::Post.new(uri.request_uri)
|
22
|
-
request.set_form_data(
|
23
|
-
request['Authorization'] = auth_header
|
24
|
-
request['Date'] =
|
22
|
+
request.set_form_data(purge: @urls.join("\n"))
|
23
|
+
request['Authorization'] = auth_header(datetime)
|
24
|
+
request['Date'] = datetime
|
25
25
|
response = http.request(request)
|
26
26
|
case response
|
27
27
|
when Net::HTTPSuccess
|
28
28
|
return JSON.parse(response.body)
|
29
29
|
else
|
30
|
-
raise Exception
|
30
|
+
raise Exception, "\n\tRequest uri:#{uri.request_uri} \n\tResponse code: #{response.code} \n\tMessage: #{response.body}"
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
def make_signature
|
34
|
+
def make_signature(datetime)
|
39
35
|
_urls = @urls.join("\n")
|
40
|
-
|
41
|
-
second_str = [_urls,@bucket_name, datetime, md5(@operator_password)].join("&")
|
36
|
+
second_str = [_urls, @bucket_name, datetime, md5(@operator_password)].join('&')
|
42
37
|
sign = md5(second_str)
|
43
38
|
sign
|
44
39
|
end
|
45
40
|
|
46
|
-
def auth_header
|
47
|
-
"UpYun #{@bucket_name}:#{@operator_name}:#{make_signature}"
|
41
|
+
def auth_header(datetime)
|
42
|
+
"UpYun #{@bucket_name}:#{@operator_name}:#{make_signature(datetime)}"
|
48
43
|
end
|
49
44
|
|
50
|
-
def md5(
|
45
|
+
def md5(str)
|
51
46
|
Digest::MD5.hexdigest str
|
52
47
|
end
|
53
|
-
|
54
48
|
end
|
55
49
|
end
|
56
50
|
end
|
data/lib/upyun/purge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upyun-purge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lester Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|