truepixabay
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -5,2 +5,3 @@ "use strict"; | ||
const Constants_1 = require("../util/Constants"); | ||
const querystring_1 = require("querystring"); | ||
class Client { | ||
@@ -14,3 +15,4 @@ constructor(options) { | ||
async getImages(options) { | ||
const cached = this._imageCache.get(options); | ||
const stringVersion = this._stringifyQuery(options); | ||
const cached = this._imageCache.get(stringVersion); | ||
if (cached) { | ||
@@ -25,3 +27,3 @@ const difference = Date.now() - cached.timestamp; | ||
if (this._isImageResponse(result)) { | ||
this._imageCache.set(options, { timestamp: Date.now(), image: result }); | ||
this._imageCache.set(stringVersion, { timestamp: Date.now(), image: result }); | ||
return result; | ||
@@ -34,3 +36,4 @@ } | ||
async getVideos(options) { | ||
const cached = this._videoCache.get(options); | ||
const stringVersion = this._stringifyQuery(options); | ||
const cached = this._videoCache.get(stringVersion); | ||
if (cached) { | ||
@@ -45,3 +48,3 @@ const difference = Date.now() - cached.timestamp; | ||
if (!this._isImageResponse(result)) { | ||
this._videoCache.set(options, { timestamp: Date.now(), video: result }); | ||
this._videoCache.set(stringVersion, { timestamp: Date.now(), video: result }); | ||
return result; | ||
@@ -53,2 +56,5 @@ } | ||
} | ||
_stringifyQuery(obj) { | ||
return querystring_1.stringify(obj); | ||
} | ||
_isImageResponse(arg) { | ||
@@ -55,0 +61,0 @@ return !arg.hits[0].duration; |
@@ -27,4 +27,5 @@ import { VideoResponse, ImageResponse } from './PixabayResponses'; | ||
getVideos(options: VideoQuery): Promise<VideoResponse>; | ||
private _stringifyQuery(obj); | ||
private _isImageResponse(arg); | ||
private _makeRequest(request); | ||
} |
{ | ||
"name": "truepixabay", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "a library to interact with pixabay api.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
30112
706