├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── lib └── tmdb.js ├── package.json └── test ├── mocha.opts └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | dev.js 2 | APIKEY 3 | *.swp 4 | *~ 5 | node_modules/ 6 | node_modules 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Mikael Emilsson (mikael.emilsson@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ALL_TESTS = $(shell find test/ -name '*test.js') 2 | 3 | run-tests: 4 | @./node_modules/.bin/mocha \ 5 | $(TESTFLAGS) \ 6 | $(TESTS) 7 | 8 | test: 9 | @$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests 10 | 11 | .PHONY: test 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Installation 2 | ``` 3 | npm install --save tmdbv3 4 | ``` 5 | 6 | ### Usage 7 | ```js 8 | const tmdb = require('tmdbv3').init(key); 9 | 10 | tmdb.misc.latest((err ,res) => { 11 | console.log(res.title); 12 | }); 13 | 14 | tmdb.movie.info(5, (err ,res) => { 15 | console.log(res.title); 16 | }); 17 | 18 | tmdb.person.info(109, (err ,res) => { 19 | console.log(res.name); 20 | }); 21 | 22 | // setting french as default language... 23 | tmdb.setLanguage('fr'); 24 | // and resetting to english. 25 | tmdb.resetLanguage(); 26 | ``` 27 | etc. 28 | 29 | All methods live right now (2012-08-08) implemented. 30 | 31 | Testing is done by mocha. 32 | 33 | See [the TMDb page about the API](https://www.themoviedb.org/documentation/api) or [view the full API](http://docs.themoviedb.apiary.io/) 34 | 35 | ### Other 36 | 37 | For TMDb's old v2.1 api, go to [kkarikos repo] (https://raw.github.com/kkarikos/tmdb). 38 | 39 | kkariko: I used part of your request code here, contact me if you have questions, I can't find a way to contact you. 40 | -------------------------------------------------------------------------------- /lib/tmdb.js: -------------------------------------------------------------------------------- 1 | var request = require('request'); 2 | String.prototype.format = function () { 3 | var content = this; 4 | for (var i = 0; i < arguments.length; i++) { 5 | var replacement = '{' + i + '}'; 6 | content = content.replace(replacement, arguments[i]); 7 | } 8 | return content; 9 | }; 10 | 11 | var me; 12 | var tmdb = function (api_key) { 13 | me = this; 14 | this.api_key = api_key; 15 | this.config = null; 16 | this.base = 'http://api.themoviedb.org/3'; 17 | this.api_urls = { 18 | configuration: this.base + '/configuration?api_key=' + this.api_key 19 | , misc_latest: this.base + '/movie/latest?api_key=' + this.api_key 20 | , misc_upcoming: this.base + '/movie/upcoming?page={0}&api_key=' + this.api_key 21 | , misc_now_playing: this.base + '/movie/now_playing?page={0}&api_key=' + this.api_key 22 | , misc_popular: this.base + '/movie/popular?page={0}&api_key=' + this.api_key 23 | , misc_top_rated: this.base + '/movie/top-rated?page={0}&api_key=' + this.api_key 24 | , movie_info: this.base + '/movie/{0}?api_key=' + this.api_key 25 | , movie_alternative_titles: this.base + '/movie/{0}/alternative_titles?api_key=' + this.api_key 26 | , movie_casts: this.base + '/movie/{0}/casts?api_key=' + this.api_key 27 | , movie_images: this.base + '/movie/{0}/images?api_key=' + this.api_key 28 | , movie_keywords: this.base + '/movie/{0}/keywords?api_key=' + this.api_key 29 | , movie_releases: this.base + '/movie/{0}/releases?api_key=' + this.api_key 30 | , movie_trailers: this.base + '/movie/{0}/trailers?api_key=' + this.api_key 31 | , movie_translations: this.base + '/movie/{0}/translations?api_key=' + this.api_key 32 | , movie_similar: this.base + '/movie/{0}/similar_movies?page={1}&api_key=' + this.api_key 33 | , person_info: this.base + '/person/{0}?api_key=' + this.api_key 34 | , person_credits: this.base + '/person/{0}/credits?api_key=' + this.api_key 35 | , person_images: this.base + '/person/{0}/images?api_key=' + this.api_key 36 | , collection_info: this.base + '/collection/{0}?api_key=' + this.api_key 37 | , search_movie: this.base + '/search/movie?query={0}&page={1}&api_key=' + this.api_key 38 | , search_person: this.base + '/search/person?query={0}&page={1}&api_key=' + this.api_key 39 | , search_companies: this.base + '/search/company?query={0}&page={1}&api_key=' + this.api_key 40 | , auth_request_token: this.base + '/authentication/token/new?api_key=' + this.api_key 41 | , auth_session_id: this.base + '/authentication/session/new?request_token={0}&api_key=' + this.api_key 42 | , write_rate_movie: this.base + '/movie/{0}/rating?session_id={1}&api_key=' + this.api_key 43 | , company_info: this.base + '/company/{0}?api_key=' + this.api_key 44 | , company_movies: this.base + '/company/{0}/movies?api_key=' + this.api_key 45 | , account_info: this.base + '/account?session_id={0}&api_key=' + this.api_key 46 | , account_add_favorite: this.base + '/account/{0}/favorite?session_id={1}&api_key=' + this.api_key 47 | , account_favorite_movies: this.base + '/account/{0}/favorite_movies?session_id={1}&api_key=' + this.api_key 48 | , account_add_movie_watchlist: this.base + '/account/{0}/movie_watchlist?session_id={1}&api_key=' + this.api_key 49 | , account_movie_watchlist: this.base + '/account/{0}/movie_watchlist?session_id={1}&api_key=' + this.api_key 50 | , account_rated_movies: this.base + '/account/{0}/rated_movies?session_id={1}&api_key=' + this.api_key 51 | , genre_list: this.base + '/genre/list?api_key=' + this.api_key 52 | , genre_movies: this.base + '/genre/{0}/movies?page={0}&page={1}&api_key=' + this.api_key 53 | }; 54 | 55 | this.configuration(function (err, res) { 56 | if (!err) { 57 | me.config = res; 58 | } else { 59 | console.error('Error loading configuration: ' + err); 60 | } 61 | }); 62 | }; 63 | 64 | /** 65 | * factory function 66 | **/ 67 | module.exports.init = function (apikey) { 68 | return new tmdb(apikey); 69 | }; 70 | 71 | /** 72 | * misc methods 73 | * all but the 'latest'-function can be supplied with a page argument, 74 | * if page is left out the first page is returned 75 | **/ 76 | tmdb.prototype.misc = { 77 | upcoming: function (p, callback) { 78 | if (arguments.length === 1) { 79 | callback = p; 80 | var page = 1; 81 | } else { 82 | var page = ((typeof p !== 'number') ? page = 1 : page = p); 83 | } 84 | var url = me.api_urls.misc_upcoming.format(page); 85 | executeQuery({ 86 | url: url 87 | }, callback); 88 | } 89 | , latest: function (callback) { 90 | var url = me.api_urls.misc_latest; 91 | executeQuery({ 92 | url: url 93 | }, callback); 94 | } 95 | , nowPlaying: function (p, callback) { 96 | if (arguments.length === 1) { 97 | callback = p; 98 | var page = 1; 99 | } else { 100 | var page = ((typeof p !== 'number') ? page = 1 : page = p); 101 | } 102 | var url = me.api_urls.misc_now_playing.format(page); 103 | executeQuery({ 104 | url: url 105 | }, callback); 106 | } 107 | , popular: function (p, callback) { 108 | if (arguments.length === 1) { 109 | callback = p; 110 | var page = 1; 111 | } else { 112 | var page = ((typeof p !== 'number') ? page = 1 : page = p); 113 | } 114 | var url = me.api_urls.misc_popular.format(page); 115 | executeQuery({ 116 | url: url 117 | }, callback); 118 | } 119 | , topRated: function (p, callback) { 120 | if (arguments.length === 1) { 121 | callback = p; 122 | var page = 1; 123 | } else { 124 | var page = ((typeof p !== 'number') ? page = 1 : page = p); 125 | } 126 | var url = me.api_urls.misc_top_rated.format(page); 127 | executeQuery({ 128 | url: url 129 | }, callback); 130 | } 131 | , }; 132 | 133 | /** 134 | * genre methods 135 | **/ 136 | tmdb.prototype.genre = { 137 | list: function (callback) { 138 | var url = me.api_urls.genre_list; 139 | executeQuery({ 140 | url: url 141 | }, callback); 142 | }, 143 | 144 | movies: function (q, p, callback) { 145 | if (arguments.length === 2) { 146 | callback = p; 147 | p = 1; 148 | } else { 149 | if (typeof p !== 'number') { 150 | p = 1; 151 | } 152 | } 153 | var url = me.api_urls.genre_movies.format(q, p); 154 | executeQuery({ 155 | url: url 156 | }, callback); 157 | } 158 | }; 159 | 160 | /** 161 | * Get current configuration for constructing complete image urls 162 | **/ 163 | tmdb.prototype.configuration = function (callback) { 164 | var url = me.api_urls.configuration; 165 | executeQuery({ 166 | url: url 167 | }, callback); 168 | }; 169 | 170 | /** 171 | * movie methods 172 | * q = id (can be either tmdb id or imdb id) 173 | * append_to_response = include one or more of the other queries (info only) 174 | * 175 | * For Language Using 176 | * language notation has to be 'iso_639_1' standard (e.g.-> 'tr' / 'en' / 'es') 177 | * Using: tmdb.movie.info(movieId, 'tr', callback); 178 | * Default Using: tmdb.movie.info(movieId, callback) 179 | **/ 180 | tmdb.prototype.movie = { 181 | info: function () { 182 | if (arguments.length == 3) { 183 | var url = me.api_urls.movie_info.format(arguments[0]) + "&language=" + arguments[1]; 184 | executeQuery({ 185 | url: url 186 | }, arguments[2]); 187 | } else { 188 | var url = me.api_urls.movie_info.format(arguments[0]); 189 | executeQuery({ 190 | url: url 191 | }, arguments[1]); 192 | } 193 | } 194 | , alternativeTitles: function (q, callback) { 195 | var url = me.api_urls.movie_alternative_titles.format(q); 196 | executeQuery({ 197 | url: url 198 | }, callback); 199 | } 200 | , casts: function (q, callback) { 201 | var url = me.api_urls.movie_casts.format(q); 202 | executeQuery({ 203 | url: url 204 | }, callback); 205 | } 206 | , images: function () { 207 | if (arguments.length == 2) { 208 | var url = me.api_urls.movie_images.format(arguments[0]); 209 | executeQuery({ 210 | url: url 211 | }, arguments[1]); 212 | } else { 213 | var url = me.api_urls.movie_images.format(arguments[0]) + "&language=" + arguments[1]; 214 | executeQuery({ 215 | url: url 216 | }, arguments[2]); 217 | } 218 | } 219 | , keywords: function (q, callback) { 220 | var url = me.api_urls.movie_keywords.format(q); 221 | executeQuery({ 222 | url: url 223 | }, callback); 224 | } 225 | , releases: function (q, callback) { 226 | var url = me.api_urls.movie_releases.format(q); 227 | executeQuery({ 228 | url: url 229 | }, callback); 230 | } 231 | , trailers: function (q, callback) { 232 | if (arguments.length == 2) { 233 | var url = me.api_urls.movie_trailers.format(arguments[0]); 234 | executeQuery({ 235 | url: url 236 | }, arguments[1]); 237 | } else { 238 | var url = me.api_urls.movie_trailers.format(arguments[0]) + "&language=" + arguments[1]; 239 | executeQuery({ 240 | url: url 241 | }, arguments[2]); 242 | } 243 | } 244 | , translations: function (q, callback) { 245 | var url = me.api_urls.movie_translations.format(q); 246 | executeQuery({ 247 | url: url 248 | }, callback); 249 | } 250 | , similar: function (q, p, callback) { 251 | if (arguments.length === 2) { 252 | callback = p; 253 | p = 1; 254 | } else { 255 | if (typeof p !== 'number') { 256 | p = 1; 257 | } 258 | } 259 | var url = me.api_urls.movie_similar.format(q, p); 260 | executeQuery({ 261 | url: url 262 | }, callback); 263 | } 264 | }; 265 | 266 | /** 267 | * search methods 268 | * q = searchterm, p = page 269 | * page defaults to 1 if not specified or invalid 270 | **/ 271 | tmdb.prototype.search = { 272 | movie: function (q, p, callback) { 273 | if (arguments.length === 2) { 274 | callback = p; 275 | p = 1; 276 | } else { 277 | if (typeof p !== 'number') { 278 | p = 1; 279 | } 280 | } 281 | var url = me.api_urls.search_movie.format(q, p); 282 | executeQuery({ 283 | url: url 284 | }, callback); 285 | } 286 | , person: function (q, p, callback) { 287 | if (arguments.length === 2) { 288 | callback = p; 289 | p = 1; 290 | } else { 291 | if (typeof p !== 'number') { 292 | p = 1; 293 | } 294 | } 295 | var url = me.api_urls.search_person.format(q, p); 296 | executeQuery({ 297 | url: url 298 | }, callback); 299 | } 300 | , companies: function (q, p, callback) { 301 | if (arguments.length === 2) { 302 | callback = p; 303 | p = 1; 304 | } else { 305 | if (typeof p !== 'number') { 306 | p = 1; 307 | } 308 | } 309 | var url = me.api_urls.search_companies.format(q, p); 310 | executeQuery({ 311 | url: url 312 | }, callback); 313 | } 314 | , }; 315 | 316 | /** 317 | * person methods 318 | * id = person id 319 | **/ 320 | tmdb.prototype.person = { 321 | info: function (id, callback) { 322 | var url = me.api_urls.person_info.format(id); 323 | executeQuery({ 324 | url: url 325 | }, callback); 326 | } 327 | , credits: function (id, callback) { 328 | var url = me.api_urls.person_credits.format(id); 329 | executeQuery({ 330 | url: url 331 | }, callback); 332 | } 333 | , images: function (id, callback) { 334 | var url = me.api_urls.person_images.format(id); 335 | executeQuery({ 336 | url: url 337 | }, callback); 338 | } 339 | , }; 340 | 341 | /** 342 | * collection methods 343 | * id = collection id 344 | **/ 345 | tmdb.prototype.collection = { 346 | info: function (id, callback) { 347 | var url = me.api_urls.collection_info.format(id); 348 | executeQuery({ 349 | url: url 350 | }, callback); 351 | } 352 | , }; 353 | 354 | /** 355 | * authentication methods 356 | **/ 357 | tmdb.prototype.authentication = { 358 | requestToken: function (callback) { 359 | var url = me.api_urls.auth_request_token; 360 | executeQuery({ 361 | url: url 362 | }, callback); 363 | } 364 | , sessionId: function (token, callback) { 365 | var url = me.api_urls.auth_session_id.format(token); 366 | executeQuery({ 367 | url: url 368 | }, callback); 369 | } 370 | }; 371 | 372 | /** 373 | * company methods 374 | **/ 375 | tmdb.prototype.company = { 376 | info: function (id, callback) { 377 | var url = me.api_urls.company_info.format(id); 378 | executeQuery({ 379 | url: url 380 | }, callback); 381 | } 382 | , movies: function (id, callback) { 383 | var url = me.api_urls.company_movies.format(id); 384 | executeQuery({ 385 | url: url 386 | }, callback); 387 | } 388 | , }; 389 | 390 | /** 391 | * account methods 392 | **/ 393 | tmdb.prototype.account = { 394 | info: function (sid, callback) { 395 | var url = me.api_urls.account_info.format(sid); 396 | executeQuery({ 397 | url: url 398 | }, callback); 399 | } 400 | , favorite_movies: function (id, sid, callback) { 401 | var url = me.api_urls.account_favorite_movies.format(id, sid); 402 | executeQuery({ 403 | url: url 404 | }, callback); 405 | } 406 | , rated_movies: function (id, sid, callback) { 407 | var url = me.api_urls.account_rated_movies.format(id, sid); 408 | executeQuery({ 409 | url: url 410 | }, callback); 411 | } 412 | , add_favorite: function (aid, mid, sid, isfavorite, callback) { 413 | var url = me.api_urls.account_add_favorite.format(aid, sid); 414 | executePost({ 415 | url: url 416 | }, { 417 | movie_id: mid 418 | , favorite: isfavorite 419 | }, callback); 420 | } 421 | , movie_watchlist: function (id, sid, callback) { 422 | var url = me.api_urls.account_movie_watchlist.format(id, sid); 423 | executeQuery({ 424 | url: url 425 | }, callback); 426 | } 427 | , add_movie_watchlist: function (aid, mid, sid, isinwatchlist, callback) { 428 | var url = me.api_urls.account_add_movie_watchlist.format(aid, sid); 429 | executePost({ 430 | url: url 431 | }, { 432 | movie_id: mid 433 | , movie_watchlist: isinwatchlist 434 | }, callback); 435 | } 436 | , }; 437 | 438 | 439 | /** 440 | * write methods 441 | * id = item id (movie id etc.) 442 | * sid = session id 443 | **/ 444 | tmdb.prototype.write = { 445 | rateMovie: function (id, sid, rating, callback) { 446 | var url = me.api_urls.write_rate_movie.format(id, sid); 447 | executePost({ 448 | url: url 449 | }, { 450 | value: rating 451 | }, callback); 452 | } 453 | , }; 454 | 455 | /** 456 | * Sends the query to tmdb and ships the response of to be processed 457 | **/ 458 | var executeQuery = function (url, callback) { 459 | request({ 460 | uri: encodeURI(url.url) 461 | , headers: { 462 | "Accept": 'application/json' 463 | } 464 | } 465 | , function (err, res, body) { 466 | processQuery(url, err, res, body, callback); 467 | } 468 | ); 469 | } 470 | 471 | /** 472 | * Processes the query response from TMDb 473 | **/ 474 | var processQuery = function (url, error, response, body, callback) { 475 | var res = null; 476 | try { 477 | res = JSON.parse(body); 478 | } catch (e) {} 479 | 480 | if (!error && response.statusCode === 200 && !res.status_code) { 481 | callback(undefined, res); 482 | return; 483 | } 484 | 485 | if (res.status_code) { 486 | switch (res.status_code) { 487 | case 6: // Invalid id 488 | callback(res, undefined); 489 | break; 490 | case 7: // Invalid API key 491 | callback(res, undefined); 492 | break; 493 | case 10: // API key suspended, not good 494 | callback(res, undefined); 495 | break; 496 | case 12: // The item/record was updated successfully 497 | callback(res, undefined); 498 | break; 499 | case 17: // Session denied 500 | callback(res, undefined); 501 | break; 502 | } 503 | } else { 504 | callback(error, res); 505 | } 506 | } 507 | 508 | /** 509 | * posts the data to TMDb and ships the response of to be processed 510 | **/ 511 | var executePost = function (url, data, callback) { 512 | request({ 513 | method: 'POST' 514 | , uri: encodeURI(url.url) 515 | , json: data 516 | , headers: { 517 | "Content-Type": 'application/json' 518 | , "Accept": 'application/json' 519 | } 520 | , } 521 | , function (err, res, body) { 522 | processPost(url, err, res, body, callback); 523 | } 524 | ); 525 | } 526 | 527 | /** 528 | * Processes the post response from TMDb 529 | **/ 530 | var processPost = function (url, error, response, body, callback) { 531 | var res = null; 532 | try { 533 | res = body; 534 | } catch (e) {} 535 | 536 | if (!error && response.statusCode === 200 && !res.status_code) { 537 | callback(undefined, res); 538 | return; 539 | } 540 | 541 | if (res.status_code) { 542 | switch (res.status_code) { 543 | case 5: // not valid json supplied 544 | callback(res, undefined); 545 | break; 546 | case 6: // Invalid id 547 | callback(res, undefined); 548 | break; 549 | case 7: // Invalid API key 550 | callback(res, undefined); 551 | break; 552 | case 10: // API key suspended, not good 553 | callback(res, undefined); 554 | break; 555 | case 12: // The item/record was updated successfully 556 | callback(undefined, res); 557 | break; 558 | case 13: // The item/record was deleted successfully 559 | callback(undefined, res); 560 | break; 561 | case 17: // Session denied 562 | callback(res, undefined); 563 | break; 564 | } 565 | } else { 566 | callback(error, res); 567 | } 568 | } 569 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tmdbv3", 3 | "version": "0.1.2", 4 | "description": "Implementation of TMDb's v3 API", 5 | "keywords": ["tmdb","moviedb","movies"], 6 | "homepage": "https://github.com/raqqa/node-tmdb", 7 | "bugs": {"url": "https://github.com/raqqa/node-tmdb/issues"}, 8 | "author": "Mikael Emilsson ", 9 | "engines": { "node": ">=0.4.0" }, 10 | "dependencies": { 11 | "request": "2.9.x" 12 | }, 13 | "devDependencies": { 14 | "should": "*", 15 | "mocha": "1.x.x" 16 | }, 17 | "main": "./lib/tmdb", 18 | "repository": { "type": "git", "url": "git://github.com/raqqa/node-tmdb.git" } 19 | } 20 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require should 2 | -R spec 3 | --timeout 10000 4 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var should = require('should'); 3 | var key = new String(fs.readFileSync(__dirname + '/APIKEY')).replace(/(\r\n|\n|\r)/gm,""); 4 | var tmdb = require('../lib/tmdb').init(key); 5 | 6 | describe("General methods", function() { 7 | it("can get configuration info", function(done) { 8 | tmdb.configuration(function(err,res) { 9 | should.exist(res); 10 | done(); 11 | }); 12 | }); 13 | }); 14 | 15 | describe("Person methods", function() { 16 | it("can fetch info on a person", function(done){ 17 | tmdb.person.info(109, function(err,res) { 18 | res.name.should.equal("Elijah Wood"); 19 | done(); 20 | }); 21 | }); 22 | 23 | it("can fetch a person's credits", function(done) { 24 | tmdb.person.credits(109, function(err,res) { 25 | res.id.should.equal(109); 26 | done(); 27 | }); 28 | }); 29 | 30 | it("can fetch a person's images", function(done) { 31 | tmdb.person.images(109, function(err,res) { 32 | res.id.should.equal(109); 33 | done(); 34 | }) 35 | }); 36 | }); 37 | 38 | describe("Search methods", function() { 39 | it("can search for movies", function(done) { 40 | tmdb.search.movie('transformers', function(err,res) { 41 | res.page.should.equal(1); 42 | done(); 43 | }); 44 | }); 45 | it("can hop to another page of a search", function(done) { 46 | tmdb.search.movie('transformers', 4, function(err,res) { 47 | res.page.should.equal(4); 48 | done(); 49 | }); 50 | }); 51 | it("can search for persons", function(done) { 52 | tmdb.search.person('mikael', function(err,res) { 53 | res.page.should.equal(1); 54 | done(); 55 | }); 56 | }); 57 | }); 58 | 59 | describe("Company methods", function() { 60 | it("can get info on a company", function(done) { 61 | tmdb.company.info(1, function(err,res) { 62 | res.name.should.equal('Lucasfilm'); 63 | done(); 64 | }); 65 | }); 66 | it("can fetch what movies a company has produced", function(done) { 67 | tmdb.company.movies(1, function(err,res) { 68 | res.id.should.equal(1); 69 | done(); 70 | }); 71 | }); 72 | }); 73 | 74 | describe("Collection methods", function() { 75 | it("can get info on collections", function(done) { 76 | tmdb.collection.info(10, function(err,res) { 77 | res.name.should.equal('Star Wars Collection'); 78 | done(); 79 | }); 80 | }); 81 | }); 82 | 83 | describe("Movie methods", function() { 84 | it("can get info on a movie", function(done) { 85 | tmdb.movie.info(11, function(err,res) { 86 | res.title.should.equal('Star Wars: Episode IV - A New Hope'); 87 | done(); 88 | }); 89 | }); 90 | 91 | it("can get info on a movie, in french", function(done) { 92 | tmdb.setLanguage('fr'); 93 | tmdb.movie.info(11, function(err,res) { 94 | res.title.should.equal('Star Wars : Épisode IV - Un nouvel espoir'); 95 | done(); 96 | }); 97 | tmdb.resetLanguage(); 98 | }); 99 | 100 | it("can get data with an imdb-id", function(done) { 101 | tmdb.movie.info('tt0076759', function(err,res) { 102 | res.title.should.equal('Star Wars: Episode IV - A New Hope'); 103 | done(); 104 | }); 105 | }); 106 | 107 | it("can get data with an imdb-id, in french", function(done) { 108 | tmdb.setLanguage('fr'); 109 | tmdb.movie.info('tt0076759', function(err,res) { 110 | res.title.should.equal('Star Wars : Épisode IV - Un nouvel espoir'); 111 | done(); 112 | }); 113 | tmdb.resetLanguage(); 114 | }); 115 | 116 | it("can get alternative titles for a movie", function(done) { 117 | tmdb.movie.alternativeTitles(11, function(err,res) { 118 | res.id.should.equal(11); 119 | done(); 120 | }); 121 | }); 122 | 123 | it("can detect invalid ids", function(done) { 124 | tmdb.movie.info(1000000001, function(err,res) { 125 | err.status_code.should.equal(6); 126 | done(); 127 | }); 128 | }); 129 | it("can get the cast for a movie", function(done) { 130 | tmdb.movie.casts(11, function(err,res) { 131 | res.id.should.equal(11); 132 | done(); 133 | }); 134 | }); 135 | it("can get images for a movie", function(done) { 136 | tmdb.movie.images(11, function(err,res) { 137 | res.id.should.equal(11); 138 | done(); 139 | }); 140 | }); 141 | it("can get keywords for a movie", function(done) { 142 | tmdb.movie.keywords(11, function(err,res) { 143 | res.id.should.equal(11); 144 | done(); 145 | }); 146 | }); 147 | it("can get release dates for a movie", function(done) { 148 | tmdb.movie.releases(11, function(err,res) { 149 | res.id.should.equal(11); 150 | done(); 151 | }); 152 | }); 153 | it("can get trailers for a movie", function(done) { 154 | tmdb.movie.trailers(11, function(err,res) { 155 | res.id.should.equal(11); 156 | done(); 157 | }); 158 | }); 159 | it("can get translations for a movie", function(done) { 160 | tmdb.movie.translations(11, function(err,res) { 161 | res.id.should.equal(11); 162 | done(); 163 | }); 164 | }); 165 | }); 166 | 167 | describe("Misc methods", function() { 168 | it("can get the latest added movie", function(done) { 169 | tmdb.misc.latest(function(err,res) { 170 | should.not.exist(err); 171 | done(); 172 | }); 173 | }); 174 | it("can get the movies playing in theaters", function(done) { 175 | tmdb.misc.nowPlaying(function(err,res) { 176 | res.total_results.should.equal(100); 177 | done(); 178 | }); 179 | }); 180 | it("can get popular movies", function(done) { 181 | tmdb.misc.popular(function(err,res) { 182 | res.page.should.equal(1); 183 | done(); 184 | }); 185 | }); 186 | it("can get the top rated movies", function(done) { 187 | tmdb.misc.topRated(function(err,res) { 188 | res.page.should.equal(1); 189 | done(); 190 | }); 191 | }); 192 | }); 193 | --------------------------------------------------------------------------------