node-pexels
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -10,3 +10,5 @@ import { IPexelsClient, IPexelsResponse } from './interfaces'; | ||
popular(perPage?: number, page?: number): Promise<IPexelsResponse>; | ||
private validatePageAndPerPageArguments(perPage?, page?); | ||
private validateSearchMethodParams(query, perPage?, page?); | ||
private makeRequest(resource, queryStringObject); | ||
} |
@@ -9,2 +9,8 @@ "use strict"; | ||
DefaultPexelsClient.prototype.search = function (query, perPage, page) { | ||
try { | ||
this.validateSearchMethodParams(query, perPage, page); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
return this.makeRequest(DefaultPexelsClient.SEARCH_RESOURCE, { | ||
@@ -17,2 +23,8 @@ query: query, | ||
DefaultPexelsClient.prototype.popular = function (perPage, page) { | ||
try { | ||
this.validatePageAndPerPageArguments(perPage, page); | ||
} | ||
catch (err) { | ||
return Promise.reject(err); | ||
} | ||
return this.makeRequest(DefaultPexelsClient.POPULAR_RESOURCE, { | ||
@@ -23,2 +35,20 @@ per_page: perPage, | ||
}; | ||
DefaultPexelsClient.prototype.validatePageAndPerPageArguments = function (perPage, page) { | ||
var errorFields = []; | ||
if (typeof perPage !== 'undefined' && typeof perPage !== 'number') { | ||
errorFields.push(perPage); | ||
} | ||
if (typeof page !== 'undefined' && typeof page !== 'number') { | ||
errorFields.push(page); | ||
} | ||
if (errorFields.length) { | ||
throw new Error('Pexels client: invalid fields passed to method ' + errorFields); | ||
} | ||
}; | ||
DefaultPexelsClient.prototype.validateSearchMethodParams = function (query, perPage, page) { | ||
this.validatePageAndPerPageArguments(perPage, page); | ||
if (typeof query !== 'string') { | ||
throw new Error('Pexels client: invalid query param: ' + query); | ||
} | ||
}; | ||
DefaultPexelsClient.prototype.makeRequest = function (resource, queryStringObject) { | ||
@@ -25,0 +55,0 @@ return got(DefaultPexelsClient.endpoint + resource, { |
{ | ||
"name": "node-pexels", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Node client for https://www.pexels.com API", | ||
@@ -10,4 +10,5 @@ "main": "build/index.js", | ||
"watch": "tsc --watch", | ||
"test": "mocha build/test/integration", | ||
"lint": "tslint './src/**/*.ts' --type-check --project tsconfig.json" | ||
"test": "istanbul cover node_modules/.bin/_mocha build/test/**/main.js", | ||
"lint": "tslint './src/**/*.ts' --type-check --project tsconfig.json", | ||
"coverage": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls" | ||
}, | ||
@@ -36,2 +37,4 @@ "repository": { | ||
"chai-json-schema": "^1.4.0", | ||
"coveralls": "^2.13.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
@@ -38,0 +41,0 @@ "tslint": "^5.1.0", |
@@ -5,2 +5,3 @@ # node-pexels | ||
[![Build Status](https://travis-ci.org/dlukanin/node-pexels.svg?branch=master)](https://travis-ci.org/dlukanin/node-pexels) | ||
[![Coverage Status](https://coveralls.io/repos/github/dlukanin/node-pexels/badge.svg)](https://coveralls.io/github/dlukanin/node-pexels) | ||
@@ -14,2 +15,5 @@ Simple api client for [Pexels](https://www.pexels.com/) powered by [got package](https://www.npmjs.com/package/got). | ||
#### v 0.0.3 | ||
Some fixes in inner logic and interfaces. Added methods args validation. Some fixes in doc. | ||
#### v 0.0.2 | ||
@@ -47,3 +51,3 @@ Some fixes in schema and ts definitions. | ||
#### search(query: string, perPage?: number, page?: number): Promise\<IPexelsResponse\> | ||
#### popular(perPage?: number, page?: number): Promise\<IPexelsResponse\> | ||
Popular photos request. | ||
@@ -50,0 +54,0 @@ |
Sorry, the diff of this file is not supported yet
8564
110
63
10
10