bing-image-search-async-iterator
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -28,5 +28,9 @@ 'use strict'; | ||
}; | ||
const apiKeyHeaderName = 'Ocp-Apim-Subscription-Key'; | ||
const clientIDHeaderName = 'X-MSEdge-ClientID'; | ||
const acceptHeaderName = 'Accept'; | ||
const HEADERS = { | ||
API_KEY: 'Ocp-Apim-Subscription-Key', | ||
CLIENT_ID: 'X-MSEdge-ClientID', | ||
CLIENT_IP: 'X-MSEdge-ClientIP', | ||
LOCATION: 'X-Search-Location', | ||
ACCEPT: 'Accept' | ||
}; | ||
const acceptHeaderValue = 'application/json'; | ||
@@ -50,5 +54,22 @@ | ||
safeSearch = _Object$assign.safeSearch, | ||
aspect = _Object$assign.aspect, | ||
color = _Object$assign.color, | ||
imageContent = _Object$assign.imageContent, | ||
imageType = _Object$assign.imageType, | ||
license = _Object$assign.license, | ||
freshness = _Object$assign.freshness, | ||
size = _Object$assign.size, | ||
width = _Object$assign.width, | ||
height = _Object$assign.height, | ||
minWidth = _Object$assign.minWidth, | ||
minHeight = _Object$assign.minHeight, | ||
maxWidth = _Object$assign.maxWidth, | ||
maxHeight = _Object$assign.maxHeight, | ||
minFileSize = _Object$assign.minFileSize, | ||
maxFileSize = _Object$assign.maxFileSize, | ||
offset = _Object$assign.offset, | ||
count = _Object$assign.count, | ||
amount = _Object$assign.amount, | ||
clientIP = _Object$assign.clientIP, | ||
location = _Object$assign.location, | ||
queryParams = _Object$assign.queryParams, | ||
@@ -61,3 +82,3 @@ headerParams = _Object$assign.headerParams, | ||
let available = currOffset + currAmount; | ||
let clientID = null; | ||
let clientID = options.clientID; | ||
@@ -69,2 +90,17 @@ while (currOffset < Math.min(currOffset + currAmount, available)) { | ||
safeSearch, | ||
aspect, | ||
color, | ||
imageContent, | ||
imageType, | ||
license, | ||
freshness, | ||
size, | ||
width, | ||
height, | ||
minWidth, | ||
minHeight, | ||
maxWidth, | ||
maxHeight, | ||
minFileSize, | ||
maxFileSize, | ||
offset: currOffset, | ||
@@ -74,5 +110,7 @@ count: Math.min(count, Math.min(currOffset + currAmount, available) - currOffset) | ||
const requestHeaders = filterNulls(_extends({ | ||
[apiKeyHeaderName]: key, | ||
[clientIDHeaderName]: clientID, | ||
[acceptHeaderName]: acceptHeaderValue | ||
[HEADERS.API_KEY]: key, | ||
[HEADERS.CLIENT_ID]: clientID, | ||
[HEADERS.CLIENT_IP]: clientIP, | ||
[HEADERS.LOCATION]: location, | ||
[HEADERS.ACCEPT]: acceptHeaderValue | ||
}, headerParams)); | ||
@@ -96,3 +134,3 @@ const requestOptions = { | ||
available = body.totalEstimatedMatches; | ||
clientID = response.headers.get(clientIDHeaderName); | ||
clientID = clientID === undefined ? response.headers.get(HEADERS.CLIENT_ID) : clientID; | ||
yield body; | ||
@@ -99,0 +137,0 @@ } |
{ | ||
"name": "bing-image-search-async-iterator", | ||
"description": "Async iterator for Bing Image Search API call responses", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "David Hu", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/funpokes/bing-image-search-async-iterator/issues", |
@@ -58,2 +58,5 @@ # Bing Image Search Async Iterator | ||
## Options | ||
### Basic Options | ||
These are the main parameters you should specify. | ||
| Parameter | Type | Default | Description | | ||
@@ -63,10 +66,38 @@ | ------------ | ---------- | -------------- | ------------------------------------------------------------------ | | ||
| query | `string` | | **(Required)** Search [query](https://msdn.microsoft.com/library/ff795620.aspx) | | ||
| amount | `integer` | 2000 | Desired count of results | | ||
| amount | `integer` | `2000` | Desired count of results | | ||
| market | `string` | | [*Market Code*](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#market-codes) of request origin (e.g., `en-US`) | | ||
| safeSearch | `string` | `Moderate` | [Filter adult content](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#safesearch) (`Off`, `Moderate`, ``Strict``) | | ||
### Filtering Options | ||
You may specify your search query's filters with the following settings. | ||
| Parameter | Type | Default | Description | | ||
| ------------ | ---------- | -------------- | ------------------------------------------------------------------ | | ||
| aspect | `string` | `All` | Filter images by aspect ratio (`Square`, `Wide`, `Tall`, `All`) | | ||
| color | `string` | | Filter images by color (`ColorOnly`, `Monochrome`, `Black`, `Blue`, `Brown`, `Gray`, `Green`, `Orange`, `Pink`, `Purple`, `Red`, `Teal`, `White`, `Yellow`) | | ||
| imageContent | `string` | | Filter images by content type (`Face`, `Portrait`) | | ||
| imageType | `string` | | Filter images by image type (`AnimatedGif`, `AnimatedGifHttps`, `Clipart`, `Line`, `Photo`, `Shopping`, `Transparent`) | | ||
| license | `string` | `All` | Filter images by image license type (`Any`, `Public`, `Share`, `ShareCommercially`, `Modify`, `ModifyCommercially`, `All`); `Any` excludes images without known license | | ||
| freshness | `string` | | Filter images by discovery time (`Day`, `Week`, `Month`) | | ||
| size | `string` | `All` | Filter images by image size (`Small`, `Medium`, `Large`, `Wallpaper`, `All`) | | ||
| width | `integer` | | Filter images by specific width | | ||
| height | `integer` | | Filter images by specific height | | ||
| minWidth | `integer` | | Filter images by where width is greater than or equal to specified value | | ||
| minHeight | `integer` | | Filter images by where height is greater than or equal to specified value | | ||
| maxWidth | `integer` | | Filter images by where width is less than or equal to specified value | | ||
| maxHeight | `integer` | | Filter images by where height is less than or equal to specified value | | ||
| minFileSize | `integer` | | Filter images by where file size is greater than or equal to specifie value | | ||
| maxFileSize | `integer` | | Filter images by where file size is less than or equal to specified value | | ||
### Advanced Options | ||
You do not need to set these parameters under normal circumstances. | ||
| Parameter | Type | Default | Description | | ||
| ------------ | ---------- | -------------- | ------------------------------------------------------------------ | | ||
| offset | `integer` | `0` | [Offset](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#offset) of the initial API call | | ||
| count | `integer` | `150` | [Count](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#count) of results per API call (lower this value may result in more API calls) | | ||
| clientID | `string` | | API request header [`X-MSEdge-ClientID`](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#clientid) (auto-determined if not set) | | ||
| clientIP | `string` | | API request header [`X-MSEdge-ClientIP`](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#clientip) | | ||
| location | `string` | | API request header [`X-Search-Location`](https://docs.microsoft.com/en-us/rest/api/cognitiveservices/bing-images-api-v7-reference#location) | | ||
| queryParams | `object` | | Additional query params (e.g., `{ imageType: "AnimatedGif" }`) | | ||
| headerParams | `object` | | Additional header params (e.g., `{ Pragma: "no-cache" }`) | | ||
| fetchCb | `function` | [`fetch`](https://github.com/bitinn/node-fetch) | Callback to construct a request that returns a response promise | | ||
| fetchCb | `function` | [`fetch`](https://github.com/bitinn/node-fetch) | Callback to construct a request that returns a response promise | | ||
@@ -73,0 +104,0 @@ ## Features |
16992
128
111