|
1 | 1 | import Request from '../Request' |
2 | 2 | import { Response } from '../Response'; |
3 | 3 |
|
| 4 | +export enum Endpoint { |
| 5 | + CompanyValidate = "company/validate", |
| 6 | + CompanySearch = "company/search", |
| 7 | + CompanyGet = "company/get", |
| 8 | + LocationValidate = "location/validate", |
| 9 | + LocationSearch = "location/search", |
| 10 | + LocationGet = "location/get", |
| 11 | + LocationLocalize = "location/localize", |
| 12 | + NameValidate = "name/validate", |
| 13 | + EmailValidate = "email/validate", |
| 14 | + EmailSearch = "email/search", |
| 15 | + PhoneValidate = "phone/validate" |
| 16 | +} |
| 17 | + |
4 | 18 | /** |
5 | 19 | * Base resource class for handling common resource functionality. |
6 | 20 | */ |
@@ -76,13 +90,10 @@ export default abstract class BaseResource { |
76 | 90 | * Sends a request to the specified endpoint with the given query parameters. |
77 | 91 | * |
78 | 92 | * @param {Record<string, any>} query - The query parameters to send with the request. |
79 | | - * @param {string} methodName - The name of the method to call on the endpoint. |
| 93 | + * @param {string} endpoint - The endpoint to call e.g. "email/validate". |
80 | 94 | * @return {Promise<Response>} A promise that resolves to the response from the request. |
81 | 95 | */ |
82 | | - protected async send(query: Record<string, any>, methodName: string): Promise<Response> { |
83 | | - const callerClass = this.constructor.name.toLowerCase(); |
84 | | - const endpoint = `${callerClass}/${methodName}`; |
85 | | - |
| 96 | + protected async send(query: Record<string, any>, endpoint: Endpoint): Promise<Response> { |
86 | 97 | this.request.setEndpoint(endpoint); |
87 | 98 | this.request.setQuery(query); |
88 | 99 | const r = await this.request.send() |
|
0 commit comments