cloudflare
Version:
The official TypeScript library for the Cloudflare API
302 lines (242 loc) • 6.41 kB
text/typescript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import { APIPromise } from '../../core/api-promise';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class BaseGeolocations extends APIResource {
static override readonly _key: readonly ['radar', 'geolocations'] = Object.freeze([
'radar',
'geolocations',
] as const);
/**
* Retrieves a list of geolocations. Geolocation names can be localized by sending
* an `Accept-Language` HTTP header with a BCP 47 language tag (e.g.,
* `Accept-Language: pt-PT`). The full quality-value chain is supported (e.g.,
* `pt-PT,pt;q=0.9,en;q=0.8`).
*
* @example
* ```ts
* const geolocations = await client.radar.geolocations.list();
* ```
*/
list(
query: GeolocationListParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<GeolocationListResponse> {
return (
this._client.get('/radar/geolocations', { query, ...options }) as APIPromise<{
result: GeolocationListResponse;
}>
)._thenUnwrap((obj) => obj.result);
}
/**
* Retrieves the requested Geolocation information. Geolocation names can be
* localized by sending an `Accept-Language` HTTP header with a BCP 47 language tag
* (e.g., `Accept-Language: pt-PT`). The full quality-value chain is supported
* (e.g., `pt-PT,pt;q=0.9,en;q=0.8`).
*
* @example
* ```ts
* const geolocation = await client.radar.geolocations.get(
* '3190509',
* );
* ```
*/
get(
geoID: string,
query: GeolocationGetParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<GeolocationGetResponse> {
return (
this._client.get(path`/radar/geolocations/${geoID}`, { query, ...options }) as APIPromise<{
result: GeolocationGetResponse;
}>
)._thenUnwrap((obj) => obj.result);
}
}
export class Geolocations extends BaseGeolocations {}
export interface GeolocationListResponse {
geolocations: Array<GeolocationListResponse.Geolocation>;
}
export namespace GeolocationListResponse {
export interface Geolocation {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
parent: Geolocation.Parent;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
export namespace Geolocation {
export interface Parent {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
parent: Parent.Parent;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
export namespace Parent {
export interface Parent {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
}
}
}
export interface GeolocationGetResponse {
geolocation: GeolocationGetResponse.Geolocation;
}
export namespace GeolocationGetResponse {
export interface Geolocation {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
parent: Geolocation.Parent;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
export namespace Geolocation {
export interface Parent {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
parent: Parent.Parent;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
export namespace Parent {
export interface Parent {
geoId: string;
/**
* A numeric string.
*/
latitude: string;
/**
* A numeric string.
*/
longitude: string;
name: string;
/**
* The type of the geolocation.
*/
type: 'CONTINENT' | 'COUNTRY' | 'ADM1';
code?: string;
/**
* BCP 47 locale code used for the geolocation name translation
*/
locale?: string;
}
}
}
}
export interface GeolocationListParams {
/**
* Format in which results will be returned.
*/
format?: 'JSON' | 'CSV';
/**
* Filters results by geolocation. Specify a comma-separated list of GeoNames IDs.
*/
geoId?: string;
/**
* Limits the number of objects returned in the response.
*/
limit?: number;
/**
* Filters results by location. Specify a comma-separated list of alpha-2 location
* codes.
*/
location?: string;
/**
* Skips the specified number of objects before fetching the results.
*/
offset?: number;
}
export interface GeolocationGetParams {
/**
* Format in which results will be returned.
*/
format?: 'JSON' | 'CSV';
}
export declare namespace Geolocations {
export {
type GeolocationListResponse as GeolocationListResponse,
type GeolocationGetResponse as GeolocationGetResponse,
type GeolocationListParams as GeolocationListParams,
type GeolocationGetParams as GeolocationGetParams,
};
}