httpi 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +11 -12
- data/Rakefile +1 -1
- data/lib/httpi/request.rb +5 -0
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/curb_spec.rb +5 -5
- data/spec/httpi/adapter/httpclient_spec.rb +6 -6
- data/spec/httpi/request_spec.rb +7 -0
- data/spec/support/matchers.rb +7 -4
- metadata +4 -17
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ HTTPI
|
|
3
3
|
|
4
4
|
HTTPI provides a common interface for Ruby HTTP libraries.
|
5
5
|
|
6
|
-
[
|
6
|
+
[Wishlist](http://httpi.uservoice.com) | [Bugs](http://github.com/rubiii/httpi/issues) | [Docs](http://rubydoc.info/gems/httpi/frames)
|
7
7
|
|
8
8
|
Installation
|
9
9
|
------------
|
@@ -48,32 +48,31 @@ HTTPI
|
|
48
48
|
-------------
|
49
49
|
|
50
50
|
The `HTTPI` module uses one of the available adapters to execute HTTP requests.
|
51
|
-
It supports GET, POST, HEAD, PUT and DELETE requests:
|
52
51
|
|
53
52
|
### GET
|
54
53
|
|
55
|
-
.get(request, adapter = nil)
|
56
|
-
.get(url, adapter = nil)
|
54
|
+
HTTPI.get(request, adapter = nil)
|
55
|
+
HTTPI.get(url, adapter = nil)
|
57
56
|
|
58
57
|
### POST
|
59
58
|
|
60
|
-
.post(request, adapter = nil)
|
61
|
-
.post(url, body, adapter = nil)
|
59
|
+
HTTPI.post(request, adapter = nil)
|
60
|
+
HTTPI.post(url, body, adapter = nil)
|
62
61
|
|
63
62
|
### HEAD
|
64
63
|
|
65
|
-
.head(request, adapter = nil)
|
66
|
-
.head(url, adapter = nil)
|
64
|
+
HTTPI.head(request, adapter = nil)
|
65
|
+
HTTPI.head(url, adapter = nil)
|
67
66
|
|
68
67
|
### PUT
|
69
68
|
|
70
|
-
.put(request, adapter = nil)
|
71
|
-
.put(url, body, adapter = nil)
|
69
|
+
HTTPI.put(request, adapter = nil)
|
70
|
+
HTTPI.put(url, body, adapter = nil)
|
72
71
|
|
73
72
|
### DELETE
|
74
73
|
|
75
|
-
.delete(request, adapter = nil)
|
76
|
-
.delete(url, adapter = nil)
|
74
|
+
HTTPI.delete(request, adapter = nil)
|
75
|
+
HTTPI.delete(url, adapter = nil)
|
77
76
|
|
78
77
|
### Notice
|
79
78
|
|
data/Rakefile
CHANGED
data/lib/httpi/request.rb
CHANGED
@@ -44,6 +44,11 @@ module HTTPI
|
|
44
44
|
# Sets the Hash of HTTP headers.
|
45
45
|
attr_writer :headers
|
46
46
|
|
47
|
+
# Adds a header information to accept gzipped content.
|
48
|
+
def gzip
|
49
|
+
headers["Accept-encoding"] = "gzip,deflate"
|
50
|
+
end
|
51
|
+
|
47
52
|
attr_accessor :body, :open_timeout, :read_timeout, :auth_type
|
48
53
|
|
49
54
|
# Returns whether any authentication credentials were specified.
|
data/lib/httpi/version.rb
CHANGED
@@ -25,7 +25,7 @@ describe HTTPI::Adapter::Curb do
|
|
25
25
|
|
26
26
|
it "should return a valid HTTPI::Response" do
|
27
27
|
request = HTTPI::Request.new :url => "http://example.com"
|
28
|
-
adapter.get(request).should
|
28
|
+
adapter.get(request).should match_response(:body => Fixture.xml)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -39,7 +39,7 @@ describe HTTPI::Adapter::Curb do
|
|
39
39
|
|
40
40
|
it "should return a valid HTTPI::Response" do
|
41
41
|
request = HTTPI::Request.new :url => "http://example.com"
|
42
|
-
adapter.post(request).should
|
42
|
+
adapter.post(request).should match_response(:body => Fixture.xml)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -53,7 +53,7 @@ describe HTTPI::Adapter::Curb do
|
|
53
53
|
|
54
54
|
it "should return a valid HTTPI::Response" do
|
55
55
|
request = HTTPI::Request.new :url => "http://example.com"
|
56
|
-
adapter.head(request).should
|
56
|
+
adapter.head(request).should match_response(:body => Fixture.xml)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -67,7 +67,7 @@ describe HTTPI::Adapter::Curb do
|
|
67
67
|
|
68
68
|
it "should return a valid HTTPI::Response" do
|
69
69
|
request = HTTPI::Request.new :url => "http://example.com"
|
70
|
-
adapter.put(request).should
|
70
|
+
adapter.put(request).should match_response(:body => Fixture.xml)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -81,7 +81,7 @@ describe HTTPI::Adapter::Curb do
|
|
81
81
|
|
82
82
|
it "should return a valid HTTPI::Response" do
|
83
83
|
request = HTTPI::Request.new :url => "http://example.com"
|
84
|
-
adapter.delete(request).should
|
84
|
+
adapter.delete(request).should match_response(:body => "")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -23,7 +23,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should return a valid HTTPI::Response" do
|
26
|
-
adapter.get(@request).should
|
26
|
+
adapter.get(@request).should match_response(:body => Fixture.xml)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -35,7 +35,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should return a valid HTTPI::Response" do
|
38
|
-
adapter.post(@request).should
|
38
|
+
adapter.post(@request).should match_response(:body => Fixture.xml)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -47,7 +47,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should return a valid HTTPI::Response" do
|
50
|
-
adapter.head(@request).should
|
50
|
+
adapter.head(@request).should match_response(:body => Fixture.xml)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -59,7 +59,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should return a valid HTTPI::Response" do
|
62
|
-
adapter.put(@request).should
|
62
|
+
adapter.put(@request).should match_response(:body => Fixture.xml)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -67,11 +67,11 @@ describe HTTPI::Adapter::HTTPClient do
|
|
67
67
|
before do
|
68
68
|
@request = HTTPI::Request.new :url => "http://example.com"
|
69
69
|
response = HTTP::Message.new_response ""
|
70
|
-
httpclient.expects(:delete).with(@request.url,
|
70
|
+
httpclient.expects(:delete).with(@request.url, @request.headers).returns(response)
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should return a valid HTTPI::Response" do
|
74
|
-
adapter.delete(@request).should
|
74
|
+
adapter.delete(@request).should match_response(:body => "")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
data/spec/httpi/request_spec.rb
CHANGED
@@ -60,6 +60,13 @@ describe HTTPI::Request do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
describe "#gzip" do
|
64
|
+
it "should add the proper 'Accept-encoding' header" do
|
65
|
+
request.gzip
|
66
|
+
request.headers["Accept-encoding"].should == "gzip,deflate"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
63
70
|
describe "#body" do
|
64
71
|
it "lets you specify the HTTP request body" do
|
65
72
|
request.body = "<some>xml</some>"
|
data/spec/support/matchers.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
RSpec::Matchers.define :
|
1
|
+
RSpec::Matchers.define :match_response do |options|
|
2
|
+
defaults = { :code => 200, :headers => {}, :body => "" }
|
3
|
+
response = defaults.merge options
|
4
|
+
|
2
5
|
match do |actual|
|
3
6
|
actual.should be_an(HTTPI::Response)
|
4
|
-
actual.code.should ==
|
5
|
-
actual.headers.should
|
6
|
-
actual.body.should ==
|
7
|
+
actual.code.should == response[:code]
|
8
|
+
actual.headers.should == response[:headers]
|
9
|
+
actual.body.should == response[:body]
|
7
10
|
end
|
8
11
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 15
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Daniel Harrington
|
@@ -16,18 +15,16 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-28 00:00:00 +02:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: httpclient
|
24
23
|
prerelease: false
|
25
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
25
|
requirements:
|
28
26
|
- - ~>
|
29
27
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 1
|
31
28
|
segments:
|
32
29
|
- 2
|
33
30
|
- 1
|
@@ -39,11 +36,9 @@ dependencies:
|
|
39
36
|
name: curb
|
40
37
|
prerelease: false
|
41
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
39
|
requirements:
|
44
40
|
- - ~>
|
45
41
|
- !ruby/object:Gem::Version
|
46
|
-
hash: 19
|
47
42
|
segments:
|
48
43
|
- 0
|
49
44
|
- 7
|
@@ -55,11 +50,9 @@ dependencies:
|
|
55
50
|
name: rspec
|
56
51
|
prerelease: false
|
57
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
53
|
requirements:
|
60
54
|
- - "="
|
61
55
|
- !ruby/object:Gem::Version
|
62
|
-
hash: 62196431
|
63
56
|
segments:
|
64
57
|
- 2
|
65
58
|
- 0
|
@@ -73,11 +66,9 @@ dependencies:
|
|
73
66
|
name: mocha
|
74
67
|
prerelease: false
|
75
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
69
|
requirements:
|
78
70
|
- - ~>
|
79
71
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 43
|
81
72
|
segments:
|
82
73
|
- 0
|
83
74
|
- 9
|
@@ -131,27 +122,23 @@ rdoc_options: []
|
|
131
122
|
require_paths:
|
132
123
|
- lib
|
133
124
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
-
none: false
|
135
125
|
requirements:
|
136
126
|
- - ">="
|
137
127
|
- !ruby/object:Gem::Version
|
138
|
-
hash: 3
|
139
128
|
segments:
|
140
129
|
- 0
|
141
130
|
version: "0"
|
142
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
132
|
requirements:
|
145
133
|
- - ">="
|
146
134
|
- !ruby/object:Gem::Version
|
147
|
-
hash: 3
|
148
135
|
segments:
|
149
136
|
- 0
|
150
137
|
version: "0"
|
151
138
|
requirements: []
|
152
139
|
|
153
140
|
rubyforge_project: httpi
|
154
|
-
rubygems_version: 1.3.
|
141
|
+
rubygems_version: 1.3.6
|
155
142
|
signing_key:
|
156
143
|
specification_version: 3
|
157
144
|
summary: Interface for Ruby HTTP libraries
|