tineye-api
Advanced tools
Comparing version 1.1.5 to 2.0.0
@@ -5,3 +5,3 @@ /* tineye_api_request.js | ||
* | ||
* Copyright (c) 2019 TinEye. All rights reserved worldwide. | ||
* Copyright (c) 2021 TinEye. All rights reserved worldwide. | ||
*/ | ||
@@ -13,3 +13,2 @@ | ||
var ApiRequest = require("./api_request.js"); | ||
var FormData = require("form-data"); | ||
@@ -21,3 +20,3 @@ const url = require("url"); | ||
function TinEyeApi(apiUrl, publicKey, privateKey) { | ||
function TinEyeApi(apiUrl, apiKey) { | ||
/* | ||
@@ -29,3 +28,3 @@ Class to ease communication with the TinEye API. | ||
var TinEye = require('tineye-api'); | ||
var api = new TinEye('https://api.tineye.com/rest/', 'yourPublicKey', 'yourPrivateKey'); | ||
var api = new TinEye('https://api.tineye.com/rest/', 'yourApiKey'); | ||
@@ -108,4 +107,4 @@ Create your callback function to read the data and pass it in as the last parameter: | ||
{ remaining_searches: 596112, | ||
start_date: '2011-09-29 11:11:31 UTC', | ||
expire_date: '2020-09-28 11:11:31 UTC' } } | ||
start_date: '2020-09-29 11:11:31 UTC', | ||
expire_date: '2022-09-28 11:11:31 UTC' } } | ||
@@ -128,13 +127,6 @@ Getting an image count: | ||
this.apiUrl = apiUrl || "https://api.tineye.com/rest/"; | ||
this.publicKey = publicKey || null; | ||
this.privateKey = privateKey || null; | ||
this.apiRequest = new ApiRequest( | ||
this.apiUrl, | ||
this.publicKey, | ||
this.privateKey | ||
); | ||
this.apiKey = apiKey || null; | ||
} | ||
TinEyeApi.prototype.request = function(method, params, imageFile, callback) { | ||
TinEyeApi.prototype.request = function (method, params, imageFile, callback) { | ||
/* | ||
@@ -152,15 +144,24 @@ Send request to API and process results. | ||
var obj = null; | ||
var apiRequest = this.apiRequest; | ||
let p = new Promise((resolve, reject) => { | ||
// If an image file was NOT provided, send a GET request, else send a POST request. | ||
var headers = { | ||
"X-API-Key": this.apiKey, | ||
}; | ||
var queryParams = new url.URLSearchParams(params); | ||
var parsedUrl = new URL( | ||
`${this.apiUrl}/${method}/?${queryParams.toString()}` | ||
); | ||
if (imageFile === null) { | ||
// No image file, A simple GET will suffice | ||
var request_url = apiRequest.getRequest(method, params); | ||
axios | ||
.get(request_url) | ||
.then(function(response) { | ||
.get(parsedUrl.toString(), { | ||
headers: headers, | ||
}) | ||
.then(function (response) { | ||
resolve(response.data); | ||
}) | ||
.catch(function(error) { | ||
.catch(function (error) { | ||
reject(error); | ||
@@ -174,21 +175,13 @@ }); | ||
filename: "image.jpg", | ||
contentType: "image/jpeg" | ||
contentType: "image/jpeg", | ||
}); | ||
var parsedUrl = url.parse(apiRequest.apiUrl); | ||
var requestData = apiRequest.postRequest( | ||
method, | ||
imageFile[0], | ||
params, | ||
form.getBoundary() | ||
); | ||
form.submit( | ||
{ | ||
host: parsedUrl.host, | ||
path: requestData, | ||
protocol: parsedUrl.protocol | ||
path: `${parsedUrl.pathname}?${parsedUrl.searchParams.toString()}`, | ||
protocol: parsedUrl.protocol, | ||
headers: headers, | ||
}, | ||
function(error, res) { | ||
function (error, res) { | ||
var body = ""; | ||
@@ -200,7 +193,7 @@ | ||
res.on("data", function(chunk) { | ||
res.on("data", function (chunk) { | ||
body += chunk; | ||
}); | ||
res.on("end", function() { | ||
res.on("end", function () { | ||
try { | ||
@@ -214,3 +207,3 @@ obj = JSON.parse(body); | ||
res.on("error", function(error) { | ||
res.on("error", function (error) { | ||
reject(error); | ||
@@ -226,6 +219,6 @@ }); | ||
p.then( | ||
data => { | ||
(data) => { | ||
callback(null, data); | ||
}, | ||
error => { | ||
(error) => { | ||
callback(error); | ||
@@ -239,3 +232,3 @@ } | ||
TinEyeApi.prototype.searchOptions = function(options) { | ||
TinEyeApi.prototype.searchOptions = function (options) { | ||
/* | ||
@@ -266,3 +259,3 @@ Parse search options from array. | ||
TinEyeApi.prototype.searchUrl = function(url, options, callback) { | ||
TinEyeApi.prototype.searchUrl = function (url, options, callback) { | ||
/* | ||
@@ -282,3 +275,3 @@ Perform searches on the TinEye index using an image URL. | ||
TinEyeApi.prototype.searchData = function(data, options, callback) { | ||
TinEyeApi.prototype.searchData = function (data, options, callback) { | ||
/* | ||
@@ -298,3 +291,3 @@ Perform searches on the TinEye index using image data. | ||
TinEyeApi.prototype.remainingSearches = function(callback) { | ||
TinEyeApi.prototype.remainingSearches = function (callback) { | ||
/* | ||
@@ -311,3 +304,3 @@ Lists the number of searches you have left in your current active block. | ||
TinEyeApi.prototype.imageCount = function(callback) { | ||
TinEyeApi.prototype.imageCount = function (callback) { | ||
/* | ||
@@ -314,0 +307,0 @@ Lists the number of indexed images on TinEye. |
{ | ||
"name": "tineye-api", | ||
"version": "1.1.5", | ||
"version": "2.0.0", | ||
"description": "TinEye API node.js library", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"jest": "^27.0.1" | ||
"jest": "^27.0.6" | ||
}, | ||
@@ -31,0 +31,0 @@ "bugs": { |
@@ -10,2 +10,3 @@ # tineye-api | ||
- [ Installation ](#installation) | ||
- [ Migrating from previous versions ](#migrating-from-previous-versions) | ||
- [ Getting started ](#getting-started) | ||
@@ -27,2 +28,27 @@ - [ Methods ](#methods) | ||
# Migrating from previous versions | ||
If you were using any version of the TinEye API library before `2.0.0`, you will need | ||
to make minor changes to your code. | ||
The API object is now instantiated using a single key, `api_key`. The value | ||
of this key is the same as your previous `private_key`. The public key is no | ||
longer used. | ||
#### New ✅ | ||
```javascript | ||
// Sandbox key | ||
// Note that this is the same value as the old private_key | ||
var apiKey = "6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^"; | ||
var api = new TinEye("https://api.tineye.com/rest/", apiKey); | ||
``` | ||
#### Old ❌ | ||
```javascript | ||
// Sandbox keys | ||
var publicKey = "LCkn,2K7osVwkX95K4Oy"; | ||
var privateKey = "6mm60lsCNIB,FwOWjJqA80QZHh9BMwc-ber4u=t^"; | ||
var api = new TinEye("https://api.tineye.com/rest/", publicKey, privateKey); | ||
``` | ||
# Getting started | ||
@@ -32,13 +58,13 @@ | ||
```javascript | ||
var TinEye = require("tineye-api"); | ||
``` | ||
var TinEye = require('tineye-api') | ||
``` | ||
Now that you've required the library, you can use it to create an instance of the API object. | ||
```javascript | ||
var api = new TinEye("https://api.tineye.com/rest/", "yourApiKey"); | ||
``` | ||
var api = new TinEye('https://api.tineye.com/rest/', <public_key>, <private_key>); | ||
``` | ||
Be sure to populate `public_key` and `private_key` with your own keys. You can test your code | ||
Be sure to populate `api_key` with your own key. You can test your code | ||
with our [API sandbox keys](https://services.tineye.com/developers/tineyeapi/sandbox), but | ||
@@ -122,2 +148,7 @@ you won't get real search results until you start using your real keys. | ||
## 2.0.0 | ||
- Swapping HMAC-SHA256 authentication with header key | ||
- Updated jest 27.0.1 -> 27.0.6 | ||
## 1.1.5 | ||
@@ -124,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
200
14191
4
249