mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Add workaround for currency and ratio api calls in order to bypass CORS policy
This commit is contained in:
parent
ba179a4004
commit
52269e6d7f
1 changed files with 7 additions and 17 deletions
|
@ -17,8 +17,8 @@ namespace CalculatorApp.DataLoaders
|
||||||
string m_responseLanguage;
|
string m_responseLanguage;
|
||||||
string m_sourceCurrencyCode;
|
string m_sourceCurrencyCode;
|
||||||
|
|
||||||
static string sc_MetadataUriLocalizeFor = "https://go.microsoft.com/fwlink/?linkid=2041093&localizeFor=";
|
static string sc_MetadataUriLocalizeFor = "https://cors-anywhere.herokuapp.com/https://go.microsoft.com/fwlink/?linkid=2041093&localizeFor=";
|
||||||
static string sc_RatiosUriRelativeTo = "https://go.microsoft.com/fwlink/?linkid=2041339&localCurrency=";
|
static string sc_RatiosUriRelativeTo = "https://cors-anywhere.herokuapp.com/https://go.microsoft.com/fwlink/?linkid=2041339&localCurrency=";
|
||||||
|
|
||||||
public CurrencyHttpClient()
|
public CurrencyHttpClient()
|
||||||
{
|
{
|
||||||
|
@ -26,30 +26,20 @@ namespace CalculatorApp.DataLoaders
|
||||||
m_responseLanguage = "en-US";
|
m_responseLanguage = "en-US";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetSourceCurrencyCode(String sourceCurrencyCode)
|
public void SetSourceCurrencyCode(string sourceCurrencyCode)
|
||||||
{
|
{
|
||||||
m_sourceCurrencyCode = sourceCurrencyCode;
|
m_sourceCurrencyCode = sourceCurrencyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetResponseLanguage(String responseLanguage)
|
public void SetResponseLanguage(string responseLanguage)
|
||||||
{
|
{
|
||||||
m_responseLanguage = responseLanguage;
|
m_responseLanguage = responseLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<String> GetCurrencyMetadata()
|
public async Task<string> GetCurrencyMetadata() => await ExecuteRequestAsync(sc_MetadataUriLocalizeFor + m_responseLanguage);
|
||||||
{
|
|
||||||
string uri = sc_MetadataUriLocalizeFor + m_responseLanguage;
|
|
||||||
var metadataUri = new Uri(uri);
|
|
||||||
|
|
||||||
return m_client.GetStringAsync(metadataUri);
|
public async Task<string> GetCurrencyRatios() => await ExecuteRequestAsync(sc_RatiosUriRelativeTo + m_sourceCurrencyCode);
|
||||||
}
|
|
||||||
|
|
||||||
public Task<String> GetCurrencyRatios()
|
private async Task<string> ExecuteRequestAsync(string url) => await m_client.GetStringAsync(new Uri(url));
|
||||||
{
|
|
||||||
string uri = sc_RatiosUriRelativeTo + m_sourceCurrencyCode;
|
|
||||||
var ratiosUri = new Uri(uri);
|
|
||||||
|
|
||||||
return m_client.GetStringAsync(ratiosUri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue