rest-client 2.0.0.rc4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68b80b5b33ba926c8c3a2b4c0aac27b4e7f756f0
4
- data.tar.gz: ba56b4b86dc27028889674a840132c6f88671f9f
3
+ metadata.gz: 9f1a91416eb9ce25f4334a31215472eee28d3835
4
+ data.tar.gz: 6cbd00246b48690123c0fe37ddc2aa2d279fce29
5
5
  SHA512:
6
- metadata.gz: c83b06c417fd471f0c80ad5a7f93c645a5748ebec48785269c8af59e198c8cb9b7b6b52c0c36be48c6c9c0cee61e9faacafe5e4012ca8be655b0edf739d0b799
7
- data.tar.gz: cea931e95b38351d4c6236189fbb781a1f2e0067eb95e3d65d94bae1eddeff7217158d1a3ca5875747371d7ceb5cd98fe2cb3fd0e189ed0db322cc913c1428b8
6
+ metadata.gz: 985246f04e76d0fd7c191b8c0d8d83ae8a173d6369b96142a038c7b320b1af2123f80e265b7a2b5e82966570bec794b467e5df72f0196003611f791ed6826454
7
+ data.tar.gz: 80f8d55c65385636b7381861a9f8dd9df2c35afe0940656e2f391715cd1526bb9d6dc75db51bed0b83ae55d954d7b8e9604c3ce8075a776b92d7e2601d048413
data/README.md CHANGED
@@ -45,6 +45,35 @@ There are also several development dependencies. It's recommended to use
45
45
  [bundler](http://bundler.io/) to manage these dependencies for hacking on
46
46
  rest-client.
47
47
 
48
+ ### Upgrading to rest-client 2.0 from 1.x
49
+
50
+ Users are encouraged to upgrade to rest-client 2.0, which cleans up a number of
51
+ API warts and wrinkles, making rest-client generally more useful. Usage is
52
+ largely compatible, so many applications will be able to upgrade with no
53
+ changes.
54
+
55
+ Overview of significant changes:
56
+
57
+ * requires Ruby >= 2.0
58
+ * `RestClient::Response` objects are a subclass of `String` rather than a
59
+ Frankenstein monster. And `#body` or `#to_s` return a true `String` object.
60
+ * cleanup of exception classes, including new `RestClient::Exceptions::Timeout`
61
+ * improvements to handling of redirects: responses and history are properly
62
+ exposed
63
+ * major changes to cookie support: cookie jars are used for browser-like
64
+ behavior throughout
65
+ * encoding: Content-Type charset response headers are used to automatically set
66
+ the encoding of the response string
67
+ * HTTP params: handling of GET/POST params is more consistent and sophisticated
68
+ for deeply nested hash objects, and `ParamsArray` can be used to pass ordered
69
+ params
70
+ * improved proxy support with per-request proxy configuration, plus the ability
71
+ to disable proxies set by environment variables
72
+ * default request headers: rest-client sets `Accept: */*` and
73
+ `User-Agent: rest-client/...`
74
+
75
+ See [history.md](./history.md) for a more complete description of changes.
76
+
48
77
  ## Usage: Raw URL
49
78
  ```ruby
50
79
  require 'rest-client'
@@ -177,10 +206,38 @@ end
177
206
  ➔ 404 Resource Not Found | text/html 282 bytes
178
207
  ```
179
208
 
180
- ### Manually following redirection
209
+ ### Redirection
210
+
211
+ By default, rest-client will follow HTTP 30x redirection requests.
212
+
213
+ __New in 2.0:__ `RestClient::Response` exposes a `#history` method that returns
214
+ a list of each response received in a redirection chain.
215
+
216
+ ```ruby
217
+ >> r = RestClient.get('http://httpbin.org/redirect/2')
218
+ => <RestClient::Response 200 "{\n \"args\":...">
219
+
220
+ # see each response in the redirect chain
221
+ >> r.history
222
+ => [<RestClient::Response 302 "<!DOCTYPE H...">, <RestClient::Response 302 "">]
223
+
224
+ # see each requested URL
225
+ >> r.request.url
226
+ => "http://httpbin.org/get"
227
+ >> r.history.map {|x| x.request.url}
228
+ => ["http://httpbin.org/redirect/2", "http://httpbin.org/relative-redirect/1"]
229
+ ```
230
+
231
+ #### Manually following redirection
181
232
 
182
233
  To disable automatic redirection, set `:max_redirects => 0`.
183
234
 
235
+ __New in 2.0:__ Prior versions of rest-client would raise
236
+ `RestClient::MaxRedirectsReached`, with no easy way to access the server's
237
+ response. In 2.0, rest-client raises the normal
238
+ `RestClient::ExceptionWithResponse` as it would with any other non-HTTP-20x
239
+ response.
240
+
184
241
  ```ruby
185
242
  >> RestClient::Request.execute(method: :get, url: 'http://httpbin.org/redirect/1')
186
243
  => RestClient::Response 200 "{\n "args":..."
@@ -226,7 +283,7 @@ Response objects have several useful methods. (See the class rdoc for more detai
226
283
  - `Response#cookies`: A hash of HTTP cookies set by the server
227
284
  - `Response#cookie_jar`: <em>New in 1.8</em> An HTTP::CookieJar of cookies
228
285
  - `Response#request`: The RestClient::Request object used to make the request
229
- - `Response#history`: If redirection was followed, a list of prior Response objects
286
+ - `Response#history`: <em>New in 2.0</em> If redirection was followed, a list of prior Response objects
230
287
 
231
288
  ```ruby
232
289
  RestClient.get('http://example.com')
@@ -59,6 +59,10 @@ module RestClient
59
59
  #
60
60
  # This list will be used by default if the Ruby global OpenSSL default
61
61
  # ciphers appear to be a weak list.
62
+ #
63
+ # TODO: either remove this code or always use it, since Ruby uses a decent
64
+ # cipher list in versions >= 2.0.
65
+ #
62
66
  DefaultCiphers = %w{
63
67
  !aNULL
64
68
  !eNULL
@@ -8,8 +8,8 @@ module RestClient
8
8
  # text. This differs from the older RFC 2616 behavior, which specifies
9
9
  # using ISO-8859-1 for text/* content types without a charset.
10
10
  #
11
- # Strings will effectively end up using `Encoding.default_external` when
12
- # this method returns nil.
11
+ # Strings will use the default encoding when this method returns nil. This
12
+ # default is likely to be UTF-8 for Ruby >= 2.0
13
13
  #
14
14
  # @param headers [Hash<Symbol,String>]
15
15
  #
@@ -1,5 +1,5 @@
1
1
  module RestClient
2
- VERSION_INFO = [2, 0, 0, 'rc4'] unless defined?(self::VERSION_INFO)
2
+ VERSION_INFO = [2, 0, 0] unless defined?(self::VERSION_INFO)
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.') unless defined?(self::VERSION)
4
4
 
5
5
  def self.version
@@ -88,14 +88,15 @@ describe RestClient do
88
88
  expect(response.encode('utf-8')).to eq body_utf8
89
89
  end
90
90
 
91
- it 'defaults to Encoding.default_external' do
91
+ it 'defaults to the default encoding' do
92
92
  stub_request(:get, 'www.example.com').to_return(
93
93
  body: 'abc', status: 200, headers: {
94
94
  'Content-Type' => 'text/plain'
95
95
  })
96
96
 
97
97
  response = RestClient.get 'www.example.com'
98
- expect(response.encoding).to eq Encoding.default_external
98
+ # expect(response.encoding).to eq Encoding.default_external
99
+ expect(response.encoding).to eq Encoding::UTF_8
99
100
  end
100
101
 
101
102
  it 'handles invalid encoding' do
@@ -105,7 +106,8 @@ describe RestClient do
105
106
  })
106
107
 
107
108
  response = RestClient.get 'www.example.com'
108
- expect(response.encoding).to eq Encoding.default_external
109
+ # expect(response.encoding).to eq Encoding.default_external
110
+ expect(response.encoding).to eq Encoding::UTF_8
109
111
  end
110
112
 
111
113
  it 'leaves images as binary' do
@@ -567,7 +567,8 @@ describe RestClient::Request, :include_helpers do
567
567
  allow(ENV).to receive(:[]).with("http_proxy").and_return("http://127.0.0.1")
568
568
  allow(ENV).to receive(:[]).with("no_proxy").and_return(nil)
569
569
  allow(ENV).to receive(:[]).with("NO_PROXY").and_return(nil)
570
- allow(ENV).to receive(:[]).with("NETRC").and_return(nil)
570
+ allow(Netrc).to receive(:read).and_return({})
571
+
571
572
  req = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
572
573
  obj = req.net_http_object('host', 80)
573
574
  expect(obj.proxy?).to be true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - REST Client Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-19 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -239,9 +239,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
239
239
  version: 2.0.0
240
240
  required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  requirements:
242
- - - ">"
242
+ - - ">="
243
243
  - !ruby/object:Gem::Version
244
- version: 1.3.1
244
+ version: '0'
245
245
  requirements: []
246
246
  rubyforge_project:
247
247
  rubygems_version: 2.4.5.1