diff --git a/src/mechanize/cookie.cr b/src/mechanize/cookie.cr index 0b3e44d..3c8c6aa 100644 --- a/src/mechanize/cookie.cr +++ b/src/mechanize/cookie.cr @@ -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, diff --git a/src/mechanize/errors/element_not_found_error.cr b/src/mechanize/errors/element_not_found_error.cr index fd35a4a..7456b35 100644 --- a/src/mechanize/errors/element_not_found_error.cr +++ b/src/mechanize/errors/element_not_found_error.cr @@ -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 diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index f546ff9..86f9236 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -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 diff --git a/src/mechanize/page/link.cr b/src/mechanize/page/link.cr index 1ecab2e..2267f64 100644 --- a/src/mechanize/page/link.cr +++ b/src/mechanize/page/link.cr @@ -1,3 +1,5 @@ +# This class represents link element like and . +# The instance of this class is clickable. class Mechanize::PageContent::Link getter node : Lexbor::Node getter page : Mechanize::Page diff --git a/src/mechanize/utils/element_matcher.cr b/src/mechanize/utils/element_matcher.cr index 4acd692..a653125 100644 --- a/src/mechanize/utils/element_matcher.cr +++ b/src/mechanize/utils/element_matcher.cr @@ -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? %}