Skip to content

Commit

Permalink
chore: minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
chaddgrimm committed Nov 25, 2024
1 parent 3d779c3 commit a36a09a
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 49 deletions.
64 changes: 30 additions & 34 deletions sample/sample.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
* Simple console application using the what3words-dotnet-wrapper.
*/

using sample.Console.Utils;
using System.Globalization;
using System.Linq;
using what3words.dotnet.wrapper;
using what3words.dotnet.wrapper.models;
using what3words.dotnet.wrapper.response;
using System.Linq;
using System.Globalization;

namespace sample.Console
{
using System;
using Utils;

class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
try
{
Expand All @@ -25,10 +22,10 @@ static void Main(string[] args)
PrintUsage();
return;
}
string apiKey = arguments.GetArgument("--api-key");
var apiKey = arguments.GetArgument("--api-key");
if (apiKey != null)
{
What3WordsV3 api = new What3WordsV3(apiKey);
var api = new What3WordsV3(apiKey);
switch (arguments.GetCommand())
{
case "convert-to-coordinates":
Expand All @@ -41,79 +38,78 @@ static void Main(string[] args)
AutoSuggest(api, arguments);
break;
default:
Console.WriteLine("Command is not supported.");
System.Console.WriteLine("Command is not supported.");
PrintUsage();
break;
}
}
}
catch (Exception error)
catch (System.Exception error)
{
Console.WriteLine("Something went wrong, " + error.Message);
System.Console.WriteLine("Something went wrong, " + error.Message);
PrintUsage();
}
}

static void PrintUsage()
private static void PrintUsage()
{
Console.WriteLine("Usage: <command> [options]");
Console.WriteLine("Required parameters:");
Console.WriteLine(" --api-key <key>");
Console.WriteLine("Commands:");
Console.WriteLine(" convert-to-coordinates --3wa <3 word address>");
Console.WriteLine(" convert-to-3wa --lat <latitude> --lng <longitude>");
Console.WriteLine(" autosuggest --input <input>");
System.Console.WriteLine("Usage: <command> [options]");
System.Console.WriteLine("Required parameters:");
System.Console.WriteLine(" --api-key <key>");
System.Console.WriteLine("Commands:");
System.Console.WriteLine(" convert-to-coordinates --3wa <3 word address>");
System.Console.WriteLine(" convert-to-3wa --lat <latitude> --lng <longitude>");
System.Console.WriteLine(" autosuggest --input <input>");
}

static void ConvertToCoordinates(What3WordsV3 api, Arguments arg)
private static void ConvertToCoordinates(What3WordsV3 api, Arguments arg)
{
var threeWords = arg.GetArgument("--3wa");
var result = api.ConvertToCoordinates(threeWords).RequestAsync().Result;
if (result.IsSuccessful)
{
Console.WriteLine("Coordinates: " + result.Data.Coordinates.Lat + ", " + result.Data.Coordinates.Lng);
System.Console.WriteLine("Coordinates: " + result.Data.Coordinates.Lat + ", " + result.Data.Coordinates.Lng);
}
else
{
Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
System.Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
}
}

static void ConvertTo3WA(What3WordsV3 api, Arguments arg)
private static void ConvertTo3WA(What3WordsV3 api, Arguments arg)
{
double latitude, longitude;
var lat = double.TryParse(arg.GetArgument("--lat"), NumberStyles.Any, CultureInfo.InvariantCulture, out latitude) ? latitude : 0.0;
var lng = double.TryParse(arg.GetArgument("--lng"), NumberStyles.Any, CultureInfo.InvariantCulture, out longitude) ? longitude : 0.0;
var lat = double.TryParse(arg.GetArgument("--lat"), NumberStyles.Any, CultureInfo.InvariantCulture, out var latitude) ? latitude : 0.0;
var lng = double.TryParse(arg.GetArgument("--lng"), NumberStyles.Any, CultureInfo.InvariantCulture, out var longitude) ? longitude : 0.0;
var coordinates = new Coordinates(lat, lng);
var result = api.ConvertTo3WA(coordinates).RequestAsync().Result;
if (result.IsSuccessful)
{
Console.WriteLine($"3 word address: https://w3w.co/{result.Data.Words}");
System.Console.WriteLine($"3 word address: https://w3w.co/{result.Data.Words}");
}
else
{
Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
System.Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
}
}

