pinch 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/pinch.rb +26 -12
  3. data/spec/pinch_spec.rb +17 -5
  4. metadata +2 -2
data/README.rdoc CHANGED
@@ -21,7 +21,7 @@ I’ve tested Pinch on 1.9.2. YMMV.
21
21
 
22
22
  require 'pinch'
23
23
 
24
- data = Pinch.get 'URL_TO_ZIP_FILE', 'path/file.ext'
24
+ data = Pinch.get 'http://peterhellberg.github.com/pinch/test.zip', 'data.json'
25
25
 
26
26
  puts data
27
27
 
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"
8
+ VERSION = "0.0.9"
9
9
 
10
10
  attr_reader :uri
11
11
 
@@ -36,11 +36,24 @@ class Pinch
36
36
  new(url).file_list
37
37
  end
38
38
 
39
+ ##
40
+ # Retrieve the size of the ZIP file
41
+ #
42
+ # @param [String] url Full URL to the ZIP file
43
+ # @return [Fixnum] Size of the ZIP file
44
+ # @example
45
+ #
46
+ # Pinch.content_length('http://peterhellberg.github.com/pinch/test.zip') #=> 2516612
47
+ #
48
+ def self.content_length(url)
49
+ new(url).content_length
50
+ end
51
+
39
52
  ##
40
53
  # Initializes a new Pinch object
41
54
  #
42
55
  # @param [String] url Full URL to the ZIP file
43
- # @note You might want to use Pinch#get instead.
56
+ # @note You might want to use Pinch.get instead.
44
57
  #
45
58
  def initialize(url)
46
59
  @uri = URI.parse(url)
@@ -48,7 +61,7 @@ class Pinch
48
61
  end
49
62
 
50
63
  ##
51
- # @note You might want to use Pinch#file_list instead.
64
+ # @note You might want to use Pinch.file_list instead.
52
65
  #
53
66
  def file_list
54
67
  file_headers.keys
@@ -59,12 +72,21 @@ class Pinch
59
72
  #
60
73
  # puts Pinch.new('http://peterhellberg.github.com/pinch/test.zip').get('data.json')
61
74
  #
62
- # @note You might want to use Pinch#get instead
75
+ # @note You might want to use Pinch.get instead
63
76
  #
64
77
  def get(file_name)
65
78
  local_file(file_name)
66
79
  end
67
80
 
81
+ ##
82
+ # @note You might want to use Pinch.content_length instead
83
+ #
84
+ def content_length
85
+ @content_length ||= prepared_connection.start { |http|
86
+ http.head(@uri.path)
87
+ }['Content-Length'].to_i
88
+ end
89
+
68
90
  private
69
91
 
70
92
  def local_file(file_name)
@@ -197,14 +219,6 @@ private
197
219
  prepared_connection.request(request)
198
220
  end
199
221
 
200
- ##
201
- # Retrieve the content length of the file
202
- def content_length
203
- @content_length ||= prepared_connection.start { |http|
204
- http.head(@uri.path)
205
- }['Content-Length'].to_i
206
- end
207
-
208
222
  ##
209
223
  # Prepare the connection and GET request
210
224
  def prepared_connection
data/spec/pinch_spec.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
  require File.dirname(__FILE__) + '/../lib/pinch'
13
13
 
14
14
  describe Pinch do
15
- describe "when calling get on a compressed zip file" do
15
+ describe "when calling get on a compressed ZIP file" do
16
16
  it "should return the contents of the file" do
17
17
  VCR.use_cassette('squeak') do
18
18
  @url = 'http://ftp.sunet.se/pub/lang/smalltalk/Squeak/current_stable/Squeak3.8-6665-full.zip'
@@ -25,7 +25,7 @@ describe Pinch do
25
25
  end
26
26
  end
27
27
 
28
- describe "when calling get on a zip file that is not compressed" do
28
+ describe "when calling get on a ZIP file that is not compressed" do
29
29
  it "should return the contents of the file" do
30
30
  VCR.use_cassette('canabalt') do
31
31
  @url = 'http://memention.com/ericjohnson-canabalt-ios-ef43b7d.zip'
@@ -38,7 +38,7 @@ describe Pinch do
38
38
  end
39
39
  end
40
40
 
41
- describe "when calling get on the example zip file" do
41
+ describe "when calling get on the example ZIP file" do
42
42
  before do
43
43
  @url = 'http://peterhellberg.github.com/pinch/test.zip'
44
44
  @file = 'data.json'
@@ -70,8 +70,8 @@ describe Pinch do
70
70
  end
71
71
  end
72
72
 
73
- describe "#file_list" do
74
- it "should return a list with all the file names in the zip" do
73
+ describe "Pinch.file_list" do
74
+ it "should return a list with all the file names in the ZIP file" do
75
75
  VCR.use_cassette('file_list') do
76
76
  @url = 'http://memention.com/ericjohnson-canabalt-ios-ef43b7d.zip'
77
77
 
@@ -80,4 +80,16 @@ describe Pinch do
80
80
  end
81
81
  end
82
82
  end
83
+
84
+ describe "Pinch.content_length" do
85
+ before do
86
+ @url = 'http://peterhellberg.github.com/pinch/test.zip'
87
+ end
88
+
89
+ it "should return the size of the ZIP file" do
90
+ VCR.use_cassette('content_length') do
91
+ Pinch.content_length(@url).must_equal 2516612
92
+ end
93
+ end
94
+ end
83
95
  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.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Hellberg
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-07 00:00:00 +02:00
14
+ date: 2011-07-18 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency