Skip to content

Commit 7b12208

Browse files
committed
Clean up documentation for other APIs
1 parent cde2e47 commit 7b12208

4 files changed

Lines changed: 26 additions & 59 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and this project adheres to
2323

2424
### Removed
2525

26-
- Remove all types for engine parameters. SerpApi's
26+
- Remove all types for engine parameters and responses. SerpApi's
2727
[documentation](https://serpapi.com/search-api) should be the only source of
2828
truth for valid engines and their parameters.
2929

mod.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ export {
99

1010
export type {
1111
AccountApiParameters,
12-
AccountInformation,
1312
BaseResponse,
1413
EngineParameters,
1514
GetBySearchIdParameters,
16-
Location,
17-
Locations,
1815
LocationsApiParameters,
1916
} from "./src/types.ts";
2017
export {

src/serpapi.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { InvalidArgumentError } from "./errors.ts";
22
import {
33
AccountApiParameters,
4-
AccountInformation,
54
BaseResponse,
65
EngineParameters,
76
GetBySearchIdParameters,
8-
Locations,
97
LocationsApiParameters,
108
} from "./types.ts";
119
import {
@@ -277,13 +275,12 @@ async function _getHtml(
277275
* Get a JSON response given a search ID.
278276
* - This search ID can be obtained from the `search_metadata.id` key in the response.
279277
* - Typically used together with the `async` parameter.
280-
* - Accepts an optional callback.
281278
*
282-
* @param {string} searchId - search ID
279+
* @param {string} searchId Search ID.
283280
* @param {object} parameters
284-
* @param {string=} [parameters.api_key] - API key
285-
* @param {number=} [parameters.timeout] - timeout in milliseconds
286-
* @param {fn=} callback - optional callback
281+
* @param {string=} [parameters.api_key] API key.
282+
* @param {number=} [parameters.timeout] Timeout in milliseconds.
283+
* @param {fn=} callback Optional callback.
287284
* @example
288285
* const response = await getJson({ engine: "google", api_key: API_KEY, async: true, q: "coffee" });
289286
* const { id } = response.search_metadata;
@@ -319,14 +316,12 @@ export async function getJsonBySearchId(
319316
* Get a HTML response given a search ID.
320317
* - This search ID can be obtained from the `search_metadata.id` key in the response.
321318
* - Typically used together with the `async` parameter.
322-
* - Accepts an optional callback.
323-
* - Responds with a JSON if the search request hasn't completed.
324319
*
325-
* @param {string} searchId - search ID
320+
* @param {string} searchId Search ID.
326321
* @param {object} parameters
327-
* @param {string=} [parameters.api_key] - API key
328-
* @param {number=} [parameters.timeout] - timeout in milliseconds
329-
* @param {fn=} callback - optional callback
322+
* @param {string=} [parameters.api_key] API key.
323+
* @param {number=} [parameters.timeout] Timeout in milliseconds.
324+
* @param {fn=} callback Optional callback.
330325
* @example
331326
* const response = await getJson({ engine: "google", api_key: API_KEY, async: true, q: "coffee" });
332327
* const { id } = response.search_metadata;
@@ -359,12 +354,13 @@ export async function getHtmlBySearchId(
359354

360355
/**
361356
* Get account information of an API key.
362-
* https://serpapi.com/account-api
357+
*
358+
* Refer to https://serpapi.com/account-api for response examples.
363359
*
364360
* @param {object} parameters
365-
* @param {string=} [parameters.api_key] - API key
366-
* @param {number=} [parameters.timeout] - timeout in milliseconds
367-
* @param {fn=} callback - optional callback
361+
* @param {string=} [parameters.api_key] API key.
362+
* @param {number=} [parameters.timeout] Timeout in milliseconds.
363+
* @param {fn=} callback Optional callback.
368364
* @example
369365
* // async/await
370366
* const info = await getAccount({ api_key: API_KEY });
@@ -374,27 +370,29 @@ export async function getHtmlBySearchId(
374370
*/
375371
export async function getAccount(
376372
parameters: AccountApiParameters = {},
377-
callback?: (info: AccountInformation) => void,
373+
// deno-lint-ignore no-explicit-any
374+
callback?: (info: any) => void,
378375
) {
379376
const key = validateApiKey(parameters.api_key);
380377
const timeout = validateTimeout(parameters.timeout);
381378
const response = await _internals.execute(ACCOUNT_PATH, {
382379
api_key: key,
383380
}, timeout);
384-
const info = JSON.parse(response) as AccountInformation;
381+
const info = JSON.parse(response);
385382
callback?.(info);
386383
return info;
387384
}
388385

389386
/**
390387
* Get supported locations. Does not require an API key.
391-
* https://serpapi.com/locations-api
388+
*
389+
* Refer to https://serpapi.com/locations-api for response examples.
392390
*
393391
* @param {object} parameters
394-
* @param {string=} [parameters.q] - query for a location
395-
* @param {number=} [parameters.limit] - limit on number of locations returned
396-
* @param {number=} [parameters.timeout] - timeout in milliseconds
397-
* @param {fn=} callback - optional callback
392+
* @param {string=} [parameters.q] Query for a location.
393+
* @param {number=} [parameters.limit] Limit on number of locations returned.
394+
* @param {number=} [parameters.timeout] Timeout in milliseconds.
395+
* @param {fn=} callback Optional callback.
398396
* @example
399397
* // async/await
400398
* const locations = await getLocations({ limit: 3 });
@@ -404,15 +402,16 @@ export async function getAccount(
404402
*/
405403
export async function getLocations(
406404
parameters: LocationsApiParameters = {},
407-
callback?: (locations: Locations) => void,
405+
// deno-lint-ignore no-explicit-any
406+
callback?: (locations: any) => void,
408407
) {
409408
const timeout = validateTimeout(parameters.timeout);
410409
const response = await _internals.execute(
411410
LOCATIONS_PATH,
412411
parameters,
413412
timeout,
414413
);
415-
const locations = JSON.parse(response) as Locations;
414+
const locations = JSON.parse(response);
416415
callback?.(locations);
417416
return locations;
418417
}

src/types.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,8 @@ export type AccountApiParameters = {
1717
api_key?: string;
1818
timeout?: number;
1919
};
20-
export type AccountInformation = {
21-
account_email: string;
22-
account_id: string;
23-
account_rate_limit_per_hour: number;
24-
api_key: string;
25-
extra_credits: number;
26-
last_hour_searches: number;
27-
plan_id: string;
28-
plan_name: string;
29-
plan_searches_left: number;
30-
searches_per_month: number;
31-
this_hour_searches: number;
32-
this_month_usage: number;
33-
total_searches_left: number;
34-
};
35-
3620
export type LocationsApiParameters = {
3721
q?: string;
3822
limit?: number;
3923
timeout?: number;
4024
};
41-
export type Location = {
42-
canonical_name: string;
43-
country_code: string;
44-
google_id: number;
45-
google_parent_id: number;
46-
gps: [number, number];
47-
id: string;
48-
keys: string[];
49-
name: string;
50-
reach: number;
51-
target_type: string;
52-
};
53-
export type Locations = Location[];

0 commit comments

Comments
 (0)