Class: Saber::Tracker::What

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

Overview

DON’T WORK for mechanize does not support javascript.

Constant Summary collapse

BASE_URL =
"https://what.cd"
LOGIN_CHECK_PATH =
"/inbox.php"
FIELDS =
{ 
  "E-Books" => { 
    "file_input" => :file_upload,
    "type" => :select_list,
    "title" => :text,
    "tags" => :text,
    "image" => :text,
    "desc" => :text
  }
}

Constants inherited from Base

Base::DELEGATE_METHODS, Base::POPULATE_TYPES

Instance Attribute Summary

Attributes inherited from Base

#agent, #name

Instance Method Summary collapse

Methods inherited from Base

can_populate?, inherited, #initialize, #login, #populate, #upload

Constructor Details

This class inherits a constructor from Saber::Tracker::Base

Instance Method Details

#do_upload(file, info) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/saber/tracker/what.rb', line 19

def do_upload(file, info)
  info["file_input"] = "#{file}.torrent"
  path = info["group_id"] ? "/upload.php?group_id=#{info['group_id']}" : "/upload.php"

  agent.get(path) {|p|
    ret = p.form_with(action: "") {|f|
      FIELDS[info.type].each {|k,t|
        f.set(t, k, info[k])
      }
    }.submit

    # error
    if ret.uri.path =~ %r~^/upload.php~
      msg = ReverseMarkdown.parse(ret.at("//*[@id='content']/div[2]/p[2]"))
      Saber.ui.error "ERROR:\n#{msg}"
      return false
    else
      return true
    end
  }
end