add checkbox
parent
da90024a96
commit
5429d89683
|
@ -1,5 +1,6 @@
|
||||||
require "./mechanize/http/agent"
|
require "./mechanize/http/agent"
|
||||||
require "./mechanize/form"
|
require "./mechanize/form"
|
||||||
|
require "./mechanize/node"
|
||||||
|
|
||||||
class Mechanize
|
class Mechanize
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
|
@ -18,7 +19,7 @@ class Mechanize
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(uri : String | URI, headers = HTTP::Headers.new, query : Hash(String, String | Array(String)) = Hash(String,String).new)
|
def post(uri : String | URI, headers = HTTP::Headers.new, query : Hash(String, String | Array(String)) = Hash(String,String).new)
|
||||||
node = Hash(String, String).new
|
node = Node.new(fake: true)
|
||||||
node["method"] = "POST"
|
node["method"] = "POST"
|
||||||
node["enctype"] = "application/x-www-form-urlencoded"
|
node["enctype"] = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
require "./form/field"
|
require "./form/field"
|
||||||
|
require "./form/check_box"
|
||||||
|
|
||||||
class MechanizeCr::Form
|
class MechanizeCr::Form
|
||||||
getter fields : Array(MechanizeCr::FormContent::Field)
|
getter fields : Array(MechanizeCr::FormContent::Field)
|
||||||
|
getter checkboxes : Array(MechanizeCr::FormContent::CheckBox)
|
||||||
|
|
||||||
def initialize(node : Hash(String, String))
|
def initialize(node : Node)
|
||||||
@enctype = node["enctype"] || "application/x-www-form-urlencoded"
|
@enctype = node["enctype"] || "application/x-www-form-urlencoded"
|
||||||
@node = node
|
@node = node
|
||||||
@fields = Array(MechanizeCr::FormContent::Field).new
|
@fields = Array(MechanizeCr::FormContent::Field).new
|
||||||
|
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||||
#@action = Mechanize::Util.html_unescape(node['action'])
|
#@action = Mechanize::Util.html_unescape(node['action'])
|
||||||
#@method = (node['method'] || 'GET').upcase
|
#@method = (node['method'] || 'GET').upcase
|
||||||
#@name = node['name']
|
#@name = node['name']
|
||||||
|
@ -15,6 +19,31 @@ class MechanizeCr::Form
|
||||||
#
|
#
|
||||||
#@encoding = node['accept-charset'] || (page && page.encoding) || nil
|
#@encoding = node['accept-charset'] || (page && page.encoding) || nil
|
||||||
#@ignore_encoding_error = false
|
#@ignore_encoding_error = false
|
||||||
#parse
|
parse
|
||||||
|
request_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def request_data
|
||||||
|
query_params = build_query
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_query()
|
||||||
|
query = [] of String
|
||||||
|
successful_controls = Array(MechanizeCr::FormContent::Field | MechanizeCr::FormContent::CheckBox).new
|
||||||
|
fields.each do |elm|
|
||||||
|
successful_controls.push(elm)
|
||||||
|
end
|
||||||
|
checkboxes.each do |elm|
|
||||||
|
if elm.checked
|
||||||
|
successful_controls << elm
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse
|
||||||
|
@fields = Array(MechanizeCr::FormContent::Field).new
|
||||||
|
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||||
|
@node.search("input").not_nil!.each do |node|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
||||||
|
property :checked
|
||||||
|
property :form
|
||||||
|
|
||||||
|
def initialize(node : Node, value : String = node["value"])
|
||||||
|
@checked = !!node["checked"]
|
||||||
|
@form = form
|
||||||
|
super(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check
|
||||||
|
#uncheck_peers
|
||||||
|
@checked = true
|
||||||
|
end
|
||||||
|
|
||||||
|
def uncheck
|
||||||
|
@checked = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def checked?
|
||||||
|
checked
|
||||||
|
end
|
||||||
|
|
||||||
|
def click
|
||||||
|
checked ? uncheck : check
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Node < Hash(String,String)
|
||||||
|
property fake : Bool
|
||||||
|
def initialize(fake = false)
|
||||||
|
@fake = fake
|
||||||
|
super()
|
||||||
|
end
|
||||||
|
|
||||||
|
def search(str)
|
||||||
|
if fake
|
||||||
|
[] of Hash(String,String)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue