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.
73 74 75 |
# File 'lib/ethon/easy/http/actionable.rb', line 73 def form @form ||= Form.new(@easy, .fetch(:body, nil)) end |
#initialize(url, options) ⇒ Action
Create a new action.
22 23 24 25 |
# File 'lib/ethon/easy/http/actionable.rb', line 22 def initialize(url, ) @url = url @options, @query_options = () end |
#options ⇒ Hash
Return the options hash.
43 44 45 |
# File 'lib/ethon/easy/http/actionable.rb', line 43 def @options end |
#params ⇒ Params
Return the params.
63 64 65 |
# File 'lib/ethon/easy/http/actionable.rb', line 63 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.
83 84 85 |
# File 'lib/ethon/easy/http/actionable.rb', line 83 def params_encoding @params_encoding ||= .fetch(:params_encoding, :typhoeus) end |
#query_options ⇒ Hash
Returns the query options hash.
53 54 55 |
# File 'lib/ethon/easy/http/actionable.rb', line 53 def @query_options end |
#set_form(easy) ⇒ Object
Setup request with form.
135 136 |
# File 'lib/ethon/easy/http/actionable.rb', line 135 def set_form(easy) end |
#set_params(easy) ⇒ Object
Setup request with params.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ethon/easy/http/actionable.rb', line 116 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.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ethon/easy/http/actionable.rb', line 93 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.
33 34 35 |
# File 'lib/ethon/easy/http/actionable.rb', line 33 def url @url end |