themoviedb 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5132d9504ddeeb045fef1f6a1d71d793f964fc34
4
+ data.tar.gz: 52d2f201f5aae4384601c6fded28625e8246b115
5
+ SHA512:
6
+ metadata.gz: 9580fa9d16a5790df94a9613e4ce44610b047862883ddb2831f90cd2304601350159aeed7281deab6f40a6e291ef081fd5497d7d2b63bcb87135d018ee9d424e
7
+ data.tar.gz: cf6b0a5897793c9b6906e878fefcb22c6d91f6671ca61ff8399e2887bd72087188d319b669151de276e0afe23cc3e64e5f7ab6415e05fb15aa42a53a784ff71d
@@ -1,17 +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
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
17
  end
@@ -1,25 +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
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
25
  end
@@ -1,27 +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
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
27
  end
@@ -1,44 +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
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
44
  end
@@ -1,137 +1,137 @@
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['cast']
76
- end
77
-
78
- #Get the cast information for a specific movie id.
79
- def self.crew(id, conditions={})
80
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/casts")
81
- search.fetch_response['crew']
82
- end
83
-
84
- #Get the images (posters and backdrops) for a specific movie id.
85
- def self.images(id, conditions={})
86
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
87
- search.fetch_response['backdrops']
88
- end
89
-
90
- #Get the plot keywords for a specific movie id.
91
- def self.keywords(id, conditions={})
92
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/keywords")
93
- search.fetch_response
94
- end
95
-
96
- #Get the release date by country for a specific movie id.
97
- def self.releases(id, conditions={})
98
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/releases")
99
- search.fetch_response
100
- end
101
-
102
- #Get the trailers for a specific movie id.
103
- def self.trailers(id, conditions={})
104
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/trailers")
105
- search.fetch_response
106
- end
107
-
108
- #Get the translations for a specific movie id.
109
- def self.translations(id, conditions={})
110
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/translations")
111
- search.fetch_response
112
- end
113
-
114
- #Get the similar movies for a specific movie id.
115
- def self.similar_movies(id, conditions={})
116
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar_movies")
117
- search.fetch_response['results']
118
- end
119
-
120
- #Get the lists that the movie belongs to.
121
- def self.lists(id, conditions={})
122
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/lists")
123
- search.fetch_response
124
- end
125
-
126
- #Get the changes for a specific movie id.
127
- #Changes are grouped by key, and ordered by date in descending order.
128
- #By default, only the last 24 hours of changes are returned.
129
- #The maximum number of days that can be returned in a single request is 14.
130
- #The language is present on fields that are translatable.
131
- def self.changes(id, conditions={})
132
- search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
133
- search.fetch_response
134
- end
135
-
136
- end
137
- end
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['cast']
76
+ end
77
+
78
+ #Get the cast information for a specific movie id.
79
+ def self.crew(id, conditions={})
80
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/casts")
81
+ search.fetch_response['crew']
82
+ end
83
+
84
+ #Get the images (posters and backdrops) for a specific movie id.
85
+ def self.images(id, conditions={})
86
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/images")
87
+ search.fetch_response
88
+ end
89
+
90
+ #Get the plot keywords for a specific movie id.
91
+ def self.keywords(id, conditions={})
92
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/keywords")
93
+ search.fetch_response
94
+ end
95
+
96
+ #Get the release date by country for a specific movie id.
97
+ def self.releases(id, conditions={})
98
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/releases")
99
+ search.fetch_response
100
+ end
101
+
102
+ #Get the trailers for a specific movie id.
103
+ def self.trailers(id, conditions={})
104
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/trailers")
105
+ search.fetch_response
106
+ end
107
+
108
+ #Get the translations for a specific movie id.
109
+ def self.translations(id, conditions={})
110
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/translations")
111
+ search.fetch_response
112
+ end
113
+
114
+ #Get the similar movies for a specific movie id.
115
+ def self.similar_movies(id, conditions={})
116
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/similar_movies")
117
+ search.fetch_response['results']
118
+ end
119
+
120
+ #Get the lists that the movie belongs to.
121
+ def self.lists(id, conditions={})
122
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/lists")
123
+ search.fetch_response
124
+ end
125
+
126
+ #Get the changes for a specific movie id.
127
+ #Changes are grouped by key, and ordered by date in descending order.
128
+ #By default, only the last 24 hours of changes are returned.
129
+ #The maximum number of days that can be returned in a single request is 14.
130
+ #The language is present on fields that are translatable.
131
+ def self.changes(id, conditions={})
132
+ search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/changes")
133
+ search.fetch_response
134
+ end
135
+
136
+ end
137
+ end
@@ -1,57 +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
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
57
  end
