torckapi 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/torckapi/errors.rb +1 -3
- data/lib/torckapi/response/announce.rb +0 -4
- data/lib/torckapi/response/error.rb +0 -2
- data/lib/torckapi/response/scrape.rb +1 -3
- data/lib/torckapi/tracker/udp.rb +12 -11
- data/lib/torckapi/version.rb +1 -1
- data/lib/torckapi.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af443d831abf10bd6fbedf125e88dc362488fa49
|
4
|
+
data.tar.gz: de96aca388dc814092a9d8a7a20e75c7569f1d06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f3202afa722b9ee81318bd7bb6f4bca4b3d15e6421ceacd2265b2ea542cfd634a4c5d1ec34e4689bd5dbd21ef82277aea6f16fcbab389e584467e5e38c2fe98
|
7
|
+
data.tar.gz: 908c4d75b6966cec35789dbd45f0db581dcc92d72ff23bec8fdaf58651089542a63abed32eca39f60d9a672b1c8eccd379fab637f48d98e80fe8abb09bebf881
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Torckapi — torrent tracker querying API
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/torckapi)
|
4
|
+
[](https://codeclimate.com/github/krupenik/torckapi)
|
5
|
+
[](https://gemnasium.com/krupenik/torckapi)
|
6
|
+
|
3
7
|
## Description
|
4
8
|
|
5
9
|
Torckapi is a querying interface to torrent trackers.
|
data/lib/torckapi/errors.rb
CHANGED
@@ -7,10 +7,8 @@ module Torckapi
|
|
7
7
|
class InvalidSchemeError < Error; end
|
8
8
|
class ConnectionFailedError < Error; end
|
9
9
|
class CommunicationError < Error; end
|
10
|
-
class CommunicationTimeoutError < CommunicationError; end
|
11
10
|
class CommunicationFailedError < CommunicationError; end
|
12
|
-
class
|
13
|
-
class ScrapeFailedError < CommunicationFailedError; end
|
11
|
+
class CommunicationTimeoutError < CommunicationError; end
|
14
12
|
end
|
15
13
|
|
16
14
|
module Response
|
@@ -19,8 +19,6 @@ module Torckapi
|
|
19
19
|
# @param data [String] UDP response data (omit action and transaction_id)
|
20
20
|
# @return [Torckapi::Response::Announce] response
|
21
21
|
def self.from_udp info_hash, data
|
22
|
-
raise ArgumentError, "info_hash cannot be nil" if info_hash.nil?
|
23
|
-
raise ArgumentError, "data cannot be nil" if data.nil?
|
24
22
|
new info_hash, *data[4..11].unpack('L>2'), peers_from_compact(data[12..-1] || '')
|
25
23
|
end
|
26
24
|
|
@@ -30,8 +28,6 @@ module Torckapi
|
|
30
28
|
# @param compact [true, false] is peer data in compact format?
|
31
29
|
# @return [Torckapi::Response::Announce] response
|
32
30
|
def self.from_http info_hash, data, compact=true
|
33
|
-
raise ArgumentError, "info_hash cannot be nil" if info_hash.nil?
|
34
|
-
raise ArgumentError, "data cannot be nil" if data.nil?
|
35
31
|
bdecoded_data = BEncode.load(data)
|
36
32
|
new info_hash, *bdecoded_data.values_at("incomplete", "complete"), peers_from_compact(bdecoded_data["peers"])
|
37
33
|
end
|
@@ -14,8 +14,6 @@ module Torckapi
|
|
14
14
|
# @param data [String] UDP response data (omit action and transaction_id)
|
15
15
|
# @return [Torckapi::Response::Error] response
|
16
16
|
def self.from_udp info_hashes, data
|
17
|
-
raise ArgumentError, "info_hashes cannot be nil" if info_hashes.nil?
|
18
|
-
raise ArgumentError, "data cannot be nil" if data.nil?
|
19
17
|
new info_hashes, data
|
20
18
|
end
|
21
19
|
|
@@ -11,9 +11,7 @@ module Torckapi
|
|
11
11
|
# @param data [String] UDP response data (omit action and transaction_id)
|
12
12
|
# @return [Torckapi::Response::Scrape] response
|
13
13
|
def self.from_udp info_hashes, data
|
14
|
-
raise ArgumentError, "
|
15
|
-
raise ArgumentError, "data cannot be nil" if data.nil?
|
16
|
-
raise ArgumentError, "data size invalid" if data.length != info_hashes.count * 12
|
14
|
+
raise ArgumentError, "data does not match info_hashes" if data.length != info_hashes.count * 12
|
17
15
|
new Hash[info_hashes.zip(data.unpack('a12' * info_hashes.count).map { |i| Hash[[:seeders, :completed, :leechers].zip i.unpack('L>3').map(&:to_i)] })]
|
18
16
|
end
|
19
17
|
|
data/lib/torckapi/tracker/udp.rb
CHANGED
@@ -10,6 +10,15 @@ module Torckapi
|
|
10
10
|
class UDP < Base
|
11
11
|
CONNECTION_TIMEOUT = 60
|
12
12
|
|
13
|
+
# index = action (connect, announce, scrape, error)
|
14
|
+
# [response class, minimum response length]
|
15
|
+
RESPONSES = [
|
16
|
+
[nil, 16],
|
17
|
+
[Torckapi::Response::Announce, 20],
|
18
|
+
[Torckapi::Response::Scrape, 8],
|
19
|
+
[Torckapi::Response::Error, 8]
|
20
|
+
].freeze
|
21
|
+
|
13
22
|
# (see Base#announce)
|
14
23
|
def announce info_hash
|
15
24
|
super info_hash
|
@@ -29,19 +38,11 @@ module Torckapi
|
|
29
38
|
response = communicate action, data
|
30
39
|
|
31
40
|
raise CommunicationFailedError if response.nil?
|
41
|
+
action = response[0][0..3].unpack('L>')[0]
|
42
|
+
raise CommunicationFailedError if RESPONSES[action][1] > response[0].length
|
32
43
|
|
33
44
|
begin
|
34
|
-
|
35
|
-
when 1
|
36
|
-
raise AnnounceFailedError if 20 > response[0].length
|
37
|
-
Torckapi::Response::Announce.from_udp(*args, response[0][8..-1])
|
38
|
-
when 2
|
39
|
-
raise ScrapeFailedError if 8 > response[0].length
|
40
|
-
Torckapi::Response::Scrape.from_udp(*args, response[0][8..-1])
|
41
|
-
when 3
|
42
|
-
raise CommunicationFailedError if 8 > response[0].length
|
43
|
-
Torckapi::Response::Error.from_udp(*args, response[0][8..-1])
|
44
|
-
end
|
45
|
+
RESPONSES[action][0].from_udp(*args, response[0][8..-1])
|
45
46
|
rescue Torckapi::Response::ArgumentError => e
|
46
47
|
$stderr.puts "Error: #{e.inspect}"
|
47
48
|
$stderr.puts "Response: #{response.inspect}"
|
data/lib/torckapi/version.rb
CHANGED
data/lib/torckapi.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'uri'
|
2
2
|
require 'torckapi/version'
|
3
3
|
require 'torckapi/errors'
|
4
|
-
require 'torckapi/tracker/http'
|
5
|
-
require 'torckapi/tracker/udp'
|
6
4
|
require 'torckapi/response/announce'
|
7
5
|
require 'torckapi/response/error'
|
8
6
|
require 'torckapi/response/scrape'
|
7
|
+
require 'torckapi/tracker/http'
|
8
|
+
require 'torckapi/tracker/udp'
|
9
9
|
|
10
10
|
module Torckapi
|
11
11
|
# Creates a tracker interface instance
|