themoviedb-jzg 0.0.27

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0e3e979b9c153288e4885017159f379fc36df0c
4
+ data.tar.gz: 90b27fadfd7f0e78e6452b7454fa0379dca144ad
5
+ SHA512:
6
+ metadata.gz: 05fc5b343b81cf08ad408f0cae23ee78b6d655e0b4b823a8b3a4c161450ee32328d12baab898c8c4c1ddbe8b9ad688674687169e3230f50baa3336f8516c6ace
7
+ data.tar.gz: db9ebd64aa33e1e9501607e5f6ae068d0da7bf393e1f661f32f3dbcab7f9a7f575e65d9da72d3cfb42623feaed0761fc13f5816bda062253799c2f7d33f68caf
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'hashugar'
4
+
5
+ ["api", "search", "resource", "configuration"].each do |inc|
6
+ require File.join(File.dirname(__FILE__), "themoviedb-jzg", inc)
7
+ end
8
+
9
+ ["movie", "tv", "season", "episode", "collection", "person", "company", "genre", "find", "job"].each do |inc|
10
+ require File.join(File.dirname(__FILE__), "themoviedb-jzg", inc)
11
+ end
12
+
@@ -0,0 +1,38 @@
1
+ module Tmdb
2
+ class Api
3
+ include HTTParty
4
+ base_uri 'http://api.themoviedb.org/3/'
5
+ format :json
6
+ headers 'Accept' => 'application/json'
7
+ headers 'Content-Type' => 'application/json'
8
+
9
+ def self.config
10
+ @@config ||= {}
11
+ end
12
+
13
+ def self.key(api_key)
14
+ self.config[:api_key] = api_key
15
+ end
16
+
17
+ def self.language(lang)
18
+ if (lang.nil?)
19
+ self.config.delete(:language)
20
+ else
21
+ self.config[:language] = lang
22
+ end
23
+ end
24
+
25
+ def self.etag(etag)
26
+ headers 'If-None-Match' => '"' + etag + '"'
27
+ end
28
+
29
+ def self.response
30
+ @@response ||= {}
31
+ end
32
+
33
+ def self.set_response(hash)
34
+ @@response = hash
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,25 @@
1
+ module Tmdb
2
+ class Collection < Resource
3
+ has_resource 'collection', :plural => 'collections'
4
+
5
+ #http://docs.themoviedb.apiary.io/#collections
6
+ @@fields = [
7
+ :backdrop_path,
8
+ :id,
9
+ :name,
10
+ :parts,
11
+ :poster_path
12
+ ]
13
+
14
+ @@fields.each do |field|
15
+ attr_accessor field
16
+ end
17
+
18
+ #Get all of the images for a particular collection by collection id.
19
+ def self.images(id, conditions={})
20
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
21
+ search.fetch_response
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module Tmdb
2
+ class Company < Resource
3
+ has_resource 'company', :plural => 'companies'
4
+
5
+ #http://docs.themoviedb.apiary.io/#companies
6
+ @@fields = [
7
+ :description,
8
+ :headquarters,
9
+ :homepage,
10
+ :id,
11
+ :logo_path,
12
+ :name,
13
+ :parent_company
14
+ ]
15
+
16
+ @@fields.each do |field|
17
+ attr_accessor field
18
+ end
19
+
20
+ #Get the list of movies associated with a particular company.
21
+ def self.movies(id, conditions={})
22
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/movies")
23
+ search.fetch
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,50 @@
1
+ module Tmdb
2
+ class Configuration
3
+ def initialize()
4
+ @params = {}
5
+ @resource = '/configuration'
6
+ self
7
+ end
8
+
9
+ # To build an image URL, you will need 3 pieces of data.
10
+ # The base_url, size and file_path.
11
+ # Simply combine them all and you will have a fully qualified URL. Here’s an example URL:
12
+ # http://cf2.imgobject.com/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg
13
+ def base_url
14
+ images_config['base_url']
15
+ end
16
+
17
+ # HTTPS
18
+ def secure_base_url
19
+ images_config['secure_base_url']
20
+ end
21
+
22
+ def poster_sizes
23
+ images_config['poster_sizes']
24
+ end
25
+
26
+ def backdrop_sizes
27
+ images_config['backdrop_sizes']
28
+ end
29
+
30
+ def profile_sizes
31
+ images_config['profile_sizes']
32
+ end
33
+
34
+ def logo_sizes
35
+ images_config['logo_sizes']
36
+ end
37
+
38
+ def fetch_response
39
+ options = @params.merge(Api.config)
40
+ response = Api.get(@resource, :query => options)
41
+ response.to_hash
42
+ end
43
+
44
+ private
45
+
46
+ def images_config
47
+ @images_config ||= fetch_response['images'] || {}
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ module Tmdb
2
+ class Episode < Resource
3
+ has_resource 'episode', :plural => 'episodes'
4
+
5
+ #Get the primary information about a TV episode by combination of a season and episode number.
6
+ def self.detail(id, season, episode, conditions={})
7
+ search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}")
8
+ search.filter(conditions)
9
+ search.fetch_response
10
+ end
11
+
12
+ #Get the TV episode cast credits by combination of season and episode number.
13
+ def self.cast(id, season, episode, conditions={})
14
+ search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}/credits")
15
+ search.fetch_response.cast
16
+ end
17
+
18
+ #Get the TV episode crew credits by combination of season and episode number.
19
+ def self.crew(id, season, episode, conditions={})
20
+ search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}/credits")
21
+ search.fetch_response.crew
22
+ end
23
+
24
+ #Get the external ids for a TV episode by comabination of a season and episode number.
25
+ def self.external_ids(id, season, episode, conditions={})
26
+ search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}/external_ids")
27
+ search.fetch_response
28
+ end
29
+
30
+ #Get the images (episode stills) for a TV episode by combination of a season and episode number.
31
+ def self.images(id, season, episode, conditions={})
32
+ search = Tmdb::Search.new("/tv/#{self.endpoint_id + id.to_s}/season/#{self.endpoint_id + season.to_s}/#{self.endpoints[:singular]}/#{self.endpoint_id + episode.to_s}/images")
33
+ search.fetch_response
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Tmdb
2
+ class Find < Resource
3
+ has_resource 'find'
4
+
5
+ def self.imdb_id(id, conditions={})
6
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
7
+ search.fetch_response(external_source: 'imdb_id')
8
+ end
9
+
10
+ def self.freebase_mid(id, conditions={})
11
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
12
+ search.fetch_response(external_source: 'freebase_mid')
13
+ end
14
+
15
+ def self.freebase_id(id, conditions={})
16
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
17
+ search.fetch_response(external_source: 'freebase_id')
18
+ end
19
+
20
+ def self.tvrage_id(id, conditions={})
21
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
22
+ search.fetch_response(external_source: 'tvrage_id')
23
+ end
24
+
25
+ def self.tvdb_id(id, conditions={})
26
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
27
+ search.fetch_response(external_source: 'tvdb_id')
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ module Tmdb
2
+ class Genre
3
+ def initialize(attributes={})
4
+ attributes.each do |key, value|
5
+ if self.respond_to?(key.to_sym)
6
+ self.instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+ end
10
+
11
+ #http://docs.themoviedb.apiary.io/#genres
12
+ @@fields = [
13
+ :id,
14
+ :page,
15
+ :total_pages,
16
+ :total_results,
17
+ :results
18
+ ]
19
+
20
+ @@fields.each do |field|
21
+ attr_accessor field
22
+ end
23
+
24
+ def self.search(query)
25
+ self.detail(self.list['genres'].detect { |g| g['name'] == query }['id'])
26
+ end
27
+
28
+ class << self
29
+ alias_method :find, :search
30
+ end
31
+
32
+ def self.list
33
+ search = Tmdb::Search.new("/genre/list")
34
+ search.fetch_response
35
+ end
36
+
37
+ def self.detail(id, conditions={})
38
+ url = "/genre/#{id}/movies"
39
+ if !conditions.empty?
40
+ url << "?"
41
+ conditions.each_with_index do |(key, value), index|
42
+ url << "#{key}=#{value}"
43
+ if index != conditions.length - 1
44
+ url << "&"
45
+ end
46
+ end
47
+ end
48
+ search = Tmdb::Search.new(url)
49
+ self.new(search.fetch_response)
50
+ end
51
+
52
+ def name
53
+ @name ||= self.class.list['genres'].detect { |g| g['id'] == @id }['name']
54
+ end
55
+
56
+ def get_page(page_number, conditions={})
57
+ if page_number != @page and page_number > 0 and page_number <= @total_pages
58
+ conditions.merge!({ :page => page_number })
59
+ self.class.detail(id, conditions)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ module Tmdb
2
+ class Job
3
+ def initialize(attributes={})
4
+ attributes.each do |key, value|
5
+ if self.respond_to?(key.to_sym)
6
+ self.instance_variable_set("@#{key}", value)
7
+ end
8
+ end
9
+ end
10
+
11
+ # http://docs.themoviedb.apiary.io/#jobs
12
+ @@fields = [
13
+ :name,
14
+ :department
15
+ ]
16
+
17
+ @@fields.each do |field|
18
+ attr_accessor field
19
+ end
20
+
21
+ def self.list
22
+ search = Tmdb::Search.new("/job/list")
23
+ search.fetch_response
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,161 @@
1
+ module Tmdb
2
+ class Movie < Resource
3
+ has_resource 'movie', :plural => 'movies'
4
+
5
+ #http://docs.themoviedb.apiary.io/#movies
6
+ @@fields = [
7
+ :adult,
8
+ :backdrop_path,
9
+ :belongs_to_collection,
10
+ :budget,
11
+ :genres,
12
+ :homepage,
13
+ :id,
14
+ :imdb_id,
15
+ :original_title,
16
+ :overview,
17
+ :popularity,
18
+ :poster_path,
19
+ :production_companies,
20
+ :production_countries,
21
+ :release_date,
22
+ :revenue,
23
+ :runtime,
24
+ :spoken_languages,
25
+ :status,
26
+ :tagline,
27
+ :title,
28
+ :vote_average,
29
+ :vote_count,
30
+ :alternative_titles,
31
+ :credits,
32
+ :images,
33
+ :keywords,
34
+ :releases,
35
+ :trailers,
36
+ :translations,
37
+ :reviews,
38
+ :lists,
39
+ :changes
40
+ ]
41
+
42
+ @@fields.each do |field|
43
+ attr_accessor field
44
+ end
45
+
46
+ #Get the latest movie id. singular
47
+ def self.latest
48
+ search = Tmdb::Search.new("/movie/latest")
49
+ search.fetch_response
50
+ end
51
+
52
+ #Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100.
53
+ def self.upcoming
54
+ search = Tmdb::Search.new("/movie/upcoming")
55
+ search.fetch
56
+ end
57
+
58
+ #Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100.
59
+ def self.now_playing
60
+ search = Tmdb::Search.new("/movie/now_playing")
61
+ search.fetch
62
+ end
63
+
64
+ #Get the list of popular movies on The Movie Database. This list refreshes every day.
65
+ def self.popular
66
+ search = Tmdb::Search.new("/movie/popular")
67
+ search.fetch
68
+ end
69
+
70
+ #Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day.
71
+ def self.top_rated
72
+ search = Tmdb::Search.new("/movie/top_rated")
73
+ search.fetch
74
+ end
75
+
76
+ #Discover movies by different types of data like average rating, number of votes, genres and certifications.
77
+ def self.discover(conditions={})
78
+ search = Tmdb::Search.new("/discover/movie")
79
+ search.filter(conditions)
80
+ search.fetch
81
+ end
82
+
83
+ #Get the alternative titles for a specific movie id.
84
+ def self.alternative_titles(id, conditions={})
85
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/alternative_titles")
86
+ search.fetch_response
87
+ end
88
+
89
+ #Get the cast information for a specific movie id.
90
+ def self.casts(id, conditions={})
91
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/casts")
92
+ search.fetch_response.cast
93
+ end
94
+
95
+ #Get the cast information for a specific movie id.
96
+ def self.crew(id, conditions={})
97
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/casts")
98
+ search.fetch_response.crew
99
+ end
100
+
101
+ #Get the images (posters and backdrops) for a specific movie id.
102
+ def self.images(id, conditions={})
103
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
104
+ search.fetch_response
105
+ end
106
+
107
+ #Get the plot keywords for a specific movie id.
108
+ def self.keywords(id, conditions={})
109
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/keywords")
110
+ search.fetch_response
111
+ end
112
+
113
+ #Get the release date by country for a specific movie id.
114
+ def self.releases(id, conditions={})
115
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/releases")
116
+ search.fetch_response
117
+ end
118
+
119
+ #Get the trailers for a specific movie id.
120
+ def self.trailers(id, conditions={})
121
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/trailers")
122
+ search.fetch_response
123
+ end
124
+
125
+ #Get the translations for a specific movie id.
126
+ def self.translations(id, conditions={})
127
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/translations")
128
+ search.fetch_response
129
+ end
130
+
131
+ #Get the similar movies for a specific movie id.
132
+ def self.similar_movies(id, conditions={})
133
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar_movies")
134
+ search.filter(conditions)
135
+ search.fetch
136
+ end
137
+
138
+ #Get the lists that the movie belongs to.
139
+ def self.lists(id, conditions={})
140
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/lists")
141
+ search.fetch_response
142
+ end
143
+
144
+ #Get the changes for a specific movie id.
145
+ #Changes are grouped by key, and ordered by date in descending order.
146
+ #By default, only the last 24 hours of changes are returned.
147
+ #The maximum number of days that can be returned in a single request is 14.
148
+ #The language is present on fields that are translatable.
149
+ def self.changes(id, conditions={})
150
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
151
+ search.fetch_response
152
+ end
153
+
154
+ #Get the credits for a specific movie id.
155
+ def self.credits(id, conditions={})
156
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/credits")
157
+ search.fetch_response
158
+ end
159
+
160
+ end
161
+ end