junkie 0.1.2 → 0.1.3

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: 299b760e5856e465a123191575aa2f0709eafa75
4
- data.tar.gz: e364723f5af594b340f312982e4f934af65af0ef
3
+ metadata.gz: 728c1f06bb30b73b2560183c18be33eac3ec38df
4
+ data.tar.gz: 2347ce511acf6f802a14ed434c002205eb7ac539
5
5
  SHA512:
6
- metadata.gz: 982562006b5265fbea20ea56858a374d8dd52b0541df29d99bc1162060081ecc476f06d9c20ad153ea809be6acdc522b4d84c9999c1c3fd814b5ac6f223b3fe1
7
- data.tar.gz: 094de64cf493a05b3f99a08cda652a89b0b1e4719d048912bb954684e309f687a94548ed089e56597352dbc8fe33ab7226f4e1acbbbd69ddfc94613d0e9fa68c
6
+ metadata.gz: ea56196f84c2276994100080b7bc7843d34f502a0f904040da3f6e9720576735f15f6ede249fb056fa29d6050a0a093c172cc52256771ae9256b4c6141ce9d81
7
+ data.tar.gz: 21a931fb9ddd8d0267850db69da03416024d7bb391a53d1a0e98811a50a2924a85ec9899591c0ae4c2ac707ee71841f209a38da4265a38ad8e6e925c2dce9dc0
@@ -23,41 +23,36 @@ module Junkie
23
23
  end
24
24
  end
25
25
 
26
+ def is_resolvable(link)
27
+ @patterns.index { |p| link.include?(p) }
28
+ end
29
+
26
30
  # resolve links that matches any pattern by issuing a HEAD request and
27
31
  # using the Location response header instead of the original supplied header
28
32
  def resolve_links(episode)
29
- multi = EventMachine::MultiRequest.new
30
- request_count = 0
31
-
32
- episode.links.each_with_index do |link, index|
33
- next unless @patterns.index { |p| link.include?(p) }
34
-
35
- request_count += 1
36
- multi.add(index, EventMachine::HttpRequest.new(link).head)
37
- end
33
+ resolvable, resolved = episode.links.partition { |link| is_resolvable(link) }
34
+ episode.links = resolved
38
35
 
39
- if request_count == 0
36
+ if resolvable.empty?
40
37
  send_episode(episode)
41
38
  else
42
- multi.callback do
43
- links = episode.links.clone
44
-
45
- responses = multi.responses[:callback]
46
- responses.each do |index, value|
47
- location = value.response_header.fetch("LOCATION") { nil }
48
-
49
- unless location.nil?
50
- links[index] = location
51
- end
52
- end
53
-
54
- episode.links = links
39
+ EM::Iterator.new(resolvable, 2).map( proc { |url, iter|
40
+ res = EventMachine::HttpRequest.new(url).head
41
+ res.callback {
42
+ iter.return(res.response_header.fetch("LOCATION") { nil })
43
+ }
44
+ res.errback {
45
+ iter.return(nil)
46
+ }
47
+ }, proc { |links|
48
+ episode.links += links.select {|l| !l.nil? }
55
49
  send_episode(episode)
56
- end
50
+ })
57
51
  end
58
52
  end
59
53
 
60
54
  def send_episode(episode)
55
+ log.debug('Resolved links: ' + episode.links.to_s)
61
56
  episode.status = :resolved
62
57
  @channels[:episodes].push(episode)
63
58
  end
@@ -1,3 +1,3 @@
1
1
  module Junkie
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junkie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philipp Böhm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-16 00:00:00.000000000 Z
11
+ date: 2016-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine