Class: Saber::Tracker::Base
- Inherits:
-
Object
- Object
- Saber::Tracker::Base
- Defined in:
- lib/saber/tracker/base.rb
Constant Summary collapse
- DELEGATE_METHODS =
[:get]
- POPULATE_TYPES =
implement
[]
- BASE_URL =
implement
""
- LOGIN_CHECK_PATH =
""
Class Attribute Summary collapse
-
.tracker_name ⇒ Object
readonly
Returns the value of attribute tracker_name.
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #login ⇒ Object
-
#populate(type, *args) ⇒ Hash
Return data by auto-fill functions provied by site.
- #upload(*torrent_files) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
35 36 37 38 |
# File 'lib/saber/tracker/base.rb', line 35 def initialize(={}) @options = @agent = Mechanize.new end |
Class Attribute Details
.tracker_name ⇒ Object (readonly)
Returns the value of attribute tracker_name.
15 16 17 |
# File 'lib/saber/tracker/base.rb', line 15 def tracker_name @tracker_name end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
33 34 35 |
# File 'lib/saber/tracker/base.rb', line 33 def agent @agent end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/saber/tracker/base.rb', line 33 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
33 34 35 |
# File 'lib/saber/tracker/base.rb', line 33 def @options end |
Class Method Details
.can_populate?(type) ⇒ Boolean
25 26 27 |
# File 'lib/saber/tracker/base.rb', line 25 def self.can_populate?(type) self::POPULATE_TYPES.include?(type.to_s) end |
Instance Method Details
#login ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/saber/tracker/base.rb', line 44 def login @agent.get(self.class::BASE_URL) if return end login_with_username Saber.ui.say "Login succesfully." end |
#populate(type, *args) ⇒ Hash
Return data by auto-fill functions provied by site.
77 78 79 80 81 82 83 84 85 |
# File 'lib/saber/tracker/base.rb', line 77 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
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/saber/tracker/base.rb', line 56 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 |