upyun-purge 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3889962b85d048baf65e383bce42fc20c693b8ba
4
- data.tar.gz: d9aaf2be06663b72268984310f862d3ec6d12bb3
3
+ metadata.gz: cafaea0663b2c8c1a4c869bcdf436844e8957cf3
4
+ data.tar.gz: 004bf545cbf8f0457bf6b9e4b86f3b9cfd5d6f4b
5
5
  SHA512:
6
- metadata.gz: 32bf305b63de12f39029b768364592808ea59d033f42d4896d1943e7b1086a23545475a0b95175f560093890fbd1ddb078f868e016540b0c11c32942c2f05ced
7
- data.tar.gz: f6637a8949e5e2b29afc40f87d9e0cc79d6226bb829d2966875ed3ad891582864c25e90704d0383482802200afa953a8a546c83d2bb3ac11b40980f8f7324db3
6
+ metadata.gz: 484555511bcb7cadcce8855bce5481542bb2fd6fda7411a5463ebd83022b8cc392c4da1be6909a1597f5919b7aaf1a18101e2e86b83a66ba750a7806494bef7f
7
+ data.tar.gz: c62a8427a87e2a17a4de689f66456874834b134b5fcc3523017c28622395b1882e7e3ce927a0f0bf262a79f820f308d8039f49d0f5fb52439f282a3c60a0eefe
@@ -4,6 +4,14 @@ module Upyun
4
4
 
5
5
  attr_accessor :urls
6
6
 
7
+ attr_accessor :bucket_name, :operator_name, :operator_password
8
+
9
+ def initialize( option={} )
10
+ @bucket_name = option[:bucket_name] || Upyun::Purge.bucket_name
11
+ @operator_name = option[:operator_name] || Upyun::Purge.operator_name
12
+ @operator_password = option[:operator_password] || Upyun::Purge.operator_password
13
+ end
14
+
7
15
  def purge( urls = nil)
8
16
  @urls = urls.is_a?(Array) ? urls : [urls]
9
17
  @urls = @urls.compact
@@ -17,9 +25,9 @@ module Upyun
17
25
  response = http.request(request)
18
26
  case response
19
27
  when Net::HTTPSuccess
20
- return response.body
28
+ return JSON.parse(response.body)
21
29
  else
22
- raise Exception.new "Request uri:#{uri.request_uri} \nResponse code: #{response.code} \nMessage: #{response.body}"
30
+ raise Exception.new "\n\tRequest uri:#{uri.request_uri} \n\tResponse code: #{response.code} \n\tMessage: #{response.body}"
23
31
  end
24
32
 
25
33
  end
@@ -30,13 +38,13 @@ module Upyun
30
38
  def make_signature
31
39
  _urls = @urls.join("\n")
32
40
  datetime = Time.now
33
- second_str = [_urls,Upyun::Purge.bucket_name, datetime, md5(Upyun::Purge.operator_password)].join("&")
41
+ second_str = [_urls,@bucket_name, datetime, md5(@operator_password)].join("&")
34
42
  sign = md5(second_str)
35
43
  sign
36
44
  end
37
45
 
38
46
  def auth_header
39
- "UpYun #{Upyun::Purge.bucket_name}:#{Upyun::Purge.operator_name}:#{make_signature}"
47
+ "UpYun #{@bucket_name}:#{@operator_name}:#{make_signature}"
40
48
  end
41
49
 
42
50
  def md5( str )
@@ -1,5 +1,5 @@
1
1
  module Upyun
2
2
  module Purge
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/upyun/purge.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "upyun/purge/version"
2
2
  require "upyun/purge/base_extend"
3
3
  require "upyun/purge/client"
4
+ require "json"
4
5
 
5
6
  module Upyun
6
7
  module Purge
@@ -30,10 +31,7 @@ module Upyun
30
31
 
31
32
 
32
33
  def self.new( hash = {} )
33
- @@bucket_name ||= hash[:bucket_name]
34
- @@operator_name ||= hash[:operator_name]
35
- @@operator_password ||= hash[:operator_password]
36
- Client.new
34
+ Client.new( hash )
37
35
  end
38
36
 
39
37
  end
data/test/purge_test.rb CHANGED
@@ -7,17 +7,24 @@ class PurgeTest < Minitest::Test
7
7
 
8
8
  def test_purge
9
9
  result = @upyun.purge("http://xx.xxxx.com/xxx.jpg")
10
+ assert_equal true, result.key?("invalid_domain_of_url")
10
11
  end
11
12
 
12
13
 
13
14
  def test_purge_mult
14
15
  result = @upyun.purge(["http://xx.xxxx.com/xxx.jpg","http://bb.bbb.com/bbb.jpg"])
15
-
16
+ assert_equal true, result.key?("invalid_domain_of_url")
16
17
  end
17
18
 
18
-
19
19
  def test_md5
20
20
  assert_equal("5f4dcc3b5aa765d61d8327deb882cf99", @upyun.md5("password"))
21
21
  end
22
22
 
23
+
24
+ def test_call_method
25
+ upyun = Upyun::Purge.new(bucket_name: Upyun::Purge.bucket_name ,operator_name: Upyun::Purge.operator_name ,operator_password: Upyun::Purge.operator_password )
26
+ result = upyun.purge("http://docs.upyun.com/css/bootstrap.min.css")
27
+ assert_equal true, result.key?("invalid_domain_of_url")
28
+ end
29
+
23
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upyun-purge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lester Zhao