mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
:timeout option for RestClient::Resource constructor
This commit is contained in:
parent
1a4d848025
commit
e91fd21c1f
1 changed files with 24 additions and 16 deletions
|
@ -12,6 +12,10 @@ module RestClient
|
||||||
# resource = RestClient::Resource.new('http://protected/resource', :user => 'user', :password => 'password')
|
# resource = RestClient::Resource.new('http://protected/resource', :user => 'user', :password => 'password')
|
||||||
# resource.delete
|
# resource.delete
|
||||||
#
|
#
|
||||||
|
# With a timeout (seconds):
|
||||||
|
#
|
||||||
|
# RestClient::Resource.new('http://slow', :timeout => 10)
|
||||||
|
#
|
||||||
# You can also use resources to share common headers. For headers keys,
|
# You can also use resources to share common headers. For headers keys,
|
||||||
# symbols are converted to strings. Example:
|
# symbols are converted to strings. Example:
|
||||||
#
|
#
|
||||||
|
@ -38,37 +42,37 @@ module RestClient
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(additional_headers={})
|
def get(additional_headers={})
|
||||||
Request.execute(:method => :get,
|
Request.execute(options.merge(
|
||||||
|
:method => :get,
|
||||||
:url => url,
|
:url => url,
|
||||||
:user => user,
|
:headers => headers.merge(additional_headers)
|
||||||
:password => password,
|
))
|
||||||
:headers => headers.merge(additional_headers))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(payload, additional_headers={})
|
def post(payload, additional_headers={})
|
||||||
Request.execute(:method => :post,
|
Request.execute(options.merge(
|
||||||
|
:method => :post,
|
||||||
:url => url,
|
:url => url,
|
||||||
:payload => payload,
|
:payload => payload,
|
||||||
:user => user,
|
:headers => headers.merge(additional_headers)
|
||||||
:password => password,
|
))
|
||||||
:headers => headers.merge(additional_headers))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def put(payload, additional_headers={})
|
def put(payload, additional_headers={})
|
||||||
Request.execute(:method => :put,
|
Request.execute(options.merge(
|
||||||
|
:method => :put,
|
||||||
:url => url,
|
:url => url,
|
||||||
:payload => payload,
|
:payload => payload,
|
||||||
:user => user,
|
:headers => headers.merge(additional_headers)
|
||||||
:password => password,
|
))
|
||||||
:headers => headers.merge(additional_headers))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(additional_headers={})
|
def delete(additional_headers={})
|
||||||
Request.execute(:method => :delete,
|
Request.execute(options.merge(
|
||||||
|
:method => :delete,
|
||||||
:url => url,
|
:url => url,
|
||||||
:user => user,
|
:headers => headers.merge(additional_headers)
|
||||||
:password => password,
|
))
|
||||||
:headers => headers.merge(additional_headers))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -87,6 +91,10 @@ module RestClient
|
||||||
options[:headers] || {}
|
options[:headers] || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def timeout
|
||||||
|
options[:timeout]
|
||||||
|
end
|
||||||
|
|
||||||
# Construct a subresource, preserving authentication.
|
# Construct a subresource, preserving authentication.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue