Advertisement
Zgragselus

Currency - comments

Dec 4th, 2022
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { System } from "../../util/system";
  2. import { Url } from "../../util/url";
  3.  
  4. /**
  5.  * Class for currency requests on frontend side
  6.  *
  7.  * Singleton - access with Rum_Currency.Instance()
  8.  */
  9. export class Rum_Currency
  10. {
  11.     /**
  12.      * Singleton instance
  13.      */
  14.     private static instance: Rum_Currency;
  15.  
  16.     /**
  17.      * Default constructor (private = non-instantiable object)
  18.      */
  19.     private constructor()
  20.     {
  21.  
  22.     }
  23.  
  24.     /**
  25.      * Instance function (get object) - singleton pattern
  26.      * @returns Object instance
  27.      */
  28.     public static Instance()
  29.     {
  30.         if (!Rum_Currency.instance)
  31.         {
  32.             Rum_Currency.instance = new Rum_Currency();
  33.         }
  34.  
  35.         return Rum_Currency.instance;
  36.     }
  37.  
  38.     /**
  39.      * Request server to obtain list of all currencies
  40.      * @returns JSON - result (status code), error (in case of any), currency (list of currencies)
  41.      */
  42.     public GetCurrencies(): Promise<any>
  43.     {
  44.         return Url.FetchJson(System.BaseURL() + "api/v1/rum/currency/read.php", true, {}, System.progress);
  45.     }
  46.  
  47.     /**
  48.      * Request server to obtain single currency
  49.      * @param currency ID of the currency to request
  50.      * @returns JSON - result (status code), error (in case of any), currency (array containing single element with specific currency)
  51.      */
  52.     public GetCurrency(currency: number): Promise<any>
  53.     {
  54.         var json = { "id": currency };
  55.  
  56.         return Url.FetchJson(System.BaseURL() + "api/v1/rum/currency/read.php", true, json, System.progress);
  57.     }
  58.  
  59.     /**
  60.      * Request currency rates from specified currency to others (base currency - EUR, or all others if requested on EUR)
  61.      * @param from_id ID of the currency for which we request rates
  62.      * @returns JSON - result (status code), error (in case of any), currency_rate (array containing currency rates for specified currency)
  63.      */
  64.     public GetRates(from_id: number): Promise<any>
  65.     {
  66.         var json = { "from_id": from_id };
  67.  
  68.         return Url.FetchJson(System.BaseURL() + "api/v1/rum/currency_rate/read.php", true, json, System.progress);
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement