Class: DownloadTV::LinkGrabber

Inherits:
Object
  • Object
show all
Defined in:
lib/download_tv/linkgrabber.rb

Overview

Interface for the grabbers

Direct Known Subclasses

Addic7ed, Eztv, KAT, ThePirateBay, TorrentAPI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ LinkGrabber

Returns a new instance of LinkGrabber.



9
10
11
12
13
# File 'lib/download_tv/linkgrabber.rb', line 9

def initialize(url)
  @url = url
  @agent = Mechanize.new
  @agent.user_agent = DownloadTV::USER_AGENT
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/download_tv/linkgrabber.rb', line 7

def url
  @url
end

Instance Method Details

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/download_tv/linkgrabber.rb', line 28

def get_links(_show)
  raise NotImplementedError
end

#online?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/download_tv/linkgrabber.rb', line 15

def online?
  @agent.read_timeout = 2
  url = if @url.include? '%s'
          format(@url, 'test')
        else
          @url
        end
  @agent.head(url)
  true
rescue Mechanize::ResponseCodeError, Net::HTTP::Persistent::Error, Errno::ECONNRESET
  false
end