class Torckapi::Response::Scrape
Scrape
response
Attributes
data[R]
@return [Hash<String, Hash>] scrape data
Public Class Methods
from_http(data)
click to toggle source
Construct response object from http response data @param data [String] HTTP response data (bencoded) @return [Torckapi::Response::Scrape] response @raise [Torckapi::Tracker::MalformedResponseError]
# 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)
click to toggle source
Construct response object from udp response data @param info_hashes [Array<String>] list of 40-char hexadecimal strings @param data [String] UDP response data (omit action and transaction_id) @return [Torckapi::Response::Scrape] response @raise [Torckapi::Tracker::MalformedResponseError]
# 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
new(data)
click to toggle source
# File lib/torckapi/response/scrape.rb, line 43 def initialize data @data = data end
Private Class Methods
counts_translated(data)
click to toggle source
# File lib/torckapi/response/scrape.rb, line 35 def self.counts_translated data counts_with_block(data) { |data| data.values_at('complete', 'downloaded', 'incomplete') } end
counts_unpacked(data)
click to toggle source
# File lib/torckapi/response/scrape.rb, line 31 def self.counts_unpacked data counts_with_block(data) { |data| data.unpack('L>3').map(&:to_i) } end
counts_with_block(data, &block)
click to toggle source
# File lib/torckapi/response/scrape.rb, line 39 def self.counts_with_block data, &block Hash[[:seeders, :completed, :leechers].zip(yield data)] end