import { Http } from "@angular/http"; import { Ajax, SuccessCallback } from "@salaxy/core"; import { Observable } from "rxjs/Observable"; import "rxjs/Rx"; import { SalaxyErrorHandler } from "../errors/SalaxyErrorHandler"; import { Token } from "./Token"; /** * The $http access to the server methods: GET, POST and DELETE * with different return types and authentication / error events. */ export declare class AjaxNg implements Ajax { private http; private token; private errorHandler; /** * The server address - root of the server * This is settable field. Will probably be changed to a configuration object in the final version. */ serverAddress: string; /** * By default credentials are not used in http-calls. * Enable credentials with this flag. */ useCredentials: boolean; constructor(http: Http, token: Token, errorHandler: SalaxyErrorHandler); /** Returns the latest API address. E.g. 'https://test-api.salaxy.com/v02/api' */ getApiAddress(): string; /** * Returns the latest Server address that is used as bases to * the HTML queries. E.g. 'https://test-api.salaxy.com' */ getServerAddress(): string; /** * Set this method to have your custom error handling for situations where server returns an error * The default error handling will log the error to console - not much details. * * @param request is the $http request object from which you * can get all the detail data about the error. See $http documentation for more information * @param textStatus - typically just "error" * @param errorThrown - high level error type */ onError(request: any, textStatus: string, errorThrown: any): Observable<{}>; /** * Gets a JSON-message from server using the API * * @param method - The API method is the url starting from api version, e.g. '/v02/api'. * E.g. '/calculator/new' * @param success - A function to be called if the request succeeds. * @param withCredentials - deprecated - do not use. * @param token - deprecated - do not use. */ getJSON(method: string, success?: SuccessCallback, withCredentials?: boolean, token?: string): any; /** Gets a HTML-message from server using the API * * @param method - The API method is the url starting from api version, e.g. '/v02/api'. * E.g. '/calculator/new' * @param success - A function to be called if the request succeeds. * @param withCredentials - deprecated - do not use. * @param token - deprecated - do not use. */ getHTML(method: string, success?: SuccessCallback, withCredentials?: boolean, token?: string): Promise; /** POSTS data to server and receives back a JSON-message. * * @param method - The API method is the url starting from api version, e.g. '/v02/api'. * E.g. '/calculator/new' * @param data - The data that is posted to the server. * @param success - A function to be called if the request succeeds. * @param withCredentials - deprecated - do not use. * @param token - deprecated - do not use. */ postJSON(method: string, data: any, success?: SuccessCallback, withCredentials?: boolean, token?: string): Promise; /** POSTS data to server and receives back HTML. * * @param method - The API method is the url starting from api version, e.g. '/v02/api'. * E.g. '/calculator/new' * @param data - The data that is posted to the server. * @param success - A function to be called if the request succeeds. * @param withCredentials - deprecated - do not use. * @param token - deprecated - do not use. */ postHTML(method: string, data: string, success?: SuccessCallback, withCredentials?: boolean, token?: string): Promise; /** Sends a DELETE-message to server using the API * * @param method - The API method is the url starting from api version, e.g. '/v02/api'. * E.g. '/calculator/new' * @param success - A function to be called if the request succeeds. * @param withCredentials - deprecated - do not use. * @param token - deprecated - do not use. */ remove(method: string, success?: SuccessCallback, withCredentials?: boolean, token?: string): Promise; /** * Handles situations where user has written decimal with comma. E.g. "1,5" * instead of "1.5". Other parsings can be added. * @param possibleNumber: A number or a string that can be converted to a number */ assureValueIsNumber(possibleNumber: any): number; /** * Gets the current token. * Will check the salaxy-token cookie if the token is persisted there */ getCurrentToken(): string; /** * Sets the current token. Persists it to cookie until the browser window * @param token - the authentication token to persist. */ setCurrentToken(token: string): void; }