torckapi 0.0.13 → 0.0.14
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/lib/torckapi/tracker/http.rb +17 -8
- 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: 146de8f36529a36d19b6c31bf0cc3db2e4df945b
|
4
|
+
data.tar.gz: 632d8cbb3b34f871a593caf454044cc45d913417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df12478369270ec572cc28e5faa599aa2f1adcfce84d89830d562dfced6d391af7529e62db2f953521d6e612f188a9f3c8ff3dd53d24440dd7c6a5540c217107
|
7
|
+
data.tar.gz: f507f6057952a51ed1e6858e51d9fe32ff0ba8ad7238f8e9febe42be5be12e0e92f80bda239e2d35e98767a7c95cf8468fab4dff6f21dc518489554b930a99f1
|
@@ -5,32 +5,41 @@ module Torckapi
|
|
5
5
|
module Tracker
|
6
6
|
|
7
7
|
class HTTP < Base
|
8
|
+
REQUEST_ACTIONS = [Announce = 1, Scrape = 2].freeze
|
8
9
|
|
9
10
|
# (see Base#announce)
|
10
11
|
def announce info_hash
|
11
12
|
super info_hash
|
12
|
-
@url.
|
13
|
-
|
14
|
-
Torckapi::Response::Announce.from_http info_hash, Net::HTTP.get(@url)
|
13
|
+
Torckapi::Response::Announce.from_http(info_hash, perform_request(url_for(@url.dup, Announce, info_hash)))
|
15
14
|
end
|
16
15
|
|
17
16
|
# (see Base#scrape)
|
18
17
|
def scrape info_hashes=[]
|
19
18
|
super info_hashes
|
20
|
-
@url.
|
21
|
-
@url.path.gsub!(/announce/, 'scrape')
|
22
|
-
|
23
|
-
Torckapi::Response::Scrape.from_http Net::HTTP.get(@url)
|
19
|
+
Torckapi::Response::Scrape.from_http(perform_request(url_for(@url.dup, Scrape, info_hashes)))
|
24
20
|
end
|
25
21
|
|
26
22
|
private
|
27
23
|
|
28
24
|
def initialize url, options={}
|
29
25
|
super url, options
|
30
|
-
|
31
26
|
@url.query ||= ""
|
32
27
|
end
|
33
28
|
|
29
|
+
def url_for url, action, data
|
30
|
+
url.query += info_hash_params [*data]
|
31
|
+
url.path.gsub!(/announce/, 'scrape') if Scrape == action
|
32
|
+
url
|
33
|
+
end
|
34
|
+
|
35
|
+
def perform_request url
|
36
|
+
begin
|
37
|
+
Net::HTTP.get(url)
|
38
|
+
rescue Errno::ECONNRESET, Errno::ETIMEDOUT, Timeout::Error
|
39
|
+
raise CommunicationFailedError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
34
43
|
def info_hash_params info_hashes
|
35
44
|
info_hashes.map { |i| "info_hash=%s" % URI.encode([i].pack('H*')) }.join('&')
|
36
45
|
end
|
data/lib/torckapi/version.rb
CHANGED