themoviedb 0.0.1

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjNlMzNkYTk3N2JjMGFlMDU5NGNmNDlhODY2NDM3NmRhNjE1NDExMQ==
5
+ data.tar.gz: !binary |-
6
+ YzE0Mzk1NTMzZmI4ZGY2OTdkNDZkZWJlZjQwNTgzYWVlYmJlNzg2ZA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGI0MjJiNjEzYjY4MTcyNjEyOTI4MzM1M2Y1OTdhMmNkOTg2M2Q1YmIzZmIz
10
+ MDY4YWY3YjhkZTIzMmM3M2VhOGZkNjk4ZDBhMmJkOTdhN2ZhZDI3OGI2ZmIx
11
+ ZjY3YTVlMTkwNGE3MGM2MjEwOTExZGY1YjdkMGUxMzhiMzEwY2I=
12
+ data.tar.gz: !binary |-
13
+ MGE3OTRmYWI4MjU5YTgwNDI3YTQ0NmZmNmViYzU1MDYyNmI2N2MwM2VmM2Y4
14
+ OTE0Nzk1OWZjNzlkN2RjMTRjY2U1NjM0NmI0NzBhYzc0MWUwZTg4Yzg5OTJi
15
+ YTlhY2JjNDZiNTAxZDI0NjJmZDUwNjM0OGRlYWI4Y2M5NGZlMDE=
@@ -0,0 +1,17 @@
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
+
8
+ def self.config
9
+ @@config
10
+ end
11
+
12
+ def self.key(api_key)
13
+ @@config = { :api_key => api_key }
14
+ end
15
+
16
+ end
17
+ 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,44 @@
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
+ fetch_response['images']['base_url']
15
+ end
16
+
17
+ # HTTPS
18
+ def secure_base_url
19
+ fetch_response['images']['secure_base_url']
20
+ end
21
+
22
+ def poster_sizes
23
+ fetch_response['images']['poster_sizes']
24
+ end
25
+
26
+ def backdrop_sizes
27
+ fetch_response['images']['backdrop_sizes']
28
+ end
29
+
30
+ def profile_sizes
31
+ fetch_response['images']['profile_sizes']
32
+ end
33
+
34
+ def logo_sizes
35
+ fetch_response['images']['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
+ end
44
+ end
@@ -0,0 +1,131 @@
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
+ ]
31
+
32
+ @@fields.each do |field|
33
+ attr_accessor field
34
+ end
35
+
36
+ #Get the latest movie id. singular
37
+ def self.latest
38
+ search = Tmdb::Search.new("/movie/latest")
39
+ search.fetch_response
40
+ end
41
+
42
+ #Get the list of upcoming movies. This list refreshes every day. The maximum number of items this list will include is 100.
43
+ def self.upcoming
44
+ search = Tmdb::Search.new("/movie/upcoming")
45
+ search.fetch
46
+ end
47
+
48
+ #Get the list of movies playing in theatres. This list refreshes every day. The maximum number of items this list will include is 100.
49
+ def self.now_playing
50
+ search = Tmdb::Search.new("/movie/now_playing")
51
+ search.fetch
52
+ end
53
+
54
+ #Get the list of popular movies on The Movie Database. This list refreshes every day.
55
+ def self.popular
56
+ search = Tmdb::Search.new("/movie/popular")
57
+ search.fetch
58
+ end
59
+
60
+ #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.
61
+ def self.top_rated
62
+ search = Tmdb::Search.new("/movie/top_rated")
63
+ search.fetch
64
+ end
65
+
66
+ #Get the alternative titles for a specific movie id.
67
+ def self.alternative_titles(id, conditions={})
68
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/alternative_titles")
69
+ search.fetch_response
70
+ end
71
+
72
+ #Get the cast information for a specific movie id.
73
+ def self.casts(id, conditions={})
74
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/casts")
75
+ search.fetch_response
76
+ end
77
+
78
+ #Get the images (posters and backdrops) for a specific movie id.
79
+ def self.images(id, conditions={})
80
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
81
+ search.fetch_response
82
+ end
83
+
84
+ #Get the plot keywords for a specific movie id.
85
+ def self.keywords(id, conditions={})
86
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/keywords")
87
+ search.fetch_response
88
+ end
89
+
90
+ #Get the release date by country for a specific movie id.
91
+ def self.releases(id, conditions={})
92
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/releases")
93
+ search.fetch_response
94
+ end
95
+
96
+ #Get the trailers for a specific movie id.
97
+ def self.trailers(id, conditions={})
98
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/trailers")
99
+ search.fetch_response
100
+ end
101
+
102
+ #Get the translations for a specific movie id.
103
+ def self.translations(id, conditions={})
104
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/translations")
105
+ search.fetch_response
106
+ end
107
+
108
+ #Get the similar movies for a specific movie id.
109
+ def self.similar_movies(id, conditions={})
110
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar_movies")
111
+ search.fetch_response
112
+ end
113
+
114
+ #Get the lists that the movie belongs to.
115
+ def self.lists(id, conditions={})
116
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/lists")
117
+ search.fetch_response
118
+ end
119
+
120
+ #Get the changes for a specific movie id.
121
+ #Changes are grouped by key, and ordered by date in descending order.
122
+ #By default, only the last 24 hours of changes are returned.
123
+ #The maximum number of days that can be returned in a single request is 14.
124
+ #The language is present on fields that are translatable.
125
+ def self.changes(id, conditions={})
126
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
127
+ search.fetch_response
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,57 @@
1
+ module Tmdb
2
+ class People < Resource
3
+ has_resource 'person', :plural => 'persons'
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
+ ]
18
+
19
+ @@fields.each do |field|
20
+ attr_accessor field
21
+ end
22
+
23
+ #Get the list of popular people on The Movie Database. This list refreshes every day.
24
+ def self.popular
25
+ search = Tmdb::Search.new("/people/popular")
26
+ search.fetch
27
+ end
28
+
29
+ #Get the latest person id.
30
+ def self.latest
31
+ search = Tmdb::Search.new("/people/latest")
32
+ search.fetch_response
33
+ end
34
+
35
+ #Get the credits for a specific person id.
36
+ def self.credits(id, conditions={})
37
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/credits")
38
+ search.fetch_response
39
+ end
40
+
41
+ #Get the images for a specific person id.
42
+ def self.images(id, conditions={})
43
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
44
+ search.fetch_response
45
+ end
46
+
47
+ #Get the changes for a specific person id.
48
+ #Changes are grouped by key, and ordered by date in descending order.
49
+ #By default, only the last 24 hours of changes are returned.
50
+ #The maximum number of days that can be returned in a single request is 14. The language is present on fields that are translatable.
51
+ def self.changes(id, conditions={})
52
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
53
+ search.fetch_response
54
+ end
55
+
56
+ end
57
+ 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
+ self.new(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,53 @@
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 resource(resource)
15
+ if resource == 'movie' then
16
+ @resource = '/search/movie'
17
+ elsif resource == 'collection' then
18
+ @resource = '/search/collection'
19
+ elsif resource == 'person' then
20
+ @resource = '/search/person'
21
+ elsif resource == 'list' then
22
+ @resource = '/search/list'
23
+ elsif resource == 'company' then
24
+ @resource = '/search/company'
25
+ elsif resource == 'keyword' then
26
+ @resource = '/search/keyword'
27
+ end
28
+ self
29
+ end
30
+
31
+ def filter(conditions)
32
+ if conditions
33
+ conditions.each do |key, value|
34
+ if self.respond_to?(key)
35
+ self.send(key, value)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ #Sends back main data
42
+ def fetch()
43
+ fetch_response['results']
44
+ end
45
+
46
+ #Send back whole response
47
+ def fetch_response
48
+ options = @params.merge(Api.config)
49
+ response = Api.get(@resource, :query => options)
50
+ response.to_hash
51
+ end
52
+ end
53
+ end
data/lib/themoviedb.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+
4
+ ["api","search","resource", "configuration"].each do |inc|
5
+ require File.join(File.dirname(__FILE__), "themoviedb", inc)
6
+ end
7
+
8
+ ["movie", "collection", "people", "company"].each do |inc|
9
+ require File.join(File.dirname(__FILE__), "themoviedb", inc)
10
+ end
11
+
12
+ module Tmdb
13
+ VERSION = "0.0.1"
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+
3
+ class MovieTest < Test::Unit::TestCase
4
+ def setup
5
+ @movie = Tmdb::Movie.detail(22855)
6
+ end
7
+
8
+ def test_case_1
9
+ assert_equal 22855, @movie.id, "Should return a valid id"
10
+ end
11
+
12
+ def test_case_2
13
+ assert_equal "tt1398941", @movie.imdb_id, "Should return a valid imdb_id"
14
+ end
15
+
16
+ def test_case_3
17
+ assert_equal 67, @movie.runtime, "Should return runtime"
18
+ end
19
+
20
+ def test_case_4
21
+ assert_equal "/mXuqM7ksHW1AJ30AInwJvJTAwut.jpg", @movie.backdrop_path, "Should return backdrop_path"
22
+ end
23
+
24
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "themoviedb"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "themoviedb"
7
+ s.version = Tmdb::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ahmet Abdi"]
10
+ s.email = ["ahmetabdi@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/themoviedb"
12
+ s.summary = %q{A Ruby wrapper for the The Movie Database API.}
13
+ s.description = %q{Provides a simple, easy to use interface for the Movie Database API.}
14
+ s.rubyforge_project = "themoviedb"
15
+ s.files = [
16
+ "themoviedb.gemspec",
17
+ "lib/themoviedb.rb",
18
+ "lib/themoviedb/api.rb",
19
+ "lib/themoviedb/collection.rb",
20
+ "lib/themoviedb/company.rb",
21
+ "lib/themoviedb/configuration.rb",
22
+ "lib/themoviedb/movie.rb",
23
+ "lib/themoviedb/people.rb",
24
+ "lib/themoviedb/resource.rb",
25
+ "lib/themoviedb/search.rb",
26
+ "test/movie_test.rb"
27
+ ]
28
+ s.test_files = [
29
+ "test/movie_test.rb"
30
+ ]
31
+ s.require_paths = ["lib"]
32
+ s.add_dependency('httparty')
33
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: themoviedb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ahmet Abdi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Provides a simple, easy to use interface for the Movie Database API.
28
+ email:
29
+ - ahmetabdi@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - themoviedb.gemspec
35
+ - lib/themoviedb.rb
36
+ - lib/themoviedb/api.rb
37
+ - lib/themoviedb/collection.rb
38
+ - lib/themoviedb/company.rb
39
+ - lib/themoviedb/configuration.rb
40
+ - lib/themoviedb/movie.rb
41
+ - lib/themoviedb/people.rb
42
+ - lib/themoviedb/resource.rb
43
+ - lib/themoviedb/search.rb
44
+ - test/movie_test.rb
45
+ homepage: http://rubygems.org/gems/themoviedb
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: themoviedb
64
+ rubygems_version: 2.0.3
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A Ruby wrapper for the The Movie Database API.
68
+ test_files:
69
+ - test/movie_test.rb