Class: Faraday::Request
- Extended by:
- AutoloadHelper
- Defined in:
- lib/faraday/request.rb
Overview
Used to setup urls, params, headers, and the request body in a sane manner.
@connection.post do |req|
req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
req.headers['b'] = '2' # Header
req.params['c'] = '3' # GET Param
req['b'] = '2' # also Header
req.body = 'abc'
end
Defined Under Namespace
Classes: JSON, Multipart, UrlEncoded
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(request_method) ⇒ Request
constructor
A new instance of Request.
-
#to_env(connection) ⇒ Object
ENV Keys :method - a symbolized request method (:get, :post) :body - the request body that will eventually be converted to a string.
- #url(path, params = {}) ⇒ Object
Methods included from AutoloadHelper
all_loaded_constants, autoload_all, load_autoloaded_constants, lookup_module, register_lookup_modules
Constructor Details
#initialize(request_method) ⇒ Request
Returns a new instance of Request.
33 34 35 36 37 |
# File 'lib/faraday/request.rb', line 33 def initialize(request_method) @method = request_method self.params = {} self.headers = {} end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
12 13 14 |
# File 'lib/faraday/request.rb', line 12 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers
12 13 14 |
# File 'lib/faraday/request.rb', line 12 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
25 26 27 |
# File 'lib/faraday/request.rb', line 25 def method @method end |
#params ⇒ Object
Returns the value of attribute params
12 13 14 |
# File 'lib/faraday/request.rb', line 12 def params @params end |
#path ⇒ Object
Returns the value of attribute path
12 13 14 |
# File 'lib/faraday/request.rb', line 12 def path @path end |
Class Method Details
.create(request_method) ⇒ Object
27 28 29 30 31 |
# File 'lib/faraday/request.rb', line 27 def self.create(request_method) new(request_method).tap do |request| yield request if block_given? end end |
Instance Method Details
#[](key) ⇒ Object
44 45 46 |
# File 'lib/faraday/request.rb', line 44 def [](key) headers[key] end |
#[]=(key, value) ⇒ Object
48 49 50 |
# File 'lib/faraday/request.rb', line 48 def []=(key, value) headers[key] = value end |
#to_env(connection) ⇒ Object
ENV Keys :method - a symbolized request method (:get, :post) :body - the request body that will eventually be converted to a string. :url - Addressable::URI instance of the URI for the current request. :status - HTTP response status code :request_headers - hash of HTTP Headers to be sent to the server :response_headers - Hash of HTTP headers from the server :parallel_manager - sent if the connection is in parallel mode :request - Hash of options for configuring the request.
:timeout - open/read timeout Integer in seconds
:open_timeout - read timeout Integer in seconds
:proxy - Hash of proxy options
:uri - Proxy Server URI
:user - Proxy server username
:password - Proxy server password
:ssl - Hash of options for configuring SSL requests.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/faraday/request.rb', line 68 def to_env(connection) env_params = connection.params.merge(params) env_headers = connection.headers.merge(headers) { :method => method, :body => body, :url => connection.build_url(path, env_params), :request_headers => env_headers, :parallel_manager => connection.parallel_manager, :request => connection..merge(:proxy => connection.proxy), :ssl => connection.ssl} end |
#url(path, params = {}) ⇒ Object
39 40 41 42 |
# File 'lib/faraday/request.rb', line 39 def url(path, params = {}) self.path = path self.params = params end |