imdb_lists 1.0.4 → 2.0.2
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/.gitignore +1 -0
- data/README.md +59 -0
- data/imdb_lists.gemspec +5 -3
- data/lib/imdb_lists.rb +164 -27
- data/lib/imdb_lists/object.rb +11 -0
- data/spec/fixtures/vcr_cassettes/qJi7_i3l25Y.yml +550 -0
- data/spec/fixtures/vcr_cassettes/random.yml +646 -0
- data/spec/fixtures/vcr_cassettes/ur10777143.yml +2099 -0
- data/spec/imdb_list_spec.rb +143 -0
- data/spec/spec_helper.rb +11 -3
- metadata +17 -36
- data/README.markdown +0 -77
- data/lib/imdb_lists/base.rb +0 -31
- data/lib/imdb_lists/container.rb +0 -49
- data/lib/imdb_lists/history.rb +0 -35
- data/lib/imdb_lists/watchlist.rb +0 -46
- data/spec/container_spec.rb +0 -38
- data/spec/fixtures/32558051.html +0 -8401
- data/spec/fixtures/empty_watchlist.html +0 -761
- data/spec/fixtures/non_public.html +0 -992
- data/spec/fixtures/non_public_watchlist.html +0 -668
- data/spec/fixtures/pagination.html +0 -1057
- data/spec/fixtures/pagination_end.html +0 -956
- data/spec/fixtures/redirect_watchlist.html +0 -2701
- data/spec/fixtures/watchlist.html +0 -3365
- data/spec/history_spec.rb +0 -124
- data/spec/watchlist_spec.rb +0 -170
@@ -0,0 +1,143 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ImdbLists do
|
4
|
+
describe "arguments" do
|
5
|
+
it "should raise an error if url is invalid" do
|
6
|
+
lambda { ImdbLists.fetch("random") }.should raise_error(ArgumentError, "Invalid url")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should NOT raise an error if url is valid" do
|
10
|
+
lambda { ImdbLists.fetch("http://www.imdb.com/user/ur10777143/ratings") }.should_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "rating list" do
|
15
|
+
let(:url) { "http://www.imdb.com/user/ur10777143/ratings" }
|
16
|
+
|
17
|
+
use_vcr_cassette "ur10777143"
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@list = ImdbLists.fetch(url)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a name" do
|
24
|
+
@list.name.should eq("Demon_Hunter777's Ratings")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should have csv link" do
|
28
|
+
@list.csv.should eq("http://www.imdb.com/list/export?list_id=ratings&author_id=ur10777143")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have 693 movies" do
|
32
|
+
@list.should have(693).movies
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a list of movies" do
|
36
|
+
@list.movies.each do |movie|
|
37
|
+
movie.id.should match(/tt\d{7}/)
|
38
|
+
movie.created_at.should be_instance_of(Time)
|
39
|
+
movie.title.should_not be_empty
|
40
|
+
movie.directors.should be_instance_of(Array)
|
41
|
+
movie.you_rated.should be_between(0, 10)
|
42
|
+
movie.rating.should be_between(0, 10)
|
43
|
+
movie.runtime.should >= 0
|
44
|
+
movie.year.should > 1900
|
45
|
+
movie.genres.map(&:titleize).should eq(movie.genres)
|
46
|
+
movie.votes.should > 1
|
47
|
+
movie.released_at.should be_instance_of(Time)
|
48
|
+
movie.details.should match(/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not calculate #movies twice" do
|
53
|
+
@list.movies.should eq(@list.movies)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be able to cache a request" do
|
57
|
+
2.times { @list.name }
|
58
|
+
a_request(:get, url).should have_been_made.once
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be able to return the given url" do
|
62
|
+
@list.url.should eq(url)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "regular list" do
|
67
|
+
let(:url) { "http://www.imdb.com/list/qJi7_i3l25Y/" }
|
68
|
+
use_vcr_cassette "qJi7_i3l25Y"
|
69
|
+
|
70
|
+
before(:each) do
|
71
|
+
@list = ImdbLists.fetch(url)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should have a name" do
|
75
|
+
@list.name.should eq("Not so good movies...")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should have csv link" do
|
79
|
+
@list.csv.should eq("http://www.imdb.com/list/export?list_id=qJi7_i3l25Y&author_id=ur28206273")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should have 17 movies" do
|
83
|
+
@list.should have(17).movies
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have a list of movies" do
|
87
|
+
@list.movies.each do |movie|
|
88
|
+
movie.id.should match(/tt\d{7}/)
|
89
|
+
movie.created_at.should be_instance_of(Time)
|
90
|
+
movie.title.should_not be_empty
|
91
|
+
movie.directors.should be_instance_of(Array)
|
92
|
+
movie.you_rated.should be_nil
|
93
|
+
movie.rating.should be_between(0, 10)
|
94
|
+
movie.runtime.should >= 0
|
95
|
+
movie.year.should > 1900
|
96
|
+
movie.genres.map(&:titleize).should eq(movie.genres)
|
97
|
+
movie.votes.should > 1
|
98
|
+
movie.released_at.should be_instance_of(Time)
|
99
|
+
movie.details.should match(/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should be able to cache a request" do
|
104
|
+
2.times { @list.name }
|
105
|
+
a_request(:get, url).should have_been_made.once
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should be able to return the given url" do
|
109
|
+
@list.url.should eq(url)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
describe "invalid url" do
|
115
|
+
let(:url) { "http://www.imdb.com/list/random/" }
|
116
|
+
use_vcr_cassette "random"
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
@list = ImdbLists.fetch(url)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should not have a name" do
|
123
|
+
@list.name.should be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should not have csv link" do
|
127
|
+
@list.csv.should be_nil
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should have 0 movies" do
|
131
|
+
@list.should have(0).movies
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should be able to cache a request" do
|
135
|
+
2.times { @list.name }
|
136
|
+
a_request(:get, url).should have_been_made.once
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should be able to return the given url" do
|
140
|
+
@list.url.should eq(url)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
require "rspec"
|
2
2
|
require "webmock/rspec"
|
3
|
+
require "vcr"
|
3
4
|
require "imdb_lists"
|
4
|
-
require "imdb_lists/container"
|
5
|
-
require "imdb_lists/history"
|
6
|
-
require "imdb_lists/watchlist"
|
7
5
|
|
8
6
|
WebMock.disable_net_connect!
|
9
7
|
|
10
8
|
RSpec.configure do |config|
|
11
9
|
config.mock_with :rspec
|
10
|
+
config.extend VCR::RSpec::Macros
|
11
|
+
end
|
12
|
+
|
13
|
+
VCR.config do |c|
|
14
|
+
c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
15
|
+
c.stub_with :webmock
|
16
|
+
c.default_cassette_options = {
|
17
|
+
record: :new_episodes
|
18
|
+
}
|
19
|
+
c.allow_http_connections_when_no_cassette = false
|
12
20
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: imdb_lists
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version:
|
5
|
+
version: 2.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Linus Oleander
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-20 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: rest-client
|
@@ -36,7 +35,7 @@ dependencies:
|
|
36
35
|
type: :runtime
|
37
36
|
version_requirements: *id002
|
38
37
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
38
|
+
name: titleize
|
40
39
|
prerelease: false
|
41
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
41
|
none: false
|
@@ -47,7 +46,7 @@ dependencies:
|
|
47
46
|
type: :runtime
|
48
47
|
version_requirements: *id003
|
49
48
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
49
|
+
name: vcr
|
51
50
|
prerelease: false
|
52
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
52
|
none: false
|
@@ -55,7 +54,7 @@ dependencies:
|
|
55
54
|
- - ">="
|
56
55
|
- !ruby/object:Gem::Version
|
57
56
|
version: "0"
|
58
|
-
type: :
|
57
|
+
type: :development
|
59
58
|
version_requirements: *id004
|
60
59
|
- !ruby/object:Gem::Dependency
|
61
60
|
name: rspec
|
@@ -92,27 +91,16 @@ files:
|
|
92
91
|
- .gitignore
|
93
92
|
- .rspec
|
94
93
|
- Gemfile
|
95
|
-
- README.
|
94
|
+
- README.md
|
96
95
|
- Rakefile
|
97
96
|
- imdb_lists.gemspec
|
98
97
|
- lib/imdb_lists.rb
|
99
|
-
- lib/imdb_lists/
|
100
|
-
-
|
101
|
-
-
|
102
|
-
-
|
103
|
-
- spec/
|
104
|
-
- spec/fixtures/32558051.html
|
105
|
-
- spec/fixtures/empty_watchlist.html
|
106
|
-
- spec/fixtures/non_public.html
|
107
|
-
- spec/fixtures/non_public_watchlist.html
|
108
|
-
- spec/fixtures/pagination.html
|
109
|
-
- spec/fixtures/pagination_end.html
|
110
|
-
- spec/fixtures/redirect_watchlist.html
|
111
|
-
- spec/fixtures/watchlist.html
|
112
|
-
- spec/history_spec.rb
|
98
|
+
- lib/imdb_lists/object.rb
|
99
|
+
- spec/fixtures/vcr_cassettes/qJi7_i3l25Y.yml
|
100
|
+
- spec/fixtures/vcr_cassettes/random.yml
|
101
|
+
- spec/fixtures/vcr_cassettes/ur10777143.yml
|
102
|
+
- spec/imdb_list_spec.rb
|
113
103
|
- spec/spec_helper.rb
|
114
|
-
- spec/watchlist_spec.rb
|
115
|
-
has_rdoc: true
|
116
104
|
homepage: https://github.com/oleander/imdb_lists
|
117
105
|
licenses: []
|
118
106
|
|
@@ -126,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
114
|
requirements:
|
127
115
|
- - ">="
|
128
116
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
117
|
+
version: 1.9.2
|
130
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
119
|
none: false
|
132
120
|
requirements:
|
@@ -136,20 +124,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
124
|
requirements: []
|
137
125
|
|
138
126
|
rubyforge_project:
|
139
|
-
rubygems_version: 1.
|
127
|
+
rubygems_version: 1.8.8
|
140
128
|
signing_key:
|
141
129
|
specification_version: 3
|
142
130
|
summary: Get easy access to any public IMDb list
|
143
131
|
test_files:
|
144
|
-
- spec/
|
145
|
-
- spec/fixtures/
|
146
|
-
- spec/fixtures/
|
147
|
-
- spec/
|
148
|
-
- spec/fixtures/non_public_watchlist.html
|
149
|
-
- spec/fixtures/pagination.html
|
150
|
-
- spec/fixtures/pagination_end.html
|
151
|
-
- spec/fixtures/redirect_watchlist.html
|
152
|
-
- spec/fixtures/watchlist.html
|
153
|
-
- spec/history_spec.rb
|
132
|
+
- spec/fixtures/vcr_cassettes/qJi7_i3l25Y.yml
|
133
|
+
- spec/fixtures/vcr_cassettes/random.yml
|
134
|
+
- spec/fixtures/vcr_cassettes/ur10777143.yml
|
135
|
+
- spec/imdb_list_spec.rb
|
154
136
|
- spec/spec_helper.rb
|
155
|
-
- spec/watchlist_spec.rb
|
data/README.markdown
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# IMDb Lists
|
2
|
-
|
3
|
-
Get easy access to any public [IMDb](http://www.imdb.com/) [vote history list](http://www.imdb.com/mymovies/list?l=19736607) and [watchlist](http://www.imdb.com/list/2BZy80bxY2U) using Ruby.
|
4
|
-
|
5
|
-
## How to use
|
6
|
-
|
7
|
-
### Find by url
|
8
|
-
|
9
|
-
$ require 'rubygems'
|
10
|
-
$ require 'imdb_lists'
|
11
|
-
|
12
|
-
$ result = ImdbLists::find_by_url("http://www.imdb.com/mymovies/list?l=32558051")
|
13
|
-
|
14
|
-
$ result.movies.count
|
15
|
-
>> 937
|
16
|
-
|
17
|
-
$ result.user
|
18
|
-
>> "eddyproca" # Not me :)
|
19
|
-
|
20
|
-
$ result.movies.last.title
|
21
|
-
>> "The Last Man on Earth"
|
22
|
-
|
23
|
-
$ result.movies.first.class
|
24
|
-
>> Container::Movie
|
25
|
-
|
26
|
-
$ result.movies.last.actors.first.name
|
27
|
-
>> "Vincent Price"
|
28
|
-
|
29
|
-
### Find by id
|
30
|
-
|
31
|
-
$ result = ImdbLists::find_by_id("32558051")
|
32
|
-
|
33
|
-
$ result.movies.count
|
34
|
-
>> 937
|
35
|
-
|
36
|
-
## Data to work with
|
37
|
-
|
38
|
-
### Accessors
|
39
|
-
|
40
|
-
- **user** (String) Owner of the list.
|
41
|
-
- **id** (Fixnum or String) A unique id for the list.
|
42
|
-
- **url** (String) Full URL to the IMDb list itself.
|
43
|
-
- **movies** (Array[Container::Movie]) A list of movies containing `Container::Movie` instances.
|
44
|
-
- **title** (String) Title of the watchlist.
|
45
|
-
- **valid?** (Boolean) Is the data that is being returned valid?
|
46
|
-
|
47
|
-
### The Container::Movie class
|
48
|
-
|
49
|
-
The `movies` method returns a list of `Container::Movie` objects, each object has two methods that returns information about the movie without doing another request to [IMDb](http://www.imdb.com/).
|
50
|
-
|
51
|
-
If you for example want to get the title of the movie you can apply the accessors that is being described [here](https://github.com/oleander/MovieSearcher).
|
52
|
-
Scroll down to the `ImdbParty::Movie` part to get information about the available accessors.
|
53
|
-
|
54
|
-
- **imdb_link** (String) The full URL to the IMDb page.
|
55
|
-
- **imdb_id** (String) The IMDb ID for the movie.
|
56
|
-
|
57
|
-
You can, as said above, use any method that `ImdbParty::Movie` provides directly from the `Container::Movie` object, like *title*, *year* and *actors*.
|
58
|
-
|
59
|
-
## How do install
|
60
|
-
|
61
|
-
[sudo] gem install imdb_lists
|
62
|
-
|
63
|
-
## How to use it in a rails 3 project
|
64
|
-
|
65
|
-
Add `gem 'imdb_lists'` to your Gemfile and run `bundle`.
|
66
|
-
|
67
|
-
## Requirements
|
68
|
-
|
69
|
-
*IMDb Lists* is tested in OS X 10.6.6 using Ruby 1.9.2 and 1.8.7.
|
70
|
-
|
71
|
-
## Thanks to
|
72
|
-
|
73
|
-
[Chicago_gangster](http://www.imdb.com/user/ur13279695/boards/profile/) for solving the [pagination problem](http://www.imdb.com/board/bd0000041/thread/178983592?d=178983592&p=1#178983592).
|
74
|
-
|
75
|
-
## License
|
76
|
-
|
77
|
-
*IMDb Lists* is released under the MIT license.
|
data/lib/imdb_lists/base.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
data/lib/imdb_lists/container.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require "movie_searcher"
|
2
|
-
|
3
|
-
module Container
|
4
|
-
class Movie
|
5
|
-
def initialize(args)
|
6
|
-
args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
|
7
|
-
end
|
8
|
-
|
9
|
-
# Returns the imdb id for the movie.
|
10
|
-
# Example:
|
11
|
-
# => tt0066026
|
12
|
-
def imdb_id
|
13
|
-
imdb_link.match(/(tt\d+)/).to_a[1]
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns the full imdb url for the movie.
|
17
|
-
# Example:
|
18
|
-
# => www.imdb.com/title/tt0066026/
|
19
|
-
def imdb_link
|
20
|
-
"http://www.imdb.com#{@imdb_link}"
|
21
|
-
end
|
22
|
-
|
23
|
-
# Does the container contains a valid imdb url?
|
24
|
-
# Return true if the url is valid.
|
25
|
-
# Example on valid url:
|
26
|
-
# => www.imdb.com/title/tt0066026/
|
27
|
-
def valid?
|
28
|
-
!! imdb_link.match(/http:\/\/www\.imdb\.com\/title\/tt\d{2,}/i)
|
29
|
-
end
|
30
|
-
|
31
|
-
def method_missing(method, *args)
|
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")
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
def exists?
|
38
|
-
! movie.nil?
|
39
|
-
end
|
40
|
-
|
41
|
-
def movie
|
42
|
-
@movie ||= MovieSearcher.find_movie_by_id(imdb_id)
|
43
|
-
end
|
44
|
-
|
45
|
-
def prepare(method)
|
46
|
-
RUBY_VERSION.to_s.match(/1\.9/) ? method.to_sym : method.to_s
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/imdb_lists/history.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require "nokogiri"
|
2
|
-
require "rest-client"
|
3
|
-
require "imdb_lists/container"
|
4
|
-
require "imdb_lists/base"
|
5
|
-
|
6
|
-
module ImdbLists
|
7
|
-
class History < ImdbLists::Base
|
8
|
-
attr_reader :url, :id
|
9
|
-
|
10
|
-
# Ingoing argument is the id to fetch movies from.
|
11
|
-
def initialize(id)
|
12
|
-
@movies = []
|
13
|
-
@url = "http://www.imdb.com/mymovies/list?l=#{@id = id.to_i}"
|
14
|
-
end
|
15
|
-
|
16
|
-
# The owners username, nil if the page doesn't exists.
|
17
|
-
def user
|
18
|
-
content.at_css(".blurb a:nth-child(1)").content
|
19
|
-
rescue NoMethodError
|
20
|
-
nil # The default value if no user i found
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def prepare!
|
25
|
-
movies = []; content.css("td.standard a").each do |movie|
|
26
|
-
movie = Container::Movie.new(:imdb_link => movie.attr("href"))
|
27
|
-
@movies << movie if movie.valid?
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def inner_url
|
32
|
-
"#{@url}&a=1"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|