-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
4,545 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
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
37 changes: 37 additions & 0 deletions
37
src/Geo.Positionstack/Abstractions/IPositionstackGeocoding.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,37 @@ | ||
// <copyright file="IPositionstackGeocoding.cs" company="Geo.NET"> | ||
// Copyright (c) Geo.NET. | ||
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information. | ||
// </copyright> | ||
|
||
namespace Geo.Positionstack | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Geo.Core.Models.Exceptions; | ||
using Geo.Positionstack.Models.Parameters; | ||
using Geo.Positionstack.Models.Responses; | ||
|
||
/// <summary> | ||
/// An interface for calling the Positionstack geocoding methods. | ||
/// </summary> | ||
public interface IPositionstackGeocoding | ||
{ | ||
/// <summary> | ||
/// Calls the Positionstack geocoding API and returns the results. | ||
/// </summary> | ||
/// <param name="parameters">A <see cref="GeocodingParameters"/> with the parameters of the request.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the request.</param> | ||
/// <returns>A <see cref="Response"/> with the response from Positionstack.</returns> | ||
/// <exception cref="GeoNETException">Thrown for multiple different reasons. Check the inner exception for more information.</exception> | ||
Task<Response> GeocodingAsync(GeocodingParameters parameters, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Calls the Positionstack reverse geocoding API and returns the results. | ||
/// </summary> | ||
/// <param name="parameters">A <see cref="ReverseGeocodingParameters"/> with the parameters of the request.</param> | ||
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the request.</param> | ||
/// <returns>A <see cref="Response"/> with the response from Positionstack.</returns> | ||
/// <exception cref="GeoNETException">Thrown for multiple different reasons. Check the inner exception for more information.</exception> | ||
Task<Response> ReverseGeocodingAsync(ReverseGeocodingParameters parameters, CancellationToken cancellationToken = default); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/Geo.Positionstack/Abstractions/Models/IFilterGeocodeParameters.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,63 @@ | ||
// <copyright file="IFilterGeocodeParameters.cs" company="Geo.NET"> | ||
// Copyright (c) Geo.NET. | ||
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information. | ||
// </copyright> | ||
|
||
namespace Geo.Positionstack.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// The base filter parameters used for geocoding or reverse geocoding. | ||
/// </summary> | ||
public interface IFilterGeocodeParameters | ||
{ | ||
/// <summary> | ||
/// Gets or sets the 2-letter(e.g.en) or the 3-letter code(e.g.eng) of your preferred language to translate specific API response objects. | ||
/// <para>Optional.</para> | ||
/// <para>Default: English.</para> | ||
/// </summary> | ||
string Language { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the country module should be enabled to include more extensive country data in your API response. | ||
/// <para>Optional.</para> | ||
/// <para>Default: false.</para> | ||
/// </summary> | ||
bool CountryModule { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the sun module should be enabled to include astrology data in your API response. | ||
/// <para>Optional.</para> | ||
/// <para>Default: false.</para> | ||
/// </summary> | ||
bool SunModule { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the timezone module should be enabled to include timezone data in your API response. | ||
/// <para>Optional.</para> | ||
/// <para>Default: false.</para> | ||
/// </summary> | ||
bool TimezoneModule { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the bounding box module should be enabled to include boundary coordinates in your API response. | ||
/// <para>Optional.</para> | ||
/// <para>Default: false.</para> | ||
/// </summary> | ||
bool BoundingBoxModule { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a limit between 1 and 80 to limit the number of results returned per geocoding query. | ||
/// <para>Optional.</para> | ||
/// <para>Default: 10.</para> | ||
/// </summary> | ||
uint Limit { get; set; } | ||
|
||
/// <summary> | ||
/// Gets a list of one or more response fields to decrease API response size. | ||
/// <para>Optional.</para> | ||
/// </summary> | ||
IList<string> Fields { get; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Geo.Positionstack/Abstractions/Models/ILocationGeocodeParameters.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,27 @@ | ||
// <copyright file="ILocationGeocodeParameters.cs" company="Geo.NET"> | ||
// Copyright (c) Geo.NET. | ||
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information. | ||
// </copyright> | ||
|
||
namespace Geo.Positionstack.Models | ||
{ | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// The location based filter parameters used for geocoding or reverse geocoding. | ||
/// </summary> | ||
public interface ILocationGeocodeParameters | ||
{ | ||
/// <summary> | ||
/// Gets one or more 2-letter(e.g.AU) or 3-letter country codes(e.g.AUS) to filter the geocoding results. | ||
/// <para>Optional.</para> | ||
/// </summary> | ||
IList<string> Countries { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets a filter for the geocoding results specifying a region. This could be a neighbourhood, district, city, county, state or administrative area. Example: region= Berlin to filter by locations in Berlin. | ||
/// <para>Optional.</para> | ||
/// </summary> | ||
string Region { get; set; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Geo.Positionstack/DependencyInjection/ServiceCollectionExtensions.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 @@ | ||
// <copyright file="ServiceCollectionExtensions.cs" company="Geo.NET"> | ||
// Copyright (c) Geo.NET. | ||
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information. | ||
// </copyright> | ||
|
||
namespace Geo.Extensions.DependencyInjection | ||
{ | ||
using System; | ||
using Geo.Positionstack; | ||
using Geo.Positionstack.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="IServiceCollection"/> class. | ||
/// </summary> | ||
public static class ServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds the Positionstack geocoding services to the service collection. | ||
/// <para> | ||
/// Adds the services: | ||
/// <list type="bullet"> | ||
/// <item><see cref="IOptions{TOptions}"/> of <see cref="IPositionstackGeocoding"/></item> | ||
/// <item><see cref="IPositionstackGeocoding"/></item> | ||
/// </list> | ||
/// </para> | ||
/// </summary> | ||
/// <param name="services">An <see cref="IServiceCollection"/> to add the Positionstack services to.</param> | ||
/// <returns>An <see cref="KeyBuilder{T}"/> to configure the Positionstack geocoding.</returns> | ||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="services"/> is null.</exception> | ||
public static KeyBuilder<IPositionstackGeocoding> AddPositionstackGeocoding(this IServiceCollection services) | ||
{ | ||
if (services == null) | ||
{ | ||
throw new ArgumentNullException(nameof(services)); | ||
} | ||
|
||
services.AddKeyOptions<IPositionstackGeocoding>(); | ||
|
||
return new KeyBuilder<IPositionstackGeocoding>(services.AddHttpClient<IPositionstackGeocoding, PositionstackGeocoding>()); | ||
} | ||
} | ||
} |
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,62 @@ | ||
// <copyright file="LoggerExtensions.cs" company="Geo.NET"> | ||
// Copyright (c) Geo.NET. | ||
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information. | ||
// </copyright> | ||
|
||
namespace Geo.Positionstack | ||
{ | ||
using System; | ||
using Geo.Positionstack.Services; | ||
using Microsoft.Extensions.Logging; | ||
|
||
/// <summary> | ||
/// Extension methods for the <see cref="ILogger"/> class. | ||
/// </summary> | ||
internal static class LoggerExtensions | ||
{ | ||
private static readonly Action<ILogger, string, Exception> _error = LoggerMessage.Define<string>( | ||
LogLevel.Error, | ||
new EventId(1, nameof(PositionstackGeocoding)), | ||
"PositionstackGeocoding: {ErrorMessage}"); | ||
|
||
private static readonly Action<ILogger, string, Exception> _warning = LoggerMessage.Define<string>( | ||
LogLevel.Warning, | ||
new EventId(2, nameof(PositionstackGeocoding)), | ||
"PositionstackGeocoding: {WarningMessage}"); | ||
|
||
private static readonly Action<ILogger, string, Exception> _debug = LoggerMessage.Define<string>( | ||
LogLevel.Debug, | ||
new EventId(3, nameof(PositionstackGeocoding)), | ||
"PositionstackGeocoding: {DebugMessage}"); | ||
|
||
/// <summary> | ||
/// "PositionstackGeocoding: {ErrorMessage}". | ||
/// </summary> | ||
/// <param name="logger">An <see cref="ILogger"/> used to log the error message.</param> | ||
/// <param name="errorMessage">The error message to log.</param> | ||
public static void PositionstackError(this ILogger logger, string errorMessage) | ||
{ | ||
_error(logger, errorMessage, null); | ||
} | ||
|
||
/// <summary> | ||
/// "PositionstackGeocoding: {WarningMessage}". | ||
/// </summary> | ||
/// <param name="logger">An <see cref="ILogger"/> used to log the warning message.</param> | ||
/// <param name="warningMessage">The warning message to log.</param> | ||
public static void PositionstackWarning(this ILogger logger, string warningMessage) | ||
{ | ||
_warning(logger, warningMessage, null); | ||
} | ||
|
||
/// <summary> | ||
/// "PositionstackGeocoding: {DebugMessage}". | ||
/// </summary> | ||
/// <param name="logger">An <see cref="ILogger"/> used to log the debug message.</param> | ||
/// <param name="debugMessage">The debug message to log.</param> | ||
public static void PositionstackDebug(this ILogger logger, string debugMessage) | ||
{ | ||
_debug(logger, debugMessage, null); | ||
} | ||
} | ||
} |
Oops, something went wrong.