rest-client 1.1.0 → 1.6.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.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- data/README.rdoc +190 -13
- data/Rakefile +35 -26
- data/VERSION +1 -1
- data/bin/restclient +43 -38
- data/history.md +112 -0
- data/lib/rest-client.rb +2 -0
- data/lib/restclient.rb +107 -40
- data/lib/restclient/abstract_response.rb +106 -0
- data/lib/restclient/exceptions.rb +187 -82
- data/lib/restclient/net_http_ext.rb +11 -11
- data/lib/restclient/payload.rb +217 -168
- data/lib/restclient/raw_response.rb +28 -24
- data/lib/restclient/request.rb +310 -248
- data/lib/restclient/resource.rb +155 -132
- data/lib/restclient/response.rb +19 -15
- data/spec/abstract_response_spec.rb +85 -0
- data/spec/base.rb +6 -0
- data/spec/exceptions_spec.rb +79 -46
- data/spec/integration/certs/equifax.crt +19 -0
- data/spec/integration/certs/verisign.crt +14 -0
- data/spec/integration/request_spec.rb +25 -0
- data/spec/integration_spec.rb +38 -0
- data/spec/payload_spec.rb +187 -99
- data/spec/raw_response_spec.rb +12 -12
- data/spec/request2_spec.rb +27 -0
- data/spec/request_spec.rb +526 -494
- data/spec/resource_spec.rb +131 -72
- data/spec/response_spec.rb +166 -18
- data/spec/restclient_spec.rb +70 -50
- metadata +79 -20
- data/lib/restclient/mixin/response.rb +0 -48
- data/spec/mixin/response_spec.rb +0 -46
metadata
CHANGED
@@ -1,29 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 6
|
9
|
+
- 3
|
10
|
+
version: 1.6.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Adam Wiggins
|
8
|
-
-
|
14
|
+
- Julien Kirch
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
14
|
-
default_executable: restclient
|
19
|
+
date: 2011-06-04 00:00:00 Z
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: mime-types
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
21
26
|
requirements:
|
22
27
|
- - ">="
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 47
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 16
|
24
33
|
version: "1.16"
|
25
|
-
|
26
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: webmock
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 57
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 9
|
48
|
+
- 1
|
49
|
+
version: 0.9.1
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: "A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete."
|
27
67
|
email: rest.client@librelist.com
|
28
68
|
executables:
|
29
69
|
- restclient
|
@@ -31,65 +71,84 @@ extensions: []
|
|
31
71
|
|
32
72
|
extra_rdoc_files:
|
33
73
|
- README.rdoc
|
74
|
+
- history.md
|
34
75
|
files:
|
35
76
|
- README.rdoc
|
36
77
|
- Rakefile
|
37
78
|
- VERSION
|
38
79
|
- bin/restclient
|
80
|
+
- lib/rest-client.rb
|
39
81
|
- lib/rest_client.rb
|
40
82
|
- lib/restclient.rb
|
83
|
+
- lib/restclient/abstract_response.rb
|
41
84
|
- lib/restclient/exceptions.rb
|
42
|
-
- lib/restclient/mixin/response.rb
|
43
85
|
- lib/restclient/net_http_ext.rb
|
44
86
|
- lib/restclient/payload.rb
|
45
87
|
- lib/restclient/raw_response.rb
|
46
88
|
- lib/restclient/request.rb
|
47
89
|
- lib/restclient/resource.rb
|
48
90
|
- lib/restclient/response.rb
|
91
|
+
- spec/abstract_response_spec.rb
|
49
92
|
- spec/base.rb
|
50
93
|
- spec/exceptions_spec.rb
|
94
|
+
- spec/integration/certs/equifax.crt
|
95
|
+
- spec/integration/certs/verisign.crt
|
96
|
+
- spec/integration/request_spec.rb
|
97
|
+
- spec/integration_spec.rb
|
51
98
|
- spec/master_shake.jpg
|
52
|
-
- spec/mixin/response_spec.rb
|
53
99
|
- spec/payload_spec.rb
|
54
100
|
- spec/raw_response_spec.rb
|
101
|
+
- spec/request2_spec.rb
|
55
102
|
- spec/request_spec.rb
|
56
103
|
- spec/resource_spec.rb
|
57
104
|
- spec/response_spec.rb
|
58
105
|
- spec/restclient_spec.rb
|
59
|
-
|
106
|
+
- history.md
|
60
107
|
homepage: http://github.com/archiloque/rest-client
|
61
108
|
licenses: []
|
62
109
|
|
63
110
|
post_install_message:
|
64
|
-
rdoc_options:
|
65
|
-
|
111
|
+
rdoc_options: []
|
112
|
+
|
66
113
|
require_paths:
|
67
114
|
- lib
|
68
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
69
117
|
requirements:
|
70
118
|
- - ">="
|
71
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
72
123
|
version: "0"
|
73
|
-
version:
|
74
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
75
126
|
requirements:
|
76
127
|
- - ">="
|
77
128
|
- !ruby/object:Gem::Version
|
129
|
+
hash: 3
|
130
|
+
segments:
|
131
|
+
- 0
|
78
132
|
version: "0"
|
79
|
-
version:
|
80
133
|
requirements: []
|
81
134
|
|
82
|
-
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.5
|
84
137
|
signing_key:
|
85
138
|
specification_version: 3
|
86
|
-
summary: Simple REST client for Ruby, inspired by microframework syntax for specifying actions.
|
139
|
+
summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.
|
87
140
|
test_files:
|
141
|
+
- spec/abstract_response_spec.rb
|
88
142
|
- spec/base.rb
|
89
143
|
- spec/exceptions_spec.rb
|
90
|
-
- spec/
|
144
|
+
- spec/integration/certs/equifax.crt
|
145
|
+
- spec/integration/certs/verisign.crt
|
146
|
+
- spec/integration/request_spec.rb
|
147
|
+
- spec/integration_spec.rb
|
148
|
+
- spec/master_shake.jpg
|
91
149
|
- spec/payload_spec.rb
|
92
150
|
- spec/raw_response_spec.rb
|
151
|
+
- spec/request2_spec.rb
|
93
152
|
- spec/request_spec.rb
|
94
153
|
- spec/resource_spec.rb
|
95
154
|
- spec/response_spec.rb
|
@@ -1,48 +0,0 @@
|
|
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
|
-
# The raw headers.
|
19
|
-
def raw_headers
|
20
|
-
@raw_headers ||= @net_http_res.to_hash
|
21
|
-
end
|
22
|
-
|
23
|
-
# Hash of cookies extracted from response headers
|
24
|
-
def cookies
|
25
|
-
@cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
|
26
|
-
key, val = raw_c.split('=')
|
27
|
-
unless %w(expires domain path secure).member?(key)
|
28
|
-
out[key] = val
|
29
|
-
end
|
30
|
-
out
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.included(receiver)
|
35
|
-
receiver.extend(RestClient::Mixin::Response::ClassMethods)
|
36
|
-
end
|
37
|
-
|
38
|
-
module ClassMethods
|
39
|
-
def beautify_headers(headers)
|
40
|
-
headers.inject({}) do |out, (key, value)|
|
41
|
-
out[key.gsub(/-/, '_').downcase.to_sym] = value.first
|
42
|
-
out
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/spec/mixin/response_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../base'
|
2
|
-
|
3
|
-
class MockResponse
|
4
|
-
include RestClient::Mixin::Response
|
5
|
-
|
6
|
-
def initialize(body, res)
|
7
|
-
@net_http_res = res
|
8
|
-
@body = @body
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe RestClient::Mixin::Response do
|
13
|
-
before do
|
14
|
-
@net_http_res = mock('net http response')
|
15
|
-
@response = MockResponse.new('abc', @net_http_res)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "fetches the numeric response code" do
|
19
|
-
@net_http_res.should_receive(:code).and_return('200')
|
20
|
-
@response.code.should == 200
|
21
|
-
end
|
22
|
-
|
23
|
-
it "beautifies the headers by turning the keys to symbols" do
|
24
|
-
h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
|
25
|
-
h.keys.first.should == :content_type
|
26
|
-
end
|
27
|
-
|
28
|
-
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
|
29
|
-
h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
|
30
|
-
h.values.first.should == 'text/html'
|
31
|
-
end
|
32
|
-
|
33
|
-
it "fetches the headers" do
|
34
|
-
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
35
|
-
@response.headers.should == { :content_type => 'text/html' }
|
36
|
-
end
|
37
|
-
|
38
|
-
it "extracts cookies from response headers" do
|
39
|
-
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
40
|
-
@response.cookies.should == { 'session_id' => '1' }
|
41
|
-
end
|
42
|
-
|
43
|
-
it "can access the net http result directly" do
|
44
|
-
@response.net_http_res.should == @net_http_res
|
45
|
-
end
|
46
|
-
end
|