Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tmdb-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tmdb-client - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

72

lib/tmbn-client.js

@@ -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;

10

package.json
{
"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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc