class DownloadTV::TorrentAPI

TorrentAPI.org grabber Interfaces with torrentapi.org/apidocs_v2.txt

Constants

TOKEN_EXPIRED_ERROR
TOO_MANY_REQUESTS_ERROR

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/download_tv/grabbers/torrentapi.rb, line 11
def initialize
  super('https://torrentapi.org/pubapi_v2.php?'\
        'mode=search&search_string=%s&token=%s&'\
        'app_id=DownloadTV&sort=seeders')
  @wait = 0.5
  @token = nil
end

Public Instance Methods

online?() click to toggle source

Specific implementation for TorrentAPI (requires token)

# File lib/download_tv/grabbers/torrentapi.rb, line 21
def online?
  renew_token
  true
rescue Mechanize::ResponseCodeError => e
  if e.response_code == '429'
    sleep(@wait)
    retry
  end
  false
rescue Net::HTTP::Persistent::Error
  false
end
renew_token() click to toggle source

Connects to Torrentapi.org and requests a token, returning it Tokens automatically expire every 15 minutes

# File lib/download_tv/grabbers/torrentapi.rb, line 45
def renew_token
  obj = request_and_parse('https://torrentapi.org/pubapi_v2'\
                          '.php?get_token=get_token&app_id='\
                          'DownloadTV')

  @token = obj['token']
end
request_and_parse(url) click to toggle source

Makes a get request tp the given url. Returns the JSON response parsed into a hash

# File lib/download_tv/grabbers/torrentapi.rb, line 37
def request_and_parse(url)
  page = @agent.get(url).content
  JSON.parse(page)
end