-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurrencyConverterControllerClass.apxc
34 lines (26 loc) · 1.27 KB
/
CurrencyConverterControllerClass.apxc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public with sharing class CurrencyConverterControllerClass{
@AuraEnabled
public static List<CurrencyInformation__c> allCountries() {
return [SELECT Id,Name,Code__c, Country__c FROM CurrencyInformation__c];
}
@AuraEnabled
public static String getCurrency(String sourceCode,String targetCode) {
String url = 'https://globalcurrencies.xignite.com/xGlobalCurrencies.json/GetRealTimeRate?Symbol=';
url += sourceCode+targetCode+'&_token=YOURTOKEN';
// Instantiate a new http object
Http http = new Http();
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('GET');
HttpResponse res = new HttpResponse();
// Send the request, and return a response
if((sourceCode != null && sourceCode.trim().length() > 0) && (targetCode != null && targetCode.trim().length() > 0))
res = http.send(req);
else
return null;
Map<String, Object> response = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
String text = (String)response.get('Text');
return text;
}
}