Skip to content

Commit

Permalink
Merge pull request #25 from TheLe0/fix-typos-adnd-improve-code-style
Browse files Browse the repository at this point in the history
Fix typos and code improvement
  • Loading branch information
TheLe0 authored May 19, 2023
2 parents 4702f70 + f21c7cd commit 621abdb
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 198 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
.idea/
.DS_STORE
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ Here I am going to explain the entities containning on this API client. In this
## Methods

1. <b>GetAllAvaliableCurrenciesAsync</b>: Returns all the currently avaliable currencies on the API
1. <b>GetAllAvailableCurrenciesAsync</b>: Returns all the currently avaliable currencies on the API

```csharp
var currencies = await frankfurter
.GetAllAvaliableCurrenciesAsync()
.GetAllAvailableCurrenciesAsync()
.ConfigureAwait(false);
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Frankfurter.API.Client" Version="1.0.0" />
<ProjectReference Include="..\..\src\Frankfurter.API.Client\Frankfurter.API.Client.csproj" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions samples/Frankfurter.API.Client.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

var frankfurter = new FrankfurterClient();

// Get All avaliable currencies
// Get All available currencies
var currencies = await frankfurter
.GetAllAvaliableCurrenciesAsync()
.GetAllAvailableCurrenciesAsync()
.ConfigureAwait(false);

// Convert a specified amount of one currency to another
Expand All @@ -17,7 +17,7 @@
CurrencyCode.USD // Currency to Convert
).ConfigureAwait(false);

// Get the equivalent of one currency in a date to anothers
// Get the currency equivalency amount of one currency in a date

exchange = await frankfurter
.CurrencyConvertByDateAsync(
Expand All @@ -26,15 +26,15 @@
CurrencyCode.BRL // Reference Currency
).ConfigureAwait(false);

// Get the equivalent of one currency in the last published date to anothers
// Get the currency equivalency amount of one currency in the last published date

exchange = await frankfurter
.CurrencyConvertByLastPublishedDateAsync(
10, // Reference Amount
CurrencyCode.BRL // Reference Currency
).ConfigureAwait(false);

// Get the equivalent of one currency in the last published date to anothers
// Get the currency equivalency amount of one currency in the last published date
// with specified currencies to convert

var toCurrencies = new List<CurrencyCode>
Expand Down Expand Up @@ -62,4 +62,4 @@
new DateTime(2021,1,1) // End Date
).ConfigureAwait(false);

Console.WriteLine("Finish Execution!");
Console.WriteLine(@"Finish Execution!");
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Frankfurter.API.Client.DependencyInjection" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Frankfurter.API.Client.DependencyInjection\Frankfurter.API.Client.DependencyInjection.csproj" />
</ItemGroup>

</Project>
6 changes: 2 additions & 4 deletions samples/Frankfurter.API.Client.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

app.UseHttpsRedirection();

app.MapGet("/currencies", (IFrankfurterClient client) =>
{
return client.GetAllAvaliableCurrenciesAsync();
})
app.MapGet("/currencies", (IFrankfurterClient client)
=> client.GetAllAvaliableCurrenciesAsync())
.WithName("Currencies")
.WithOpenApi();
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>1.1.0</Version>
<Version>1.5.0</Version>
<Authors>Leonardo Tosin</Authors>
<PackageProjectUrl>https://github.com/TheLe0/frankfurter-api-client</PackageProjectUrl>
<PackageIconUrl>https://user-images.githubusercontent.com/40045069/235474192-f401db30-9f2f-4202-8370-4670ab6d6953.png</PackageIconUrl>
Expand All @@ -12,11 +12,11 @@
<Description>A DI package for the Frankfurter.API.Client package</Description>
<Copyright>Copyright © Leonardo Tosin</Copyright>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>
<AssemblyVersion>1.5.0</AssemblyVersion>
<FileVersion>1.5.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>latest</LangVersion>
<PackageVersion>1.1.0</PackageVersion>
<PackageVersion>1.5.0</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Frankfurter.API.Client/Domain/CurrencyCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public enum CurrencyCode
{
None,
NONE,
AUD, // Australian Dollar
BGN, // Bulgarian Lev
BRL, // Brazilian Real
Expand Down
97 changes: 33 additions & 64 deletions src/Frankfurter.API.Client/Extensions/CurrencyCodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,39 @@ internal static class CurrencyCodeParser
{
internal static CurrencyCode ToCurrencyCode(this string currencyCodeStr)
{
if (currencyCodeStr == Currencies.AustralianDollar)
return CurrencyCode.AUD;
else if (currencyCodeStr == Currencies.BrazilianReal)
return CurrencyCode.BRL;
else if (currencyCodeStr == Currencies.BritishPound)
return CurrencyCode.GBP;
else if (currencyCodeStr == Currencies.BulgarianLev)
return CurrencyCode.BGN;
else if (currencyCodeStr == Currencies.CanadianDollar)
return CurrencyCode.CAD;
else if (currencyCodeStr == Currencies.ChineseRenminbiYuan)
return CurrencyCode.CNY;
else if (currencyCodeStr == Currencies.CzechKoruna)
return CurrencyCode.CZK;
else if (currencyCodeStr == Currencies.DanishKrone)
return CurrencyCode.DKK;
else if (currencyCodeStr == Currencies.Euro)
return CurrencyCode.EUR;
else if (currencyCodeStr == Currencies.HongKongDollar)
return CurrencyCode.HKD;
else if (currencyCodeStr == Currencies.HungarianForint)
return CurrencyCode.HUF;
else if (currencyCodeStr == Currencies.IcelandicKrona)
return CurrencyCode.ISK;
else if (currencyCodeStr == Currencies.IndianRupee)
return CurrencyCode.INR;
else if (currencyCodeStr == Currencies.IndonesianRupiah)
return CurrencyCode.IDR;
else if (currencyCodeStr == Currencies.IsraeliNewSheqel)
return CurrencyCode.ILS;
else if (currencyCodeStr == Currencies.JapaneseYen)
return CurrencyCode.JPY;
else if (currencyCodeStr == Currencies.MalaysianRinggit)
return CurrencyCode.MYR;
else if (currencyCodeStr == Currencies.MexicanPeso)
return CurrencyCode.MXN;
else if (currencyCodeStr == Currencies.NewZealandDollar)
return CurrencyCode.NZD;
else if (currencyCodeStr == Currencies.NorwegianKrone)
return CurrencyCode.NOK;
else if (currencyCodeStr == Currencies.PhilippinePeso)
return CurrencyCode.PHP;
else if (currencyCodeStr == Currencies.PolishZloty)
return CurrencyCode.PLN;
else if (currencyCodeStr == Currencies.RomanianLeu)
return CurrencyCode.RON;
else if (currencyCodeStr == Currencies.SingaporeDollar)
return CurrencyCode.SGD;
else if (currencyCodeStr == Currencies.SouthAfricanRand)
return CurrencyCode.ZAR;
else if (currencyCodeStr == Currencies.SouthKoreanWon)
return CurrencyCode.KRW;
else if (currencyCodeStr == Currencies.SwedishKrona)
return CurrencyCode.SEK;
else if (currencyCodeStr == Currencies.SwissFranc)
return CurrencyCode.CHF;
else if (currencyCodeStr == Currencies.ThaiBaht)
return CurrencyCode.THB;
else if (currencyCodeStr == Currencies.TurkishLira)
return CurrencyCode.TRY;
else if (currencyCodeStr == Currencies.UnitedStatesDollar)
return CurrencyCode.USD;
else
return CurrencyCode.None;
if (currencyCodeStr == Currencies.AustralianDollar) return CurrencyCode.AUD;
if (currencyCodeStr == Currencies.BrazilianReal) return CurrencyCode.BRL;
if (currencyCodeStr == Currencies.BritishPound) return CurrencyCode.GBP;
if (currencyCodeStr == Currencies.BulgarianLev) return CurrencyCode.BGN;
if (currencyCodeStr == Currencies.CanadianDollar) return CurrencyCode.CAD;
if (currencyCodeStr == Currencies.ChineseRenminbiYuan) return CurrencyCode.CNY;
if (currencyCodeStr == Currencies.CzechKoruna) return CurrencyCode.CZK;
if (currencyCodeStr == Currencies.DanishKrone) return CurrencyCode.DKK;
if (currencyCodeStr == Currencies.Euro) return CurrencyCode.EUR;
if (currencyCodeStr == Currencies.HongKongDollar) return CurrencyCode.HKD;
if (currencyCodeStr == Currencies.HungarianForint) return CurrencyCode.HUF;
if (currencyCodeStr == Currencies.IcelandicKrona) return CurrencyCode.ISK;
if (currencyCodeStr == Currencies.IndianRupee) return CurrencyCode.INR;
if (currencyCodeStr == Currencies.IndonesianRupiah) return CurrencyCode.IDR;
if (currencyCodeStr == Currencies.IsraeliNewSheqel) return CurrencyCode.ILS;
if (currencyCodeStr == Currencies.JapaneseYen) return CurrencyCode.JPY;
if (currencyCodeStr == Currencies.MalaysianRinggit) return CurrencyCode.MYR;
if (currencyCodeStr == Currencies.MexicanPeso) return CurrencyCode.MXN;
if (currencyCodeStr == Currencies.NewZealandDollar) return CurrencyCode.NZD;
if (currencyCodeStr == Currencies.NorwegianKrone) return CurrencyCode.NOK;
if (currencyCodeStr == Currencies.PhilippinePeso) return CurrencyCode.PHP;
if (currencyCodeStr == Currencies.PolishZloty) return CurrencyCode.PLN;
if (currencyCodeStr == Currencies.RomanianLeu) return CurrencyCode.RON;
if (currencyCodeStr == Currencies.SingaporeDollar) return CurrencyCode.SGD;
if (currencyCodeStr == Currencies.SouthAfricanRand) return CurrencyCode.ZAR;
if (currencyCodeStr == Currencies.SouthKoreanWon) return CurrencyCode.KRW;
if (currencyCodeStr == Currencies.SwedishKrona) return CurrencyCode.SEK;
if (currencyCodeStr == Currencies.SwissFranc) return CurrencyCode.CHF;
if (currencyCodeStr == Currencies.ThaiBaht) return CurrencyCode.THB;
if (currencyCodeStr == Currencies.TurkishLira) return CurrencyCode.TRY;
if (currencyCodeStr == Currencies.UnitedStatesDollar) return CurrencyCode.USD;

return CurrencyCode.NONE;
}

internal static string ToString(this CurrencyCode currencyCode)
Expand Down
40 changes: 12 additions & 28 deletions src/Frankfurter.API.Client/Extensions/CurrencyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,26 @@ internal static class CurrencyParser
{
internal static IEnumerable<Currency> ToCurrencyList(this JsonObject jsonObject)
{
var currencies = new List<Currency>();

var listJsonObjs = jsonObject.ToArray();

for ( var i = 0; i < listJsonObjs.Length; i++)
{
currencies.Add(
new Currency
{
Name = listJsonObjs[i].Value.ToString(),
Code = listJsonObjs[i].Key.ToString().ToCurrencyCode()
}
);
}

return currencies;
return listJsonObjs.Select(node
=> new Currency
{
Name = node.Value.ToString(),
Code = node.Key.ToString().ToCurrencyCode()
}).ToList();
}

internal static IEnumerable<CurrencyRate> ToCurrencyRateList(this JsonObject jsonObject)
{
var currencies = new List<CurrencyRate>();

var listJsonObjs = jsonObject.ToArray();

for (var i = 0; i < listJsonObjs.Length; i++)
{
currencies.Add(
new CurrencyRate
{
Amount = (decimal) listJsonObjs[i].Value,
CurrencyCode = listJsonObjs[i].Key.ToCurrencyCode()
}
);
}

return currencies;
return listJsonObjs.Select(node
=> new CurrencyRate
{
Amount = (decimal) node.Value,
CurrencyCode = node.Key.ToCurrencyCode()
}).ToList();
}
}
}
19 changes: 4 additions & 15 deletions src/Frankfurter.API.Client/Extensions/EndpointParameterBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Frankfurter.API.Client.Domain;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace Frankfurter.API.Client.Extensions
Expand All @@ -11,23 +10,13 @@ internal static class EndpointParameterBuilder
internal static string ToParameter(this IEnumerable<CurrencyCode> currencies)
{
var currenciesStr = new StringBuilder();
var isFirstRow = true;

foreach (var currency in currencies)
{
if (currency != CurrencyCode.None)
{
if (isFirstRow)
{
currenciesStr.Append(',');
}
else
{
isFirstRow = false;
}

currenciesStr.Append(currency.ToString());
}
if (currency == CurrencyCode.NONE) continue;

currenciesStr.Append(',');
currenciesStr.Append(currency.ToString());
}

return currenciesStr.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,16 @@ internal static Exchange ToExchange(this ExchangeBaseApiResponse apiResponse)

internal static IEnumerable<Exchange> ToExchangeList(this ExchangeBaseApiResponse apiResponse)
{
var exchangeList = new List<Exchange>();
var listJsonObjs = apiResponse.Rates.ToArray();

for (var i = 0; i < listJsonObjs.Length; i++)
{
exchangeList.Add(
new Exchange
{
ReferenceDate = DateTime.Parse(listJsonObjs[i].Key),
ReferenceAmount = apiResponse.Amount,
ReferenceCurrency = apiResponse.Currency.ToCurrencyCode(),
Rates = listJsonObjs[i].Value.AsObject().ToCurrencyRateList()
}
);
}

return exchangeList;
return listJsonObjs.Select(node
=> new Exchange
{
ReferenceDate = DateTime.Parse(node.Key),
ReferenceAmount = apiResponse.Amount,
ReferenceCurrency = apiResponse.Currency.ToCurrencyCode(),
Rates = node.Value.AsObject().ToCurrencyRateList()
}).ToList();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using Frankfurter.API.Client.DTO.Response;
using System;

namespace Frankfurter.API.Client.Extensions
{
internal static class ExchangeBaseApiResponseValidator
{
internal static bool IsNull(this ExchangeBaseApiResponse exchangeBaseApiResponse)
{
if (exchangeBaseApiResponse == null) return true;
if (exchangeBaseApiResponse.Rates == null) return true;
if (exchangeBaseApiResponse?.Rates == null) return true;
if (exchangeBaseApiResponse.Amount == decimal.Zero) return true;
if (exchangeBaseApiResponse.Currency == null) return true;

return false;
return exchangeBaseApiResponse.Currency == null;
}
}
}
Loading

0 comments on commit 621abdb

Please sign in to comment.