Comparing version
@@ -0,1 +1,21 @@ | ||
# Version 2.1.0 -> 2.2.0 | ||
Added promise API | ||
## Promises | ||
```js | ||
imdb.get('The Toxic Avenger').then(function(data) { console.log(data); }); | ||
``` | ||
# Version 2.0.0 -> 2.1.0 | ||
Adds the ability to filter by year | ||
## Filtering by year | ||
```js | ||
imdb.getReq({name: 'James Bond', year: 2015}, function(err, data) { console.log(data) }); | ||
``` | ||
# Version 1.3.3 -> 2.0.0 | ||
@@ -2,0 +22,0 @@ |
@@ -86,4 +86,2 @@ "use strict"; | ||
TVShow.prototype.episodes = function (cb) { | ||
if (typeof (cb) !== "function") | ||
throw new TypeError("cb must be a function"); | ||
if (this._episodes.length !== 0) { | ||
@@ -97,3 +95,3 @@ return cb(undefined, this._episodes); | ||
} | ||
Promise.all(funcs) | ||
var prom = Promise.all(funcs) | ||
.then(function (ep_data) { | ||
@@ -104,3 +102,7 @@ var eps = []; | ||
if (interfaces_1.isError(datum)) { | ||
return cb(new ImdbError(datum.Error, undefined), undefined); | ||
var err = new ImdbError(datum.Error, undefined); | ||
if (cb) { | ||
return cb(err, undefined); | ||
} | ||
return Promise.reject(err); | ||
} | ||
@@ -115,7 +117,15 @@ else { | ||
tvShow._episodes = eps; | ||
return cb(undefined, eps); | ||
}) | ||
.catch(function (err) { | ||
return cb(err, undefined); | ||
if (cb) { | ||
return cb(undefined, eps); | ||
} | ||
return Promise.resolve(eps); | ||
}); | ||
if (cb) { | ||
prom.catch(function (err) { | ||
return cb(err, undefined); | ||
}); | ||
} | ||
else { | ||
return prom; | ||
} | ||
}; | ||
@@ -136,4 +146,2 @@ return TVShow; | ||
var responseData = ""; | ||
if (typeof (cb) !== "function") | ||
throw new TypeError("cb must be a function"); | ||
var qs = { plot: "full", r: "json", y: req.year }; | ||
@@ -146,3 +154,3 @@ if (req.name) { | ||
} | ||
rp({ "qs": qs, url: omdbapi, json: true }).then(function (data) { | ||
var prom = rp({ "qs": qs, url: omdbapi, json: true }).then(function (data) { | ||
var ret; | ||
@@ -153,14 +161,31 @@ if (interfaces_1.isError(data)) { | ||
else { | ||
if (interfaces_1.isMovie(data)) | ||
if (interfaces_1.isMovie(data)) { | ||
ret = new Movie(data); | ||
else if (interfaces_1.isTvshow(data)) | ||
} | ||
else if (interfaces_1.isTvshow(data)) { | ||
ret = new TVShow(data); | ||
else | ||
return cb(new ImdbError("type: " + data.Type + " not valid", req), undefined); | ||
return cb(undefined, ret); | ||
} | ||
else { | ||
var err = new ImdbError("type: " + data.Type + " not valid", req); | ||
if (cb) { | ||
return cb(err, undefined); | ||
} | ||
else { | ||
return Promise.reject(err); | ||
} | ||
} | ||
if (cb) { | ||
return cb(undefined, ret); | ||
} | ||
return Promise.resolve(ret); | ||
} | ||
}) | ||
.catch(function (err) { | ||
cb(err, undefined); | ||
}); | ||
if (cb) { | ||
prom.catch(function (err) { | ||
cb(err, undefined); | ||
}); | ||
} | ||
else { | ||
return prom; | ||
} | ||
} | ||
@@ -167,0 +192,0 @@ exports.getReq = getReq; |
@@ -5,3 +5,3 @@ { | ||
"description": "Queries unofficial imdb APIs to get movie and television information from imdb", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"main": "lib/imdb.js", | ||
@@ -8,0 +8,0 @@ "homepage": "https://github.com/worr/node-imdb-api", |
@@ -28,3 +28,3 @@ # node-imdb-api | ||
Call get. | ||
Call get/getReq/getById | ||
@@ -35,2 +35,7 @@ var movie; | ||
}); | ||
// Promises! | ||
imdb.get('The Toxic Avenger').then(function(data) { console.log(data) }); | ||
imdb.getById('tt0090190).then(function(data) { console.log(data) }); | ||
imdb.getReq({ name: 'The Toxic Avenger' }).then(function(data) { console.log(data) }); | ||
@@ -102,4 +107,10 @@ DATA | ||
Well, it's a function! Give it a callback! | ||
Well, it's a promise (or a function that takes a callback). | ||
imdb.get('How I Met Your Mother').then(function(things) { | ||
things.episodes().then(function(data) { | ||
console.log(data); | ||
}) | ||
}); | ||
imdb.get('How I Met Your Mother', function(err, things) { | ||
@@ -106,0 +117,0 @@ things.episodes(function(err, moreThings) { |
@@ -131,6 +131,3 @@ /// <reference path="../typings/index.d.ts"/> | ||
public episodes(cb: (err: Error, data: Episode[]) => any) { | ||
if (typeof(cb) !== "function") | ||
throw new TypeError("cb must be a function"); | ||
public episodes(cb?: (err: Error, data: Episode[]) => any) { | ||
if (this._episodes.length !== 0) { | ||
@@ -147,3 +144,3 @@ return cb(undefined, this._episodes); | ||
Promise.all(funcs) | ||
let prom = Promise.all(funcs) | ||
.then(function(ep_data: OmdbSeason[] | OmdbError[]) { | ||
@@ -154,3 +151,8 @@ let eps: Episode[] = []; | ||
if (isError(datum)) { | ||
return cb(new ImdbError(datum.Error, undefined), undefined); | ||
let err = new ImdbError(datum.Error, undefined); | ||
if (cb) { | ||
return cb(err, undefined); | ||
} | ||
return Promise.reject(err); | ||
} else { | ||
@@ -165,7 +167,16 @@ let season = parseInt(datum.Season); | ||
tvShow._episodes = eps; | ||
return cb(undefined, eps); | ||
}) | ||
.catch(function(err) { | ||
if (cb) { | ||
return cb(undefined, eps); | ||
} | ||
return Promise.resolve(eps); | ||
}); | ||
if (cb) { | ||
prom.catch(function(err) { | ||
return cb(err, undefined); | ||
}); | ||
} else { | ||
return prom; | ||
} | ||
} | ||
@@ -181,8 +192,4 @@ } | ||
export function getReq(req: MovieRequest, cb: (err: Error, data: Movie) => any) { | ||
export function getReq(req: MovieRequest, cb?: (err: Error, data: Movie) => any) { | ||
let responseData = ""; | ||
if (typeof(cb) !== "function") | ||
throw new TypeError("cb must be a function"); | ||
let qs = {plot: "full", r: "json", y: req.year}; | ||
@@ -196,3 +203,3 @@ | ||
rp({"qs": qs, url: omdbapi, json: true}).then(function(data: OmdbMovie | OmdbError) { | ||
let prom = rp({"qs": qs, url: omdbapi, json: true}).then(function(data: OmdbMovie | OmdbError) { | ||
let ret: Movie; | ||
@@ -202,23 +209,38 @@ if (isError(data)) { | ||
} else { | ||
if (isMovie(data)) | ||
if (isMovie(data)) { | ||
ret = new Movie(data); | ||
else if (isTvshow(data)) | ||
} else if (isTvshow(data)) { | ||
ret = new TVShow(data); | ||
else | ||
return cb(new ImdbError("type: " + data.Type + " not valid", req), undefined); | ||
} else { | ||
let err = new ImdbError("type: " + data.Type + " not valid", req); | ||
if (cb) { | ||
return cb(err, undefined); | ||
} else { | ||
return Promise.reject(err); | ||
} | ||
} | ||
return cb(undefined, ret); | ||
if (cb) { | ||
return cb(undefined, ret); | ||
} | ||
return Promise.resolve(ret); | ||
} | ||
}) | ||
.catch(function(err) { | ||
cb(err, undefined); | ||
}); | ||
if (cb) { | ||
prom.catch(function(err) { | ||
cb(err, undefined); | ||
}); | ||
} else { | ||
return prom; | ||
} | ||
} | ||
export function get(name: string, cb: (err: Error, data: Movie) => any) { | ||
export function get(name: string, cb?: (err: Error, data: Movie) => any): Promise<Movie> { | ||
return getReq({id: undefined, name: name }, cb); | ||
}; | ||
export function getById(imdbid: string, cb: (err: Error, data: Movie) => any) { | ||
export function getById(imdbid: string, cb?: (err: Error, data: Movie) => any): Promise<Movie> { | ||
return getReq({id: imdbid, name: undefined}, cb); | ||
} |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
181385
2.7%36
2.86%3852
2.58%180
6.51%4
33.33%