pinch 0.0.9 → 0.1.0
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.
- data/lib/pinch.rb +11 -4
 - data/spec/pinch_spec.rb +8 -0
 - metadata +16 -5
 
    
        data/lib/pinch.rb
    CHANGED
    
    | 
         @@ -5,7 +5,7 @@ require 'zlib' 
     | 
|
| 
       5 
5 
     | 
    
         
             
            # @author Peter Hellberg
         
     | 
| 
       6 
6 
     | 
    
         
             
            # @author Edward Patel
         
     | 
| 
       7 
7 
     | 
    
         
             
            class Pinch
         
     | 
| 
       8 
     | 
    
         
            -
              VERSION = "0.0 
     | 
| 
      
 8 
     | 
    
         
            +
              VERSION = "0.1.0"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              attr_reader :uri
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
         @@ -82,9 +82,16 @@ class Pinch 
     | 
|
| 
       82 
82 
     | 
    
         
             
              # @note You might want to use Pinch.content_length instead
         
     | 
| 
       83 
83 
     | 
    
         
             
              #
         
     | 
| 
       84 
84 
     | 
    
         
             
              def content_length
         
     | 
| 
       85 
     | 
    
         
            -
                @content_length ||=  
     | 
| 
       86 
     | 
    
         
            -
                  http 
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                @content_length ||= begin
         
     | 
| 
      
 86 
     | 
    
         
            +
                  response = prepared_connection.start { |http|
         
     | 
| 
      
 87 
     | 
    
         
            +
                    http.head(@uri.path)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  }
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                  # Raise exception if the response code isn’t in the 2xx range
         
     | 
| 
      
 91 
     | 
    
         
            +
                  response.error! unless response.kind_of?(Net::HTTPSuccess)
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                  response['Content-Length'].to_i
         
     | 
| 
      
 94 
     | 
    
         
            +
                end
         
     | 
| 
       88 
95 
     | 
    
         
             
              end
         
     | 
| 
       89 
96 
     | 
    
         | 
| 
       90 
97 
     | 
    
         
             
            private
         
     | 
    
        data/spec/pinch_spec.rb
    CHANGED
    
    | 
         @@ -91,5 +91,13 @@ describe Pinch do 
     | 
|
| 
       91 
91 
     | 
    
         
             
                    Pinch.content_length(@url).must_equal 2516612
         
     | 
| 
       92 
92 
     | 
    
         
             
                  end
         
     | 
| 
       93 
93 
     | 
    
         
             
                end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                it "should raise an exception if the file doesn't exist" do
         
     | 
| 
      
 96 
     | 
    
         
            +
                  VCR.use_cassette('content_length_404') do
         
     | 
| 
      
 97 
     | 
    
         
            +
                    lambda {
         
     | 
| 
      
 98 
     | 
    
         
            +
                      Pinch.content_length(@url+'404')
         
     | 
| 
      
 99 
     | 
    
         
            +
                    }.must_raise Net::HTTPServerException
         
     | 
| 
      
 100 
     | 
    
         
            +
                  end
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
       94 
102 
     | 
    
         
             
              end
         
     | 
| 
       95 
103 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: pinch
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - Peter Hellberg
         
     | 
| 
         @@ -11,11 +11,11 @@ autorequire: 
     | 
|
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            date: 2011-07- 
     | 
| 
      
 14 
     | 
    
         
            +
            date: 2011-07-19 00:00:00 +02:00
         
     | 
| 
       15 
15 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       16 
16 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       17 
17 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       18 
     | 
    
         
            -
              name:  
     | 
| 
      
 18 
     | 
    
         
            +
              name: yard
         
     | 
| 
       19 
19 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       20 
20 
     | 
    
         
             
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
       21 
21 
     | 
    
         
             
                none: false
         
     | 
| 
         @@ -26,7 +26,7 @@ dependencies: 
     | 
|
| 
       26 
26 
     | 
    
         
             
              type: :development
         
     | 
| 
       27 
27 
     | 
    
         
             
              version_requirements: *id001
         
     | 
| 
       28 
28 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       29 
     | 
    
         
            -
              name:  
     | 
| 
      
 29 
     | 
    
         
            +
              name: minitest
         
     | 
| 
       30 
30 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       31 
31 
     | 
    
         
             
              requirement: &id002 !ruby/object:Gem::Requirement 
         
     | 
| 
       32 
32 
     | 
    
         
             
                none: false
         
     | 
| 
         @@ -37,7 +37,7 @@ dependencies: 
     | 
|
| 
       37 
37 
     | 
    
         
             
              type: :development
         
     | 
| 
       38 
38 
     | 
    
         
             
              version_requirements: *id002
         
     | 
| 
       39 
39 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
       40 
     | 
    
         
            -
              name:  
     | 
| 
      
 40 
     | 
    
         
            +
              name: fakeweb
         
     | 
| 
       41 
41 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       42 
42 
     | 
    
         
             
              requirement: &id003 !ruby/object:Gem::Requirement 
         
     | 
| 
       43 
43 
     | 
    
         
             
                none: false
         
     | 
| 
         @@ -47,6 +47,17 @@ dependencies: 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    version: "0"
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              version_requirements: *id003
         
     | 
| 
      
 50 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 51 
     | 
    
         
            +
              name: vcr
         
     | 
| 
      
 52 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 53 
     | 
    
         
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 54 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 55 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 56 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 57 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 58 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 59 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 60 
     | 
    
         
            +
              version_requirements: *id004
         
     | 
| 
       50 
61 
     | 
    
         
             
            description: Pinch makes it possible to download a specific file from within a ZIP file over HTTP 1.1.
         
     | 
| 
       51 
62 
     | 
    
         
             
            email: peter@c7.se
         
     | 
| 
       52 
63 
     | 
    
         
             
            executables: []
         
     |