imdb_lists 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "imdb_lists"
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"]
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency("rest-client")
20
20
  s.add_dependency("nokogiri")
21
21
  s.add_dependency("movie_searcher")
22
+ s.add_dependency("abstract")
22
23
 
23
24
  s.add_development_dependency("rspec")
24
25
  s.add_development_dependency("webmock")
@@ -0,0 +1,31 @@
1
+ require "abstract"
2
+
3
+ module ImdbLists
4
+ class Base
5
+ def download
6
+ RestClient.get(inner_url, :timeout => 10)
7
+ rescue RestClient::Exception => error
8
+ @errors == true ? raise(error) : warn("Error: #{error}, Where: #{error.backtrace.first}")
9
+ end
10
+
11
+ def content
12
+ @content ||= Nokogiri::HTML(download)
13
+ end
14
+
15
+ def movies
16
+ prepare! unless @movies.any?; @movies
17
+ end
18
+
19
+ def errors(boolean)
20
+ tap { @errors = boolean }
21
+ end
22
+
23
+ def prepare!
24
+ not_implemented
25
+ end
26
+
27
+ def inner_url
28
+ not_implemented
29
+ end
30
+ end
31
+ end
@@ -30,7 +30,7 @@ module Container
30
30
 
31
31
  def method_missing(method, *args)
32
32
  return movie.send(method, *args) if exists? and movie.methods.include?(prepare(method))
33
- raise exists? ? NoMethodError.new("Undefined method `#{method}' for #{movie.class}") : ArgumentError.new("The imdb #{imdb_id} is invalid")
33
+ raise exists? ? NoMethodError.new("Undefined method '#{method}' for #{movie.class}") : ArgumentError.new("The imdb #{imdb_id} is invalid")
34
34
  end
35
35
 
36
36
  private
@@ -1,15 +1,16 @@
1
1
  require "nokogiri"
2
2
  require "rest-client"
3
3
  require "imdb_lists/container"
4
+ require "imdb_lists/base"
4
5
 
5
6
  module ImdbLists
6
- class History
7
- attr_reader :url
7
+ class History < ImdbLists::Base
8
+ attr_reader :url, :id
8
9
 
9
10
  # Ingoing argument is the id to fetch movies from.
10
11
  def initialize(id)
11
12
  @movies = []
12
- @url = "http://www.imdb.com/mymovies/list?l=#{id}"
13
+ @url = "http://www.imdb.com/mymovies/list?l=#{@id = id.to_i}"
13
14
  end
14
15
 
15
16
  # The owners username, nil if the page doesn't exists.
@@ -19,22 +20,6 @@ module ImdbLists
19
20
  nil # The default value if no user i found
20
21
  end
21
22
 
22
- # A unique id for this particular list.
23
- # Return type is Fixnum.
24
- def id
25
- @url.match(/list\?l=(\d+)/).to_a[1].to_i
26
- end
27
-
28
- # Should we fetch all movies, even though pagination exists?
29
- def all
30
- @all = self
31
- end
32
-
33
- # Returns a list of movies of the Container::Movie type.
34
- def movies
35
- prepare! unless @movies.any?; @movies
36
- end
37
-
38
23
  private
39
24
  def prepare!
40
25
  movies = []; content.css("td.standard a").each do |movie|
@@ -46,13 +31,5 @@ module ImdbLists
46
31
  def inner_url
47
32
  "#{@url}&a=1"
48
33
  end
49
-
50
- def download
51
- RestClient.get(inner_url, :timeout => 10) rescue ""
52
- end
53
-
54
- def content
55
- @content ||= Nokogiri::HTML download
56
- end
57
34
  end
58
35
  end
@@ -1,16 +1,16 @@
1
1
  require "nokogiri"
2
2
  require "rest-client"
3
3
  require "imdb_lists/container"
4
+ require "imdb_lists/base"
4
5
 
5
6
  module ImdbLists
6
- class Watchlist
7
+ class Watchlist < ImdbLists::Base
7
8
  attr_reader :url, :id
8
9
 
9
10
  # Ingoing argument is the id to fetch movies from.
10
11
  def initialize(id)
12
+ @url = "http://www.imdb.com/list/#{@id = id}"
11
13
  @movies = []
12
- @url = "http://www.imdb.com/list/#{id}"
13
- @id = id
14
14
  end
15
15
 
16
16
  # The owners username, nil if the page doesn't exists.
@@ -21,12 +21,8 @@ module ImdbLists
21
21
  end
22
22
 
23
23
  def title
24
- content.at_css("h1").content
25
- end
26
-
27
- # Returns a list of movies of the Container::Movie type.
28
- def movies
29
- prepare! unless @movies.any?; @movies
24
+ @_title ||= content.at_css("h1").content
25
+ @_title == "Newest Lists" ? nil : @_title
30
26
  end
31
27
 
32
28
  private
@@ -40,15 +36,5 @@ module ImdbLists
40
36
  def inner_url
41
37
  "#{@url}/?view=compact&sort=listorian:asc"
42
38
  end
43
-
44
- def download
45
- RestClient.get(inner_url, :timeout => 10)
46
- rescue => error
47
- raise error unless false
48
- end
49
-
50
- def content
51
- @content ||= Nokogiri::HTML(download)
52
- end
53
39
  end
54
40
  end