Skip to content

Instantly share code, notes, and snippets.

@JonasEriksson
Last active July 17, 2018 00:17
Show Gist options
  • Save JonasEriksson/f4d8b393209fae2727c9d35c41eacec7 to your computer and use it in GitHub Desktop.
Save JonasEriksson/f4d8b393209fae2727c9d35c41eacec7 to your computer and use it in GitHub Desktop.
Get ExchangeRates from ECB via api.openrates.io and write them into Mura CMS Extended Attributes
<!--- Requirements
Set up (or import - see below) Extended Attributes in Mura CMS.
--->
<cfscript>
remote any function getExchangeRates(){
cfhttp(url="http://api.openrates.io/latest?symbols=NOK,SEK,GBP,USD", result="rs", method="get"){
}
return deserializeJSON(rs.filecontent);
};
</cfscript>
<!-- output a few for testing / QC -->
<cfset exchangerates = "#getExchangeRates()#">
<cfdump var="#exchangerates#">
<cfdump var="#exchangerates.rates#">
<cfdump var="#exchangerates.rates.USD#">
<cfoutput>
<p>date: #exchangerates.date#</p>
<p>exchangerates.rates.USD: #exchangerates.rates.USD#</p>
<p>exchangerates.rates.SEK: #exchangerates.rates.SEK#</p>
<p>exchangerates.rates.NOK: #exchangerates.rates.NOK#</p>
</cfoutput>
<!--- making sure the dateformat is what we want --->
<cfset XE_Date_Updated = #DateFormat(exchangerates.date, "yyyy-mm-dd")#>
<!--- get a siteBean, based on the current siteID --->
<cfset siteBean = m.getBean('site').loadBy(siteid=session.siteid)>
<!--- set (write) values to extended attributes, and then save siteBean --->
<cfscript>
siteBean.set('XE_EUR_to_NOK', '#exchangerates.rates.NOK#');
siteBean.set('XE_EUR_to_SEK', '#exchangerates.rates.SEK#');
siteBean.set('XE_EUR_to_GBP', '#exchangerates.rates.GBP#');
siteBean.set('XE_EUR_to_USD', '#exchangerates.rates.USD#');
siteBean.set('XE_Date_Updated', '#XE_Date_Updated#');
siteBean.save();
</cfscript>
<!--- import xmlfile for Site/default --->
<!---
<?xml version="1.0" encoding="UTF-8"?>
<mura>
<extensions>
<extension adminonly="0" availablesubtypes="" basekeyfield="baseID" basetable="tsettings" datatable="tclassextenddata" description="" hasassocfile="1" hasbody="1" hasconfigurator="1" hassummary="1" iconclass="" subtype="Default" type="Site">
<attributeset categoryid="" container="Default" name="ExchangeRates" orderno="1">
<attribute adminonly="0" defaultvalue="" hint="" label="XE_EUR_to_NOK" message="" name="XE_EUR_to_NOK" optionlabellist="" optionlist="" orderno="1" regex="" required="false" type="TextBox" validation=""/>
<attribute adminonly="0" defaultvalue="" hint="" label="XE_EUR_to_SEK" message="" name="XE_EUR_to_SEK" optionlabellist="" optionlist="" orderno="2" regex="" required="false" type="TextBox" validation=""/>
<attribute adminonly="0" defaultvalue="" hint="" label="XE_EUR_to_USD" message="" name="XE_EUR_to_USD" optionlabellist="" optionlist="" orderno="3" regex="" required="false" type="TextBox" validation=""/>
<attribute adminonly="0" defaultvalue="" hint="" label="XE_EUR_to_GBP" message="" name="XE_EUR_to_GBP" optionlabellist="" optionlist="" orderno="4" regex="" required="false" type="TextBox" validation=""/>
<attribute adminonly="1" defaultvalue="" hint="" label="XE_Date_Updated" message="" name="XE_Date_Updated" optionlabellist="" optionlist="" orderno="5" regex="" required="false" type="TextBox" validation=""/>
</attributeset>
</extension>
</extensions>
</mura>
--->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment