class TTWatcher::Sites::Site

Attributes

connection[R]

@return [TTWatcher::Connection]

name[R]

@return [Symbol]

Site name (autogenerated, depends from class name).

Public Class Methods

new() click to toggle source

Creates new Site object.

@return [Site]

# File sources/ttwatcher/sites/site.rb, line 33
def initialize
  @name = H::class_name self
  @connection = Connection.new self
end

Public Instance Methods

address(path='') click to toggle source

Generates an url that includes scheme + domain name + path (optional)

example: input ==> @domain_name = “some.site.com”, path = 'hello/world'

output ==> "http://some.site.com/hello/world"

if path not selected it returns scheme + +@domain_name+

# File sources/ttwatcher/sites/site.rb, line 46
def address(path='')
  scheme = connection.url.scheme
  if !path.empty? && domain_name_included?(path)
    InternetConnection::Scheme.add_scheme!(path, scheme)
  else
    hn = domain_name.dup # prevent unnecessary +domain_name+ mutation
    InternetConnection::Scheme.add_scheme!(hn, scheme)
    path = '/' + path unless path[0] == '/'
    hn + path
  end
end
domain_name() click to toggle source

@return [String]

Returns full domain name.
# File sources/ttwatcher/sites/site.rb, line 19
def domain_name
  @domain_name ||=
    if S[name][:domain_name]
      S[name][:domain_name]
    else
      raise DomainNameNotFound, self
    end
end
download_page(url, request_params = {}) click to toggle source

@param [String] url

@param [Hash] request_params

@return [String, NilClass]

# File sources/ttwatcher/sites/site.rb, line 64
def download_page(url, request_params = {})
  url = address(url) unless domain_name_included? url
  page = connection.download url, request_params

  return page
end

Private Instance Methods

domain_name_included?(url) click to toggle source

@param [String] url

Url or an url part.

@return [TrueClass, FalseClass]

+true+ when url includes domain name
+false+ otherwise.
# File sources/ttwatcher/sites/site.rb, line 80
def domain_name_included?(url)
  url[domain_name.to_s]
end