UNPKG

nd-common

Version:

74 lines (73 loc) 4.05 kB
import { HttpClient, HttpHeaders } from "@angular/common/http"; import { Observable } from "rxjs"; import { CallParameters } from "nd-common"; import { ITokenController } from "./nd_token_controller"; export declare class RestAPIBaseService { private http; private DEFAULT_REST_VERSION; private tokenService; constructor(http: HttpClient, _token: ITokenController); /** * This is the rest API call method. This method puts all the parameters in the correct order, * get the authorization token, and handle the call. If the initial call fails because of * 401 then the function makes the same call again after getting a new access token. * * Note: In order to actually see the call go out, you will need to observe it. This is done * by subscribing to it. Search code base for implementation examples. * * @param CallParameters p The call parameter needed for making a RestAPI call. * @return Observable<HttpResponse<any>> RxJs observable of type response, this same type should be return to the controllers caller. */ call<T>(p: CallParameters, stripResponse?: boolean): Observable<T>; /** Creates a query argument string based off of the object passed in. This uses the objects labels as the argument labels. * @param obj The object the query arguments will be based off. * @return The query argument string (without "?") */ generateQueryArgs(obj: any): string; /** Getter for the access token * @return The access token stored in the classes memory. If empty returns an empty string. */ /** Setter for the access token. NOTE: This will trim any white space from the param. * @param newToken The new access token for the RestAPI to use. */ AccessToken: string; private _baseUrl; /** Gets the base url for api request. If the value has not been set, the method calls GenerateBaseUrl(), which will fill in default values. */ readonly BaseUrl: string; /** Generates the host url need to make api calls * @param host The service where the request should be made (defaults to vault.netvoyage.com) * @param https Indicates if the request should be made via https (defaults to true) * @param api Indicates if the request should be made against the api pool (defaults to true) */ static GenerateBaseUrl(host?: string, https?: boolean, api?: boolean): string; /** Construct the URL request string by appending: baseUrl + api version + path * @param path The controller path provided by the caller. Example: /System/info/... * @param version The API version number the caller is directing to. If no number is provided the default verion is assumed. * @return The url the API controller will call to. */ private getUrl(path, version?); /** Getter for the request headers. This will add in the access token as well as the response acceptance type (JSON) * @return The Http header object. */ readonly BaseHeaders: HttpHeaders; /** * A well known array of strings that is used to determine if double encoding is needed. */ private static ENCODING_SUBSTRINGS; /** * Handle url string encoding. Ensures double encoding when necessary. * @param attribute The string to be url encoded. */ static urlEncodeString(attribute: string): string; /** * Prepare an attribute value for the call to the Rest API. * Enclose in double quote marks an attribute that contains a comma or a double quote. * Replace double quote marks with pairs of double quote marks. * See the "Lookup table query" section of the Rest API documentation. * @param attribute user-supplied workspace attribute needing prep and encoding */ static attributeQueryEncode(attribute: string): string; static cleanEnv(envUrl: string): string; static createFilterList(filter: Array<string>): string; }