ruby-tmdb 0.1.1 → 0.1.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.rdoc +49 -14
- data/VERSION +1 -1
- data/lib/ruby-tmdb/tmdb.rb +1 -0
- data/lib/ruby-tmdb/tmdb_cast.rb +3 -1
- data/lib/ruby-tmdb/tmdb_movie.rb +3 -1
- data/ruby-tmdb.gemspec +9 -4
- data/test/setup/setup_api_key.rb +3 -0
- data/test/test_helper.rb +2 -5
- data/test/unit/test_direct_require.rb +25 -0
- data/test/unit/tmdb_test.rb +9 -0
- metadata +8 -3
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/README.rdoc
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
1
|
+
= ruby-tmdb
|
2
2
|
|
3
|
-
ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org
|
3
|
+
ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org (TMDb)}[http://www.themoviedb.org/]. ruby-tmdb is designed to make common tasks much easier than they would be if dealing directly with the URL based API.
|
4
4
|
|
5
5
|
=== Installation
|
6
6
|
|
7
7
|
gem install ruby-tmdb
|
8
8
|
|
9
|
-
===
|
9
|
+
=== Example
|
10
10
|
|
11
11
|
require 'rubygems'
|
12
12
|
require 'ruby-tmdb'
|
@@ -15,7 +15,7 @@ ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org}[http://www.t
|
|
15
15
|
Tmdb.api_key = "t478f8de5776c799de5a"
|
16
16
|
|
17
17
|
@movie = TmdbMovie.find(:title => "Iron Man", :limit => 1)
|
18
|
-
# => <
|
18
|
+
# => <OpenStruct>
|
19
19
|
|
20
20
|
@movie.name
|
21
21
|
# => "Iron Man"
|
@@ -26,31 +26,66 @@ ruby-tmdb is an ActiveRecord-style API wrapper for {TheMovieDB.org}[http://www.t
|
|
26
26
|
@movie.posters.first.data
|
27
27
|
# => [binary blob representing JPEG]
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
=== Usage
|
30
|
+
|
31
|
+
ruby-tmdb provides 2 main objects that you will use to query the API
|
32
|
+
|
33
|
+
TmdbMovie
|
34
|
+
TmdbCast
|
35
|
+
|
36
|
+
These objects provide access to movie and cast listing respectively.
|
37
|
+
|
38
|
+
Each object provides a find() method which accepts a number of options:
|
39
|
+
|
40
|
+
TmdbMovie.find(:id => 123, :title => "fight club", :imdb => 'tt0401792', :limit => 10, :expand_results => true)
|
41
|
+
|
42
|
+
|
43
|
+
[:id] specifies an individual movie via it's TMDb id
|
44
|
+
[:title] specifies a query string to look for in the movie titles
|
45
|
+
[:imdb] specifies an idividual movie via it's IMDB id
|
46
|
+
[:limit] specifies the maximum number of results to be returned
|
47
|
+
[:expand_results] The TMDb API by default returns only partial info for any API method that can return multiple results. When :expand_results is set to true ruby-tmdb automatically makes extra API calls to fetch the full information for each item. This can result in *very* slow requests though. If you only need basic information for a search listing then set this to false. Defaults to 'true'.
|
31
48
|
|
32
|
-
|
33
|
-
|
49
|
+
|
50
|
+
TmdbCast.find( :id => 123, :name => "Brad", :limit => 1, :expand_results => true)
|
34
51
|
|
35
|
-
|
36
|
-
|
52
|
+
[:id] specifies an idividual cast member via their TMDb id
|
53
|
+
[:name] specifies a query string to look for in the cast names
|
54
|
+
[:limit] see TmdbMovie
|
55
|
+
[:expand_results] see TmdbMovie
|
37
56
|
|
38
|
-
|
57
|
+
|
58
|
+
=== Usage Examples
|
59
|
+
|
60
|
+
Find all movies whose titles match a given string:
|
39
61
|
|
40
62
|
@movies = TmdbMovie.find(:title => 'Iron Man')
|
41
63
|
|
42
|
-
Find the movie most likely to be associated with a given title
|
64
|
+
Find the movie most likely to be associated with a given title:
|
43
65
|
|
44
66
|
@movie = TmdbMovie.find(:title => 'Sin City', :limit => 1)
|
45
67
|
|
46
|
-
Find a single movie by it's TMDb ID
|
68
|
+
Find a single movie by it's TMDb ID:
|
47
69
|
|
48
70
|
@movie = TmdbMovie.find(:id => 187)
|
49
71
|
|
50
|
-
Find a single movie by it's IMDB ID
|
72
|
+
Find a single movie by it's IMDB ID:
|
51
73
|
|
52
74
|
@movie = TmdbMovie.find(:imdb => 'tt0401792')
|
53
75
|
|
76
|
+
Find all cast members whose names match a given string:
|
77
|
+
|
78
|
+
@actors = TmdbCast.find(:name => 'Fred')
|
79
|
+
|
80
|
+
Find an individual cast member via their TMDb ID:
|
81
|
+
|
82
|
+
@actor = TmdbCast.find(:id => 101)
|
83
|
+
|
84
|
+
|
85
|
+
=== Item information
|
86
|
+
|
87
|
+
To find out more about the information each object offers on retrieved items have a look at the {TMDb API Docs}[http://api.themoviedb.org/2.1]. For the most accurate information about the information available have a look at the data directly through ruby-tmdb by calling @item.raw_data.inspect
|
88
|
+
|
54
89
|
=== Author & Credits
|
55
90
|
|
56
91
|
Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/ruby-tmdb/tmdb.rb
CHANGED
@@ -22,6 +22,7 @@ class Tmdb
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.api_call(method, data, language = "en")
|
25
|
+
raise ArgumentError, "Tmdb.api_key must be set before using the API" if(Tmdb.api_key.nil? || Tmdb.api_key.empty?)
|
25
26
|
url = Tmdb.base_api_url + method + '/' + language + '/yaml/' + Tmdb.api_key + '/' + CGI::escape(data.to_s)
|
26
27
|
response = Tmdb.get_url(url)
|
27
28
|
if(response.code.to_i != 200)
|
data/lib/ruby-tmdb/tmdb_cast.rb
CHANGED
@@ -32,7 +32,9 @@ class TmdbCast
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.new(raw_data, expand_results = false)
|
35
|
-
|
35
|
+
# expand the result by calling Person.getInfo unless :expand_results is set to false or the data is already complete
|
36
|
+
# (as determined by checking for the 'known_movies' property)
|
37
|
+
raw_data = Tmdb.api_call('Person.getInfo', raw_data["id"]).first if(expand_results && !raw_data.has_key?("known_movies"))
|
36
38
|
return Tmdb.data_to_object(raw_data)
|
37
39
|
end
|
38
40
|
|
data/lib/ruby-tmdb/tmdb_movie.rb
CHANGED
@@ -36,7 +36,9 @@ class TmdbMovie
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.new(raw_data, expand_results = false)
|
39
|
-
|
39
|
+
# expand the result by calling Movie.getInfo unless :expand_results is false or the data is already complete
|
40
|
+
# (as determined by checking for the trailer property in the raw data)
|
41
|
+
raw_data = Tmdb.api_call('Movie.getInfo', raw_data["id"]).first if(expand_results && !raw_data.has_key?("trailer"))
|
40
42
|
return Tmdb.data_to_object(raw_data)
|
41
43
|
end
|
42
44
|
|
data/ruby-tmdb.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ruby-tmdb}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Gough"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-20}
|
13
13
|
s.description = %q{An ActiveRecord-style API wrapper for TheMovieDB.org}
|
14
14
|
s.email = %q{aaron@aarongough.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,7 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README.rdoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
-
"
|
20
|
+
".gitignore",
|
21
|
+
"MIT-LICENSE",
|
21
22
|
"README.rdoc",
|
22
23
|
"Rakefile",
|
23
24
|
"VERSION",
|
@@ -36,9 +37,11 @@ Gem::Specification.new do |s|
|
|
36
37
|
"test/fixtures/person_get_info.txt",
|
37
38
|
"test/fixtures/person_search.txt",
|
38
39
|
"test/setup/.gitignore",
|
40
|
+
"test/setup/setup_api_key.rb",
|
39
41
|
"test/setup/test_unit_extensions.rb",
|
40
42
|
"test/setup/url_mocks.rb",
|
41
43
|
"test/test_helper.rb",
|
44
|
+
"test/unit/test_direct_require.rb",
|
42
45
|
"test/unit/tmdb_cast_test.rb",
|
43
46
|
"test/unit/tmdb_movie_test.rb",
|
44
47
|
"test/unit/tmdb_test.rb"
|
@@ -49,9 +52,11 @@ Gem::Specification.new do |s|
|
|
49
52
|
s.rubygems_version = %q{1.3.7}
|
50
53
|
s.summary = %q{An ActiveRecord-style API wrapper for TheMovieDB.org}
|
51
54
|
s.test_files = [
|
52
|
-
"test/setup/
|
55
|
+
"test/setup/setup_api_key.rb",
|
56
|
+
"test/setup/test_unit_extensions.rb",
|
53
57
|
"test/setup/url_mocks.rb",
|
54
58
|
"test/test_helper.rb",
|
59
|
+
"test/unit/test_direct_require.rb",
|
55
60
|
"test/unit/tmdb_cast_test.rb",
|
56
61
|
"test/unit/tmdb_movie_test.rb",
|
57
62
|
"test/unit/tmdb_test.rb"
|
data/test/test_helper.rb
CHANGED
@@ -2,8 +2,6 @@ TEST_LIVE_API = false
|
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'test/unit'
|
5
|
-
require 'yaml'
|
6
|
-
require 'net/http'
|
7
5
|
|
8
6
|
unless(TEST_LIVE_API)
|
9
7
|
require 'webmock/test_unit'
|
@@ -18,6 +16,5 @@ require_files.each do |file|
|
|
18
16
|
require File.expand_path(file)
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
19
|
+
#load(File.join('unit', 'test_direct_require.rb'), true)
|
20
|
+
system('ruby ' + File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'test_direct_require.rb')))
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
|
3
|
+
require_files = []
|
4
|
+
require_files << File.join(File.dirname(__FILE__), "..", "..", "lib", "ruby-tmdb.rb")
|
5
|
+
require_files.concat Dir[File.join(File.dirname(__FILE__), '..', 'setup', '*.rb')]
|
6
|
+
|
7
|
+
require_files.each do |file|
|
8
|
+
require File.expand_path(file)
|
9
|
+
end
|
10
|
+
|
11
|
+
class DirectRequireTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
test "TmdbMovie should not raise exception when directly required without using rubygems" do
|
14
|
+
assert_nothing_raised do
|
15
|
+
TmdbMovie.find(:id => 187)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "TmdbCast should not raise exception when directly required without using rubygems" do
|
20
|
+
assert_nothing_raised do
|
21
|
+
TmdbCast.find(:id => 287)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/unit/tmdb_test.rb
CHANGED
@@ -28,6 +28,15 @@ class TmdbTest < Test::Unit::TestCase
|
|
28
28
|
assert_equal 404, test_response.code.to_i
|
29
29
|
end
|
30
30
|
|
31
|
+
test "api_call should raise exception if api_key is not set" do
|
32
|
+
old_api_key = Tmdb.api_key
|
33
|
+
Tmdb.api_key = ""
|
34
|
+
assert_raises ArgumentError do
|
35
|
+
Tmdb.api_call('Movie.search', 'Transformers')
|
36
|
+
end
|
37
|
+
Tmdb.api_key = old_api_key
|
38
|
+
end
|
39
|
+
|
31
40
|
test "should perform Movie.search API call and return array of results" do
|
32
41
|
movies = Tmdb.api_call('Movie.search', 'Transformers')
|
33
42
|
assert_kind_of Array, movies
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Gough
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ extra_rdoc_files:
|
|
53
53
|
- MIT-LICENSE
|
54
54
|
- README.rdoc
|
55
55
|
files:
|
56
|
+
- .gitignore
|
56
57
|
- MIT-LICENSE
|
57
58
|
- README.rdoc
|
58
59
|
- Rakefile
|
@@ -72,9 +73,11 @@ files:
|
|
72
73
|
- test/fixtures/person_get_info.txt
|
73
74
|
- test/fixtures/person_search.txt
|
74
75
|
- test/setup/.gitignore
|
76
|
+
- test/setup/setup_api_key.rb
|
75
77
|
- test/setup/test_unit_extensions.rb
|
76
78
|
- test/setup/url_mocks.rb
|
77
79
|
- test/test_helper.rb
|
80
|
+
- test/unit/test_direct_require.rb
|
78
81
|
- test/unit/tmdb_cast_test.rb
|
79
82
|
- test/unit/tmdb_movie_test.rb
|
80
83
|
- test/unit/tmdb_test.rb
|
@@ -113,9 +116,11 @@ signing_key:
|
|
113
116
|
specification_version: 3
|
114
117
|
summary: An ActiveRecord-style API wrapper for TheMovieDB.org
|
115
118
|
test_files:
|
119
|
+
- test/setup/setup_api_key.rb
|
116
120
|
- test/setup/test_unit_extensions.rb
|
117
121
|
- test/setup/url_mocks.rb
|
118
122
|
- test/test_helper.rb
|
123
|
+
- test/unit/test_direct_require.rb
|
119
124
|
- test/unit/tmdb_cast_test.rb
|
120
125
|
- test/unit/tmdb_movie_test.rb
|
121
126
|
- test/unit/tmdb_test.rb
|