torrents 1.0.2 → 1.0.3

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.
data/README.md CHANGED
@@ -40,13 +40,22 @@ The `page` method can be places anywhere before the `results` method.
40
40
 
41
41
  It starts counting from `1` and goes up, no matter what is used on the site it self.
42
42
 
43
- >> Torrents.the_pirate_bay.page(6).results
43
+ $ Torrents.the_pirate_bay.page(6).results
44
44
 
45
45
  ### Specify some cookies
46
46
 
47
47
  Some trackers requires cookies to work, even though [The Pirate Bay](http://thepiratebay.org/) is not one of them.
48
48
 
49
- >> Torrents.the_pirate_bay.cookies(user_id: "123", hash: "c4656002ce46f9b418ce72daccfa5424").results
49
+ $ Torrents.the_pirate_bay.cookies(user_id: "123", hash: "c4656002ce46f9b418ce72daccfa5424").results
50
+
51
+ ### Step through torrents
52
+
53
+ Here is an example of how to step through the 10 first pages.
54
+
55
+ $ torrents = Torrents.the_pirate_bay.step
56
+ $ 10.times { torrents.results }
57
+
58
+ You just add the step method and it will increment `page` everytime you apply the `results` method.
50
59
 
51
60
  ## What methods to work with
52
61
 
data/lib/torrents.rb CHANGED
@@ -26,7 +26,8 @@ class Torrents < Container::Shared
26
26
  end
27
27
 
28
28
  def content
29
- @content ||= Nokogiri::HTML(self.download(self.url))
29
+ @content = {} unless @content
30
+ @content[self.inner_page] ||= Nokogiri::HTML(self.download(self.url))
30
31
  end
31
32
 
32
33
  # Set the default page
@@ -40,6 +41,10 @@ class Torrents < Container::Shared
40
41
  gsub('<PAGE>', self.inner_page)
41
42
  end
42
43
 
44
+ def step
45
+ @step = true; self
46
+ end
47
+
43
48
  # Makes this the {tracker} tracker
44
49
  def add(tracker)
45
50
  @tracker = tracker.to_s; self
@@ -114,7 +119,7 @@ class Torrents < Container::Shared
114
119
  end
115
120
 
116
121
  def results
117
- return @torrents if @torrents.any?
122
+ return @torrents if @torrents.any? and not @step
118
123
  counter = 0
119
124
  rejected = 0
120
125
  self.inner_torrents(self.content).each do |tr|
@@ -135,6 +140,8 @@ class Torrents < Container::Shared
135
140
  end
136
141
 
137
142
  @errors << "#{counter} torrents where found, #{rejected} where not valid" unless rejected.zero?
143
+ @page += 1 if @step
144
+
138
145
  return @torrents
139
146
  end
140
147
  end
@@ -192,7 +192,7 @@ describe Torrents do
192
192
  rest_client("http://thepiratebay.org/torrent/6173093/", "details")
193
193
  torrent = Torrents.the_pirate_bay.find_by_details("http://thepiratebay.org/torrent/6173093/")
194
194
 
195
- # Makes sure that all methods returnes something
195
+ # Makes sure that all methods returns something
196
196
  [:seeders, :title, :dead?, :imdb, :imdb_id, :domain, :id].each do |method|
197
197
  torrent.send(method).to_s.should_not be_empty
198
198
  end
@@ -228,4 +228,13 @@ describe Torrents do
228
228
  end.should_not change(errors, :count)
229
229
  end
230
230
  end
231
+
232
+ context "the step method" do
233
+ it "should be possible to step from 0 to 10" do
234
+ 10.times do |n|
235
+ RestClient.should_receive(:get).with("http://thepiratebay.org/recent/#{n}", {:timeout => 10, :cookies => nil}).exactly(1).times.and_return("")
236
+ @torrents.step.results
237
+ end
238
+ end
239
+ end
231
240
  end
data/torrents.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "torrents"
6
- s.version = "1.0.2"
6
+ s.version = "1.0.3"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Linus Oleander"]
9
9
  s.email = ["linus@oleander.nu"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torrents
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Linus Oleander