Class: Saber::Tracker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/saber/tracker/base.rb

Direct Known Subclasses

BB, BIB, CHD, PTP, STP, What

Constant Summary collapse

DELEGATE_METHODS =
[:get]
POPULATE_TYPES =

implement

[]
BASE_URL =

implement

""
LOGIN_CHECK_PATH =
""

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



34
35
36
# File 'lib/saber/tracker/base.rb', line 34

def initialize
  @agent = Mechanize.new 
end

Class Attribute Details

.tracker_nameObject (readonly)

Returns the value of attribute tracker_name.



13
14
15
# File 'lib/saber/tracker/base.rb', line 13

def tracker_name
  @tracker_name
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



31
32
33
# File 'lib/saber/tracker/base.rb', line 31

def agent
  @agent
end

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/saber/tracker/base.rb', line 32

def name
  @name
end

Class Method Details

.can_populate?(type) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/saber/tracker/base.rb', line 23

def self.can_populate?(type)
  self::POPULATE_TYPES.include?(type.to_s)
end

.inherited(child) ⇒ Object



8
9
10
# File 'lib/saber/tracker/base.rb', line 8

def self.inherited(child)
  Tracker.trackers[child.name.demodulize.underscore] = child
end

Instance Method Details

#loginObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/saber/tracker/base.rb', line 42

def 
  @agent.get(self.class::BASE_URL)

  if 
    return
  end

  

  Saber.ui.say "Login succesfully."
end

#populate(type, *args) ⇒ Hash

Return data by auto-fill functions provied by site.

Examples:


populate("ebook", isbn)

Returns:



75
76
77
78
79
80
81
82
83
# File 'lib/saber/tracker/base.rb', line 75

def populate(type, *args)
  meth = "populate_#{type}"

  if respond_to?(meth) then
    send meth, *args
  else
    raise ArgumentError, "Not support this type -- #{type}"
  end
end

#upload(*torrent_files) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/saber/tracker/base.rb', line 54

def upload(*torrent_files)
  files = torrent_files.map{|v| Pa.delete_ext(v, ".torrent")}

  files.each {|file|
    info = Optimism.require!("./#{file}.yml")

    if do_upload(file, info)
      Saber.ui.say "Upload Complete: #{file}"
    else
      Saber.ui.error "Upload Failed: #{file}"
    end
  }
end