From c7cd34b0e0c66c30aa9bb9d7989c13905baf53ec Mon Sep 17 00:00:00 2001 From: Alexey V Zapparov Date: Mon, 13 Apr 2015 00:51:57 +0200 Subject: [PATCH] Mark all `with_` chainable methods as deprecated. Closes #207. --- CHANGES.md | 1 + README.md | 13 +++++-------- lib/http/chainable.rb | 19 +++++++++++++++---- spec/lib/http_spec.rb | 4 ++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 95f4e95c..8ba26808 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## master (unreleased) +* Deprecate chainable methods with `with_` prefix. See #207. (@ixti) * Add support of HTTPS connections through proxy. See #186. (@Connorhd) diff --git a/README.md b/README.md index 0bc84377..87e4bed1 100644 --- a/README.md +++ b/README.md @@ -170,19 +170,16 @@ the full, raw power of HTTP, we can perform content negotiation the way HTTP intends us to, by using the Accept header: ```ruby -HTTP.with_headers(:accept => 'application/json'). +HTTP.headers(:accept => 'application/json'). get('https://github.com/httprb/http.rb/commit/HEAD') ``` This requests JSON from GitHub. GitHub is smart enough to understand our request and returns a response with Content-Type: application/json. -Shorter aliases exists for HTTP.with_headers: +Shorter alias exists for `HTTP.headers`: ```ruby -HTTP.with(:accept => 'application/json'). - get('https://github.com/httprb/http.rb/commit/HEAD') - HTTP[:accept => 'application/json']. get('https://github.com/httprb/http.rb/commit/HEAD') ``` @@ -208,7 +205,7 @@ And Chain all together! ```ruby HTTP.basic_auth(:user => 'user', :pass => 'pass') - .with('Cookie' => '9wq3w') + .headers('Cookie' => '9wq3w') .get('https://example.com') ``` @@ -258,8 +255,8 @@ so. ```ruby require 'http' -http = HTTP.with_cache(metastore: "file:/var/cache/my-app-http/meta", - entitystore: "file:/var/cache/my-app-http/entity") +http = HTTP.cache(:metastore => "file:/var/cache/my-app-http/meta", + :entitystore => "file:/var/cache/my-app-http/entity") http.get("http://example.com/") # makes request http.get("http://example.com/") # skips making request and returns diff --git a/lib/http/chainable.rb b/lib/http/chainable.rb index fdd2fa4d..2df19855 100644 --- a/lib/http/chainable.rb +++ b/lib/http/chainable.rb @@ -140,20 +140,31 @@ def follow(opts = {}) branch default_options.with_follow opts end - # @deprecated + # @deprecated will be removed in 1.0.0 # @see #follow alias_method :with_follow, :follow - def with_cache(cache) + def cache(cache) branch default_options.with_cache(cache) end + # @deprecated will be removed in 1.0.0 + # @see #cache + alias_method :with_cache, :cache + # Make a request with the given headers # @param headers - def with_headers(headers) + def headers(headers) branch default_options.with_headers(headers) end - alias_method :with, :with_headers + + # @deprecated will be removed in 1.0.0 + # @see #headers + alias_method :with, :headers + + # @deprecated will be removed in 1.0.0 + # @see #headers + alias_method :with_headers, :headers # Accept the given MIME type(s) # @param type diff --git a/spec/lib/http_spec.rb b/spec/lib/http_spec.rb index ec6eca39..327b7d33 100644 --- a/spec/lib/http_spec.rb +++ b/spec/lib/http_spec.rb @@ -190,10 +190,10 @@ end end - describe ".with_cache" do + describe ".cache" do it "sets cache option" do cache = double(:cache, :perform => nil) - client = HTTP.with_cache cache + client = HTTP.cache cache expect(client.default_options[:cache]).to eq cache end end