Class: Torckapi::Response::Scrape

Inherits:
Base
  • Object
show all
Defined in:
lib/torckapi/response/scrape.rb

Overview

Scrape response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#dataHash<String, Hash> (readonly)

Returns scrape data.

Returns:

  • (Hash<String, Hash>)

    scrape data



8
9
10
# File 'lib/torckapi/response/scrape.rb', line 8

def data
  @data
end

Class Method Details

.from_http(data) ⇒ Torckapi::Response::Scrape

Construct response object from http response data

Parameters:

  • data (String)

    HTTP response data (bencoded)

Returns:

Raises:



24
25
26
27
# File 'lib/torckapi/response/scrape.rb', line 24

def self.from_http data
  bdecoded_data = bdecode_and_check data, 'files'
  new Hash[bdecoded_data['files'].map { |info_hash, counts| [info_hash.unpack('H*').join, counts_translated(counts) ]}]
end

.from_udp(info_hashes, data) ⇒ Torckapi::Response::Scrape

Construct response object from udp response data

Parameters:

  • info_hashes (Array<String>)

    list of 40-char hexadecimal strings

  • data (String)

    UDP response data (omit action and transaction_id)

Returns:

Raises:



15
16
17
18
# File 'lib/torckapi/response/scrape.rb', line 15

def self.from_udp info_hashes, data
  raise Torckapi::Tracker::MalformedResponseError if data.length != info_hashes.count * 12
  new Hash[info_hashes.zip(data.unpack('a12' * info_hashes.count).map { |i| counts_unpacked(i) })]
end