Module: Ethon::Easy::Http::Actionable

Included in:
Delete, Get, Head, Options, Patch, Post, Put
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.

Instance Method Summary collapse

Instance Method Details

#formForm

Return the form.

Examples:

Return form.

action.form

Returns:

  • (Form)

    The form.



61
62
63
# File 'lib/ethon/easy/http/actionable.rb', line 61

def form
  @form ||= Form.new(@easy, options.delete(:body))
end

#initialize(url, options) ⇒ Action

Create a new action.

Examples:

Create a new action.

Action.new("www.example.com", {})

Parameters:

  • url (String)

    The url.

  • options (Hash)

    The options.

Returns:

  • (Action)

    A new action.



20
21
22
23
# File 'lib/ethon/easy/http/actionable.rb', line 20

def initialize(url, options)
  @url = url
  @options = options.dup
end

#optionsHash

Return the options hash.

Examples:

Return options.

action.options

Returns:

  • (Hash)

    The options.



41
42
43
# File 'lib/ethon/easy/http/actionable.rb', line 41

def options
  @options
end

#paramsParams

Return the params.

Examples:

Return params.

action.params

Returns:



51
52
53
# File 'lib/ethon/easy/http/actionable.rb', line 51

def params
  @params ||= Params.new(@easy, options.delete(:params))
end

#set_form(easy) ⇒ Object

Setup request with form.

Examples:

Setup nothing.

action.set_form(easy)

Parameters:

  • easy (Easy)

    The easy to setup.



99
100
# File 'lib/ethon/easy/http/actionable.rb', line 99

def set_form(easy)
end

#set_params(easy) ⇒ Object

Setup request with params.

Examples:

Setup nothing.

action.set_params(easy)

Parameters:

  • easy (Easy)

    The easy to setup.



88
89
90
91
# File 'lib/ethon/easy/http/actionable.rb', line 88

def set_params(easy)
  params.escape = true
  easy.url = "#{url}?#{params.to_s}"
end

#setup(easy) ⇒ Object

Setup everything necessary for a proper request.

Examples:

setup.

action.setup(easy)

Parameters:

  • easy (easy)

    the easy to setup.



71
72
73
74
75
76
77
78
79
80
# File 'lib/ethon/easy/http/actionable.rb', line 71

def setup(easy)
  @easy = easy
  if params.empty?
    easy.url = url
  else
    set_params(easy)
  end
  set_form(easy) unless form.empty?
  easy.set_attributes(options)
end

#urlString

Return the url.

Examples:

Return url.

action.url

Returns:

  • (String)

    The url.



31
32
33
# File 'lib/ethon/easy/http/actionable.rb', line 31

def url
  @url
end