Files
api/services/nginx/app/interfaces/fxratesapi_i.php
T
Jepp9350 9b53ae4403 Add fxratesapi module for currency conversion functionality
Integrated a new fxratesapi module to handle currency conversions, including API configurations, rate conversion actions, and request logging. Added support for module settings such as enablement status, API key, and daily request limits. New routes, database interactions, and object handling were implemented to facilitate the module's operations.
2025-03-31 13:19:45 +02:00

134 lines
5.4 KiB
PHP

<?php
namespace interfaces;
use Exception;
interface fxratesapi_i
{
/**
* Get conversion rate for a given base currency
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @return object The response from the fxratesapi
*/
function getConversionRate(string $base, string $target, string $endpoint, array $data): object;
/**
* Get the daily request counter
* @return int The daily request counter
*/
function getDailyRequestCounter(): int;
/**
* Send a request to the fxratesapi
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @param string $method The method to use for the request (e.g. "GET")
* @return object The response from the fxratesapi
*/
function sendRequest(string $base, string $target, string $endpoint, array $data, string $method): object;
/**
* Require the module to be enabled
* @return void
* @throws Exception If the module is not enabled
*/
function requireModuleEnabled(): void;
/**
* Require the currency to be valid
* @param string $currency The currency to check
* @return void
* @throws Exception If the currency is not valid
*/
function requireValidCurrency(string $currency): void;
/**
* Require the daily limit to not be exceeded
* @return void
* @throws Exception If the daily limit is exceeded
*/
function requireDailyLimitNotExceeded(): void;
/**
* Require the secret key to be valid
* @return void
* @throws Exception If the secret key is not valid
*/
function requireValidSecretKey(): void;
/**
* Send a GET request to the fxratesapi
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @return object The response from the fxratesapi
*/
function sendGetRequest(string $base, string $target, string $endpoint, array $data): object;
/**
* Send a POST request to the fxratesapi
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @return object The response from the fxratesapi
*/
function sendPostRequest(string $base, string $target, string $endpoint, array $data): object;
/**
* Send a PUT request to the fxratesapi
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @return object The response from the fxratesapi
*/
function sendPutRequest(string $base, string $target, string $endpoint, array $data): object;
/**
* Send a DELETE request to the fxratesapi
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to (e.g. "latest")
* @param array $data The data to send with the request (e.g. ["key" => "value"])
* @return object The response from the fxratesapi
*/
function sendDeleteRequest(string $base, string $target, string $endpoint, array $data): object;
/**
* Add a request to the log
* @param string $base The base currency to use (e.g. "DKK")
* @param string $target The target currency, (e.g. "EUR")
* @param string $endpoint The endpoint to send the request to
* @param object $response The response from the fxratesapi
* @return void
*/
function addRequestToLog(string $base, string $target, string $endpoint, object $response): void;
/**
* Check if a conversion rate is stored in the log/local database/cache
* @param string $base The base currency to check
* @param string $target The target currency to check
* @return bool Whether the conversion rate is stored in the log/local database/cache
* @throws Exception If the base or target currency is not valid
*/
function isCached(string $base, string $target): bool;
/**
* Cache the response for a conversion rate
* @param string $base The base currency to cache
* @param string $target The target currency to cache
* @return object The cached response
* @throws Exception If the base or target currency is not valid
* @throws Exception If the response is not valid
* @throws Exception If the response is not an object
*/
function getCachedResponse(string $base, string $target): object;
}