rest-client 1.6.14

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rest-client might be problematic. Click here for more details.

Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +3 -0
  5. data/AUTHORS +75 -0
  6. data/Gemfile +7 -0
  7. data/README.rdoc +300 -0
  8. data/Rakefile +49 -0
  9. data/bin/restclient +93 -0
  10. data/history.md +160 -0
  11. data/lib/rest-client.rb +2 -0
  12. data/lib/rest_client.rb +2 -0
  13. data/lib/restclient.rb +170 -0
  14. data/lib/restclient/abstract_response.rb +106 -0
  15. data/lib/restclient/exceptions.rb +198 -0
  16. data/lib/restclient/net_http_ext.rb +55 -0
  17. data/lib/restclient/payload.rb +240 -0
  18. data/lib/restclient/platform.rb +29 -0
  19. data/lib/restclient/raw_response.rb +34 -0
  20. data/lib/restclient/request.rb +360 -0
  21. data/lib/restclient/resource.rb +169 -0
  22. data/lib/restclient/response.rb +26 -0
  23. data/lib/restclient/version.rb +7 -0
  24. data/rest-client.gemspec +26 -0
  25. data/spec/abstract_response_spec.rb +85 -0
  26. data/spec/base.rb +13 -0
  27. data/spec/exceptions_spec.rb +98 -0
  28. data/spec/integration/capath_digicert/244b5494.0 +19 -0
  29. data/spec/integration/capath_digicert/81b9768f.0 +19 -0
  30. data/spec/integration/capath_digicert/README +8 -0
  31. data/spec/integration/capath_digicert/digicert.crt +19 -0
  32. data/spec/integration/certs/digicert.crt +19 -0
  33. data/spec/integration/certs/verisign.crt +14 -0
  34. data/spec/integration/request_spec.rb +75 -0
  35. data/spec/integration_spec.rb +38 -0
  36. data/spec/master_shake.jpg +0 -0
  37. data/spec/payload_spec.rb +244 -0
  38. data/spec/raw_response_spec.rb +17 -0
  39. data/spec/request2_spec.rb +35 -0
  40. data/spec/request_spec.rb +528 -0
  41. data/spec/resource_spec.rb +136 -0
  42. data/spec/response_spec.rb +169 -0
  43. data/spec/restclient_spec.rb +73 -0
  44. metadata +192 -0
