move Node class under Mechanize namespace
parent
a247432bc4
commit
f62c04949a
|
@ -73,13 +73,13 @@ class Mechanize
|
||||||
def post(uri : String | URI,
|
def post(uri : String | URI,
|
||||||
headers = ::HTTP::Headers.new,
|
headers = ::HTTP::Headers.new,
|
||||||
query : Hash(String, String | Array(String)) = Hash(String, String).new) : Mechanize::Page
|
query : Hash(String, String | Array(String)) = Hash(String, String).new) : Mechanize::Page
|
||||||
node = Node.new
|
node = Mechanize::Node.new
|
||||||
node["method"] = "POST"
|
node["method"] = "POST"
|
||||||
node["enctype"] = "application/x-www-form-urlencoded"
|
node["enctype"] = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
form = Mechanize::Form.new(node)
|
form = Mechanize::Form.new(node)
|
||||||
query.each do |k, v|
|
query.each do |k, v|
|
||||||
node = Node.new
|
node = Mechanize::Node.new
|
||||||
node["name"] = k
|
node["name"] = k
|
||||||
form.fields << Mechanize::FormContent::Field.new(node, v)
|
form.fields << Mechanize::FormContent::Field.new(node, v)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Mechanize
|
||||||
class Form
|
class Form
|
||||||
include ElementMatcher
|
include ElementMatcher
|
||||||
|
|
||||||
getter node : Node | Lexbor::Node
|
getter node : Mechanize::Node | Lexbor::Node
|
||||||
# returns hoge array of `Mechanize::FormContent::Field` in the form.
|
# returns hoge array of `Mechanize::FormContent::Field` in the form.
|
||||||
getter fields : Array(FormContent::Field)
|
getter fields : Array(FormContent::Field)
|
||||||
# returns an array of input tags whose type is checkbox in the form.
|
# returns an array of input tags whose type is checkbox in the form.
|
||||||
|
@ -35,7 +35,7 @@ class Mechanize
|
||||||
# returns the page which includes the form.
|
# returns the page which includes the form.
|
||||||
getter page : Page?
|
getter page : Page?
|
||||||
|
|
||||||
def initialize(node : Node | Lexbor::Node, page : Page? = nil)
|
def initialize(node : Mechanize::Node | Lexbor::Node, page : Page? = nil)
|
||||||
@enctype = node.fetch("enctype", "application/x-www-form-urlencoded")
|
@enctype = node.fetch("enctype", "application/x-www-form-urlencoded")
|
||||||
@node = node
|
@node = node
|
||||||
@fields = Array(FormContent::Field).new
|
@fields = Array(FormContent::Field).new
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
# This class represents button related html element.
|
# This class represents button related html element.
|
||||||
# <button>, and <input> whose type is button, reset, image, submit.
|
# <button>, and <input> whose type is button, reset, image, submit.
|
||||||
class Mechanize::FormContent::Button < Mechanize::FormContent::Field
|
class Mechanize::FormContent::Button < Mechanize::FormContent::Field
|
||||||
getter form_node : Node | Lexbor::Node
|
getter form_node : Mechanize::Node | Lexbor::Node
|
||||||
|
|
||||||
def initialize(node : Node | Lexbor::Node, form_node : Node | Lexbor::Node, value = nil)
|
def initialize(node : Mechanize::Node | Lexbor::Node, form_node : Mechanize::Node | Lexbor::Node, value = nil)
|
||||||
@form_node = form_node
|
@form_node = form_node
|
||||||
super(node, value)
|
super(node, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,9 +9,9 @@ class Mechanize::FormContent::Field
|
||||||
# returns field's 'value' attribute.
|
# returns field's 'value' attribute.
|
||||||
# value property is changeable, but this property stores raw value.
|
# value property is changeable, but this property stores raw value.
|
||||||
getter raw_value : String?
|
getter raw_value : String?
|
||||||
getter node : Node | Lexbor::Node
|
getter node : Mechanize::Node | Lexbor::Node
|
||||||
|
|
||||||
def initialize(node : Node | Lexbor::Node, value = nil)
|
def initialize(node : Mechanize::Node | Lexbor::Node, value = nil)
|
||||||
@node = node
|
@node = node
|
||||||
@name = node.fetch("name", "")
|
@name = node.fetch("name", "")
|
||||||
@value = value || node.fetch("value", nil)
|
@value = value || node.fetch("value", nil)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
|
class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
|
||||||
property :checked, :form
|
property :checked, :form
|
||||||
|
|
||||||
def initialize(node : Node | Lexbor::Node, form : Form)
|
def initialize(node : Mechanize::Node | Lexbor::Node, form : Form)
|
||||||
@checked = !!node.fetch("checked", nil)
|
@checked = !!node.fetch("checked", nil)
|
||||||
@form = form
|
@form = form
|
||||||
super(node)
|
super(node)
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
require "lexbor"
|
require "lexbor"
|
||||||
|
|
||||||
# This is a fake node used when sending post request.
|
class Mechanize
|
||||||
class Node < Hash(String, String)
|
# This is a fake node used when sending post request.
|
||||||
def css(str)
|
class Node < Hash(String, String)
|
||||||
[] of Hash(String, String)
|
def css(str)
|
||||||
end
|
[] of Hash(String, String)
|
||||||
|
end
|
||||||
|
|
||||||
def inner_text
|
def inner_text
|
||||||
""
|
""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is a real Node got from html.
|
# This is a real Node got from html.
|
||||||
|
# TODO: create PR to https://github.com/kostya/lexbor
|
||||||
struct Lexbor::Node
|
struct Lexbor::Node
|
||||||
delegate :[], to: attributes
|
delegate :[], to: attributes
|
||||||
delegate :[]=, to: attributes
|
delegate :[]=, to: attributes
|
||||||
|
|
Loading…
Reference in New Issue