Skip to content

Commit

Permalink
refactor: remove the word Request from custom geocoding RequestOption…
Browse files Browse the repository at this point in the history
…s interfaces

AFFECTS PACKAGES:
@esri/arcgis-rest-geocoding
@esri/arcgis-rest-routing

BREAKING CHANGE:
IGeocodeRequesttOptions is now IGeocodeOptions, IBulkGeocodingRequestOptions is now
IBulkGeocodeOptions
  • Loading branch information
jgravois committed Apr 18, 2019
1 parent 9028d82 commit f8c6255
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 44 deletions.
20 changes: 6 additions & 14 deletions packages/arcgis-rest-geocoding/src/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
* Apache-2.0 */

import { request, cleanUrl } from "@esri/arcgis-rest-request";

import { ISpatialReference, IPoint } from "@esri/arcgis-rest-types";

import {
ARCGIS_ONLINE_GEOCODING_URL,
IEndpointRequestOptions
} from "./helpers";
import { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from "./helpers";

// it'd be better if doc didnt display these properties in alphabetical order
export interface IAddressBulk {
Expand All @@ -31,15 +27,15 @@ export interface IAddressBulk {
countryCode?: string;
}

export interface IBulkGeocodeRequestOptions extends IEndpointRequestOptions {
export interface IBulkGeocodeOptions extends IEndpointOptions {
addresses: IAddressBulk[];
}

export interface IBulkGeocodeResponse {
spatialReference: ISpatialReference;
locations: Array<{
address: string;
location: IPoint;
location?: IPoint; // candidates with a score of 0 wont include a location
score: number;
attributes: object;
}>;
Expand All @@ -66,9 +62,9 @@ export interface IBulkGeocodeResponse {
* @returns A Promise that will resolve with the data from the response. The spatial reference will be added to address locations unless `rawResponse: true` was passed.
*/
export function bulkGeocode(
requestOptions: IBulkGeocodeRequestOptions // must POST, which is the default
) {
const options: IBulkGeocodeRequestOptions = {
requestOptions: IBulkGeocodeOptions // must POST, which is the default
): Promise<IBulkGeocodeResponse> {
const options: IBulkGeocodeOptions = {
endpoint: ARCGIS_ONLINE_GEOCODING_URL,
params: {
forStorage: true,
Expand Down Expand Up @@ -107,7 +103,3 @@ export function bulkGeocode(
return response;
});
}

export default {
bulkGeocode
};
13 changes: 5 additions & 8 deletions packages/arcgis-rest-geocoding/src/geocode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ import {

import { IExtent, ISpatialReference, IPoint } from "@esri/arcgis-rest-types";

import {
ARCGIS_ONLINE_GEOCODING_URL,
IEndpointRequestOptions
} from "./helpers";
import { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from "./helpers";

export interface IGeocodeRequestOptions extends IEndpointRequestOptions {
export interface IGeocodeOptions extends IEndpointOptions {
/**
* use this if all your address info is contained in a single string.
*/
Expand Down Expand Up @@ -82,17 +79,17 @@ export interface IGeocodeResponse {
* @returns A Promise that will resolve with address candidates for the request. The spatial reference will be added to candidate locations and extents unless `rawResponse: true` was passed.
*/
export function geocode(
address: string | IGeocodeRequestOptions
address: string | IGeocodeOptions
): Promise<IGeocodeResponse> {
let options: IGeocodeRequestOptions = {};
let options: IGeocodeOptions;
let endpoint: string;

if (typeof address === "string") {
options.params = { singleLine: address };
endpoint = ARCGIS_ONLINE_GEOCODING_URL;
} else {
endpoint = address.endpoint || ARCGIS_ONLINE_GEOCODING_URL;
options = appendCustomParams<IGeocodeRequestOptions>(
options = appendCustomParams<IGeocodeOptions>(
address,
[
"singleLine",
Expand Down
6 changes: 3 additions & 3 deletions packages/arcgis-rest-geocoding/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ARCGIS_ONLINE_GEOCODING_URL =
"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/";

// nice to have: verify custom endpoints contain 'GeocodeServer' and end in a '/'
export interface IEndpointRequestOptions extends IRequestOptions {
export interface IEndpointOptions extends IRequestOptions {
/**
* Any ArcGIS Geocoding service (example: http://sampleserver6.arcgisonline.com/arcgis/rest/services/Locators/SanDiego/GeocodeServer )
*/
Expand Down Expand Up @@ -39,12 +39,12 @@ export interface IGetGeocodeServiceResponse {
* @returns A Promise that will resolve with the data from the response.
*/
export function getGeocodeService(
requestOptions?: IEndpointRequestOptions
requestOptions?: IEndpointOptions
): Promise<IGetGeocodeServiceResponse> {
const url =
(requestOptions && requestOptions.endpoint) || ARCGIS_ONLINE_GEOCODING_URL;

const options: IEndpointRequestOptions = {
const options: IEndpointOptions = {
httpMethod: "GET",
maxUrlLength: 2000,
...requestOptions
Expand Down
9 changes: 3 additions & 6 deletions packages/arcgis-rest-geocoding/src/reverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { request, cleanUrl } from "@esri/arcgis-rest-request";

import { IPoint, ILocation } from "@esri/arcgis-rest-types";

import {
ARCGIS_ONLINE_GEOCODING_URL,
IEndpointRequestOptions
} from "./helpers";
import { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from "./helpers";

export interface IReverseGeocodeResponse {
address: {
Expand Down Expand Up @@ -57,9 +54,9 @@ function isLocation(
*/
export function reverseGeocode(
coords: IPoint | ILocation | [number, number],
requestOptions?: IEndpointRequestOptions
requestOptions?: IEndpointOptions
): Promise<IReverseGeocodeResponse> {
const options: IEndpointRequestOptions = {
const options: IEndpointOptions = {
endpoint: ARCGIS_ONLINE_GEOCODING_URL,
params: {},
...requestOptions
Expand Down
9 changes: 3 additions & 6 deletions packages/arcgis-rest-geocoding/src/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

import { request, cleanUrl } from "@esri/arcgis-rest-request";

import {
ARCGIS_ONLINE_GEOCODING_URL,
IEndpointRequestOptions
} from "./helpers";
import { ARCGIS_ONLINE_GEOCODING_URL, IEndpointOptions } from "./helpers";

export interface ISuggestResponse {
suggestions: Array<{
Expand All @@ -30,9 +27,9 @@ export interface ISuggestResponse {
*/
export function suggest(
partialText: string,
requestOptions?: IEndpointRequestOptions
requestOptions?: IEndpointOptions
): Promise<ISuggestResponse> {
const options: IEndpointRequestOptions = {
const options: IEndpointOptions = {
endpoint: ARCGIS_ONLINE_GEOCODING_URL,
params: {},
...requestOptions
Expand Down
11 changes: 7 additions & 4 deletions packages/arcgis-rest-geocoding/test/mocks/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Apache-2.0 */

import { IGeocodeResponse } from "../../src/geocode";
import { ISuggestResponse } from "../../src/suggest";
import { IReverseGeocodeResponse } from "../../src/reverse";
import { IBulkGeocodeResponse } from "../../src/bulk";

export const FindAddressCandidates: IGeocodeResponse = {
spatialReference: {
Expand Down Expand Up @@ -93,7 +96,7 @@ export const FindAddressCandidatesNullExtent: IGeocodeResponse = {
]
};

export const Suggest = {
export const Suggest: ISuggestResponse = {
suggestions: [
{
text: "LAX, Los Angeles, CA, USA",
Expand Down Expand Up @@ -128,7 +131,7 @@ export const Suggest = {
]
};

export const ReverseGeocode = {
export const ReverseGeocode: IReverseGeocodeResponse = {
address: {
Match_addr: "LA Airport",
LongLabel: "LA Airport, Los Angeles, CA, USA",
Expand Down Expand Up @@ -161,7 +164,7 @@ export const ReverseGeocode = {
}
};

export const GeocodeAddresses = {
export const GeocodeAddresses: IBulkGeocodeResponse = {
spatialReference: { wkid: 4326, latestWkid: 4326 },
locations: [
{
Expand Down Expand Up @@ -295,7 +298,7 @@ export const GeocodeAddresses = {
{
address: "foo bar baz",
score: 0,
attributes: {}
attributes: {} as any
}
]
};
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-routing/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const ARCGIS_ONLINE_ROUTING_URL =
"https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";

// nice to have: verify custom endpoints contain 'NAServer' and end in a '/'
export interface IEndpointRequestOptions extends IRequestOptions {
export interface IEndpointOptions extends IRequestOptions {
/**
* Any ArcGIS Routing service (example: https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/ ) to use for the routing service request.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/arcgis-rest-routing/src/solveRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
IFeature
} from "@esri/arcgis-rest-types";

import { ARCGIS_ONLINE_ROUTING_URL, IEndpointRequestOptions } from "./helpers";
import { ARCGIS_ONLINE_ROUTING_URL, IEndpointOptions } from "./helpers";

export interface ISolveRouteRequestOptions extends IEndpointRequestOptions {
export interface ISolveRouteRequestOptions extends IEndpointOptions {
/**
* Specify two or more locations between which the route is to be found.
*/
Expand Down

0 comments on commit f8c6255

Please sign in to comment.