torckapi 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torckapi/errors.rb +5 -0
- data/lib/torckapi/response/announce.rb +2 -0
- data/lib/torckapi/response/error.rb +13 -5
- data/lib/torckapi/response/scrape.rb +2 -0
- data/lib/torckapi/tracker/udp.rb +13 -7
- data/lib/torckapi/version.rb +1 -1
- 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: 2c9a7381eb1ab2a6327c590e2f536e6c37e57b08
|
4
|
+
data.tar.gz: 8b3eb6f625736f2189f9c1a62f0185d04bcfeb9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2b7de86de6fdd7b2041616b9b781f5a2cf74505cf6a9a1690844d409b6bc377afe8dab0053948ded9cbe73e4caaedfb4f9ff323b6b9f1b7e2b66d1e75abbfe9
|
7
|
+
data.tar.gz: 92faf338aa7741f54996764877c35da4f8f6910b5904cae16155e503c2a69e50b56fc8baf3365f6c520ef411f231fbf5843170aaf6d8ba0d732b27fd87eaf835
|
data/lib/torckapi/errors.rb
CHANGED
@@ -19,6 +19,8 @@ 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?
|
22
24
|
new info_hash, *data[4..11].unpack('L>2'), peers_from_compact(data[12..-1])
|
23
25
|
end
|
24
26
|
|
@@ -3,22 +3,30 @@ module Torckapi
|
|
3
3
|
class Error
|
4
4
|
# @!attribute [r] info_hash
|
5
5
|
# @return [String] 40-char hexadecimal string
|
6
|
+
# @!attribute [r] info_hashes
|
7
|
+
# @return [Array<String>] an array of 40-char hexadecimal strings
|
6
8
|
# @!attribute [r] message
|
7
9
|
# @return [String] error description
|
8
|
-
attr_reader :info_hash, :message
|
10
|
+
attr_reader :info_hash, :info_hashes, :message
|
9
11
|
|
10
12
|
# Construct response object from udp response data
|
11
13
|
# @param info_hash [String] 40-char hexadecimal string
|
12
14
|
# @param data [String] UDP response data (omit action and transaction_id)
|
13
15
|
# @return [Torckapi::Response::Error] response
|
14
|
-
def self.from_udp
|
15
|
-
|
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
|
+
new info_hashes, data
|
20
|
+
end
|
21
|
+
|
22
|
+
def info_hash
|
23
|
+
info_hashes[0]
|
16
24
|
end
|
17
25
|
|
18
26
|
private
|
19
27
|
|
20
|
-
def initialize
|
21
|
-
@
|
28
|
+
def initialize info_hashes, message
|
29
|
+
@info_hashes = [*info_hashes]
|
22
30
|
@message = message
|
23
31
|
end
|
24
32
|
end
|
@@ -11,6 +11,8 @@ 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, "info_hashes cannot be nil" if info_hashes.nil?
|
15
|
+
raise ArgumentError, "data cannot be nil" if data.nil?
|
14
16
|
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)] })]
|
15
17
|
end
|
16
18
|
|
data/lib/torckapi/tracker/udp.rb
CHANGED
@@ -28,13 +28,19 @@ module Torckapi
|
|
28
28
|
connect
|
29
29
|
response = communicate action, data
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
begin
|
32
|
+
case response[0][0..3].unpack('L>')[0] # action
|
33
|
+
when 1
|
34
|
+
Torckapi::Response::Announce.from_udp(*args, response[0][8..-1])
|
35
|
+
when 2
|
36
|
+
Torckapi::Response::Scrape.from_udp(*args, response[0][8..-1])
|
37
|
+
when 3
|
38
|
+
Torckapi::Response::Error.from_udp(*args, response[0][8..-1])
|
39
|
+
end
|
40
|
+
rescue Torckapi::Response::ArgumentError => e
|
41
|
+
puts "Error: #{e.inspect}"
|
42
|
+
puts "Response: #{response.inspect}"
|
43
|
+
raise CommunicationFailedError
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
data/lib/torckapi/version.rb
CHANGED