Module: Ethon::Easy::Http::Actionable
- Defined in:
- lib/ethon/easy/http/actionable.rb
Overview
This module represents a Http Action and is a factory for more real actions like GET, HEAD, POST and PUT.
Constant Summary collapse
- QUERY_OPTIONS =
[ :params, :body, :params_encoding ]
Instance Method Summary collapse
-
#form ⇒ Form
Return the form.
-
#initialize(url, options) ⇒ Action
Create a new action.
-
#options ⇒ Hash
Return the options hash.
-
#params ⇒ Params
Return the params.
-
#params_encoding ⇒ Object
Get the requested array encoding.
-
#query_options ⇒ Hash
Returns the query options hash.
-
#set_form(easy) ⇒ Object
Setup request with form.
-
#set_params(easy) ⇒ Object
Setup request with params.
-
#setup(easy) ⇒ Object
Setup everything necessary for a proper request.
-
#url ⇒ String
Return the url.
Instance Method Details
#form ⇒ Form
Return the form.
74 75 76 |
# File 'lib/ethon/easy/http/actionable.rb', line 74 def form @form ||= Form.new(@easy, .fetch(:body, nil), .fetch(:multipart, nil)) end |
#initialize(url, options) ⇒ Action
Create a new action.
23 24 25 26 |
# File 'lib/ethon/easy/http/actionable.rb', line 23 def initialize(url, ) @url = url @options, @query_options = () end |
#options ⇒ Hash
Return the options hash.
44 45 46 |
# File 'lib/ethon/easy/http/actionable.rb', line 44 def @options end |
#params ⇒ Params
Return the params.
64 65 66 |
# File 'lib/ethon/easy/http/actionable.rb', line 64 def params @params ||= Params.new(@easy, .fetch(:params, nil)) end |
#params_encoding ⇒ Object
Get the requested array encoding. By default it’s :typhoeus, but it can also be set to :rack.
84 85 86 |
# File 'lib/ethon/easy/http/actionable.rb', line 84 def params_encoding @params_encoding ||= .fetch(:params_encoding, :typhoeus) end |
#query_options ⇒ Hash
Returns the query options hash.
54 55 56 |
# File 'lib/ethon/easy/http/actionable.rb', line 54 def @query_options end |
#set_form(easy) ⇒ Object
Setup request with form.
136 137 |
# File 'lib/ethon/easy/http/actionable.rb', line 136 def set_form(easy) end |
#set_params(easy) ⇒ Object
Setup request with params.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ethon/easy/http/actionable.rb', line 117 def set_params(easy) params.escape = easy.escape? params.params_encoding = params_encoding base_url, base_params = url.split('?') base_url << '?' base_url << base_params.to_s base_url << '&' if base_params base_url << params.to_s easy.url = base_url end |
#setup(easy) ⇒ Object
Setup everything necessary for a proper request.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ethon/easy/http/actionable.rb', line 94 def setup(easy) @easy = easy # Order is important, @easy will be used to provide access to options # relevant to the following operations (like whether or not to escape # values). easy.set_attributes() set_form(easy) unless form.empty? if params.empty? easy.url = url else set_params(easy) end end |
#url ⇒ String
Return the url.
34 35 36 |
# File 'lib/ethon/easy/http/actionable.rb', line 34 def url @url end |