@@ -1,58 +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
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
58
  end
@@ -1,53 +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, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
50
- response.to_hash
51
- end
52
- end
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, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
50
+ response.to_hash
51
+ end
52
+ end
53
53
  end
data/lib/themoviedb.rb CHANGED
@@ -10,5 +10,5 @@ end
10
10
  end
11
11
 
12
12
  module Tmdb
13
- VERSION = "0.0.6"
14
- end
13
+ VERSION = "0.0.7"
14
+ end
@@ -0,0 +1,190 @@
1
+
2
+ require 'rspec'
3
+ require 'spec_helper'
4
+
5
+ describe Tmdb::Movie do
6
+
7
+ @fields = [:id,:adult,:backdrop_path,:belongs_to_collection,
8
+ :budget,:genres,:homepage,:imdb_id,:original_title,
9
+ :overview,:popularity,:poster_path,:production_companies,
10
+ :production_countries,:release_date,:revenue,:runtime,
11
+ :spoken_languages,:status,:tagline,:title,:vote_average,
12
+ :vote_count]
13
+
14
+ @fields.each do |field|
15
+ it { should respond_to field }
16
+ end
17
+
18
+ describe "For a movie" do
19
+ before(:each) do
20
+ @movie = Tmdb::Movie
21
+ end
22
+
23
+ it "should return the latest movies" do
24
+ @movie.latest.should be_true
25
+ end
26
+
27
+ it "should return the upcoming movies" do
28
+ @movie.upcoming.should be_true
29
+ end
30
+
31
+ it "should show movies that are now playing" do
32
+ @movie.now_playing.should be_true
33
+ end
34
+
35
+ it "should return popular movies" do
36
+ @movie.popular.should be_true
37
+ end
38
+
39
+ it "should return top rated movies" do
40
+ @movie.top_rated.should be_true
41
+ end
42
+
43
+ it "should return alternative titles for an ID" do
44
+ @movie.alternative_titles(5).should be_true
45
+ end
46
+
47
+ it "should return cast information for an ID" do
48
+ @movie.casts(5).should be_true
49
+ end
50
+
51
+ it "should return crew for an ID" do
52
+ @movie.crew(5).should be_true
53
+ end
54
+ it "should return keywords for an ID" do
55
+ @movie.keywords(5).should be_true
56
+ end
57
+ it "should return releases for an ID" do
58
+ @movie.releases(5).should be_true
59
+ end
60
+
61
+ it "should return trailers for an ID" do
62
+ @movie.trailers(5).should be_true
63
+ end
64
+
65
+ it "should return translations for an ID" do
66
+ @movie.translations(5).should be_true
67
+ end
68
+
69
+ it "should return similar_movies for an ID" do
70
+ @movie.similar_movies(5).should be_true
71
+ end
72
+
73
+ it "should return the list the movie belongs to" do
74
+ @movie.lists(5).should be_true
75
+ end
76
+
77
+ it "should return the changes made" do
78
+ @movie.changes(5).should be_true
79
+ end
80
+ end
81
+
82
+ describe "For a movie detail" do
83
+
84
+ before(:each) do
85
+ @movie = Tmdb::Movie.detail(22855)
86
+ end
87
+
88
+ it "should return a id" do
89
+ @movie.id.should == 22855
90
+ end
91
+
92
+ it "should return a adult" do
93
+ @movie.adult.should == false
94
+ end
95
+
96
+ it "should return a backdrop_path" do
97
+ @movie.backdrop_path.should == "/mXuqM7ksHW1AJ30AInwJvJTAwut.jpg"
98
+ end
99
+
100
+ it "should return a belongs_to_collection" do
101
+ @movie.belongs_to_collection.should == {"id"=>51845, "name"=>"DC Universe Animated Original Movies", "poster_path"=>"/qB1Qe5qIbHvr3NsH9xKwCi6WHMn.jpg", "backdrop_path"=>"/3DMJMsy8Yo1LjgFckXIAnHgLo9O.jpg"}
102
+ end
103
+
104
+ it "should return a budget" do
105
+ @movie.budget.should == 0
106
+ end
107
+
108
+ it "should return genres" do
109
+ @movie.genres.should == [{"id"=>28, "name"=>"Action"}, {"id"=>12, "name"=>"Adventure"}, {"id"=>16, "name"=>"Animation"}]
110
+ end
111
+
112
+ it "should return homepage" do
113
+ @movie.homepage.should == "http://www.warnervideo.com/supermanbatmandvd/"
114
+ end
115
+
116
+ it "should return a imdb_id" do
117
+ @movie.imdb_id.should == "tt1398941"
118
+ end
119
+
120
+ it "should return a original_title" do
121
+ @movie.original_title.should == "Superman/Batman: Public Enemies"
122
+ end
123
+
124
+ it "should return a overview" do
125
+ @movie.overview.should == "United States President Lex Luthor uses the oncoming trajectory of a Kryptonite meteor to frame Superman and declare a $1 billion bounty on the heads of the Man of Steel and his ‘partner in crime’, Batman. Heroes and villains alike launch a relentless pursuit of Superman and Batman, who must unite—and recruit help—to try and stave off the action-packed onslaught, stop the meteor Luthors plot."
126
+ end
127
+
128
+ it "should return popularity" do
129
+ @movie.popularity.should == 1.04449268
130
+ end
131
+
132
+ it "should return poster_path" do
133
+ @movie.poster_path.should == "/7eaHkUKAzfstt6XQCiXyuKiZUAw.jpg"
134
+ end
135
+
136
+ it "should return production_companies" do
137
+ @movie.production_companies.should == [{"name"=>"DC Comics", "id"=>429}, {"name"=>"Warner Premiere", "id"=>4811}]
138
+ end
139
+
140
+ it "should return production_countries" do
141
+ @movie.production_countries.should == [{"iso_3166_1"=>"US", "name"=>"United States of America"}]
142
+ end
143
+
144
+ it "should return release_date" do
145
+ @movie.release_date.should == "2009-09-29"
146
+ end
147
+
148
+ it "should return revenue" do
149
+ @movie.revenue.should == 0
150
+ end
151
+
152
+ it "should return a runtime" do
153
+ @movie.runtime.should == 67
154
+ end
155
+
156
+ it "should return spoken_languages" do
157
+ @movie.spoken_languages.should == [{"iso_639_1"=>"en", "name"=>"English"}]
158
+ end
159
+
160
+ it "should return status" do
161
+ @movie.status.should == "Released"
162
+ end
163
+
164
+ it "should return vote_average" do
165
+ @movie.vote_average.should == 7.4
166
+ end
167
+
168
+ it "should return vote_count" do
169
+ @movie.vote_count.should == 11
170
+ end
171
+ end
172
+
173
+ describe "For a movies images" do
174
+
175
+ before(:each) do
176
+ @movie = Tmdb::Movie.images(22855)
177
+ end
178
+
179
+ it "should return backdrops" do
180
+ @movie['backdrops'].should be_true
181
+ end
182
+
183
+ it "should return posters" do
184
+ @movie['posters'].should be_true
185
+ end
186
+
187
+ end
188
+
189
+
190
+ end
data/themoviedb.gemspec CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
  "lib/themoviedb/people.rb",