@@ -0,0 +1,26 @@
1
+ module RestClient
2
+
3
+ # A Response from RestClient, you can access the response body, the code or the headers.
4
+ #
5
+ module Response
6
+
7
+ include AbstractResponse
8
+
9
+ attr_accessor :args, :net_http_res
10
+
11
+ attr_writer :body
12
+
13
+ def body
14
+ self
15
+ end
16
+
17
+ def Response.create body, net_http_res, args
18
+ result = body || ''
19
+ result.extend Response
20
+ result.net_http_res = net_http_res
21
+ result.args = args
22
+ result
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module RestClient
2
+ VERSION = '1.6.14' unless defined?(self::VERSION)
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path("../lib/restclient/version", __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'rest-client'
7
+ s.version = RestClient::VERSION
8
+ s.authors = ['REST Client Team']
9
+ s.description = 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework style of specifying actions: get, put, post, delete.'
10
+ s.license = 'MIT'
11
+ s.email = 'rest.client@librelist.com'
12
+ s.executables = ['restclient']
13
+ s.extra_rdoc_files = ["README.rdoc", "history.md"]
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- spec/*`.split("\n")
16
+ s.homepage = 'https://github.com/rest-client/rest-client'
17
+ s.summary = 'Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.'
18
+
19
+ s.add_dependency(%q<mime-types>, ["~> 1.16"])
20
+ s.add_development_dependency(%q<rdoc>, [">= 2.4.2"])
21
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
22
+ s.add_development_dependency(%q<webmock>, ["~> 1.4"])
23
+ s.add_development_dependency(%q<rspec>, ["~> 2.4"])
24
+ s.add_development_dependency(%q<pry>)
25
+ end
26
+
@@ -0,0 +1,85 @@
1
+ require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
2
+
3
+ describe RestClient::AbstractResponse do
4
+
5
+ class MyAbstractResponse
6
+
7
+ include RestClient::AbstractResponse
8
+
9
+ attr_accessor :size
10
+
11
+ def initialize net_http_res, args
12
+ @net_http_res = net_http_res
13
+ @args = args
14
+ end
15
+
16
+ end
17
+
18
+ before do
19
+ @net_http_res = double('net http response')
20
+ @response = MyAbstractResponse.new(@net_http_res, {})
21
+ end
22
+
23
+ it "fetches the numeric response code" do
24
+ @net_http_res.should_receive(:code).and_return('200')
25
+ @response.code.should eq 200
26
+ end
27
+
28
+ it "has a nice description" do
29
+ @net_http_res.should_receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
30
+ @net_http_res.should_receive(:code).and_return('200')
31
+ @response.description.should eq "200 OK | application/pdf bytes\n"
32
+ end
33
+
34
+ it "beautifies the headers by turning the keys to symbols" do
35
+ h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
36
+ h.keys.first.should eq :content_type
37
+ end
38
+
39
+ it "beautifies the headers by turning the values to strings instead of one-element arrays" do
40
+ h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
41
+ h.values.first.should eq 'text/html'
42
+ end
43
+
44
+ it "fetches the headers" do
45
+ @net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
46
+ @response.headers.should eq({ :content_type => 'text/html' })
47
+ end
48
+
49
+ it "extracts cookies from response headers" do
50
+ @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
51
+ @response.cookies.should eq({ 'session_id' => '1' })
52
+ end
53
+
54
+ it "extract strange cookies" do
55
+ @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
56
+ @response.cookies.should eq({ 'session_id' => 'ZJ%2FHQVH6YE+rVkTpn0zvTQ%3D%3D' })
57
+ end
58
+
59
+ it "doesn't escape cookies" do
60
+ @net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
61
+ @response.cookies.should eq({ 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' })
62
+ end
63
+
64
+ it "can access the net http result directly" do
65
+ @response.net_http_res.should eq @net_http_res
66
+ end
67
+
68
+ describe "#return!" do
69
+ it "should return the response itself on 200-codes" do
70
+ @net_http_res.should_receive(:code).and_return('200')
71
+ @response.return!.should be_equal(@response)
72
+ end
73
+
74
+ it "should raise RequestFailed on unknown codes" do
75
+ @net_http_res.should_receive(:code).and_return('1000')
76
+ lambda { @response.return! }.should raise_error RestClient::RequestFailed
77
+ end
78
+
79
+ it "should raise an error on a redirection after non-GET/HEAD requests" do
80
+ @net_http_res.should_receive(:code).and_return('301')
81
+ @response.args.merge(:method => :put)
82
+ lambda { @response.return! }.should raise_error RestClient::RequestFailed
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,13 @@
1
+ def is_ruby_19?
2
+ RUBY_VERSION > '1.9'
3
+ end
4
+
5
+ require 'rubygems'
6
+
7
+ begin
8
+ require "ruby-debug"
9
+ rescue LoadError
10
+ # NOP, ignore
11
+ end
12
+
13
+ require File.dirname(__FILE__) + '/../lib/restclient'
@@ -0,0 +1,98 @@
1
+ require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
2
+
3
+ require 'webmock/rspec'
4
+ include WebMock::API
5
+
6
+ describe RestClient::Exception do
7
+ it "returns a 'message' equal to the class name if the message is not set, because 'message' should not be nil" do
8
+ e = RestClient::Exception.new
9
+ e.message.should eq "RestClient::Exception"
10
+ end
11
+
12
+ it "returns the 'message' that was set" do
13
+ e = RestClient::Exception.new
14
+ message = "An explicitly set message"
15
+ e.message = message
16
+ e.message.should eq message
17
+ end
18
+
19
+ it "sets the exception message to ErrorMessage" do
20
+ RestClient::ResourceNotFound.new.message.should eq 'Resource Not Found'
21
+ end
22
+
23
+ it "contains exceptions in RestClient" do
24
+ RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
25
+ RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
26
+ end
27
+ end
28
+
29
+ describe RestClient::ServerBrokeConnection do
30
+ it "should have a default message of 'Server broke connection'" do
31
+ e = RestClient::ServerBrokeConnection.new
32
+ e.message.should eq 'Server broke connection'
33
+ end
34
+ end
35
+
36
+ describe RestClient::RequestFailed do
37
+ before do
38
+ @response = double('HTTP Response', :code => '502')
39
+ end
40
+
41
+ it "stores the http response on the exception" do
42
+ response = "response"
43
+ begin
44
+ raise RestClient::RequestFailed, response
45
+ rescue RestClient::RequestFailed => e
46
+ e.response.should eq response
47
+ end
48
+ end
49
+
50
+ it "http_code convenience method for fetching the code as an integer" do
51
+ RestClient::RequestFailed.new(@response).http_code.should eq 502
52
+ end
53
+
54
+ it "http_body convenience method for fetching the body (decoding when necessary)" do
55
+ RestClient::RequestFailed.new(@response).http_code.should eq 502
56
+ RestClient::RequestFailed.new(@response).message.should eq 'HTTP status code 502'
57
+ end
58
+
59
+ it "shows the status code in the message" do
60
+ RestClient::RequestFailed.new(@response).to_s.should match(/502/)
61
+ end
62
+ end
63
+
64
+ describe RestClient::ResourceNotFound do
65
+ it "also has the http response attached" do
66
+ response = "response"
67
+ begin
68
+ raise RestClient::ResourceNotFound, response
69
+ rescue RestClient::ResourceNotFound => e
70
+ e.response.should eq response
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "backwards compatibility" do
76
+ it "alias RestClient::Request::Redirect to RestClient::Redirect" do
77
+ RestClient::Request::Redirect.should eq RestClient::Redirect
78
+ end
79
+
80
+ it "alias RestClient::Request::Unauthorized to RestClient::Unauthorized" do
81
+ RestClient::Request::Unauthorized.should eq RestClient::Unauthorized
82
+ end
83
+
84
+ it "alias RestClient::Request::RequestFailed to RestClient::RequestFailed" do
85
+ RestClient::Request::RequestFailed.should eq RestClient::RequestFailed
86
+ end
87
+
88
+ it "make the exception's response act like an Net::HTTPResponse" do
89
+ body = "body"
90
+ stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
91
+ begin
92
+ RestClient.get "www.example.com"
93
+ raise
94
+ rescue RestClient::ResourceNotFound => e
95
+ e.response.body.should eq body
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,19 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
3
+ EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
4
+ KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
5
+ MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
6
+ MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
7
+ Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
8
+ Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
9
+ OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
10
+ MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
11
+ NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
12
+ h10a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hvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
8
+ Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
9
+ OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
10
+ MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
11
+ NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
12
+ h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQFMAMB
13
+ Af8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaAFLE+w2kD+L9HAdSY
14
+ JhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3NecnzyIZgYIVyHbIUf4KmeqvxgydkAQ
15
+ V8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6zeM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFp
16
+ myPInngiK3BD41VHMWEZ71jFhS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkK
17
+ mNEVX58Svnw2Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe
18
+ vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep+OkuE6N36B9K
19
+ -----END CERTIFICATE-----
@@ -0,0 +1,8 @@
1
+ The CA path symlinks can be created by c_rehash(1ssl).
2
+
3
+ But in order for the tests to work on Windows, they have to be regular files.
4
+ You can turn them all into regular files by running this on a GNU system:
5
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AwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
6
+ BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
7
+ YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
8
+ ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
9
+ BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
10
+ I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
11
+ CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
12
+ lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
13
+ AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
14
+ -----END CERTIFICATE-----
@@ -0,0 +1,75 @@
1
+ require File.join( File.dirname(File.expand_path(__FILE__)), '../base')
2
+
3
+ describe RestClient::Request do
4
+ describe "ssl verification" do
5
+ it "is successful with the correct ca_file" do
6
+ request = RestClient::Request.new(
7
+ :method => :get,
8
+ :url => 'https://www.mozilla.org',
9
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
10
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
11
+ )
12
+ expect { request.execute }.to_not raise_error
13
+ end
14
+
15
+ # I don' think this feature is useful anymore (under 1.9.3 at the very least).
16
+ #
17
+ # Exceptions in verify_callback are ignored; RestClient has to catch OpenSSL::SSL::SSLError
18
+ # and either re-throw it as is, or throw SSLCertificateNotVerified
19
+ # based on the contents of the message field of the original exception
20
+ #.
21
+ # The client has to handle OpenSSL::SSL::SSLError exceptions anyway,
22
+ # why make them handle both OpenSSL *AND* RestClient exceptions???
23
+ #
24
+ # also see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
25
+ it "is unsuccessful with an incorrect ca_file" do
26
+ request = RestClient::Request.new(
27
+ :method => :get,
28
+ :url => 'https://www.mozilla.com',
29
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
30
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt")
31
+ )
32
+ expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
33
+ end
34
+
35
+ it "executes the verify_callback" do
36
+ ran_callback = false
37
+ request = RestClient::Request.new(
38
+ :method => :get,
39
+ :url => 'https://www.mozilla.org',
40
+ :verify_ssl => true,
41
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx|
42
+ ran_callback = true
43
+ preverify_ok
44
+ },
45
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
46
+ )
47
+ expect {request.execute }.to_not raise_error
48
+ ran_callback.should eq(true)
49
+ end
50
+
51
+ it "fails verification when the callback returns false",
52
+ :unless => RestClient::Platform.mac? do
53
+ request = RestClient::Request.new(
54
+ :method => :get,
55
+ :url => 'https://www.mozilla.org',
56
+ :verify_ssl => true,
57
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx| false },
58
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
59
+ )
60
+ expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
61
+ end
62
+
63
+ it "succeeds verification when the callback returns true",
64
+ :unless => RestClient::Platform.mac? do
65
+ request = RestClient::Request.new(
66
+ :method => :get,
67
+ :url => 'https://www.mozilla.org',
68
+ :verify_ssl => true,
69
+ :ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt"),
70
+ :ssl_verify_callback => lambda { |preverify_ok, store_ctx| true }
71
+ )
72
+ expect { request.execute }.to_not raise_error
73
+ end
74
+ end
75
+ end