add comment

master
Kanezoh 2021-10-10 08:57:47 +09:00
parent 8a78fce180
commit 396af4c28b
1 changed files with 14 additions and 4 deletions

View File

@ -29,14 +29,14 @@ require "./mechanize/errors/*"
class Mechanize class Mechanize
VERSION = "0.2.0" VERSION = "0.2.0"
AGENT = { USER_AGENT = {
"Mechanize" => "Mechanize/#{VERSION} Crystal/#{Crystal::VERSION} (https://github.com/Kanezoh/mechanize.cr)", "Mechanize" => "Mechanize/#{VERSION} Crystal/#{Crystal::VERSION} (https://github.com/Kanezoh/mechanize.cr)",
} }
def initialize def initialize
@agent = MechanizeCr::HTTP::Agent.new @agent = MechanizeCr::HTTP::Agent.new
@agent.context = self @agent.context = self
@agent.user_agent = AGENT["Mechanize"] @agent.user_agent = USER_AGENT["Mechanize"]
end end
def get(uri : String | URI, def get(uri : String | URI,
@ -125,17 +125,27 @@ class Mechanize
@agent.history @agent.history
end end
# add page to history(MechanizeCr::History).
# if you send request, mechanize calls this method and records page,
# so you don't need to call this on your own.
def add_to_history(page) def add_to_history(page)
history.push(page) history.push(page)
end end
# Get maximum number of items allowed in the history. # Get maximum number of pages allowed in the history.
# The default setting is 100 pages. # The default setting is 100 pages.
# ```
# agent.max_history # => 100
# ```
def max_history def max_history
history.max_size history.max_size
end end
# Set maximum number of items allowed in the history. # Set maximum number of pages allowed in the history.
# The default setting is 100 pages.
# ```
# agent.max_history = 150
# ```
def max_history=(length) def max_history=(length)
history.max_size = length history.max_size = length
end end