Class: Torckapi::Tracker::Base

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

Overview

Public interface for torrent trackers

Direct Known Subclasses

HTTP, UDP

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/torckapi/tracker/base.rb', line 6

def url
  @url
end

Instance Method Details

#announce(info_hash, peer_id = SecureRandom.random_bytes(20)) ⇒ Torckapi::Response::Announce

Announce request

Parameters:

  • info_hash (String)

    40-char hexadecimal string

  • peer_id (String) (defaults to: SecureRandom.random_bytes(20))

    20-byte binary string

Returns:

Raises:



15
16
17
# File 'lib/torckapi/tracker/base.rb', line 15

def announce info_hash, peer_id=SecureRandom.random_bytes(20)
  raise Torckapi::InvalidInfohashError if info_hash !~ /\A[0-9a-f]{40}\z/i
end

#scrape(info_hashes = []) ⇒ Torckapi::Response::Scrape

Scrape request

Parameters:

  • info_hashes (Array<String>) (defaults to: [])

    An array of 40-char hexadecimal strings

Returns:

Raises:



25
26
27
# File 'lib/torckapi/tracker/base.rb', line 25

def scrape info_hashes=[]
  raise Torckapi::InvalidInfohashError if info_hashes.any? { |i| i !~ /\A[0-9a-f]{40}\z/i }
end