25
25
  "lib/themoviedb/resource.rb",
26
26
  "lib/themoviedb/search.rb",
27
- "test/movie_test.rb"
27
+ "spec/movie_spec.rb"
28
28
  ]
29
29
  s.test_files = [
30
- "test/movie_test.rb"
30
+ "spec/movie_spec.rb"
31
31
  ]
32
32
  s.require_paths = ["lib"]
33
33
  s.add_dependency('httparty')
34
- end
34
+ end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themoviedb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ahmet Abdi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-03 00:00:00.000000000 Z
11
+ date: 2013-07-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Provides a simple, easy to use interface for the Movie Database API.
@@ -45,30 +42,29 @@ files:
45
42
  - lib/themoviedb/people.rb
46
43
  - lib/themoviedb/resource.rb
47
44
  - lib/themoviedb/search.rb
48
- - test/movie_test.rb
45
+ - spec/movie_spec.rb
49
46
  homepage: http://rubygems.org/gems/themoviedb
50
47
  licenses: []
48
+ metadata: {}
51
49
  post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
- - - ! '>='
55
+ - - '>='
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
- - - ! '>='
60
+ - - '>='
65
61
  - !ruby/object:Gem::Version
66
62
  version: '0'
67
63
  requirements: []
68
64
  rubyforge_project: themoviedb
69
- rubygems_version: 1.8.24
65
+ rubygems_version: 2.0.0.rc.2
70
66
  signing_key:
71
- specification_version: 3
67
+ specification_version: 4
72
68
  summary: A Ruby wrapper for the The Movie Database API.
73
69
  test_files:
74
- - test/movie_test.rb
70
+ - spec/movie_spec.rb
data/test/movie_test.rb DELETED
@@ -1,24 +0,0 @@
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