themoviedb-jzg 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/themoviedb-jzg.rb +12 -0
- data/lib/themoviedb-jzg/api.rb +38 -0
- data/lib/themoviedb-jzg/collection.rb +25 -0
- data/lib/themoviedb-jzg/company.rb +27 -0
- data/lib/themoviedb-jzg/configuration.rb +50 -0
- data/lib/themoviedb-jzg/episode.rb +37 -0
- data/lib/themoviedb-jzg/find.rb +31 -0
- data/lib/themoviedb-jzg/genre.rb +63 -0
- data/lib/themoviedb-jzg/job.rb +26 -0
- data/lib/themoviedb-jzg/movie.rb +161 -0
- data/lib/themoviedb-jzg/person.rb +86 -0
- data/lib/themoviedb-jzg/resource.rb +58 -0
- data/lib/themoviedb-jzg/search.rb +79 -0
- data/lib/themoviedb-jzg/season.rb +37 -0
- data/lib/themoviedb-jzg/tv.rb +82 -0
- data/lib/themoviedb-jzg/version.rb +3 -0
- data/spec/company_spec.rb +97 -0
- data/spec/find_spec.rb +31 -0
- data/spec/movie_spec.rb +316 -0
- data/spec/person_spec.rb +145 -0
- data/spec/tv_spec.rb +458 -0
- data/themoviedb-jzg.gemspec +52 -0
- metadata +154 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
module Tmdb
|
2
|
+
class Person < Resource
|
3
|
+
has_resource 'person', :plural => 'people'
|
4
|
+
|
5
|
+
#http://docs.themoviedb.apiary.io/#people
|
6
|
+
@@fields = [
|
7
|
+
:adult,
|
8
|
+
:also_known_as,
|
9
|
+
:biography,
|
10
|
+
:birthday,
|
11
|
+
:deathday,
|
12
|
+
:homepage,
|
13
|
+
:id,
|
14
|
+
:name,
|
15
|
+
:place_of_birth,
|
16
|
+
:profile_path,
|
17
|
+
:movie_credits,
|
18
|
+
:tv_credits,
|
19
|
+
:combined_credits,
|
20
|
+
:images,
|
21
|
+
:changes
|
22
|
+
]
|
23
|
+
|
24
|
+
@@fields.each do |field|
|
25
|
+
attr_accessor field
|
26
|
+
end
|
27
|
+
|
28
|
+
#Get the list of popular people on The Movie Database. This list refreshes every day.
|
29
|
+
def self.popular
|
30
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/popular")
|
31
|
+
search.fetch
|
32
|
+
end
|
33
|
+
|
34
|
+
#Get the latest person id.
|
35
|
+
def self.latest
|
36
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/latest")
|
37
|
+
search.fetch_response
|
38
|
+
end
|
39
|
+
|
40
|
+
#Get the combined credits for a specific person id.
|
41
|
+
def self.credits(id, conditions={})
|
42
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/combined_credits")
|
43
|
+
search.fetch_response
|
44
|
+
end
|
45
|
+
|
46
|
+
#Get film credits for a specific person id.
|
47
|
+
def self.movie_credits(id, conditions={})
|
48
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/movie_credits")
|
49
|
+
search.fetch_response
|
50
|
+
end
|
51
|
+
|
52
|
+
#Get TV credits for a specific person id.
|
53
|
+
def self.tv_credits(id, conditions={})
|
54
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/tv_credits")
|
55
|
+
search.fetch_response
|
56
|
+
end
|
57
|
+
|
58
|
+
#Get external ID's for a specific person id.
|
59
|
+
def self.external_ids(id, conditions={})
|
60
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/external_ids")
|
61
|
+
search.fetch_response
|
62
|
+
end
|
63
|
+
|
64
|
+
#Get the images for a specific person id.
|
65
|
+
def self.images(id, conditions={})
|
66
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
|
67
|
+
search.fetch_response
|
68
|
+
end
|
69
|
+
|
70
|
+
#Get the tagged images for a specific person id.
|
71
|
+
def self.tagged_images(id, conditions={})
|
72
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/tagged_images")
|
73
|
+
search.fetch_response
|
74
|
+
end
|
75
|
+
|
76
|
+
#Get the changes for a specific person id.
|
77
|
+
#Changes are grouped by key, and ordered by date in descending order.
|
78
|
+
#By default, only the last 24 hours of changes are returned.
|
79
|
+
#The maximum number of days that can be returned in a single request is 14. The language is present on fields that are translatable.
|
80
|
+
def self.changes(id, conditions={})
|
81
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
|
82
|
+
search.fetch_response
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Tmdb
|
2
|
+
class Resource
|
3
|
+
@@endpoints = {}
|
4
|
+
@@endpoint_id = {}
|
5
|
+
|
6
|
+
def self.has_resource(singular=nil, opts={})
|
7
|
+
@@endpoints[self.name.downcase] = {
|
8
|
+
:singular => singular.nil? ? "#{self.name.downcase}" : singular,
|
9
|
+
:plural => opts[:plural].nil? ? "#{self.name.downcase}s" : opts[:plural]
|
10
|
+
}
|
11
|
+
@@endpoint_id[self.name.downcase] = opts[:id].nil? ? "" : "#{opts[:id]}-"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.endpoints
|
15
|
+
@@endpoints[self.name.downcase]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.endpoint_id
|
19
|
+
@@endpoint_id[self.name.downcase]
|
20
|
+
end
|
21
|
+
|
22
|
+
#Get the basic resource information for a specific id.
|
23
|
+
def self.detail(id, conditions={})
|
24
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
|
25
|
+
search.filter(conditions)
|
26
|
+
search.fetch_response
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.list(conditions={})
|
30
|
+
search = Tmdb::Search.new("/#{self.endpoints[:plural]}")
|
31
|
+
search.filter(conditions)
|
32
|
+
search.fetch.collect do |result|
|
33
|
+
self.new(result)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.search(query)
|
38
|
+
search = Tmdb::Search.new
|
39
|
+
search.resource("#{self.endpoints[:singular]}")
|
40
|
+
search.query(query)
|
41
|
+
search.fetch.collect do |result|
|
42
|
+
self.new(result)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
alias_method :find, :search
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize(attributes={})
|
51
|
+
attributes.each do |key, value|
|
52
|
+
if self.respond_to?(key.to_sym)
|
53
|
+
self.instance_variable_set("@#{key}", value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Tmdb
|
2
|
+
class Search
|
3
|
+
def initialize(resource=nil)
|
4
|
+
@params = {}
|
5
|
+
@resource = resource.nil? ? '/search/movie' : resource
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def query(query)
|
10
|
+
@params[:query] = "#{query}"
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def year(year)
|
15
|
+
@params[:year] = "#{year}"
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def primary_realease_year(year)
|
20
|
+
@params[:primary_release_year] = "#{year}"
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def resource(resource)
|
25
|
+
@resource = case resource
|
26
|
+
when 'movie'
|
27
|
+
'/search/movie'
|
28
|
+
when 'collection'
|
29
|
+
'/search/collection'
|
30
|
+
when 'tv'
|
31
|
+
'/search/tv'
|
32
|
+
when 'person'
|
33
|
+
'/search/person'
|
34
|
+
when 'list'
|
35
|
+
'/search/list'
|
36
|
+
when 'company'
|
37
|
+
'/search/company'
|
38
|
+
when 'keyword'
|
39
|
+
'/search/keyword'
|
40
|
+
when 'find'
|
41
|
+
'/find'
|
42
|
+
end
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def filter(conditions)
|
47
|
+
if conditions
|
48
|
+
conditions.each do |key, value|
|
49
|
+
if self.respond_to?(key)
|
50
|
+
self.send(key, value)
|
51
|
+
else
|
52
|
+
@params[key] = value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
#Sends back main data
|
59
|
+
def fetch
|
60
|
+
fetch_response.results
|
61
|
+
end
|
62
|
+
|
63
|
+
#Send back whole response
|
64
|
+
def fetch_response(conditions={})
|
65
|
+
if conditions[:external_source]
|
66
|
+
options = @params.merge(Api.config.merge({external_source: conditions[:external_source]}))
|
67
|
+
else
|
68
|
+
options = @params.merge(Api.config)
|
69
|
+
end
|
70
|
+
response = Api.get(@resource, :query => options)
|
71
|
+
|
72
|
+
original_etag = response.headers.fetch('etag', '')
|
73
|
+
etag = original_etag.gsub(/"/, '')
|
74
|
+
|
75
|
+
Api.set_response({'code' => response.code, 'etag' => etag})
|
76
|
+
return response.to_hash.to_hashugar
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Tmdb
|
2
|
+
class Season < Resource
|
3
|
+
has_resource 'season', :plural => 'seasons'
|
4
|
+
|
5
|
+
#Get the primary information about a TV season by its season number.
|
6
|
+
def self.detail(id, season, conditions={})
|
7
|
+
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}")
|
8
|
+
search.filter(conditions)
|
9
|
+
search.fetch_response
|
10
|
+
end
|
11
|
+
|
12
|
+
#Get the cast credits for a TV season by season number.
|
13
|
+
def self.cast(id, season, conditions={})
|
14
|
+
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}/credits")
|
15
|
+
search.fetch_response.cast
|
16
|
+
end
|
17
|
+
|
18
|
+
#Get the crew credits for a TV season by season number.
|
19
|
+
def self.crew(id, season, conditions={})
|
20
|
+
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}/credits")
|
21
|
+
search.fetch_response.crew
|
22
|
+
end
|
23
|
+
|
24
|
+
#Get the external ids that we have stored for a TV season by season number.
|
25
|
+
def self.external_ids(id, season, conditions={})
|
26
|
+
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}/external_ids")
|
27
|
+
search.fetch_response
|
28
|
+
end
|
29
|
+
|
30
|
+
#Get the images (posters) that we have stored for a TV season by season number.
|
31
|
+
def self.images(id, season, conditions={})
|
32
|
+
search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + season.to_s}/images")
|
33
|
+
search.fetch_response
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Tmdb
|
2
|
+
class TV < Resource
|
3
|
+
has_resource 'tv', :plural => 'tv'
|
4
|
+
|
5
|
+
#http://docs.themoviedb.apiary.io/#tv
|
6
|
+
@@fields = [
|
7
|
+
:backdrop_path,
|
8
|
+
:created_by,
|
9
|
+
:episode_run_time,
|
10
|
+
:first_air_date,
|
11
|
+
:genres,
|
12
|
+
:homepage,
|
13
|
+
:id,
|
14
|
+
:in_production,
|
15
|
+
:languages,
|
16
|
+
:last_air_date,
|
17
|
+
:name,
|
18
|
+
:networks,
|
19
|
+
:number_of_episodes,
|
20
|
+
:number_of_seasons,
|
21
|
+
:original_name,
|
22
|
+
:origin_country,
|
23
|
+
:overview,
|
24
|
+
:popularity,
|
25
|
+
:poster_path,
|
26
|
+
:seasons,
|
27
|
+
:status,
|
28
|
+
:vote_average,
|
29
|
+
:vote_count,
|
30
|
+
:credits,
|
31
|
+
:external_ids
|
32
|
+
]
|
33
|
+
|
34
|
+
@@fields.each do |field|
|
35
|
+
attr_accessor field
|
36
|
+
end
|
37
|
+
|
38
|
+
#Get the list of popular TV shows. This list refreshes every day.
|
39
|
+
def self.popular
|
40
|
+
search = Tmdb::Search.new("/tv/popular")
|
41
|
+
search.fetch
|
42
|
+
end
|
43
|
+
|
44
|
+
#Get the list of top rated TV shows. By default, this list will only include TV shows that have 2 or more votes. This list refreshes every day.
|
45
|
+
def self.top_rated
|
46
|
+
search = Tmdb::Search.new("/tv/top_rated")
|
47
|
+
search.fetch
|
48
|
+
end
|
49
|
+
|
50
|
+
#Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates
|
51
|
+
def self.discover(conditions={})
|
52
|
+
search = Tmdb::Search.new("/discover/tv")
|
53
|
+
search.filter(conditions)
|
54
|
+
search.fetch
|
55
|
+
end
|
56
|
+
|
57
|
+
#Get the cast information about a TV series.
|
58
|
+
def self.cast(id, conditions={})
|
59
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/credits")
|
60
|
+
search.fetch_response.cast
|
61
|
+
end
|
62
|
+
|
63
|
+
#Get the crew information about a TV series.
|
64
|
+
def self.crew(id, conditions={})
|
65
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/credits")
|
66
|
+
search.fetch_response.crew
|
67
|
+
end
|
68
|
+
|
69
|
+
#Get the external ids that we have stored for a TV series.
|
70
|
+
def self.external_ids(id, conditions={})
|
71
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/external_ids")
|
72
|
+
search.fetch_response
|
73
|
+
end
|
74
|
+
|
75
|
+
#Get the images (posters and backdrops) for a TV series.
|
76
|
+
def self.images(id, conditions={})
|
77
|
+
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
|
78
|
+
search.fetch_response
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
describe Tmdb::Company do
|
6
|
+
|
7
|
+
@fields = [
|
8
|
+
:description,
|
9
|
+
:headquarters,
|
10
|
+
:homepage,
|
11
|
+
:id,
|
12
|
+
:logo_path,
|
13
|
+
:name,
|
14
|
+
:parent_company
|
15
|
+
]
|
16
|
+
|
17
|
+
@fields.each do |field|
|
18
|
+
it { should respond_to field }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "For a company detail" do
|
22
|
+
|
23
|
+
before(:each) do
|
24
|
+
VCR.use_cassette 'company/detail' do
|
25
|
+
@company = Tmdb::Company.detail(5)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return a id" do
|
30
|
+
@company.id.should eq(5)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have a description" do
|
34
|
+
@company.description.should eq("Columbia Pictures Industries, Inc. (CPII) is an American film production and distribution company. Columbia Pictures now forms part of the Columbia TriStar Motion Picture Group, owned by Sony Pictures Entertainment, a subsidiary of the Japanese conglomerate Sony. It is one of the leading film companies in the world, a member of the so-called Big Six. It was one of the so-called Little Three among the eight major film studios of Hollywood's Golden Age.")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have a homepage" do
|
38
|
+
@company.homepage.should eq("http://www.sonypictures.com/")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have logo" do
|
42
|
+
@company.logo_path.should eq("/mjUSfXXUhMiLAA1Zq1TfStNSoLR.png")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have a name" do
|
46
|
+
@company.name.should eq("Columbia Pictures")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "could have a parent company" do
|
50
|
+
@company.parent_company.name.should eq("Sony Pictures Entertainment")
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "For a company movies" do
|
56
|
+
before(:each) do
|
57
|
+
VCR.use_cassette 'company/movies' do
|
58
|
+
@movies = Tmdb::Company.movies(5)
|
59
|
+
@movie = @movies.first
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should give back multiple movies" do
|
64
|
+
@movies.count.should > 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have a id" do
|
68
|
+
@movie.id.should eq(97020)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have a title" do
|
72
|
+
@movie.title.should eq("RoboCop")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should have a original title" do
|
76
|
+
@movie.original_title.should eq("RoboCop")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should have a poster" do
|
80
|
+
@movie.poster_path.should eq("/xxLhczZMiJt1iRdhfkVkuMu87si.jpg")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should have a popularity rating" do
|
84
|
+
@movie.popularity.should eq(3.13451193740971)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should show whether it is an adult movie" do
|
88
|
+
@movie.adult.should eq(false)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should have a release date" do
|
92
|
+
@movie.release_date.should eq("2014-02-07")
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|