Class: RutrackerApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rutracker_api/client.rb

Constant Summary collapse

LOGIN_PAGE =
'https://rutracker.org/forum/login.php'.freeze
SEARCH_PAGE =
'https://rutracker.org/forum/tracker.php'.freeze
ORDER_OPTIONS =
{ date: 1, name: 2, downloads: 4, shows: 6, seeders: 10,
leechers: 11, size: 7, last_post: 8, speed_up: 12,
speed_down: 13, message_count: 5, last_seed: 9 }.freeze
SORT_OPTIONS =
{ asc: 1, desc: 2 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, pass) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
# File 'lib/rutracker_api/client.rb', line 18

def initialize(username, pass)
  @agent = Mechanize.new
  @agent.user_agent_alias = 'Mac Safari'
  (username, pass)
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



8
9
10
# File 'lib/rutracker_api/client.rb', line 8

def agent
  @agent
end

Instance Method Details

#search(options = {}) ⇒ Hash

Advance search throw rutracker

Parameters:

  • options (Hash) (defaults to: {})

    the format type, ‘:category`, `:term`, `:sort`, `:order_by`

Returns:

  • (Hash)

    the options keys with search result



28
29
30
31
32
# File 'lib/rutracker_api/client.rb', line 28

def search(options = {})
  query = prepare_query_string options
  @agent.get query
  parse_search
end