torckapi 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 979d317e486ddd5e74790d41d1f987a637eb12ef
4
- data.tar.gz: 9a46f9e9944e82e5087e026c1feab81801e94922
3
+ metadata.gz: 146de8f36529a36d19b6c31bf0cc3db2e4df945b
4
+ data.tar.gz: 632d8cbb3b34f871a593caf454044cc45d913417
5
5
  SHA512:
6
- metadata.gz: acffe09aa8a0c9170b82e6d8d96c1b0fb03ee6c24369353941447e8aa748f49e3d5bcc160a3c1c3a16883155f24eb97c9ffdd3d2185b459b33eb0fa2d881bf85
7
- data.tar.gz: 7556ff3679e20b19aded7e54cccc42f1458433d2de7f88ecdd96ef8d4984698daf6ecfc76680294899c7b31ce7ba111578c6b2a9bf9fccb0dac6309be0831279
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.query += info_hash_params [info_hash]
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.query += info_hash_params info_hashes
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
@@ -1,3 +1,3 @@
1
1
  module Torckapi
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torckapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Krupenik