httpi 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ script: "rake"
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - ree
6
+ - rbx
7
+ - jruby
@@ -1,4 +1,17 @@
1
- ## 0.9.3 (2010-04-28)
1
+ ## 0.9.4 (2011-05-15)
2
+
3
+ * Fix: issues [34](https://github.com/rubiii/httpi/issues/34) and
4
+ [29](https://github.com/rubiii/httpi/issues/29) - replaced the dependency
5
+ on `ntlm-http` with a dependency on `pyu-ntlm-http` which comes with quite
6
+ a few bugfixes.
7
+
8
+ * Fix: Setting the default adapter did not always load the adapter's client library.
9
+
10
+ * Improvement: Added a shortcut method to set the default adapter to use.
11
+
12
+ HTTPI.adapter = :net_http
13
+
14
+ ## 0.9.3 (2011-04-28)
2
15
 
3
16
  * Fix: [issue 31](https://github.com/rubiii/httpi/issues/31) missing headers when using httpclient.
4
17
 
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source :rubygems
2
2
  gemspec
3
3
 
4
- group :test do
5
- gem "mock-server", :git => "git://github.com/ichverstehe/mock-server.git", :branch => "custom-class"
6
- end
4
+ gem "jruby-openssl", :platforms => :jruby
5
+
6
+ # http clients
7
+ gem "httpclient", "~> 2.1.7"
8
+ gem "curb", "~> 0.7.8", :platforms => :ruby
data/README.md CHANGED
@@ -1,92 +1,98 @@
1
- HTTPI
1
+ HTTPI [![Build Status](http://travis-ci.org/rubiii/httpi.png)](http://travis-ci.org/rubiii/httpi)
2
2
  =====
3
3
 
4
4
  HTTPI provides a common interface for Ruby HTTP libraries.
5
5
 
6
- [Wishlist](http://httpi.uservoice.com) | [Bugs](http://github.com/rubiii/httpi/issues) | [Docs](http://rubydoc.info/gems/httpi/frames)
6
+ [Bugs](http://github.com/rubiii/httpi/issues) | [RDoc](http://rubydoc.info/gems/httpi/frames)
7
7
 
8
8
  Installation
9
9
  ------------
10
10
 
11
- The gem is available through [Rubygems](http://rubygems.org/gems/httpi) and can be installed via:
12
-
13
- $ gem install httpi
14
-
15
- Some examples
16
- -------------
17
-
18
- Executing a POST request with the most basic request object:
11
+ HTTPI is available through [Rubygems](http://rubygems.org/gems/httpi) and can be installed via:
19
12
 
20
- request = HTTPI::Request.new "http://example.com"
21
- HTTPI.get request
13
+ ```
14
+ $ gem install httpi
15
+ ```
22
16
 
23
- Here's a POST request with a request object:
24
17
 
25
- request = HTTPI::Request.new
26
- request.url = "http://post.example.com"
27
- request.body = "send me"
28
-
29
- HTTPI.post request
30
-
31
- And a GET request using HTTP basic auth and the Curb adapter:
18
+ Getting started
19
+ ---------------
32
20
 
33
- request = HTTPI::Request.new
34
- request.url = "http://auth.example.com"
35
- request.auth.basic "username", "password"
21
+ In order to provide a common interface, HTTPI provides the `HTTPI::Request` object for you to
22
+ configure your request. Here's a very simple GET request.
36
23
 
37
- HTTPI.get request, :curb
24
+ ``` ruby
25
+ request = HTTPI::Request.new("http://example.com")
26
+ HTTPI.get request
27
+ ```
38
28
 
39
- HTTPI also comes shortcuts. This executes a PUT request:
29
+ To execute a POST request, you may want to specify a payload.
40
30
 
41
- HTTPI.put "http://example.com", "<some>xml</some>"
31
+ ``` ruby
32
+ request = HTTPI::Request.new
33
+ request.url = "http://post.example.com"
34
+ request.body = "some data"
42
35
 
43
- And this executes a DELETE request:
36
+ HTTPI.post request
37
+ ```
44
38
 
45
- HTTPI.delete "http://example.com"
46
39
 
47
40
  HTTPI
48
- -------------
41
+ -----
49
42
 
50
43
  The `HTTPI` module uses one of the available adapters to execute HTTP requests.
51
44
 
52
- ### GET
45
+ #### GET
53
46
 
54
- HTTPI.get(request, adapter = nil)
55
- HTTPI.get(url, adapter = nil)
47
+ ``` ruby
48
+ HTTPI.get(request, adapter = nil)
49
+ HTTPI.get(url, adapter = nil)
50
+ ```
56
51
 
57
- ### POST
52
+ #### POST
58
53
 
59
- HTTPI.post(request, adapter = nil)
60
- HTTPI.post(url, body, adapter = nil)
54
+ ``` ruby
55
+ HTTPI.post(request, adapter = nil)
56
+ HTTPI.post(url, body, adapter = nil)
57
+ ```
61
58
 
62
- ### HEAD
59
+ #### HEAD
63
60
 
64
- HTTPI.head(request, adapter = nil)
65
- HTTPI.head(url, adapter = nil)
61
+ ``` ruby
62
+ HTTPI.head(request, adapter = nil)
63
+ HTTPI.head(url, adapter = nil)
64
+ ```
66
65
 
67
- ### PUT
66
+ #### PUT
68
67
 
69
- HTTPI.put(request, adapter = nil)
70
- HTTPI.put(url, body, adapter = nil)
68
+ ``` ruby
69
+ HTTPI.put(request, adapter = nil)
70
+ HTTPI.put(url, body, adapter = nil)
71
+ ```
71
72
 
72
- ### DELETE
73
+ #### DELETE
73
74
 
74
- HTTPI.delete(request, adapter = nil)
75
- HTTPI.delete(url, adapter = nil)
75
+ ``` ruby
76
+ HTTPI.delete(request, adapter = nil)
77
+ HTTPI.delete(url, adapter = nil)
78
+ ```
76
79
 
77
- ### Notice
80
+ #### Notice
78
81
 
79
82
  * You can specify the adapter to use per request
80
83
  * And request methods always return an `HTTPI::Response`
81
84
 
82
- ### More control
85
+ #### More control
83
86
 
84
- If you need more control over the request, you can access the HTTP client instance represented
85
- by your adapter in a block:
87
+ If you need more control over the request, you can access the HTTP client instance
88
+ represented by your adapter in a block:
89
+
90
+ ``` ruby
91
+ HTTPI.post request do |http|
92
+ http.use_ssl = true # Curb example
93
+ end
94
+ ```
86
95
 
87
- HTTPI.post request do |http|
88
- http.use_ssl = true # Curb example
89
- end
90
96
 
91
97
  HTTPI::Adapter
92
98
  --------------
@@ -100,94 +106,118 @@ It currently contains adapters for:
100
106
 
101
107
  You can manually specify the adapter to use via:
102
108
 
103
- HTTPI::Adapter.use = :curb # or one of [:httpclient, :net_http]
109
+ ``` ruby
110
+ HTTPI.adapter = :curb # or one of [:httpclient, :net_http]
111
+ ```
104
112
 
105
113
  If you don't specify which adapter to use, HTTPI try to load HTTPClient, then Curb and finally NetHTTP.
106
114
 
107
- Notice: HTTPI does not force you to install any of these libraries. If you'd like to use on of the more advanced libraries (HTTPClient or Curb),
108
- you have to make sure they're in your LOAD_PATH. HTTPI will then load the library when executing HTTP requests.
115
+ #### Notice
116
+
117
+ HTTPI does not force you to install any of these libraries. If you'd like to use on of the more advanced
118
+ libraries (HTTPClient or Curb), you have to make sure they're in your LOAD_PATH. HTTPI will then load the
119
+ library when executing HTTP requests.
120
+
109
121
 
110
122
  HTTPI::Request
111
123
  --------------
112
124
 
113
- The `HTTPI::Request` serves as a common denominator of options that HTTPI adapters need to support.
114
- It represents an HTTP request and lets you customize various settings through the following methods:
125
+ #### URL
126
+
127
+ ``` ruby
128
+ request.url = "http://example.com"
129
+ request.url # => #<URI::HTTP:0x101c1ab18 URL:http://example.com>
130
+ ```
131
+
132
+ #### Proxy
133
+
134
+ ``` ruby
135
+ request.proxy = "http://example.com"
136
+ request.proxy # => #<URI::HTTP:0x101c1ab18 URL:http://example.com>
137
+ ```
115
138
 
116
- #url # the URL to access
117
- #proxy # the proxy server to use
118
- #ssl # whether to use SSL
119
- #headers # a Hash of HTTP headers
120
- #body # the HTTP request body
121
- #open_timeout # the open timeout (sec)
122
- #read_timeout # the read timeout (sec)
139
+ #### Headers
123
140
 
124
- ### Usage example
141
+ ``` ruby
142
+ request.headers["Accept-Charset"] = "utf-8"
143
+ request.headers = { "Accept-Charset" => "utf-8" }
144
+ request.headers # => { "Accept-Charset" => "utf-8" }
145
+ ```
146
+
147
+ #### Body
148
+
149
+ ``` ruby
150
+ request.body = "some data"
151
+ request.body # => "some data"
152
+ ```
153
+
154
+ #### Open timeout
155
+
156
+ ``` ruby
157
+ request.open_timeout = 30 # sec
158
+ ```
159
+
160
+ #### Read timeout
161
+
162
+ ``` ruby
163
+ request.read_timeout = 30 # sec
164
+ ```
125
165
 
126
- request = HTTPI::Request.new
127
- request.url = "http://example.com"
128
- request.read_timeout = 30
129
166
 
130
167
  HTTPI::Auth
131
168
  -----------
132
169
 
133
170
  `HTTPI::Auth` supports HTTP basic and digest authentication.
134
171
 
135
- #basic(username, password) # HTTP basic auth credentials
136
- #digest(username, password) # HTTP digest auth credentials
137
- #ntlm(username, password) # NTLM auth credentials
172
+ ``` ruby
173
+ request.auth.basic("username", "password") # HTTP basic auth credentials
174
+ request.auth.digest("username", "password") # HTTP digest auth credentials
175
+ request.auth.ntlm("username", "password") # NTLM auth credentials
176
+ ```
138
177
 
139
- ### Usage example
140
-
141
- request = HTTPI::Request.new
142
- request.auth.basic "username", "password"
143
178
 
144
179
  HTTPI::Auth::SSL
145
180
  ----------------
146
181
 
147
182
  `HTTPI::Auth::SSL` manages SSL client authentication.
148
183
 
149
- #cert_key_file # the private key file to use
150
- #cert_file # the certificate file to use
151
- #ca_cert_file # the ca certificate file to use
152
- #verify_mode # one of [:none, :peer, :fail_if_no_peer_cert, :client_once]
153
-
154
- ### Usage example
184
+ ``` ruby
185
+ request.auth.ssl.cert_key_file = "client_key.pem" # the private key file to use
186
+ request.auth.ssl.cert_key_password = "C3rtP@ssw0rd" # the key file's password
187
+ request.auth.ssl.cert_file = "client_cert.pem" # the certificate file to use
188
+ request.auth.ssl.ca_cert_file = "ca_cert.pem" # the ca certificate file to use
189
+ request.auth.ssl.verify_mode = :none # or one of [:peer, :fail_if_no_peer_cert, :client_once]
190
+ ```
155
191
 
156
- request = HTTPI::Request.new
157
- request.auth.ssl.cert_key_file = "client_key.pem"
158
- request.auth.ssl.cert_key_password = "C3rtP@ssw0rd"
159
- request.auth.ssl.cert_file = "client_cert.pem"
160
- request.auth.ssl.verify_mode = :none
161
192
 
162
193
  HTTPI::Response
163
194
  ---------------
164
195
 
165
- As mentioned before, every request method return an `HTTPI::Response`.
166
- It contains the response code, headers and body.
196
+ Every request returns an `HTTPI::Response`. It contains the response code, headers and body.
167
197
 
168
- response = HTTPI.get request
198
+ ``` ruby
199
+ response = HTTPI.get request
169
200
 
170
- response.code # => 200
171
- response.headers # => { "Content-Encoding" => "gzip" }
172
- response.body # => "<!DOCTYPE HTML PUBLIC ...>"
201
+ response.code # => 200
202
+ response.headers # => { "Content-Encoding" => "gzip" }
203
+ response.body # => "<!DOCTYPE HTML PUBLIC ...>"
204
+ ```
173
205
 
174
206
  The `response.body` handles gzipped and [DIME](http://en.wikipedia.org/wiki/Direct_Internet_Message_Encapsulation) encoded responses.
175
207
 
176
- ### TODO
208
+ #### TODO
177
209
 
178
210
  * Return the original `HTTPI::Request` for debugging purposes
179
211
  * Return the time it took to execute the request
180
212
 
213
+
181
214
  Logging
182
215
  -------
183
216
 
184
217
  HTTPI by default logs each HTTP request to STDOUT using a log level of :debug.
185
218
 
186
- HTTPI.log = false # disabling logging
187
- HTTPI.logger = MyLogger # changing the logger
188
- HTTPI.log_level = :info # changing the log level
189
-
190
- Participate
191
- -----------
192
-
193
- Any help and feedback appreciated. So please get in touch!
219
+ ``` ruby
220
+ HTTPI.log = false # disable logging
221
+ HTTPI.logger = MyLogger # change the logger
222
+ HTTPI.log_level = :info # change the log level
223
+ ```
data/Rakefile CHANGED
@@ -1,47 +1,17 @@
1
- require "rake"
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
2
3
 
3
- begin
4
- require "yard"
5
-
6
- YARD::Rake::YardocTask.new do |t|
7
- t.files = ["README.md", "lib/**/*.rb"]
8
- end
9
- rescue LoadError
10
- desc message = %{"gem install yard" to generate documentation}
11
- task("yard") { abort message }
12
- end
4
+ require "rspec/core/rake_task"
13
5
 
14
- begin
15
- require "metric_fu"
16
-
17
- MetricFu::Configuration.run do |c|
18
- c.metrics = [:churn, :flog, :flay, :reek, :roodi, :saikuro] # :rcov seems to be broken
19
- c.graphs = [:flog, :flay, :reek, :roodi]
20
- c.flay = { :dirs_to_flay => ["lib"], :minimum_score => 20 }
21
- c.rcov[:rcov_opts] << "-Ilib -Ispec"
22
- end
23
- rescue LoadError
24
- desc message = %{"gem install metric_fu" to generate metrics}
25
- task("metrics:all") { abort message }
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = "spec/httpi/**/*_spec.rb"
8
+ t.rspec_opts = %w(-fd -c)
26
9
  end
27
10
 
28
- begin
29
- require "rspec/core/rake_task"
30
-
31
- RSpec::Core::RakeTask.new do |t|
32
- t.pattern = "spec/httpi/**/*_spec.rb"
33
- t.rspec_opts = %w(-fd -c)
34
- end
35
-
36
- desc "Run RSpec integration examples"
37
- RSpec::Core::RakeTask.new "spec:integration" do |t|
38
- t.pattern = "spec/integration/*_spec.rb"
39
- t.rspec_opts = %w(-fd -c)
40
- end
41
- rescue LoadError
42
- task :spec do
43
- abort "Run 'gem install rspec' to be able to run specs"
44
- end
11
+ desc "Run RSpec integration examples"
12
+ RSpec::Core::RakeTask.new "spec:integration" do |t|
13
+ t.pattern = "spec/integration/*_spec.rb"
14
+ t.rspec_opts = %w(-fd -c)
45
15
  end
46
16
 
47
17
  task :default => :spec
@@ -4,26 +4,24 @@ $:.unshift lib unless $:.include?(lib)
4
4
  require "httpi/version"
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "httpi"
8
- s.version = HTTPI::VERSION
9
- s.authors = ["Daniel Harrington", "Martin Tepper"]
10
- s.email = "me@rubiii.com"
11
- s.homepage = "http://github.com/rubiii/#{s.name}"
12
- s.summary = "Interface for Ruby HTTP libraries"
7
+ s.name = "httpi"
8
+ s.version = HTTPI::VERSION
9
+ s.authors = ["Daniel Harrington", "Martin Tepper"]
10
+ s.email = "me@rubiii.com"
11
+ s.homepage = "http://github.com/rubiii/#{s.name}"
12
+ s.summary = "Interface for Ruby HTTP libraries"
13
13
  s.description = "HTTPI provides a common interface for Ruby HTTP libraries."
14
14
 
15
15
  s.rubyforge_project = s.name
16
16
 
17
17
  s.add_dependency "rack"
18
- s.add_dependency "ntlm-http", ">= 0.1.1"
18
+ s.add_dependency "pyu-ntlm-http", ">= 0.1.3.1"
19
19
 
20
- s.add_development_dependency "httpclient", "~> 2.1.7"
21
- s.add_development_dependency "curb", "~> 0.7.8"
22
-
23
- s.add_development_dependency "rspec", "~> 2.2"
20
+ s.add_development_dependency "rspec", "~> 2.2"
24
21
  s.add_development_dependency "autotest"
25
- s.add_development_dependency "mocha", "~> 0.9.9"
26
- s.add_development_dependency "webmock", "~> 1.4.0"
22
+ s.add_development_dependency "mocha", "~> 0.9.9"
23
+ s.add_development_dependency "webmock", "~> 1.4.0"
24
+ s.add_development_dependency "mock-server", "~> 0.1.1"
27
25
 
28
26
  s.files = `git ls-files`.split("\n")
29
27
  s.require_path = "lib"