class Morito::Client

Public Class Methods

new(user_agent) click to toggle source
# File lib/morito/client.rb, line 5
def initialize(user_agent)
  @user_agent = user_agent
end

Public Instance Methods

allowed?(requesting_url, cache: true) click to toggle source
# File lib/morito/client.rb, line 9
def allowed?(requesting_url, cache: true)
  uri = URI.parse(requesting_url)
  robots_txt_body = robots_txt_body(uri, cache: cache)
  Morito::Processor.new(robots_txt_body).allowed?(@user_agent, path(uri))
end

Private Instance Methods

path(uri) click to toggle source
# File lib/morito/client.rb, line 17
def path(uri)
  if uri.query
    "#{uri.path}?#{uri.query}"
  else
    uri.path
  end
end
robots_txt_body(uri, cache: true) click to toggle source
# File lib/morito/client.rb, line 25
def robots_txt_body(uri, cache: true)
  if cache
    with_cache(uri.host) do
      robots_txt_body_without_cache(uri)
    end
  else
    robots_txt_body_without_cache(uri)
  end
end
robots_txt_body_without_cache(uri) click to toggle source
# File lib/morito/client.rb, line 35
def robots_txt_body_without_cache(uri)
  Morito::Connector.new(uri).get
end
with_cache(host) { || ... } click to toggle source
# File lib/morito/client.rb, line 39
def with_cache(host, &block)
  @cache ||= {}
  @cache[host] ||= yield
end