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.

Public Class Methods

new(url, options) click to toggle source

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 20
def initialize(url, options)
  @url = url
  @options = options.dup
end

Public Instance Methods

form() click to toggle source

Return the form.

@example Return form.

action.form

@return [ Form ] The form.

# File lib/ethon/easy/http/actionable.rb, line 61
def form
  @form ||= Form.new(@easy, options.delete(:body))
end
options() click to toggle source

Return the options hash.

@example Return options.

action.options

@return [ Hash ] The options.

# File lib/ethon/easy/http/actionable.rb, line 41
def options
  @options
end
params() click to toggle source

Return the params.

@example Return params.

action.params

@return [ Params ] The params.

# File lib/ethon/easy/http/actionable.rb, line 51
def params
  @params ||= Params.new(@easy, options.delete(:params))
end
set_form(easy) click to toggle source

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 107
def set_form(easy)
end
set_nothing(easy) click to toggle source

Setup request as if there were no params and form.

@example Setup nothing.

action.set_nothing(easy)

@param [ Easy ] easy The easy to setup.

# File lib/ethon/easy/http/actionable.rb, line 86
def set_nothing(easy)
  easy.url = url
end
set_params(easy) click to toggle source

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 96
def set_params(easy)
  params.escape = true
  easy.url = "#{url}?#{params.to_s}"
end
setup(easy) click to toggle source

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 71
def setup(easy)
  @easy = easy
  easy.url = url
  set_nothing(easy) if params.empty? && form.empty?
  set_params(easy) unless params.empty?
  set_form(easy) unless form.empty?
  easy.set_attributes(options)
end
url() click to toggle source

Return the url.

@example Return url.

action.url

@return [ String ] The url.

# File lib/ethon/easy/http/actionable.rb, line 31
def url
  @url
end