static void AutoSuggest(What3WordsV3 api, Arguments arg)
private static void AutoSuggest(What3WordsV3 api, Arguments arg)
{
var input = arg.GetArgument("--input");
var result = api.Autosuggest(input).RequestAsync().Result;
if (result.IsSuccessful)
{
if (result.Data.Suggestions.Count > 0)
{
Console.WriteLine("Suggestions: " + string.Join(", ", result.Data.Suggestions.Select(x => $"https://w3w.co/{x.Words}")));
System.Console.WriteLine("Suggestions: " + string.Join(", ", result.Data.Suggestions.Select(x => $"https://w3w.co/{x.Words}")));
}
else
{
Console.WriteLine("No suggestions found.");
System.Console.WriteLine("No suggestions found.");
}
}
else
{
Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
System.Console.WriteLine(result.Error.Code + " - " + result.Error.Message);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions sample/sample.Console/sample.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
<ProjectReference Include="..\..\what3words.dotnet.wrapper\what3words.dotnet.wrapper.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions what3words.dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sample.Console", "sample\sample.Console\sample.Console.csproj", "{F338C03F-A651-484D-AFEF-AC0F225E0819}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -187,6 +189,30 @@ Global
{E949A39D-C622-46F4-A26E-9120CD54A5E7}.Release|x64.Build.0 = Release|Any CPU
{E949A39D-C622-46F4-A26E-9120CD54A5E7}.Release|x86.ActiveCfg = Release|Any CPU
{E949A39D-C622-46F4-A26E-9120CD54A5E7}.Release|x86.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|ARM.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|ARM.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|iPhone.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|x64.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|x64.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|x86.ActiveCfg = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Debug|x86.Build.0 = Debug|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|Any CPU.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|ARM.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|ARM.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|iPhone.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|iPhone.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|x64.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|x64.Build.0 = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|x86.ActiveCfg = Release|Any CPU
{F338C03F-A651-484D-AFEF-AC0F225E0819}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 2 additions & 3 deletions what3words.dotnet.wrapper.utests/Autosuggest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Xunit;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using what3words.dotnet.wrapper.models;
using what3words.dotnet.wrapper.request;
using what3words.dotnet.wrapper.response;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class Autosuggest
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public Autosuggest()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using Xunit;
using System;
using System.Linq;
using System.Threading.Tasks;
using what3words.dotnet.wrapper.models;
using what3words.dotnet.wrapper.request;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class AutosuggestWithCoordinates
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public AutosuggestWithCoordinates()
{
Expand Down
4 changes: 2 additions & 2 deletions what3words.dotnet.wrapper.utests/AvailableLanguages.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Xunit;
using System;
using System.Threading.Tasks;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class AvailableLanguages
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public AvailableLanguages()
{
Expand Down
4 changes: 2 additions & 2 deletions what3words.dotnet.wrapper.utests/ConvertTo3WA.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Xunit;
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using what3words.dotnet.wrapper.models;
using what3words.dotnet.wrapper.response;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class ConvertTo3WA
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public ConvertTo3WA()
{
Expand Down
4 changes: 2 additions & 2 deletions what3words.dotnet.wrapper.utests/ConvertToCoordinates.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Xunit;
using System;
using System.Threading.Tasks;
using what3words.dotnet.wrapper.response;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{

public class ConvertToCoordinates
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public ConvertToCoordinates()
{
Expand Down
4 changes: 2 additions & 2 deletions what3words.dotnet.wrapper.utests/GridSection.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Xunit;
using System;
using System.Threading.Tasks;
using what3words.dotnet.wrapper.models;
using what3words.dotnet.wrapper.response;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class GridSection
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public GridSection()
{
Expand Down
4 changes: 2 additions & 2 deletions what3words.dotnet.wrapper.utests/Validate3wa.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Xunit;
using System;
using System.Linq;
using Xunit;

namespace what3words.dotnet.wrapper.utests
{
public class Validate3wa
{
private What3WordsV3 api;
private readonly What3WordsV3 api;

public Validate3wa()
{
Expand Down

0 comments on commit a36a09a

Please sign in to comment.