delete unnnecessary namespace
parent
eec62fade2
commit
83f390bd2a
|
@ -2,8 +2,8 @@ require "./form/field"
|
||||||
require "./form/check_box"
|
require "./form/check_box"
|
||||||
|
|
||||||
class MechanizeCr::Form
|
class MechanizeCr::Form
|
||||||
getter fields : Array(MechanizeCr::FormContent::Field)
|
getter fields : Array(FormContent::Field)
|
||||||
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
getter checkboxes : Array(FormContent::CheckBox)
|
||||||
getter enctype : String
|
getter enctype : String
|
||||||
getter method : String
|
getter method : String
|
||||||
getter name : String
|
getter name : String
|
||||||
|
@ -12,8 +12,8 @@ class MechanizeCr::Form
|
||||||
def initialize(node : Node | Myhtml::Node)
|
def initialize(node : Node | Myhtml::Node)
|
||||||
@enctype = node.fetch("enctype", "application/x-www-form-urlencoded")
|
@enctype = node.fetch("enctype", "application/x-www-form-urlencoded")
|
||||||
@node = node
|
@node = node
|
||||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
@fields = Array(FormContent::Field).new
|
||||||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
@checkboxes = Array(FormContent::CheckBox).new
|
||||||
@action = node.fetch("action", "")
|
@action = node.fetch("action", "")
|
||||||
@method = node.fetch("method", "GET").upcase
|
@method = node.fetch("method", "GET").upcase
|
||||||
@name = node.fetch("name", "")
|
@name = node.fetch("name", "")
|
||||||
|
@ -49,21 +49,21 @@ class MechanizeCr::Form
|
||||||
|
|
||||||
def field_with(criteria)
|
def field_with(criteria)
|
||||||
f = fields_with(criteria)
|
f = fields_with(criteria)
|
||||||
raise MechanizeCr::ElementNotFoundError.new(:field, criteria) if f.nil?
|
raise ElementNotFoundError.new(:field, criteria) if f.nil?
|
||||||
f.first
|
f.first
|
||||||
end
|
end
|
||||||
|
|
||||||
private def parse
|
private def parse
|
||||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
@fields = Array(FormContent::Field).new
|
||||||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
@checkboxes = Array(FormContent::CheckBox).new
|
||||||
@node.css("input").not_nil!.each do |html_node|
|
@node.css("input").not_nil!.each do |html_node|
|
||||||
html_node = html_node.as(Myhtml::Node)
|
html_node = html_node.as(Myhtml::Node)
|
||||||
type = (html_node["type"] || "text").downcase
|
type = (html_node["type"] || "text").downcase
|
||||||
case type
|
case type
|
||||||
when "checkbox"
|
when "checkbox"
|
||||||
@checkboxes << MechanizeCr::FormContent::CheckBox.new(html_node, self)
|
@checkboxes << FormContent::CheckBox.new(html_node, self)
|
||||||
else
|
else
|
||||||
@fields << MechanizeCr::FormContent::Field.new(html_node)
|
@fields << FormContent::Field.new(html_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -77,7 +77,7 @@ class MechanizeCr::Form
|
||||||
|
|
||||||
private def build_query
|
private def build_query
|
||||||
query = [] of Array(String)
|
query = [] of Array(String)
|
||||||
successful_controls = Array(MechanizeCr::FormContent::Field | MechanizeCr::FormContent::CheckBox).new
|
successful_controls = Array(FormContent::Field | FormContent::CheckBox).new
|
||||||
fields.each do |elm|
|
fields.each do |elm|
|
||||||
successful_controls << elm
|
successful_controls << elm
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
||||||
property :checked, :form
|
property :checked, :form
|
||||||
|
|
||||||
def initialize(node : Node | Myhtml::Node, form : MechanizeCr::Form)
|
def initialize(node : Node | Myhtml::Node, form : Form)
|
||||||
@checked = !!node["checked"]
|
@checked = !!node["checked"]
|
||||||
@form = form
|
@form = form
|
||||||
super(node)
|
super(node)
|
||||||
|
|
|
@ -5,9 +5,9 @@ module MechanizeCr
|
||||||
module HTTP
|
module HTTP
|
||||||
class Agent
|
class Agent
|
||||||
property :request_headers, :context, :cookies
|
property :request_headers, :context, :cookies
|
||||||
property history : Array(MechanizeCr::Page)
|
property history : Array(Page)
|
||||||
def initialize(@context : Mechanize | Nil = nil)
|
def initialize(@context : Mechanize | Nil = nil)
|
||||||
@history = Array(MechanizeCr::Page).new
|
@history = Array(Page).new
|
||||||
@request_headers = ::HTTP::Headers.new
|
@request_headers = ::HTTP::Headers.new
|
||||||
@context = context
|
@context = context
|
||||||
@cookies = Hash(String, ::HTTP::Cookies).new
|
@cookies = Hash(String, ::HTTP::Cookies).new
|
||||||
|
|
|
@ -22,7 +22,7 @@ class MechanizeCr::Page < MechanizeCr::File
|
||||||
|
|
||||||
def forms
|
def forms
|
||||||
forms = css("form").map do |html_form|
|
forms = css("form").map do |html_form|
|
||||||
form = MechanizeCr::Form.new(html_form)
|
form = Form.new(html_form)
|
||||||
form.action ||= @uri.to_s
|
form.action ||= @uri.to_s
|
||||||
form
|
form
|
||||||
end.to_a
|
end.to_a
|
||||||
|
|
Loading…
Reference in New Issue