tmdb-api 0.0.4 → 0.0.5

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9b8d08a9adcc408e37d3d6cfa7e47db4ec0f8ac
4
+ data.tar.gz: 955ccb36720d7b92811f610a6427ca986927e3cc
5
+ SHA512:
6
+ metadata.gz: 91cfbbce17ba850da6cced53ef2cee5d29cb4274c97cdffae2ddc3a705b38dba141090d32ca3c1f3bf9653bdfdc5d7652de7b197379e9ae438476b240c466b83
7
+ data.tar.gz: dc80bd3e13f7240df1112a293ee6cdd292e152da9e4e6febe0b17c133a52b1e8c0efdc552b779b99ed4a56f9430c1bd4a3e4d7b654b79d6c5b0cbf69f85ead0d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The Movie Database API
2
2
 
3
- [![Build Status](https://travis-ci.org/andrielfn/tmdb-api.png)](https://travis-ci.org/andrielfn/tmdb-api)
3
+ [![Build Status](https://travis-ci.org/andrielfn/tmdb-api.png?branch=master)](https://travis-ci.org/andrielfn/tmdb-api)
4
4
  [![Code Climate](https://codeclimate.com/github/andrielfn/tmdb-api.png)](https://codeclimate.com/github/andrielfn/tmdb-api)
5
5
 
6
6
  A simple Ruby wrapper for the The Movie Database API v3.
@@ -19,7 +19,7 @@ And then execute:
19
19
 
20
20
  Or install it yourself as:
21
21
 
22
- $ gem install tmdb
22
+ $ gem install tmdb-api
23
23
 
24
24
 
25
25
  ## API Key
@@ -29,6 +29,12 @@ First of all, you need set your API Key provided by TMDb.
29
29
  TMDb.api_key = '56565958363476674e5e63643c787867'
30
30
  ```
31
31
 
32
+ Also it's possible set the API in the `TMDB_API_KEY` environment variable:
33
+
34
+ ```
35
+ export TMDB_API_KEY='56565958363476674e5e63643c787867'
36
+ ```
37
+
32
38
  ## Usage
33
39
 
34
40
  ### Find a movie by id
@@ -82,6 +88,58 @@ movie.alternative_titles(country: 'br')
82
88
  # => [{"iso_3166_1"=>"BR", "title"=>"Cidade de Deus"}]
83
89
  ```
84
90
 
91
+ ### Cast
92
+ Get the cast for a specific movie id.
93
+
94
+ ```ruby
95
+ TMDb::Movie.cast(550)
96
+ # => [
97
+ # {
98
+ # "id"=>819,
99
+ # "name"=>"Edward Norton",
100
+ # "character"=>"The Narrator",
101
+ # "order"=>0,
102
+ # "cast_id"=>4,
103
+ # "profile_path"=>"/588Hrov6wwM9WcU88nJHlw2iufN.jpg"
104
+ # },
105
+ # {
106
+ # "id"=>287,
107
+ # "name"=>"Brad Pitt",
108
+ # "character"=>"Tyler Durden",
109
+ # "order"=>1,
110
+ # "cast_id"=>5,
111
+ # "profile_path"=>"/kc3M04QQAuZ9woUvH3Ju5T7ZqG5.jpg"
112
+ # },
113
+ # {
114
+ # ...
115
+ # }
116
+ # ]
117
+
118
+ ### Crew
119
+ Get the crew for a specific movie id.
120
+
121
+ ```ruby
122
+ TMDb::Movie.crew(550)
123
+ # => [
124
+ # {
125
+ # "id"=>7469,
126
+ # "name"=>"Jim Uhls",
127
+ # "department"=>"Writing",
128
+ # "job"=>"Author",
129
+ # "profile_path"=>nil
130
+ # },
131
+ # {
132
+ # "id"=>7474,
133
+ # "name"=>"Ross Grayson Bell",
134
+ # "department"=>"Production",
135
+ # "job"=>"Producer",
136
+ # "profile_path"=>nil
137
+ # },
138
+ # {
139
+ # ...
140
+ # }
141
+ # ]
142
+
85
143
  ### Images
86
144
  Get the images (posters and backdrops) for a specific movie id.
87
145
 
@@ -132,6 +190,33 @@ TMDb::Movie.keywords(68721)
132
190
  # ]
133
191
  ```
134
192
 
193
+ ### Movie trailers
194
+
195
+ Get the trailers for a specific movie id.
196
+
197
+ ```ruby
198
+ TMDb::Movie.trailers(68721)
199
+ # => {"id"=>68721,
200
+ # "quicktime"=> [
201
+ # {
202
+ # "name"=>"Teaser"
203
+ # "sources"=> [
204
+ # {"size"=>"480p","source"=>"http://trailers.apple.com/movies/marvel/ironman3/ironman3-tlr1-m4mb0_h480p.mov"},
205
+ # {"size"=>"720p","source"=>"http://trailers.apple.com/movies/marvel/ironman3/ironman3-tlr1-m4mb0_h720p.mov"},
206
+ # {"size"=>"1080p","source"=>"http://trailers.apple.com/movies/marvel/ironman3/ironman3-tlr1-m4mb0_h1080p.mov"}
207
+ # ]
208
+ # }
209
+ # "youtube"=> [
210
+ # {
211
+ # "name"=>"Iron Man 3 Trailer 2",
212
+ # "size"=>"HD",
213
+ # "source"=>"YLorLVa95Xo",
214
+ # "type"=>"Trailer"
215
+ # }
216
+ # ]
217
+ # }
218
+ ```
219
+
135
220
  ### Movie releases
136
221
 
137
222
  Get the release date by country for a specific movie id.
@@ -171,6 +256,78 @@ TMDb::Movie.upcoming
171
256
  # ]
172
257
  ```
173
258
 
259
+ ### Find a person by ID
260
+
261
+ Get the basic person information for a specific person id.
262
+
263
+ ```ruby
264
+ TMDB::Person.find(138)
265
+ # => #<TMDb::Person:0x007ff02a081278 @adult=false, @id=138, @imdb_id="nm0000233", @name="Quentin Tarantino" ... >
266
+ ```
267
+
268
+ Available attributes: `id`, `name`, `adult`, `also_known_as`, `biography`
269
+ `birthday`, `deathday`, `homepage`, `place_of_birth`, `profile_path`, `popularity`, `imdb_id`.
270
+
271
+ ### Search people
272
+ Search for people by name.
273
+
274
+ ```ruby
275
+ TMDb::Person.search('Paul')
276
+ # => [#<TMDb::Person:0x007fb572c30558 @id=8167, @name="Paul Walker", ...>,
277
+ # #<TMDb::Person:0x007fb572c302b0 @id=5129, @name="Paul Reubens", ...>, ...]
278
+
279
+ TMDb::Person.search('Paul', page: 4)
280
+ # => [#<TMDb::Person:0x007fb572d68d80 @id=455, @name="Paul Haggis", ...>, ...]
281
+ ```
282
+ Available options are `:page` and `:include_adult`.
283
+
284
+ ### Person images
285
+
286
+ Gets the images for a specific person id.
287
+
288
+ ```ruby
289
+ TMDb::Person.images(138)
290
+ # => {"id" => 138,
291
+ # "profiles" => [
292
+ # {
293
+ # "file_path" => "/iws3gBdQJ6tF7x6CIpepYfUKc58.jpg",
294
+ # "width" => 1000,
295
+ # "height" => 1500,
296
+ # "iso_639_1" => nil,
297
+ # "aspect_ratio" => 0.67
298
+ # },
299
+ # {
300
+ # "file_path" => "/ubJ3VWz1Zr7dempsJGH8lgREkrS.jpg",
301
+ # "width" => 399,
302
+ # "height" => 599,
303
+ # "iso_639_1" => nil,
304
+ # "aspect_ratio" => 0.67
305
+ # }]
306
+ # }
307
+ ```
308
+
309
+ ### Popular people
310
+
311
+ Gets a list of popular people.
312
+
313
+ ```ruby
314
+ TMDb::Person.popular
315
+ # => [
316
+ # #<TMDb::Person:0x007ff0289d1550
317
+ # @adult=false,
318
+ # @id=18918,
319
+ # @name="Dwayne Johnson",
320
+ # @popularity=27.5754694040027,
321
+ # @profile_path="/gQIWcpYo2W4MHw8UhTP2cW0jojF.jpg">,
322
+ # #<TMDb::Person:0x007ff0289d1208
323
+ # @adult=false,
324
+ # @id=12835,
325
+ # @name="Vin Diesel",
326
+ # @popularity=20.5472519159021,
327
+ # @profile_path="/qwyfzMKIhxJ7ols66FgEf7eGdcI.jpg">
328
+ # ]
329
+ ```
330
+
174
331
  ## Contributing
175
332
 
176
333
  1. Fork it
@@ -5,6 +5,7 @@ require 'tmdb-api/httparty'
5
5
 
6
6
  require 'tmdb-api/base'
7
7
  require 'tmdb-api/searchable'
8
+ require 'tmdb-api/inflections'
8
9
 
9
10
  require 'tmdb-api/movie'
10
11
  require 'tmdb-api/genre'
@@ -12,13 +13,19 @@ require 'tmdb-api/production_company'
12
13
  require 'tmdb-api/production_country'
13
14
  require 'tmdb-api/spoken_language'
14
15
  require 'tmdb-api/changes'
16
+ require 'tmdb-api/person'
15
17
 
16
18
  require 'tmdb-api/version'
17
19
 
18
20
  module TMDb
19
21
  class << self
20
- # Set the API Key that will be use to fetch the data.
21
- attr_accessor :api_key
22
+ # Set the API Key that will be use to fetch the data or
23
+ # retrieve it from the environment variable $TMDB_API_KEY.
24
+ attr_writer :api_key
25
+
26
+ def api_key
27
+ @api_key || ENV['TMDB_API_KEY']
28
+ end
22
29
 
23
30
  # Set the default language of the fetched data.
24
31
  attr_accessor :default_language
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext/string'
2
+ require "pry"
2
3
 
3
4
  module TMDb
4
5
  class Base
@@ -38,11 +39,20 @@ module TMDb
38
39
  # Returns nothing
39
40
  def load(attributes)
40
41
  attributes.each do |key, value|
41
- value = build_objects(key, value) if value.is_a?(Array)
42
+ value = build_objects(key, value) if candidate_to_object?(value)
42
43
  self.instance_variable_set("@#{key}", value)
43
44
  end
44
45
  end
45
46
 
47
+ # Internal: Verifies if the value is an array of hashs.
48
+ #
49
+ # value - value to be evaluated
50
+ #
51
+ # Returns true or false
52
+ def candidate_to_object?(value)
53
+ value.is_a?(Array) && value.all? { |h| h.is_a?(Hash) }
54
+ end
55
+
46
56
  # Internal: Builds objects for the nested resources from API.
47
57
  #
48
58
  # key - attribute related to the object (ex: genres, spoken_languages).
@@ -0,0 +1,3 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ inflect.uncountable %w( also_known_as )
3
+ end
@@ -40,6 +40,34 @@ module TMDb
40
40
  res.success? ? res['titles'] : bad_response(res)
41
41
  end
42
42
 
43
+ # Public: Get the cast for a specific movie ID.
44
+ #
45
+ # options - The hash options used to filter the search (default: {}):
46
+ # :language - Images of a specific language (ISO 639-1 code).
47
+ #
48
+ # Examples
49
+ #
50
+ # TMDb::Movie.cast(68721, language: pt)
51
+
52
+ def self.cast(id, options = {})
53
+ res = get("/movie/#{id}/casts", query: options)
54
+ res.success? ? res['cast'] : bad_response(res)
55
+ end
56
+
57
+ # Public: Get the crew for a specific movie ID.
58
+ #
59
+ # options - The hash options used to filter the search (default: {}):
60
+ # :language - Images of a specific language (ISO 639-1 code).
61
+ #
62
+ # Examples
63
+ #
64
+ # TMDb::Movie.crew(68721, language: pt)
65
+
66
+ def self.crew(id, options = {})
67
+ res = get("/movie/#{id}/casts", query: options)
68
+ res.success? ? res['crew'] : bad_response(res)
69
+ end
70
+
43
71
  # Public: Get the images (posters and backdrops) for a specific movie ID.
44
72
  #
45
73
  # options - The hash options used to filter the search (default: {}):
@@ -49,6 +77,7 @@ module TMDb
49
77
  #
50
78
  # TMDb::Movie.find(68721).images
51
79
  # TMDb::Movie.images(68721, language: 'pt')
80
+
52
81
  def self.images(id, options = {})
53
82
  res = get("/movie/#{id}/images", query: options)
54
83
  res.success? ? res : bad_response(res)
@@ -67,6 +96,19 @@ module TMDb
67
96
  res.success? ? res['keywords'] : bad_response(res)
68
97
  end
69
98
 
99
+ # Public: Get the trailers for a specific movie ID.
100
+ #
101
+ # options - The hash options used to filter the search (default: {}):
102
+ # :language - Images of a specific language (ISO 639-1 code).
103
+ #
104
+ # Examples
105
+ #
106
+ # TMDb::Movie.trailers(68721, language: pt)
107
+ def self.trailers(id, options = {})
108
+ res = get("/movie/#{id}/trailers", query: options)
109
+ res.success? ? res : bad_response(res)
110
+ end
111
+
70
112
  # Public: Get the release date by country for a specific movie ID.
71
113
  #
72
114
  # Examples
@@ -0,0 +1,56 @@
1
+ module TMDb
2
+ class Person < Base
3
+ extend Searchable
4
+
5
+ # Person attributes
6
+ ATTRIBUTES = :id, :adult, :also_known_as, :biography, :birthday, :deathday,
7
+ :homepage, :name, :place_of_birth, :profile_path, :popularity, :imdb_id
8
+
9
+ attr_reader *ATTRIBUTES
10
+
11
+ # Public: Gets the basic person information for a specific person ID.
12
+ #
13
+ # id - The ID of the person.
14
+ # options - The hash options used to filter the search (default: {}):
15
+ # More information about the options, check the api documentation
16
+ #
17
+ # Examples
18
+ #
19
+ # TMDb::Person.find(138)
20
+ def self.find(id, options = {})
21
+ res = get("/person/#{id}", query: options)
22
+ res.success? ? Person.new(res) : bad_response(res)
23
+ end
24
+
25
+ # Public: Gets the images for a specific person ID.
26
+ #
27
+ # id - The person's ID
28
+ #
29
+ # Examples
30
+ #
31
+ # TMDb::Person.images(138)
32
+ def self.images(id)
33
+ res = get("/person/#{id}/images")
34
+ res.success? ? res : bad_response(res)
35
+ end
36
+
37
+ # Public: Gets a list of popular people.
38
+ #
39
+ # options - The hash options used to filter the search (default: {}):
40
+ # :page - List's page.
41
+ #
42
+ # Examples
43
+ #
44
+ # TMDb::Person.popular
45
+ # TMDb::Person.popular(page: 4)
46
+ def self.popular(options = {})
47
+ res = get('/person/popular', query: options)
48
+
49
+ if res.success?
50
+ res['results'].map { |person| Person.new(person) }
51
+ else
52
+ bad_response(res)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -16,6 +16,10 @@ module TMDb
16
16
  # TMDb::Movie.search('Iron Man')
17
17
  # TMDb::Movie.search('The Matrix', year: 1999)
18
18
  # TMDb::Movie.search('Forret Gump', language: 'pt', year: 1994)
19
+ #
20
+ ## For a person
21
+ # TMDb::Person.search('Peter Jackson')
22
+ # TMDb::Person.search('Paul', page: 4)
19
23
  def search(query, options = {})
20
24
  options.merge!(query: query)
21
25
  res = get("/search/#{resource}", query: options)
@@ -1,3 +1,3 @@
1
1
  module TMDb
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,253 @@
1
+ {
2
+ "cast":
3
+ [
4
+ {
5
+ "id": 819,
6
+ "name": "Edward Norton",
7
+ "character": "The Narrator",
8
+ "order": 0,
9
+ "cast_id": 4,
10
+ "profile_path": "/588Hrov6wwM9WcU88nJHlw2iufN.jpg"
11
+ },
12
+ {
13
+ "id": 287,
14
+ "name": "Brad Pitt",
15
+ "character": "Tyler Durden",
16
+ "order": 1,
17
+ "cast_id": 5,
18
+ "profile_path": "/kc3M04QQAuZ9woUvH3Ju5T7ZqG5.jpg"
19
+ },
20
+ {
21
+ "id": 1283,
22
+ "name": "Helena Bonham Carter",
23
+ "character": "Marla Singer",
24
+ "order": 2,
25
+ "cast_id": 6,
26
+ "profile_path": "/58oJPFG1wefMC0Vj7sFzHPrm67J.jpg"
27
+ },
28
+ {
29
+ "id": 7470,
30
+ "name": "Meat Loaf",
31
+ "character": "Robert 'Bob' Paulson",
32
+ "order": 3,
33
+ "cast_id": 7,
34
+ "profile_path": "/pwNyXgegO1nlZ8uWT847JM8EjGj.jpg"
35
+ },
36
+ {
37
+ "id": 7471,
38
+ "name": "Zach Grenier",
39
+ "character": "Richard Chesler",
40
+ "order": 4,
41
+ "cast_id": 8,
42
+ "profile_path": "/jghYiKdNkVehKpiVyE97AWrU9KQ.jpg"
43
+ },
44
+ {
45
+ "id": 7472,
46
+ "name": "Richmond Arquette",
47
+ "character": "Intern",
48
+ "order": 5,
49
+ "cast_id": 9,
50
+ "profile_path": null
51
+ },
52
+ {
53
+ "id": 7219,
54
+ "name": "David Andrews",
55
+ "character": "Thomas",
56
+ "order": 6,
57
+ "cast_id": 10,
58
+ "profile_path": "/pxmxn29UHW9r6uvLrd7bEwLswlQ.jpg"
59
+ },
60
+ {
61
+ "id": 7473,
62
+ "name": "Rachel Singer",
63
+ "character": "Chloe",
64
+ "order": 11,
65
+ "cast_id": 11,
66
+ "profile_path": null
67
+ },
68
+ {
69
+ "id": 7497,
70
+ "name": "Holt McCallany",
71
+ "character": "The Mechanic",
72
+ "order": 20,
73
+ "cast_id": 22,
74
+ "profile_path": "/hQBfcw9KVszdenlTZTR8AIrSpex.jpg"
75
+ },
76
+ {
77
+ "id": 7498,
78
+ "name": "Eion Bailey",
79
+ "character": "Ricky",
80
+ "order": 22,
81
+ "cast_id": 23,
82
+ "profile_path": "/4MnRgrwuiJvHsfoiJrIUL4TkfoC.jpg"
83
+ },
84
+ {
85
+ "id": 7499,
86
+ "name": "Jared Leto",
87
+ "character": "Angel Face",
88
+ "order": 23,
89
+ "cast_id": 24,
90
+ "profile_path": "/lzQSuu5o0JC9mCncYjVnncSH5lO.jpg"
91
+ },
92
+ {
93
+ "id": 7500,
94
+ "name": "Peter Iacangelo",
95
+ "character": "Lou",
96
+ "order": 24,
97
+ "cast_id": 25,
98
+ "profile_path": null
99
+ },
100
+ {
101
+ "id": 56112,
102
+ "name": "David Lee Smith",
103
+ "character": "Walter",
104
+ "order": 19,
105
+ "cast_id": 30,
106
+ "profile_path": "/xYkMA9AWtUN93KV5hWzlDkcnebB.jpg"
107
+ },
108
+ {
109
+ "id": 1129738,
110
+ "name": "George Maguire",
111
+ "character": "Group Leader",
112
+ "order": 7,
113
+ "cast_id": 31,
114
+ "profile_path": null
115
+ },
116
+ {
117
+ "id": 197790,
118
+ "name": "Eugenie Bondurant",
119
+ "character": "Weeping Woman",
120
+ "order": 8,
121
+ "cast_id": 32,
122
+ "profile_path": null
123
+ },
124
+ {
125
+ "id": 68277,
126
+ "name": "Christina Cabot",
127
+ "character": "Group Leader",
128
+ "order": 9,
129
+ "cast_id": 33,
130
+ "profile_path": "/7UBTv5lW6apPdVLnOqTTBMTJWwY.jpg"
131
+ },
132
+ {
133
+ "id": 202080,
134
+ "name": "Sydney 'Big Dawg' Colston",
135
+ "character": "Speaker",
136
+ "order": 10,
137
+ "cast_id": 34,
138
+ "profile_path": null
139
+ },
140
+ {
141
+ "id": 1172435,
142
+ "name": "Christie Cronenweth",
143
+ "character": "Airline Attendant",
144
+ "order": 12,
145
+ "cast_id": 35,
146
+ "profile_path": null
147
+ },
148
+ {
149
+ "id": 956719,
150
+ "name": "Tim De Zarn",
151
+ "character": "Inspector Bird",
152
+ "order": 13,
153
+ "cast_id": 36,
154
+ "profile_path": null
155
+ },
156
+ {
157
+ "id": 59285,
158
+ "name": "Ezra Buzzington",
159
+ "character": "Inspector Dent",
160
+ "order": 14,
161
+ "cast_id": 37,
162
+ "profile_path": "/dl0SIqpOqS05UpJHKuDQqZTwUvP.jpg"
163
+ },
164
+ {
165
+ "id": 1269622,
166
+ "name": "Dierdre Downing-Jackson",
167
+ "character": "Woman on Plane",
168
+ "order": 15,
169
+ "cast_id": 38,
170
+ "profile_path": null
171
+ },
172
+ {
173
+ "id": 543293,
174
+ "name": "Bob Stephenson",
175
+ "character": "Airport Security Officer (as Robert J. Stephenson)",
176
+ "order": 16,
177
+ "cast_id": 39,
178
+ "profile_path": "/iH86ZmoSGOCnWZ8aycavGdlu3ht.jpg"
179
+ },
180
+ {
181
+ "id": 62846,
182
+ "name": "Charlie Dell",
183
+ "character": "Doorman",
184
+ "order": 17,
185
+ "cast_id": 40,
186
+ "profile_path": "/z0JgZxazJAVlHxLYXWM8eUZlOk8.jpg"
187
+ },
188
+ {
189
+ "id": 530040,
190
+ "name": "Rob Lanza",
191
+ "character": "Man in Suit",
192
+ "order": 18,
193
+ "cast_id": 41,
194
+ "profile_path": null
195
+ },
196
+ {
197
+ "id": 137425,
198
+ "name": "Joel Bissonnette",
199
+ "character": "Food Court Maitre D'",
200
+ "order": 21,
201
+ "cast_id": 42,
202
+ "profile_path": null
203
+ },
204
+ {
205
+ "id": 175120,
206
+ "name": "Evan Mirand",
207
+ "character": "Steph",
208
+ "order": 25,
209
+ "cast_id": 43,
210
+ "profile_path": null
211
+ },
212
+ {
213
+ "id": 169636,
214
+ "name": "Robby Robinson",
215
+ "character": "Next Month's Opponent",
216
+ "order": 26,
217
+ "cast_id": 44,
218
+ "profile_path": null
219
+ },
220
+ {
221
+ "id": 168924,
222
+ "name": "Lou Beatty Jr.",
223
+ "character": "Cop at Marla's Building",
224
+ "order": 27,
225
+ "cast_id": 45,
226
+ "profile_path": null
227
+ },
228
+ {
229
+ "id": 1219497,
230
+ "name": "Thom Gossom Jr.",
231
+ "character": "Detective Stern",
232
+ "order": 28,
233
+ "cast_id": 46,
234
+ "profile_path": null
235
+ },
236
+ {
237
+ "id": 157938,
238
+ "name": "Valerie Bickford",
239
+ "character": "Susan, Cosmetics Dealer",
240
+ "order": 29,
241
+ "cast_id": 47,
242
+ "profile_path": null
243
+ },
244
+ {
245
+ "id": 42824,
246
+ "name": "Carl Ciarfalio",
247
+ "character": "Lou's Body Guard (as Carl N. Ciarfalio)",
248
+ "order": 30,
249
+ "cast_id": 48,
250
+ "profile_path": null
251
+ }
252
+ ]
253
+ }