-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added method for creating base parameters consistently.
- Loading branch information
1 parent
c7cb820
commit 6c5c238
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Weatherstack/Service/Extensions/CreateBaseParameters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
|
||
namespace Weatherstack; | ||
|
||
public static partial class WeatherstackServiceExtensions | ||
{ | ||
private static Dictionary<string, string> CreateBaseParameters( | ||
this IWeatherstackService source, | ||
UnitPreference? unitPreference = null, | ||
LanguagePreference? languagePreference = null) | ||
{ | ||
var token = source.GetToken(); | ||
Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs GitHub Actions / build
Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs GitHub Actions / build
Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs GitHub Actions / build
Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs GitHub Actions / build
|
||
var parameters = new Dictionary<string, string> | ||
{ | ||
["access_key"] = token | ||
}; | ||
|
||
parameters.AddUnitPreference(unitPreference); | ||
parameters.AddLanguagePreference(languagePreference); | ||
return parameters; | ||
} | ||
|
||
private static void AddUnitPreference( | ||
this IDictionary<string, string> parameters, | ||
UnitPreference? unitPreference) | ||
{ | ||
if (!unitPreference.HasValue) | ||
return; | ||
|
||
var literalValue = UnitPreferenceAdapter.Convert(unitPreference.Value); | ||
parameters["units"] = literalValue; | ||
} | ||
|
||
private static void AddLanguagePreference( | ||
this IDictionary<string, string> parameters, | ||
LanguagePreference? languagePreference) | ||
{ | ||
if (!languagePreference.HasValue) | ||
return; | ||
|
||
var isoCode = LanguagePreferenceAdapter.Convert(languagePreference.Value); | ||
parameters["language"] = isoCode; | ||
} | ||
} |