chuckle 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
data/chuckle.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
10
10
  s.authors = ["Adam Doppelt"]
11
11
  s.email = ["amd@gurge.com"]
12
12
  s.homepage = "http://github.com/gurgeous/chuckle"
13
- s.summary = "Chuckle - caching http client that wraps curl."
14
- s.description = "A caching http client that wraps curl."
13
+ s.summary = "Chuckle - an http client that caches on disk."
14
+ s.description = "An http client that caches on disk."
15
15
 
16
16
  s.rubyforge_project = "chuckle"
17
17
 
data/lib/chuckle/cache.rb CHANGED
@@ -20,11 +20,13 @@ module Chuckle
20
20
  end
21
21
 
22
22
  def set(request, curl)
23
- %w(body headers).each do |i|
24
- src, dst = curl.send("#{i}_path"), request.send("#{i}_path")
25
- FileUtils.mkdir_p(File.dirname(dst))
26
- FileUtils.mv(src, dst)
27
- end
23
+ # mkdirs
24
+ FileUtils.mkdir_p([File.dirname(request.headers_path), File.dirname(request.body_path)])
25
+
26
+ # now mv
27
+ FileUtils.mv(curl.headers_path, request.headers_path)
28
+ FileUtils.mv(curl.body_path, request.body_path)
29
+
28
30
  Response.new(request)
29
31
  end
30
32
 
@@ -71,7 +71,7 @@ module Chuckle
71
71
  if !cache_errors?
72
72
  cache.clear(response.request)
73
73
  end
74
- raise Error.new("#{Error.class}, #{error}", response)
74
+ raise Error.new("Chuckle::Error, #{error}", response)
75
75
  end
76
76
 
77
77
  def vputs(s)
@@ -29,15 +29,16 @@ module Chuckle
29
29
  def parse
30
30
  self.curl_exit_code = Curl.exit_code_from_headers(headers)
31
31
 
32
+ self.uri = request.uri
32
33
  locations = headers.scan(/^Location: ([^\r\n]+)/m).flatten
33
34
  if !locations.empty?
34
35
  location = locations.last
35
36
  # some buggy servers do this. sigh.
36
37
  location = location.gsub(" ", "%20")
37
- self.uri = URI.parse(location)
38
+ self.uri += location
38
39
  end
39
40
 
40
- codes = headers.scan(/^HTTP\/\d\.\d (\d+).*?\r\n\r\n/m).flatten
41
+ codes = headers.scan(/^HTTP\/\d\.\d (\d+).*?\r\n/m).flatten
41
42
  codes = codes.map(&:to_i)
42
43
  self.code = codes.last
43
44
  end
@@ -1,4 +1,4 @@
1
1
  module Chuckle
2
2
  # Gem version
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
data/test/helper.rb CHANGED
@@ -46,6 +46,15 @@ module Helper
46
46
  hello
47
47
  EOF
48
48
 
49
+ HTTP_302_RELATIVE = <<-EOF.gsub(/(^|\n) +/, "\\1")
50
+ HTTP/1.1 302 FOUND
51
+ Location: /two
52
+
53
+ HTTP/1.0 200 OK
54
+
55
+ hello
56
+ EOF
57
+
49
58
  HTTP_404 = <<-EOF.gsub(/(^|\n) +/, "\\1")
50
59
  HTTP/1.1 404 Not Found
51
60
 
@@ -24,6 +24,13 @@ class TestRequests < Minitest::Test
24
24
  assert_equal "hello\n", response.body
25
25
  end
26
26
 
27
+ def test_302_relative
28
+ response = mcurl(HTTP_302_RELATIVE) { client.get(URL) }
29
+ assert_equal 200, response.code
30
+ assert_equal URI.parse("#{URL}/two"), response.uri
31
+ assert_equal "hello\n", response.body
32
+ end
33
+
27
34
  def test_404
28
35
  e = assert_raises Chuckle::Error do
29
36
  mcurl(HTTP_404) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chuckle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -91,7 +91,7 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- description: A caching http client that wraps curl.
94
+ description: An http client that caches on disk.
95
95
  email:
96
96
  - amd@gurge.com
97
97
  executables: []
@@ -99,6 +99,7 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
+ - .travis.yml
102
103
  - Gemfile
103
104
  - LICENSE
104
105
  - README.md
@@ -139,13 +140,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
140
  version: '0'
140
141
  segments:
141
142
  - 0
142
- hash: 2600014295267267585
143
+ hash: -3317364503700294322
143
144
  requirements: []
144
145
  rubyforge_project: chuckle
145
146
  rubygems_version: 1.8.24
146
147
  signing_key:
147
148
  specification_version: 3
148
- summary: Chuckle - caching http client that wraps curl.
149
+ summary: Chuckle - an http client that caches on disk.
149
150
  test_files:
150
151
  - test/helper.rb
151
152
  - test/test_cache.rb