module Ethon::Easy::Http::Actionable
This module represents a Http
Action and is a factory for more real actions like GET, HEAD, POST and PUT.
Constants
- QUERY_OPTIONS
Public Class Methods
Create a new action.
@example Create a new action.
Action.new("www.example.com", {})
@param [ String ] url The url. @param [ Hash ] options The options.
@return [ Action ] A new action.
# File lib/ethon/easy/http/actionable.rb, line 23 def initialize(url, options) @url = url @options, @query_options = parse_options(options) end
Public Instance Methods
Return the form.
@example Return form.
action.form
@return [ Form
] The form.
# File lib/ethon/easy/http/actionable.rb, line 74 def form @form ||= Form.new(@easy, query_options.fetch(:body, nil), options.fetch(:multipart, nil)) end
Return the options hash.
@example Return options.
action.options
@return [ Hash ] The options.
# File lib/ethon/easy/http/actionable.rb, line 44 def options @options end
Return the params.
@example Return params.
action.params
@return [ Params
] The params.
# File lib/ethon/easy/http/actionable.rb, line 64 def params @params ||= Params.new(@easy, query_options.fetch(:params, nil)) end
Returns the query options hash.
@example Return query options.
action.query_options
@return [ Hash ] The query options.
# File lib/ethon/easy/http/actionable.rb, line 54 def query_options @query_options end
Setup request with form.
@example Setup nothing.
action.set_form(easy)
@param [ Easy
] easy The easy to setup.
# File lib/ethon/easy/http/actionable.rb, line 136 def set_form(easy) end
Setup request with params.
@example Setup nothing.
action.set_params(easy)
@param [ Easy
] easy The easy to setup.
# 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 everything necessary for a proper request.
@example setup.
action.setup(easy)
@param [ easy ] easy the easy to setup.
# 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(options) set_form(easy) unless form.empty? if params.empty? easy.url = url else set_params(easy) end end
Return the url.
@example Return url.
action.url
@return [ String ] The url.
# File lib/ethon/easy/http/actionable.rb, line 34 def url @url end
Private Instance Methods
# File lib/ethon/easy/http/actionable.rb, line 141 def parse_options(options) query_options = {} options = options.dup QUERY_OPTIONS.each do |query_option| if options.key?(query_option) query_options[query_option] = options.delete(query_option) end end return options, query_options end