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

chucknorris-io

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chucknorris-io - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

src/Entity/JokeCollection.js

2

package.json
{
"name": "chucknorris-io",
"version": "1.0.3",
"version": "1.0.4",
"description": "chucknorris.io api client library for node.js returning promises.",

@@ -5,0 +5,0 @@ "main": "./src/Client.js",

@@ -46,2 +46,9 @@ [![Build Status](https://travis-ci.org/chucknorris-io/client-nodejs.svg?branch=master)](https://travis-ci.org/chucknorris-io/client-nodejs)

});
// Free text search
client.search(searchTerm).then(function (response) {
// to stuff here
}).catch(function (err) {
// handle error
});
```

@@ -48,0 +55,0 @@

'use strict';
const https = require('https'),
Joke = require('./Entity/Joke'),
JokeMapper = require('./Mapper/Joke'),
pkg = require('../package.json'),
querystring = require('querystring'),
url = require('url'),
util = require('util');
const https = require('https'),
Joke = require('./Entity/Joke'),
JokeCollection = require('./Entity/JokeCollection'),
JokeMapper = require('./Mapper/Joke'),
JokeCollectionMapper = require('./Mapper/JokeCollection'),
pkg = require('../package.json'),
querystring = require('querystring'),
url = require('url'),
util = require('util');

@@ -119,2 +121,22 @@ /**

/**
* Free text search
* @param {String} searchTerm
* @return {Promise}
*/
Chuck.prototype.search = function(searchTerm) {
const query = {
query : searchTerm
};
const response = this._request('get', 'jokes/search', query, {
'accept' : 'application/json',
'user-agent' : util.format('chucknorris-io/client-nodejs#v%s', pkg.version)
});
return new Promise(function(resolve, reject) {
response.then(JokeCollectionMapper.fromApiResponse).then(resolve).catch(reject);
});
};
module.exports = Chuck;

@@ -26,15 +26,24 @@ 'use strict';

/**
* Create an instance of Joke from a json string
* @param {String} jsonString
* Create an instance of Joke from json string or object
* @param {Object|String} json
* @throws {TypeError}
* @return {Joke}
*/
JokeMapper.fromJson = function(jsonString) {
if ('string' !== typeof jsonString) {
throw new TypeError('Property "body" must be of type string.');
JokeMapper.fromJson = function(json) {
let data;
switch (typeof json) {
case 'object':
data = json;
break;
case 'string':
data = JSON.parse(json);
break;
default:
throw new TypeError('Argument "json" must be of type string or object.');
}
const data = JSON.parse(jsonString);
return new Joke(data.category, data.icon_url, data.id, data.url, data.value);
};
'use strict';
const assert = require('chai').assert,
Chuck = require('../src/Client'),
Joke = require('../src/Entity/Joke'),
pkg = require('../package.json'),
util = require('util');
const assert = require('chai').assert,
Chuck = require('../src/Client'),
Joke = require('../src/Entity/Joke'),
JokeCollection = require('../src/Entity/JokeCollection'),
pkg = require('../package.json'),
util = require('util');

@@ -59,2 +60,14 @@ describe(util.format('%s/Client', pkg.name), function () {

describe('#search', function() {
it('Should return a collection of joke', function(done) {
const client = new Chuck(),
response = client.search('Charlie Sheen');
response.then(function (response) {
assert.instanceOf(response, JokeCollection);
done();
});
});
});
});
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