Class: Torrenter::Tracker::HTTPTracker

Inherits:
Torrenter::Tracker show all
Defined in:
lib/torrenter/tracker/http_tracker.rb

Instance Attribute Summary collapse

Attributes inherited from Torrenter::Tracker

#address

Instance Method Summary collapse

Methods inherited from Torrenter::Tracker

#format_peers

Constructor Details

#initialize(url, params) ⇒ HTTPTracker

Returns a new instance of HTTPTracker.



8
9
10
11
# File 'lib/torrenter/tracker/http_tracker.rb', line 8

def initialize(url, params)
  @address = URI(url)
  @params  = params
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/torrenter/tracker/http_tracker.rb', line 7

def response
  @response
end

Instance Method Details

#connectObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/torrenter/tracker/http_tracker.rb', line 13

def connect
  @address.query = URI.encode_www_form(@params)
  begin
    @response = BEncode.load(Net::HTTP.get(@address))
  rescue Exception => e
    false
  end

  return self
end

#connect_intervalObject



28
29
30
# File 'lib/torrenter/tracker/http_tracker.rb', line 28

def connect_interval
  @response['min interval']
end

#connected?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/torrenter/tracker/http_tracker.rb', line 36

def connected?
  @response
end

#peer_listObject



24
25
26
# File 'lib/torrenter/tracker/http_tracker.rb', line 24

def peer_list
  format_peers(peers)
end

#peersObject



32
33
34
# File 'lib/torrenter/tracker/http_tracker.rb', line 32

def peers
  @response['peers']
end