import { RequestBullet, BufferType } from './request-bullet'; import { HttpClient } from '@angular/common/http'; export declare class ApiGunService { _HttpClient: HttpClient; private MainBuffer; private OfflineBuffer; private ErrorBuffer; private SuccessBuffer; private _headers; private _secretKey; algorithm: string; constructor(_HttpClient: HttpClient); /** * Sets a secret for encrypting buffer when need to save on clients LocalStorage * @param secretKey */ setEncryptSecret(secretKey: string): void; /** * Set username and password Authorization Header * @param username * @param password */ setBasicAuthorizationHeader(username: string, password: string): void; /** * Set any Key value pair to the Header * @param key * @param value */ appendHeader(key: string, value: string): void; /** * Add a new request to *MainBuffer* to Shoot later and returns a ID*(GUID String)* to track the response and status anytime using the method *checkSingleBuffer* * @param request */ loadSingleBullet(request: RequestBullet): string; /** * Adds multiple requests to *MainBuffer* to Shoot later * @param requestBullets */ fillBullets(requestBullets: RequestBullet[]): void; /** * Updated the *MainBuffer* with a new request on behalf of ID and returns the element. * It returns null if found none * @param id * @param request */ updateSingleBullet(id: any, request: RequestBullet): RequestBullet; /** * Shoots a single Request from the *MainBuffer* to the server by ID * @param id */ shootSingleBullet(id: string): void; /** * Check a single request element from the *MainBuffer* * @param id */ checkSingleBullet(id: any): RequestBullet; /** * Shoots everything from the MainBuffer to the server and saves the response accordingly * Checks if client is online, it shoots the request to the server else saves the request to *OfflineBuffer* */ fire(): void; recoil(request: RequestBullet): void; /** * Reload * Copy *ErrorBuffer* and *OfflineBuffer* into the *MainBuffer* */ reload(): void; /** * Retries all present in the *ErrorBuffer* * Checks if client is online, it shoots the request to the server else saves the request to *OfflineBuffer* */ retryErrors(): void; /** * Retries all Request *(OfflineBuffer)* which where made when the client was not connected to any network */ retryOfflines(): void; /** * Shoot one request to a server which ever is passed * @param element */ private shootToServer(element); /** * Just Logs all requests in client's browser console. * @param bufferType */ logBufferToConsole(bufferType: BufferType): void; /** * Save all requests in client's browser LocalStorage. */ saveBulletsToLS(): void; /** * Gets all requests in client's browser LocalStorage. */ loadBulletsFromLS(): void; /** * Clears *MainBuffer* to a new state , but leaves the headers intact to let other request process easily. */ clearBuffersOnly(): void; /** * Clears only the SuccessBuffer */ clearSuccessBuffersOnly(): void; /** * Clears everything and takes this to a new state */ clearAll(): void; /** * Private GET Request * @param req */ private GetRequest(req); /** * Private POST Request * @param req */ private PostRequest(req); /** * Private PUT Request * @param req */ private PutRequest(req); /** * Private DELETE Request * @param req */ private deleteRequest(req); /** * Private PATCH Request * @param req */ private patchRequest(req); /** * The backend returned an error response. * @param req * @param err */ private handelError(req, err); /** * Checks if the *ErrorBuffer* is Already has the request * @param req */ private addToErrorBuffer(req); /** * It Handles whenever there is a success response from the server * |1-> It checks if the request of this response was made from *MainBuffer* it moves the req from the *MainBuffer* to the *SuccessBuffer* * |2-> It checks if the request of this response was made from *ErrorBuffer* it moves the req from the *ErrorBuffer* to the *SuccessBuffer* * |3-> It checks if the request of this response was made from *OfflineBuffer* it moves the req from the *OfflineBuffer* to the *SuccessBuffer* * @param req * @param res */ private handelSuccess(req, res); /** * handles Success response * @param req */ private addToSuccessBuffer(req); /** * Handles Request if the Client is Offline * @param req */ private handelOffline(req); /** * Checks if the request is not already in the *OfflineBuffer* it add to it. else do nothing. * @param req */ private addToOfflineBuffer(req); /** * AES Encryption * @param text */ encrypt(text: any): string; /** * AES Decryption * @param text */ decrypt(text: any): string; }