tmdb-client
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -0,7 +1,79 @@ | ||
// dependency modules | ||
var request = require('request'); | ||
var cdnaUtils = require('cdna-utils'); | ||
// shortcut for api in modules | ||
var MapObject = cdnaUtils.MapObject; | ||
// error message | ||
var errorMessage = { | ||
parseBody: 'unable to parse body to json' | ||
}; | ||
// default url to tmdb api | ||
var tmdbApi = { | ||
key: '5850a992cce5c609f88466d906e77e88', | ||
host: 'http://api.themoviedb.org/3', | ||
path: { | ||
movieLatest: '/movie/popular' | ||
} | ||
}; | ||
// default find params | ||
var findParams = { | ||
pageIndex: 1 | ||
}; | ||
// the movie database client | ||
// using for create new instance of the movie database client | ||
// params | ||
// - api: object contain url to tmdb api | ||
function TmdbClient(api) { | ||
var self = this; | ||
self.api = api || tmdbApi; | ||
} | ||
// shortcut for the movie database prototype | ||
var prototype = TmdbClient.prototype; | ||
// return url to api | ||
prototype.apiUrl = function(path) { | ||
var self = this; | ||
return self.api.host + path; | ||
} | ||
// find movie | ||
prototype.find = function(selector, callback) { | ||
var self = this; | ||
var params = {}; | ||
params.page = selector.pageIndex || findParams.pageIndex; | ||
params.api_key = self.api.key; | ||
var options = {url: self.apiUrl(self.api.path.movieLatest), qs: params}; | ||
request(options, function(err, res, body) { | ||
// check error | ||
if(err) { callback(err); return; } | ||
if(res.statusCode != 200) { callback(res); return; } | ||
// parse body to javascript object | ||
var jsonBody = JSON.parse(body); | ||
if(!jsonBody) { | ||
callback({ message: errorMessage.parseBody, response: response }); | ||
return; | ||
} | ||
// valid data | ||
if(!jsonBody.results) { | ||
callback({ message: 'results not in body', response: response }); | ||
return; | ||
} | ||
// callback with items | ||
callback(null, jsonBody.results); | ||
}); | ||
} | ||
module.exports = TmdbClient; |
{ | ||
"name": "tmdb-client", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "the movie database api for client", | ||
@@ -26,3 +26,11 @@ "main": "index.js", | ||
"url": "https://github.com/thelordofthetimes/tmdb-client/issues" | ||
}, | ||
"dependencies": { | ||
"cdna-utils": "~0.1.0", | ||
"request": "~2.67.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "~3.4.1", | ||
"mocha": "~2.3.4" | ||
} | ||
} |
# tmdb-client | ||
the movie database api for client | ||
## note | ||
module compative with the movie database api version 3 | ||
the movie database api version 3 document [tmdb-api-v3](http://docs.themoviedb.apiary.io/) | ||
almost api has removed because it not neccessary | ||
## installation | ||
```shell | ||
# use node package manager | ||
npm install tmdb-client | ||
``` | ||
## usage | ||
### import module | ||
```javascript | ||
var TmdbClient = require('tmdb-client'); | ||
``` | ||
### create an instance of tmdb client | ||
```javascript | ||
// using default api | ||
var tmdbClient = new TmdbClient(); | ||
// using custom api | ||
// using when tmdb change api url, not change api params and response | ||
var api = { | ||
host: <string>, // url to endpoint api | ||
key: <string>, // api key | ||
path: <object> // object contain pair key: value, it is relative path to api | ||
}; | ||
var tmdbClient = new TmdbClient(api); | ||
``` | ||
### find movie with selector | ||
```javascript | ||
var selector = { | ||
pageIndex: <number> // index of page [1, 1000] | ||
}; | ||
tmdbClient.find(selector, function(error, items) {}); | ||
``` | ||
## development | ||
```shell | ||
# clone form revision system control | ||
git clone git@github.com:thelordofthetimes/tmdb-client.git | ||
cd tmdb-client | ||
# install dependency module | ||
npm install | ||
# run test | ||
npm test | ||
# write code and more.. | ||
# update revision system control | ||
# require ssh-key, please contact with owner to get one | ||
git add . | ||
git commit -am '<message>' | ||
git push | ||
``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
4608
82
74
0
2
2
1
+ Addedcdna-utils@~0.1.0
+ Addedrequest@~2.67.0
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbl@1.0.3(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedcdna-utils@0.1.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.21.0.3(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-validator@2.0.6(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedqs@5.2.1(transitive)
+ Addedreadable-stream@2.0.6(transitive)
+ Addedrequest@2.67.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtough-cookie@2.2.2(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxtend@4.0.2(transitive)