add comment to other classes

master
Kanezoh 2021-11-18 11:45:30 +09:00
parent 794a2085de
commit 2c26835252
5 changed files with 32 additions and 7 deletions

View File

@ -1,5 +1,6 @@
# TODO: want to add methods with safe way like Ruby's refinement.
# TODO: want to property's without open HTTP::Cookie class.
# This class represents http cookie.
# open HTTP::Cookie class to add origin property.
# origin property represents the origin of the resource.
# if cookie's domain attribute isn't designated,

View File

@ -1,5 +1,6 @@
require "./base_error"
# This error means matched elements are not found by *_with method.
class Mechanize::ElementNotFoundError < Mechanize::Error
getter element : Symbol
getter conditions : String

View File

@ -6,12 +6,13 @@ require "../history"
class Mechanize
module HTTP
class Agent
property :request_headers, :context
property request_headers : ::HTTP::Headers
property context : Mechanize?
property history : Mechanize::History
property user_agent : String
property request_cookies : ::HTTP::Cookies
def initialize(@context : Mechanize | Nil = nil)
def initialize(@context : Mechanize? = nil)
@history = Mechanize::History.new
@request_headers = ::HTTP::Headers.new
@context = context
@ -19,6 +20,9 @@ class Mechanize
@user_agent = ""
end
# send http request and return page.
# This method is called from Mechanize#get, #post and other methods.
# There's no need to call this method directly.
def fetch(uri, method = :get, headers = ::HTTP::Headers.new, params = Hash(String, String).new,
referer = (current_page unless history.empty?))
uri = resolve_url(uri, referer)
@ -51,7 +55,8 @@ class Mechanize
fetch(uri)
end
def http_request(uri, method, params)
# send http request
private def http_request(uri, method, params) : ::HTTP::Client::Response?
case uri.scheme.not_nil!.downcase
when "http", "https"
case method
@ -63,20 +68,34 @@ class Mechanize
end
end
def current_page
# returns the page now mechanize visiting.
# ```
# agent.current_page
# ```
def current_page : Mechanize::Page
@history.last
end
def back
# returns the page mechanize previous visited.
# ```
# agent.back
# ```
def back : Mechanize::Page
@history.pop
end
# Get maximum number of items allowed in the history. The default setting is 100 pages.
def max_history
# ```
# agent.max_history # => 100
# ```
def max_history : Int32
@history.max_size
end
# Set maximum number of items allowed in the history.
# ```
# agent.max_history = 1000
# ```
def max_history=(length)
@history.max_size = length
end

View File

@ -1,3 +1,5 @@
# This class represents link element like <a> and <area>.
# The instance of this class is clickable.
class Mechanize::PageContent::Link
getter node : Lexbor::Node
getter page : Mechanize::Page

View File

@ -1,4 +1,6 @@
class Mechanize
# This module is for macros making *_with methods.
# These methods are useful for searching elements by its' attribute.
module ElementMatcher
macro elements_with(singular, plural = "")
{% plural = "#{singular.id}s" if plural.empty? %}