Skip to content

Commit

Permalink
Added method for creating base parameters consistently.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Jul 31, 2024
1 parent c7cb820 commit 6c5c238
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Weatherstack/Service/Extensions/CreateBaseParameters.cs
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

View workflow job for this annotation

GitHub Actions / build

'IWeatherstackService' does not contain a definition for 'GetToken' and no accessible extension method 'GetToken' accepting a first argument of type 'IWeatherstackService' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs

View workflow job for this annotation

GitHub Actions / build

'IWeatherstackService' does not contain a definition for 'GetToken' and no accessible extension method 'GetToken' accepting a first argument of type 'IWeatherstackService' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs

View workflow job for this annotation

GitHub Actions / build

'IWeatherstackService' does not contain a definition for 'GetToken' and no accessible extension method 'GetToken' accepting a first argument of type 'IWeatherstackService' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 12 in src/Weatherstack/Service/Extensions/CreateBaseParameters.cs

View workflow job for this annotation

GitHub Actions / build

'IWeatherstackService' does not contain a definition for 'GetToken' and no accessible extension method 'GetToken' accepting a first argument of type 'IWeatherstackService' could be found (are you missing a using directive or an assembly reference?)
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;
}
}

0 comments on commit 6c5c238

Please sign in to comment.