From 3a6520111bfca616a745c56f33fc72d1e1abd23a Mon Sep 17 00:00:00 2001 From: Isaiah Clifford Opoku Date: Fri, 21 Jun 2024 12:39:01 +0000 Subject: [PATCH] Refactor: Update documentation and samples, enrich README with method explanations, and rename GetCountryEmojiFlag to GetCountryFlag for clarity. --- README.md | 20 ++++++++++++++++++- docs/README.md | 6 +++--- sample/CountryData.Sample.Console/Program.cs | 2 +- .../Controllers/CountryController.cs | 2 +- src/CountryData.Standard/CountryHelper.cs | 4 ++-- .../CountryHelperTests.cs | 2 +- 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d5e0a46..adcc848 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ For more detailed instructions and comprehensive information about the library, .ToList(); ``` - +### Get Country Data by Country Code This example demonstrates how to retrieve a country with a specific phone code using the `GetCountryByPhoneCode` method. In this case, we're fetching the country with the phone code "+233". ```csharp @@ -90,6 +90,24 @@ Console.WriteLine(CountryName); ``` + + +### Methods and Descriptions + +The CountryData.Standard library provides a set of methods that allow you to retrieve country data, flags, regions, and phone codes. The following table lists the available methods and their descriptions. + +| Method | Description | +|--------|-------------| +| [`GetCountryData()`](./docs/README.md) | Returns all country data including region, short code, and country name. | +| [`GetCountryByCode(string shortCode)`](./docs/README.md) | Returns a single country's data by its short code. | +| [`GetCountryFlag(string shortCode)`](./docs/README.md) | Gets the flag of the country, represented as an emoji, by the country's short code. | +| [`GetRegionByCountryCode(string ShortCode)`](./docs/README.md) | Selects and returns a list of regions for a particular country identified by its short code. | +| [`GetCountries()`](./docs/README.md) | Gets the list of all country names. | +| [`GetPhoneCodeByCountryShortCode(string shortCode)`](./docs/README.md) | Returns a single country's phone code by its short code. | +| [`GetCountryByPhoneCode(string phoneCode)`](./docs/README.md) | Returns country data for the country associated with the specified phone code. | + + + ### ISO-3166-1 country codes For a list of supported ISO-3166-1 country codes, PhoneCode, Flags, ISO and , Unicode please refer to the [Country Details](./CountryData/CountryDetails.md) file. diff --git a/docs/README.md b/docs/README.md index 07ebd5a..c758582 100644 --- a/docs/README.md +++ b/docs/README.md @@ -116,14 +116,14 @@ This method is particularly useful for applications that need to display or anal -### GetCountryEmojiFlag(string shortCode) +### GetCountryFlag (string shortCode) -The `GetCountryEmojiFlag()` method is designed to fetch the flag of a specific country using its ISO 3166-1 alpha-2 code. This method provides a simple and effective way to visually represent countries in your application. +The `GetCountryFlag ()` method is designed to fetch the flag of a specific country using its ISO 3166-1 alpha-2 code. This method provides a simple and effective way to visually represent countries in your application. Here's the method signature in C#: ```csharp -string GetCountryEmojiFlag(string shortCode); +string GetCountryFlag (string shortCode); ``` This method returns the em flag of the country corresponding to the provided ISO code. It's particularly useful when you need to display a country's flag in a user interface or in text-based communication. diff --git a/sample/CountryData.Sample.Console/Program.cs b/sample/CountryData.Sample.Console/Program.cs index ee16da7..f158139 100644 --- a/sample/CountryData.Sample.Console/Program.cs +++ b/sample/CountryData.Sample.Console/Program.cs @@ -83,7 +83,7 @@ static void GetRegionsByCountryCode(string countryCode) /// The country short code. static void GetCountryFlag(string shortCode) { - var flag = _helper.GetCountryEmojiFlag(shortCode); + var flag = _helper.GetCountryFlag(shortCode); Console.WriteLine($"Flag for {shortCode}:"); Console.WriteLine(flag); } diff --git a/sample/CountryData.Sample.Web.API/Controllers/CountryController.cs b/sample/CountryData.Sample.Web.API/Controllers/CountryController.cs index 893904a..03688ea 100644 --- a/sample/CountryData.Sample.Web.API/Controllers/CountryController.cs +++ b/sample/CountryData.Sample.Web.API/Controllers/CountryController.cs @@ -107,7 +107,7 @@ public IActionResult GetRegionsByCountryCode([FromQuery] string countryCode) [ProducesResponseType(404)] public IActionResult GetCountryFlag([FromQuery] string countryCode) { - var flag = _helper.GetCountryEmojiFlag(countryCode); + var flag = _helper.GetCountryFlag(countryCode); if (flag == null) { return NotFound(); diff --git a/src/CountryData.Standard/CountryHelper.cs b/src/CountryData.Standard/CountryHelper.cs index 7bb1e49..d4d829f 100644 --- a/src/CountryData.Standard/CountryHelper.cs +++ b/src/CountryData.Standard/CountryHelper.cs @@ -17,7 +17,7 @@ public CountryHelper() _Countries = JsonConvert.DeserializeObject>(json); foreach (var country in _Countries) { - country.CountryFlag = GetCountryEmojiFlag(country.CountryShortCode); + country.CountryFlag = GetCountryFlag(country.CountryShortCode); } } @@ -67,7 +67,7 @@ public Country GetCountryByCode(string shortCode) /// /// /// - public string GetCountryEmojiFlag(string shortCode) + public string GetCountryFlag (string shortCode) { return string.Concat(shortCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5))); } diff --git a/test/CountryData.UnitTests/CountryHelperTests.cs b/test/CountryData.UnitTests/CountryHelperTests.cs index 7691aad..2caced4 100644 --- a/test/CountryData.UnitTests/CountryHelperTests.cs +++ b/test/CountryData.UnitTests/CountryHelperTests.cs @@ -55,7 +55,7 @@ public void GetCountryByCode_WithCorrectCode_ShouldReturnCountry(string shortCod public void GetCountryFlagByCode_WithCorrectCode_ShouldReturnEmojiFlag(string shortCode) { //Act - var countryFlag = _countryHelper.GetCountryEmojiFlag(shortCode); + var countryFlag = _countryHelper.GetCountryFlag(shortCode); //Assert countryFlag.Should().NotBeNull();