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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cafaea0663b2c8c1a4c869bcdf436844e8957cf3
4
- data.tar.gz: 004bf545cbf8f0457bf6b9e4b86f3b9cfd5d6f4b
3
+ metadata.gz: b9b8bf1a641cd4c58f0d6129f264b788adbd93e3
4
+ data.tar.gz: f2da9ecd1720d0325221daaa568604ac370e3f30
5
5
  SHA512:
6
- metadata.gz: 484555511bcb7cadcce8855bce5481542bb2fd6fda7411a5463ebd83022b8cc392c4da1be6909a1597f5919b7aaf1a18101e2e86b83a66ba750a7806494bef7f
7
- data.tar.gz: c62a8427a87e2a17a4de689f66456874834b134b5fcc3523017c28622395b1882e7e3ce927a0f0bf262a79f820f308d8039f49d0f5fb52439f282a3c60a0eefe
6
+ metadata.gz: 5f4b0a4ca4704077b0b19774a8a251365cdc37abc012adeb60d9b87b5d2ef29d3e4a639788bc9ec2410ffc84e3df767c4a1ed45efc27f442d3369bcc32612c08
7
+ data.tar.gz: 02788c16e1b31986f1619a418d320ad326a01e58d579765177a1899245d304c1ae1a5b0fbe8f8f10b11628cf5b7dd6b13f7b2688946a7a4379de6956bd1f0bd7
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Upyun::Purge
2
2
 
3
- TODO: Write a gem description
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/[my-github-username]/upyun-purge/fork )
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`)
@@ -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( option={} )
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( urls = nil)
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( purge: @urls.join("\n") )
23
- request['Authorization'] = auth_header
24
- request['Date'] = Time.now
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.new "\n\tRequest uri:#{uri.request_uri} \n\tResponse code: #{response.code} \n\tMessage: #{response.body}"
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
- datetime = Time.now
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( str )
45
+ def md5(str)
51
46
  Digest::MD5.hexdigest str
52
47
  end
53
-
54
48
  end
55
49
  end
56
50
  end
@@ -1,5 +1,5 @@
1
1
  module Upyun
2
2
  module Purge
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
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.3
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: 2015-12-23 00:00:00.000000000 Z
11
+ date: 2016-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler