adamwiggins-rest-client 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -141,7 +141,7 @@ Patches contributed by: Chris Anderson, Greg Borenstein, Ardekantur, Pedro
141
141
  Belo, Rafael Souza, Rick Olson, Aman Gupta, Blake Mizerany, Brian Donovan, Ivan
142
142
  Makfinsky, Marc-André Cournoyer, Coda Hale, Tetsuo Watanabe, Dusty Doris,
143
143
  Lennon Day-Reynolds, James Edward Gray II, Cyril Rohr, Juan Alvarez, and Adam
144
- Jacob
144
+ Jacob, and Paul Dlug
145
145
 
146
146
  Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
147
147
 
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ require 'rake/gempackagetask'
31
31
  require 'rake/rdoctask'
32
32
  require 'fileutils'
33
33
 
34
- version = "1.0"
34
+ version = "1.0.1"
35
35
  name = "rest-client"
36
36
 
37
37
  spec = Gem::Specification.new do |s|
@@ -0,0 +1,43 @@
1
+ module RestClient
2
+ module Mixin
3
+ module Response
4
+ attr_reader :net_http_res
5
+
6
+ # HTTP status code, always 200 since RestClient throws exceptions for
7
+ # other codes.
8
+ def code
9
+ @code ||= @net_http_res.code.to_i
10
+ end
11
+
12
+ # A hash of the headers, beautified with symbols and underscores.
13
+ # e.g. "Content-type" will become :content_type.
14
+ def headers
15
+ @headers ||= self.class.beautify_headers(@net_http_res.to_hash)
16
+ end
17
+
18
+ # Hash of cookies extracted from response headers
19
+ def cookies
20
+ @cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
21
+ key, val = raw_c.split('=')
22
+ unless %w(expires domain path secure).member?(key)
23
+ out[key] = val
24
+ end
25
+ out
26
+ end
27
+ end
28
+
29
+ def self.included(receiver)
30
+ receiver.extend(RestClient::Mixin::Response::ClassMethods)
31
+ end
32
+
33
+ module ClassMethods
34
+ def beautify_headers(headers)
35
+ headers.inject({}) do |out, (key, value)|
36
+ out[key.gsub(/-/, '_').to_sym] = value.first
37
+ out
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -213,7 +213,7 @@ module RestClient
213
213
  end
214
214
 
215
215
  def response_log(res)
216
- size = @raw_response ? File.size(@tf.path) : res.body.size
216
+ size = @raw_response ? File.size(@tf.path) : (res.body.nil? ? 0 : res.body.size)
217
217
  "# => #{res.code} #{res.class.to_s.gsub(/^Net::HTTP/, '')} | #{(res['Content-type'] || '').gsub(/;.*$/, '')} #{size} bytes"
218
218
  end
219
219
 
data/rest-client.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rest-client"
3
- s.version = "1.0"
3
+ s.version = "1.0.1"
4
4
  s.summary = "Simple REST client for Ruby, inspired by microframework syntax for specifying actions."
5
5
  s.description = "A simple REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
6
6
  s.author = "Adam Wiggins"
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  lib/rest_client.rb lib/restclient.rb
14
14
  lib/restclient/request.rb lib/restclient/response.rb
15
15
  lib/restclient/exceptions.rb lib/restclient/resource.rb
16
+ lib/restclient/mixin/response.rb
16
17
  spec/base.rb spec/request_spec.rb spec/response_spec.rb
17
18
  spec/exceptions_spec.rb spec/resource_spec.rb spec/restclient_spec.rb
18
19
  bin/restclient)
data/spec/request_spec.rb CHANGED
@@ -278,6 +278,12 @@ describe RestClient::Request do
278
278
  @request.response_log(res).should == "# => 200 OK | 4 bytes"
279
279
  end
280
280
 
281
+ it "logs a response with a nil body" do
282
+ res = mock('result', :code => '200', :class => Net::HTTPOK, :body => nil)
283
+ res.stub!(:[]).with('Content-type').and_return('text/html; charset=utf-8')
284
+ @request.response_log(res).should == "# => 200 OK | text/html 0 bytes"
285
+ end
286
+
281
287
  it "strips the charset from the response content type" do
282
288
  res = mock('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
283
289
  res.stub!(:[]).with('Content-type').and_return('text/html; charset=utf-8')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamwiggins-rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -31,6 +31,7 @@ files:
31
31
  - lib/restclient/response.rb
32
32
  - lib/restclient/exceptions.rb
33
33
  - lib/restclient/resource.rb
34
+ - lib/restclient/mixin/response.rb
34
35
  - spec/base.rb
35
36
  - spec/request_spec.rb
36
37
  - spec/response_spec.rb