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 +4 -4
- data/lib/upyun/purge/client.rb +12 -4
- data/lib/upyun/purge/version.rb +1 -1
- data/lib/upyun/purge.rb +2 -4
- data/test/purge_test.rb +9 -2
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cafaea0663b2c8c1a4c869bcdf436844e8957cf3
         | 
| 4 | 
            +
              data.tar.gz: 004bf545cbf8f0457bf6b9e4b86f3b9cfd5d6f4b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 484555511bcb7cadcce8855bce5481542bb2fd6fda7411a5463ebd83022b8cc392c4da1be6909a1597f5919b7aaf1a18101e2e86b83a66ba750a7806494bef7f
         | 
| 7 | 
            +
              data.tar.gz: c62a8427a87e2a17a4de689f66456874834b134b5fcc3523017c28622395b1882e7e3ce927a0f0bf262a79f820f308d8039f49d0f5fb52439f282a3c60a0eefe
         | 
    
        data/lib/upyun/purge/client.rb
    CHANGED
    
    | @@ -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 " | 
| 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 | 
| 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 #{ | 
| 47 | 
            +
                    "UpYun #{@bucket_name}:#{@operator_name}:#{make_signature}"
         | 
| 40 48 | 
             
                  end
         | 
| 41 49 |  | 
| 42 50 | 
             
                  def md5( str )
         | 
    
        data/lib/upyun/purge/version.rb
    CHANGED
    
    
    
        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 | 
            -
                   | 
| 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
         |