@@ -1603,6 +1603,7 @@ def edit_path(path)
1603
1603
#
1604
1604
# With a block given, calls the block with the response body:
1605
1605
#
1606
+ # http = Net::HTTP.new(hostname)
1606
1607
# http.get('/todos/1') do |res|
1607
1608
# p res
1608
1609
# end # => #<Net::HTTPOK 200 OK readbody=true>
@@ -1660,6 +1661,7 @@ def head(path, initheader = nil)
1660
1661
# With a block given, calls the block with the response body:
1661
1662
#
1662
1663
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1664
+ # http = Net::HTTP.new(hostname)
1663
1665
# http.post('/todos', data) do |res|
1664
1666
# p res
1665
1667
# end # => #<Net::HTTPCreated 201 Created readbody=true>
@@ -1693,6 +1695,7 @@ def post(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segme
1693
1695
# With a block given, calls the block with the response body:
1694
1696
#
1695
1697
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1698
+ # http = Net::HTTP.new(hostname)
1696
1699
# http.patch('/todos/1', data) do |res|
1697
1700
# p res
1698
1701
# end # => #<Net::HTTPOK 200 OK readbody=true>
@@ -1716,6 +1719,7 @@ def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segm
1716
1719
# created from string +path+, string +data+, and initial headers hash +initheader+.
1717
1720
#
1718
1721
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1722
+ # http = Net::HTTP.new(hostname)
1719
1723
# http.put('/todos/1', data) # => #<Net::HTTPOK 200 OK readbody=true>
1720
1724
#
1721
1725
def put ( path , data , initheader = nil )
@@ -1729,6 +1733,7 @@ def put(path, data, initheader = nil)
1729
1733
# created from string +path+, string +body+, and initial headers hash +initheader+.
1730
1734
#
1731
1735
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1736
+ # http = Net::HTTP.new(hostname)
1732
1737
# http.proppatch('/todos/1', data)
1733
1738
#
1734
1739
def proppatch ( path , body , initheader = nil )
@@ -1742,6 +1747,7 @@ def proppatch(path, body, initheader = nil)
1742
1747
# created from string +path+, string +body+, and initial headers hash +initheader+.
1743
1748
#
1744
1749
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1750
+ # http = Net::HTTP.new(hostname)
1745
1751
# http.lock('/todos/1', data)
1746
1752
#
1747
1753
def lock ( path , body , initheader = nil )
@@ -1755,6 +1761,7 @@ def lock(path, body, initheader = nil)
1755
1761
# created from string +path+, string +body+, and initial headers hash +initheader+.
1756
1762
#
1757
1763
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1764
+ # http = Net::HTTP.new(hostname)
1758
1765
# http.unlock('/todos/1', data)
1759
1766
#
1760
1767
def unlock ( path , body , initheader = nil )
@@ -1767,6 +1774,7 @@ def unlock(path, body, initheader = nil)
1767
1774
# The request is based on the Net::HTTP::Options object
1768
1775
# created from string +path+ and initial headers hash +initheader+.
1769
1776
#
1777
+ # http = Net::HTTP.new(hostname)
1770
1778
# http.options('/')
1771
1779
#
1772
1780
def options ( path , initheader = nil )
@@ -1780,6 +1788,7 @@ def options(path, initheader = nil)
1780
1788
# created from string +path+, string +body+, and initial headers hash +initheader+.
1781
1789
#
1782
1790
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1791
+ # http = Net::HTTP.new(hostname)
1783
1792
# http.propfind('/todos/1', data)
1784
1793
#
1785
1794
def propfind ( path , body = nil , initheader = { 'Depth' => '0' } )
@@ -1792,6 +1801,7 @@ def propfind(path, body = nil, initheader = {'Depth' => '0'})
1792
1801
# The request is based on the Net::HTTP::Delete object
1793
1802
# created from string +path+ and initial headers hash +initheader+.
1794
1803
#
1804
+ # http = Net::HTTP.new(hostname)
1795
1805
# http.delete('/todos/1')
1796
1806
#
1797
1807
def delete ( path , initheader = { 'Depth' => 'Infinity' } )
@@ -1804,6 +1814,7 @@ def delete(path, initheader = {'Depth' => 'Infinity'})
1804
1814
# The request is based on the Net::HTTP::Move object
1805
1815
# created from string +path+ and initial headers hash +initheader+.
1806
1816
#
1817
+ # http = Net::HTTP.new(hostname)
1807
1818
# http.move('/todos/1')
1808
1819
#
1809
1820
def move ( path , initheader = nil )
@@ -1816,6 +1827,7 @@ def move(path, initheader = nil)
1816
1827
# The request is based on the Net::HTTP::Copy object
1817
1828
# created from string +path+ and initial headers hash +initheader+.
1818
1829
#
1830
+ # http = Net::HTTP.new(hostname)
1819
1831
# http.copy('/todos/1')
1820
1832
#
1821
1833
def copy ( path , initheader = nil )
@@ -1830,6 +1842,7 @@ def copy(path, initheader = nil)
1830
1842
#
1831
1843
# data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
1832
1844
# http.mkcol('/todos/1', data)
1845
+ # http = Net::HTTP.new(hostname)
1833
1846
#
1834
1847
def mkcol ( path , body = nil , initheader = nil )
1835
1848
request ( Mkcol . new ( path , initheader ) , body )
@@ -1841,6 +1854,7 @@ def mkcol(path, body = nil, initheader = nil)
1841
1854
# The request is based on the Net::HTTP::Trace object
1842
1855
# created from string +path+ and initial headers hash +initheader+.
1843
1856
#
1857
+ # http = Net::HTTP.new(hostname)
1844
1858
# http.trace('/todos/1')
1845
1859
#
1846
1860
def trace ( path , initheader = nil )
@@ -1873,50 +1887,56 @@ def request_get(path, initheader = nil, &block) # :yield: +response+
1873
1887
request ( Get . new ( path , initheader ) , &block )
1874
1888
end
1875
1889
1876
- # Sends a HEAD request to the +path+ and returns the response
1877
- # as a Net::HTTPResponse object.
1878
- #
1879
- # Returns the response.
1890
+ # Sends a HEAD request to the server;
1891
+ # returns an instance of a subclass of Net::HTTPResponse.
1880
1892
#
1881
- # This method never raises Net::* exceptions.
1893
+ # The request is based on the Net::HTTP::Head object
1894
+ # created from string +path+ and initial headers hash +initheader+.
1882
1895
#
1883
- # response = http.request_head('/index.html' )
1884
- # p response['content-type']
1896
+ # http = Net::HTTP.new(hostname )
1897
+ # http.head('/todos/1') # => #<Net::HTTPOK 200 OK readbody=true>
1885
1898
#
1886
1899
def request_head ( path , initheader = nil , &block )
1887
1900
request ( Head . new ( path , initheader ) , &block )
1888
1901
end
1889
1902
1890
- # Sends a POST request to the +path+.
1903
+ # Sends a POST request to the server;
1904
+ # forms the response into a Net::HTTPResponse object.
1891
1905
#
1892
- # Returns the response as a Net::HTTPResponse object.
1906
+ # The request is based on the Net::HTTP::Post object
1907
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
1893
1908
#
1894
- # When called with a block, the block is passed an HTTPResponse
1895
- # object. The body of that response will not have been read yet;
1896
- # the block can process it using HTTPResponse#read_body, if desired.
1909
+ # With no block given, returns the response object:
1897
1910
#
1898
- # Returns the response.
1911
+ # http = Net::HTTP.new(hostname)
1912
+ # http.post('/todos', 'xyzzy')
1913
+ # # => #<Net::HTTPCreated 201 Created readbody=true>
1914
+ #
1915
+ # With a block given, calls the block with the response body
1916
+ # and returns the response object:
1899
1917
#
1900
- # This method never raises Net::* exceptions.
1918
+ # http.post('/todos', 'xyzzy') do |res|
1919
+ # p res
1920
+ # end # => #<Net::HTTPCreated 201 Created readbody=true>
1901
1921
#
1902
- # # example
1903
- # response = http.request_post('/cgi-bin/nice.rb', 'datadatadata...')
1904
- # p response.status
1905
- # puts response.body # body is already read in this case
1922
+ # Output:
1906
1923
#
1907
- # # using block
1908
- # http.request_post('/cgi-bin/nice.rb', 'datadatadata...') {|response|
1909
- # p response.status
1910
- # p response['content-type']
1911
- # response.read_body do |str| # read body now
1912
- # print str
1913
- # end
1914
- # }
1924
+ # "{\n \"xyzzy\": \"\",\n \"id\": 201\n}"
1915
1925
#
1916
1926
def request_post ( path , data , initheader = nil , &block ) # :yield: +response+
1917
1927
request Post . new ( path , initheader ) , data , &block
1918
1928
end
1919
1929
1930
+ # Sends a PUT request to the server;
1931
+ # returns an instance of a subclass of Net::HTTPResponse.
1932
+ #
1933
+ # The request is based on the Net::HTTP::Put object
1934
+ # created from string +path+, string +data+, and initial headers hash +initheader+.
1935
+ #
1936
+ # http = Net::HTTP.new(hostname)
1937
+ # http.put('/todos/1', 'xyzzy')
1938
+ # # => #<Net::HTTPOK 200 OK readbody=true>
1939
+ #
1920
1940
def request_put ( path , data , initheader = nil , &block ) #:nodoc:
1921
1941
request Put . new ( path , initheader ) , data , &block
1922
1942
end
@@ -1926,37 +1946,61 @@ def request_put(path, data, initheader = nil, &block) #:nodoc:
1926
1946
alias post2 request_post #:nodoc: obsolete
1927
1947
alias put2 request_put #:nodoc: obsolete
1928
1948
1929
-
1930
- # Sends an \HTTP request to the \HTTP server.
1931
- # Also sends a DATA string if +data+ is given.
1949
+ # Sends an \HTTP request to the server;
1950
+ # returns an instance of a subclass of Net::HTTPResponse.
1932
1951
#
1933
- # Returns a Net::HTTPResponse object.
1952
+ # The request is based on the Net::HTTPRequest object
1953
+ # created from string +path+, string +data+, and initial headers hash +header+.
1954
+ # That object is an instance of the
1955
+ # {subclass of Net::HTTPRequest}[rdoc-ref:Net::HTTPRequest@Request+Subclasses],
1956
+ # that corresponds to the given uppercase string +name+,
1957
+ # which must be
1958
+ # an {HTTP request method}[https://en.wikipedia.org/wiki/HTTP#Request_methods]
1959
+ # or a {WebDAV request method}[https://en.wikipedia.org/wiki/WebDAV#Implementation].
1934
1960
#
1935
- # This method never raises Net::* exceptions.
1961
+ # Examples:
1936
1962
#
1937
- # response = http.send_request('GET', '/index.html')
1938
- # puts response.body
1963
+ # http = Net::HTTP.new(hostname)
1964
+ # http.send_request('GET', '/todos/1')
1965
+ # # => #<Net::HTTPOK 200 OK readbody=true>
1966
+ # http.send_request('POST', '/todos', 'xyzzy')
1967
+ # # => #<Net::HTTPCreated 201 Created readbody=true>
1939
1968
#
1940
1969
def send_request ( name , path , data = nil , header = nil )
1941
1970
has_response_body = name != 'HEAD'
1942
1971
r = HTTPGenericRequest . new ( name , ( data ? true : false ) , has_response_body , path , header )
1943
1972
request r , data
1944
1973
end
1945
1974
1946
- # Sends an HTTPRequest object +req+ to the \HTTP server.
1975
+ # Sends the given request +req+ to the server;
1976
+ # forms the response into a Net::HTTPResponse object.
1977
+ #
1978
+ # The given +req+ must be an instance of a
1979
+ # {subclass of Net::HTTPRequest}[rdoc-ref:Net::HTTPRequest@Request+Subclasses].
1980
+ # Argument +body+ should be given only if needed for the request.
1981
+ #
1982
+ # With no block given, returns the response object:
1983
+ #
1984
+ # http = Net::HTTP.new(hostname)
1947
1985
#
1948
- # If + req+ is a Net::HTTP::Post or Net::HTTP::Put request containing
1949
- # data, the data is also sent. Providing data for a Net::HTTP::Head or
1950
- # \ Net::HTTP::Get request results in an ArgumentError.
1986
+ # req = Net::HTTP::Get.new('/todos/1')
1987
+ # http.request(req)
1988
+ # # => #< Net::HTTPOK 200 OK readbody=true>
1951
1989
#
1952
- # Returns an HTTPResponse object.
1990
+ # req = Net::HTTP::Post.new('/todos')
1991
+ # http.request(req, 'xyzzy')
1992
+ # # => #<Net::HTTPCreated 201 Created readbody=true>
1993
+ #
1994
+ # With a block given, calls the block with the response and returns the response:
1953
1995
#
1954
- # When called with a block, passes an HTTPResponse object to the block.
1955
- # The body of the response will not have been read yet;
1956
- # the block can process it using HTTPResponse#read_body,
1957
- # if desired.
1996
+ # req = Net::HTTP::Get.new('/todos/1')
1997
+ # http.request(req) do |res|
1998
+ # p res
1999
+ # end # => #<Net::HTTPOK 200 OK readbody=true>
1958
2000
#
1959
- # This method never raises Net::* exceptions.
2001
+ # Output:
2002
+ #
2003
+ # #<Net::HTTPOK 200 OK readbody=false>
1960
2004
#
1961
2005
def request ( req , body = nil , &block ) # :yield: +response+
1962
2006
unless started?
0 commit comments