/trunk/DLL/CurConv.dproj |
---|
7,12 → 7,22 |
<TargetedPlatforms>3</TargetedPlatforms> |
<AppType>Library</AppType> |
<FrameworkType>None</FrameworkType> |
<ProjectVersion>18.8</ProjectVersion> |
<Platform Condition="'$(Platform)'==''">Win32</Platform> |
<ProjectVersion>19.2</ProjectVersion> |
<Platform Condition="'$(Platform)'==''">Win64</Platform> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''"> |
<Base>true</Base> |
</PropertyGroup> |
<PropertyGroup Condition="('$(Platform)'=='Android' and '$(Base)'=='true') or '$(Base_Android)'!=''"> |
<Base_Android>true</Base_Android> |
<CfgParent>Base</CfgParent> |
<Base>true</Base> |
</PropertyGroup> |
<PropertyGroup Condition="('$(Platform)'=='Android64' and '$(Base)'=='true') or '$(Base_Android64)'!=''"> |
<Base_Android64>true</Base_Android64> |
<CfgParent>Base</CfgParent> |
<Base>true</Base> |
</PropertyGroup> |
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''"> |
<Base_Win32>true</Base_Win32> |
<CfgParent>Base</CfgParent> |
71,6 → 81,18 |
<DCC_Namespace>Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace> |
<DCC_ExeOutput>D:\SVN\CurrencyConverter\trunk\Output\</DCC_ExeOutput> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Base_Android)'!=''"> |
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192> |
<VerInfo_Keys>package=com.embarcadero.$(MSBuildProjectName);label=$(MSBuildProjectName);versionCode=1;versionName=1.0.0;persistent=False;restoreAnyVersion=False;installLocation=auto;largeHeap=False;theme=TitleBar;hardwareAccelerated=true;apiKey=</VerInfo_Keys> |
<BT_BuildType>Debug</BT_BuildType> |
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar</EnabledSysJars> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Base_Android64)'!=''"> |
<Android_LauncherIcon192>$(BDS)\bin\Artwork\Android\FM_LauncherIcon_192x192.png</Android_LauncherIcon192> |
<VerInfo_Keys>package=com.embarcadero.$(MSBuildProjectName);label=$(MSBuildProjectName);versionCode=1;versionName=1.0.0;persistent=False;restoreAnyVersion=False;installLocation=auto;largeHeap=False;theme=TitleBar;hardwareAccelerated=true;apiKey=</VerInfo_Keys> |
<BT_BuildType>Debug</BT_BuildType> |
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar</EnabledSysJars> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Base_Win32)'!=''"> |
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo> |
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys> |
143,6 → 165,8 |
</Excluded_Packages> |
</Delphi.Personality> |
<Platforms> |
<Platform value="Android">False</Platform> |
<Platform value="Android64">False</Platform> |
<Platform value="Win32">True</Platform> |
<Platform value="Win64">True</Platform> |
</Platforms> |
/trunk/DLL/CurConv.res |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/trunk/DLL Usage Demo/Delphi/CurConvDLLDemo.dproj |
---|
7,7 → 7,7 |
<TargetedPlatforms>3</TargetedPlatforms> |
<AppType>Application</AppType> |
<FrameworkType>VCL</FrameworkType> |
<ProjectVersion>18.8</ProjectVersion> |
<ProjectVersion>19.2</ProjectVersion> |
<Platform Condition="'$(Platform)'==''">Win32</Platform> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''"> |
67,7 → 67,6 |
<DCC_ExeOutput>D:\SVN\CurrencyConverter\trunk\Output\</DCC_ExeOutput> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Base_Win32)'!=''"> |
<DCC_Namespace>System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace> |
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo> |
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys> |
<VerInfo_Locale>1033</VerInfo_Locale> |
100,6 → 99,9 |
</PropertyGroup> |
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''"> |
<BT_BuildType>Debug</BT_BuildType> |
<Manifest_File>$(BDS)\bin\default_app.manifest</Manifest_File> |
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes> |
<AppDPIAwarenessMode>PerMonitor</AppDPIAwarenessMode> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Cfg_2)'!=''"> |
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define> |
143,8 → 145,8 |
<Source Name="MainSource">CurConvDLLDemo.dpr</Source> |
</Source> |
<Excluded_Packages> |
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k260.bpl">Microsoft Office 2000 Beispiele für gekapselte Komponenten für Automatisierungsserver</Excluded_Packages> |
<Excluded_Packages Name="$(BDSBIN)\dclofficexp260.bpl">Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server</Excluded_Packages> |
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k270.bpl">Microsoft Office 2000 Beispiele für gekapselte Komponenten für Automatisierungsserver</Excluded_Packages> |
<Excluded_Packages Name="$(BDSBIN)\dclofficexp270.bpl">Microsoft Office XP Beispiele für gekapselte Komponenten für Automation Server</Excluded_Packages> |
</Excluded_Packages> |
</Delphi.Personality> |
<Platforms> |
306,6 → 308,16 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="Android_LauncherIcon192"> |
<Platform Name="Android"> |
<RemoteDir>res\drawable-xxxhdpi</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="Android64"> |
<RemoteDir>res\drawable-xxxhdpi</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="Android_LauncherIcon36"> |
<Platform Name="Android"> |
<RemoteDir>res\drawable-ldpi</RemoteDir> |
557,6 → 569,32 |
<Operation>0</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iOS_AppStore1024"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_AppIcon152"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_AppIcon167"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_Launch1024x768"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
656,6 → 694,16 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_Launch2x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_Launch768x1024"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
667,6 → 715,66 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_LaunchDark2x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_Notification40"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_Setting58"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPad_SpotLight80"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_AppIcon120"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_AppIcon180"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Launch1125"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
766,6 → 874,16 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Launch2x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Launch320"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
777,6 → 895,16 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Launch3x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Launch640"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
821,6 → 949,86 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_LaunchDark2x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_LaunchDark3x"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Notification40"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Notification60"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Setting58"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Setting87"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Spotlight120"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="iPhone_Spotlight80"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset</RemoteDir> |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="ProjectAndroidManifest"> |
<Platform Name="Android"> |
<Operation>1</Operation> |
868,6 → 1076,16 |
<Operation>1</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="ProjectiOSLaunchScreen"> |
<Platform Name="iOSDevice64"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen</RemoteDir> |
<Operation>64</Operation> |
</Platform> |
<Platform Name="iOSSimulator"> |
<RemoteDir>..\$(PROJECTNAME).launchscreen</RemoteDir> |
<Operation>64</Operation> |
</Platform> |
</DeployClass> |
<DeployClass Name="ProjectiOSResource"> |
<Platform Name="iOSDevice32"> |
<Operation>1</Operation> |
/trunk/PHP/currency_calc.inc.php |
---|
1,143 → 1,148 |
<?php |
// PHP library for CurrencyLayer |
// (C) 2017 ViaThinkSoft, Daniel Marschall |
// Revision: 2017-03-25 |
// |
// More information at https://currencylayer.com/documentation |
# EXAMPLE |
/* |
$x = new CurCalc('cache.json', 'YOUR API KEY HERE', false); |
if ($x->needs_download(1*60*60)) $x->download_exchange_rates(); // refresh data every hour |
$val = $x->convert_cur(100, 'EUR', 'RUB'); |
echo "100 EUR are $val RUB.\n"; |
*/ |
# --- |
class CurCalcException extends Exception {} |
class CurrencyLayerException extends CurCalcException {} |
class CurCalc { |
protected $jsonfile = null; |
protected $apikey = null; |
protected $use_https = null; |
function __construct($jsonfile, $apikey, $use_https=true) { |
$this->jsonfile = $jsonfile; |
$this->apikey = $apikey; |
$this->use_https = $use_https; |
} |
public function exchange_rates_age() { |
$this->check_json_file_exists(); |
// return time() - filemtime($this->jsonfile); |
$cont = file_get_contents($this->jsonfile); |
$data = json_decode($cont, true); |
$this->check_data_ok($data); |
return time() - $data['timestamp']; |
} |
public function needs_download($max_age=-1) { |
if (!$this->check_json_file_exists(false)) { |
return true; |
} else if (!$this->check_data_ok(null, false)) { |
return true; |
} else if ($max_age == -1) { |
return false; |
} else { |
return $this->exchange_rates_age() > $max_age; |
} |
} |
private function check_json_file_exists($raise_exception=true) { |
if (!file_exists($this->jsonfile)) { |
if ($raise_exception) { |
throw new CurCalcException('JSON file '.$this->jsonfile.' not found. Please download it first.'); |
} else { |
return false; |
} |
} else { |
return true; |
} |
} |
private function check_data_ok($data, $raise_exception=true) { |
if (is_null($data)) { |
$ret = $this->check_json_file_exists($raise_exception); |
if ((!$raise_exception) && (!$ret)) return $ret; |
$cont = file_get_contents($this->jsonfile); |
$data = json_decode($cont, true); |
} |
if ((!isset($data['success'])) || ($data['success'] !== true)) { |
if ($raise_exception) { |
if (isset($data['error'])) throw new CurrencyLayerException($data['error']['code'] . ' : ' . $data['error']['info']); |
throw new CurCalcException('JSON file '.$this->jsonfile.' does not contain valid request data. Please download it again.'); |
} else { |
return false; |
} |
} |
return true; |
} |
public function download_exchange_rates() { |
// 1. Download |
$protocol = $this->use_https ? 'https' : 'http'; |
$cont = file_get_contents($protocol.'://www.apilayer.net/api/live?access_key='.$this->apikey); |
if (!$cont) throw new CurCalcException('Failed to download from CurrencyLayer.'); |
// 2. Test result |
$test_data = json_decode($cont, true); |
$this->check_data_ok($test_data); |
// 3. Save |
if (!file_put_contents($this->jsonfile, $cont)) throw new CurCalcException('Saving to '.$this->jsonfile.' failed.'); |
// 4. OK |
$this->cache_exchange_rates_ary = null; |
return 0; |
} |
private $cache_exchange_rates_ary = null; |
private function get_exchange_rates_ary() { |
if (!is_null($this->cache_exchange_rates_ary)) return $this->cache_exchange_rates_ary; |
$this->check_json_file_exists(); |
$data = json_decode(file_get_contents($this->jsonfile), true); |
$this->check_data_ok($data); |
$exchange_rates_ary = array(); |
$quotes = $data['quotes']; |
foreach ($quotes as $n => $v) { |
$exchange_rates_ary[substr($n, 3, 3)] = $v; // key: USDxxx=12.345 |
} |
unset($quotes); |
$this->cache_exchange_rates_ary = $exchange_rates_ary; |
return $exchange_rates_ary; |
} |
public function get_supported_currencies() { |
return array_keys($this->get_exchange_rates_ary()); |
} |
public function convert_cur($value, $from_cur, $to_cur) { |
$from_cur = strtoupper(trim($from_cur)); |
$to_cur = strtoupper(trim($to_cur)); |
if ($from_cur == $to_cur) return $value; |
$exchange_rates_ary = $this->get_exchange_rates_ary(); |
if (!isset($exchange_rates_ary[$from_cur])) throw new CurCalcException('Source curreny $from_cur not found in exchange data.'); |
if (!isset($exchange_rates_ary[$to_cur])) throw new CurCalcException('Destination curreny $to_cur not found in exchange data.'); |
return $value * $exchange_rates_ary[$to_cur]/$exchange_rates_ary[$from_cur]; |
} |
<?php |
// PHP library for CurrencyLayer |
// (C) 2017-2022 ViaThinkSoft, Daniel Marschall |
// Revision: 2022-08-06 |
// |
// More information at https://currencylayer.com/documentation |
# EXAMPLE |
/* |
$x = new CurCalc('cache.json', 'YOUR API KEY HERE', false); |
if ($x->needs_download(1*60*60)) $x->download_exchange_rates(); // refresh data every hour |
$val = $x->convert_cur(100, 'EUR', 'RUB'); |
echo "100 EUR are $val RUB.\n"; |
*/ |
# --- |
class CurCalcException extends Exception {} |
class CurrencyLayerException extends CurCalcException {} |
class CurCalc { |
protected $jsonfile = null; |
protected $apikey = null; |
protected $use_https = null; |
function __construct($jsonfile, $apikey, $use_https=true) { |
$this->jsonfile = $jsonfile; |
$this->apikey = $apikey; |
$this->use_https = $use_https; |
} |
public function exchange_rates_age() { |
$this->check_json_file_exists(); |
// return time() - filemtime($this->jsonfile); |
$cont = file_get_contents($this->jsonfile); |
$data = json_decode($cont, true); |
$this->check_data_ok($data); |
return time() - $data['timestamp']; |
} |
public function needs_download($max_age=-1) { |
if (!$this->check_json_file_exists(false)) { |
return true; |
} else if (!$this->check_data_ok(null, false)) { |
return true; |
} else if ($max_age == -1) { |
return false; |
} else { |
return $this->exchange_rates_age() > $max_age; |
} |
} |
private function check_json_file_exists($raise_exception=true) { |
if (!file_exists($this->jsonfile)) { |
if ($raise_exception) { |
throw new CurCalcException('JSON file '.$this->jsonfile.' not found. Please download it first.'); |
} else { |
return false; |
} |
} else { |
return true; |
} |
} |
private function check_data_ok($data, $raise_exception=true) { |
if (is_null($data)) { |
$ret = $this->check_json_file_exists($raise_exception); |
if ((!$raise_exception) && (!$ret)) return $ret; |
$cont = file_get_contents($this->jsonfile); |
$data = json_decode($cont, true); |
} |
if ((!isset($data['success'])) || ($data['success'] !== true)) { |
if ($raise_exception) { |
if (isset($data['error'])) throw new CurrencyLayerException($data['error']['code'] . ' : ' . $data['error']['info']); |
throw new CurCalcException('JSON file '.$this->jsonfile.' does not contain valid request data. Please download it again.'); |
} else { |
return false; |
} |
} |
return true; |
} |
public function download_exchange_rates() { |
// 1. Download |
$protocol = $this->use_https ? 'https' : 'http'; |
$cont = file_get_contents($protocol.'://www.apilayer.net/api/live?access_key='.$this->apikey); |
if (!$cont) throw new CurCalcException('Failed to download from CurrencyLayer.'); |
// 2. Test result |
$test_data = json_decode($cont, true); |
$this->check_data_ok($test_data); |
// 3. Save |
if (!file_put_contents($this->jsonfile, $cont)) throw new CurCalcException('Saving to '.$this->jsonfile.' failed.'); |
// 4. OK |
$this->cache_exchange_rates_ary = null; |
return 0; |
} |
private $cache_exchange_rates_ary = null; |
private function get_exchange_rates_ary() { |
if (!is_null($this->cache_exchange_rates_ary)) return $this->cache_exchange_rates_ary; |
$this->check_json_file_exists(); |
$data = json_decode(file_get_contents($this->jsonfile), true); |
$this->check_data_ok($data); |
$exchange_rates_ary = array(); |
$source = $data['source']; |
$quotes = $data['quotes']; |
$quotes['USDUSD'] = 1; // missing 06 Aug 2022. A bug?? Reported https://github.com/apilayer/currencylayer-API/issues/16 |
foreach ($quotes as $n => $v) { |
if ($source == substr($n, 0, 3)) { |
$exchange_rates_ary[substr($n, 3, 3)] = $v; // key: USDxxx=12.345 |
} |
} |
unset($quotes); |
asort($exchange_rates_ary); |
$this->cache_exchange_rates_ary = $exchange_rates_ary; |
return $exchange_rates_ary; |
} |
public function get_supported_currencies() { |
return array_keys($this->get_exchange_rates_ary()); |
} |
public function convert_cur($value, $from_cur, $to_cur) { |
$from_cur = strtoupper(trim($from_cur)); |
$to_cur = strtoupper(trim($to_cur)); |
if ($from_cur == $to_cur) return $value; |
$exchange_rates_ary = $this->get_exchange_rates_ary(); |
if (!isset($exchange_rates_ary[$from_cur])) throw new CurCalcException("Source curreny $from_cur not found in exchange data."); |
if (!isset($exchange_rates_ary[$to_cur])) throw new CurCalcException("Destination curreny $to_cur not found in exchange data."); |
return $value * $exchange_rates_ary[$to_cur]/$exchange_rates_ary[$from_cur]; |
} |
} |
/trunk/RTL/VtsCurConv.pas |
---|
548,6 → 548,10 |
end; |
result := sJSON; |
// "USDUSD" missing 06 Aug 2022. A bug?? Reported https://github.com/apilayer/currencylayer-API/issues/16 |
if Pos('"USDUSD"', result) = 0 then |
result := StringReplace(result, '"quotes":{', '"quotes":{"USDUSD":1.00,', []); |
end; |
end. |