Skip to content

Commit a5d2266

Browse files
committed
Mark all with_ chainable methods as deprecated.
Closes #207.
1 parent bf427d9 commit a5d2266

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## master (unreleased)
22

3+
* Deprecate chainable methods with `with_` prefix. See #207. (@ixti)
34
* Add support of HTTPS connections through proxy. See #186. (@Connorhd)
45

56

README.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,16 @@ the full, raw power of HTTP, we can perform content negotiation the way HTTP
170170
intends us to, by using the Accept header:
171171

172172
```ruby
173-
HTTP.with_headers(:accept => 'application/json').
173+
HTTP.headers(:accept => 'application/json').
174174
get('https://github.com/httprb/http.rb/commit/HEAD')
175175
```
176176

177177
This requests JSON from GitHub. GitHub is smart enough to understand our
178178
request and returns a response with Content-Type: application/json.
179179

180-
Shorter aliases exists for HTTP.with_headers:
180+
Shorter alias exists for `HTTP.headers`:
181181

182182
```ruby
183-
HTTP.with(:accept => 'application/json').
184-
get('https://github.com/httprb/http.rb/commit/HEAD')
185-
186183
HTTP[:accept => 'application/json'].
187184
get('https://github.com/httprb/http.rb/commit/HEAD')
188185
```
@@ -208,7 +205,7 @@ And Chain all together!
208205

209206
```ruby
210207
HTTP.basic_auth(:user => 'user', :pass => 'pass')
211-
.with('Cookie' => '9wq3w')
208+
.headers('Cookie' => '9wq3w')
212209
.get('https://example.com')
213210
```
214211

@@ -258,8 +255,8 @@ so.
258255
```ruby
259256
require 'http'
260257

261-
http = HTTP.with_cache(metastore: "file:/var/cache/my-app-http/meta",
262-
entitystore: "file:/var/cache/my-app-http/entity")
258+
http = HTTP.cache(:metastore => "file:/var/cache/my-app-http/meta",
259+
:entitystore => "file:/var/cache/my-app-http/entity")
263260

264261
http.get("http://example.com/") # makes request
265262
http.get("http://example.com/") # skips making request and returns

lib/http/chainable.rb

+15-4
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,31 @@ def follow(opts = {})
140140
branch default_options.with_follow opts
141141
end
142142

143-
# @deprecated
143+
# @deprecated will be removed in 1.0.0
144144
# @see #follow
145145
alias_method :with_follow, :follow
146146

147-
def with_cache(cache)
147+
def cache(cache)
148148
branch default_options.with_cache(cache)
149149
end
150150

151+
# @deprecated will be removed in 1.0.0
152+
# @see #cache
153+
alias_method :with_cache, :cache
154+
151155
# Make a request with the given headers
152156
# @param headers
153-
def with_headers(headers)
157+
def headers(headers)
154158
branch default_options.with_headers(headers)
155159
end
156-
alias_method :with, :with_headers
160+
161+
# @deprecated will be removed in 1.0.0
162+
# @see #headers
163+
alias_method :with, :headers
164+
165+
# @deprecated will be removed in 1.0.0
166+
# @see #headers
167+
alias_method :with_headers, :headers
157168

158169
# Accept the given MIME type(s)
159170
# @param type

spec/lib/http_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@
190190
end
191191
end
192192

193-
describe ".with_cache" do
193+
describe ".cache" do
194194
it "sets cache option" do
195195
cache = double(:cache, :perform => nil)
196-
client = HTTP.with_cache cache
196+
client = HTTP.cache cache
197197
expect(client.default_options[:cache]).to eq cache
198198
end
199199
end

0 commit comments

Comments
 (0)