Skip to content

Commit

Permalink
Refactor: Update documentation and samples, enrich README with method…
Browse files Browse the repository at this point in the history
… explanations, and rename GetCountryEmojiFlag to GetCountryFlag for clarity.
  • Loading branch information
Clifftech123 committed Jun 21, 2024
1 parent 23b7fa6 commit 3a65201
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sample/CountryData.Sample.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void GetRegionsByCountryCode(string countryCode)
/// <param name="shortCode">The country short code.</param>
static void GetCountryFlag(string shortCode)
{
var flag = _helper.GetCountryEmojiFlag(shortCode);
var flag = _helper.GetCountryFlag(shortCode);
Console.WriteLine($"Flag for {shortCode}:");
Console.WriteLine(flag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/CountryData.Standard/CountryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CountryHelper()
_Countries = JsonConvert.DeserializeObject<List<Country>>(json);
foreach (var country in _Countries)
{
country.CountryFlag = GetCountryEmojiFlag(country.CountryShortCode);
country.CountryFlag = GetCountryFlag(country.CountryShortCode);
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ public Country GetCountryByCode(string shortCode)
/// </summary>
/// <param name="country"></param>
/// <returns></returns>
public string GetCountryEmojiFlag(string shortCode)
public string GetCountryFlag (string shortCode)
{
return string.Concat(shortCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}
Expand Down
2 changes: 1 addition & 1 deletion test/CountryData.UnitTests/CountryHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3a65201

Please sign in to comment.