Skip to content

Commit

Permalink
Added format field to lookup for project-usa (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjohnsonsmarty authored Oct 26, 2023
1 parent 1afebf1 commit da543fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/sdk/USStreetApi/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SmartyStreets.USStreetApi
using SmartyStreets.USReverseGeoApi;

namespace SmartyStreets.USStreetApi
{
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -66,9 +68,12 @@ private static void PopulateQueryString(Lookup address, Request request)
request.SetParameter("addressee", address.Addressee);
request.SetParameter("urbanization", address.Urbanization);
request.SetParameter("match", address.MatchStrategy);

if (address.MaxCandidates != 1)
if (address.MaxCandidates != 1)
request.SetParameter("candidates", address.MaxCandidates.ToString(CultureInfo.InvariantCulture));

if (address.GetFormatString() != "default")
request.SetParameter("format", address.GetFormatString());
}

private static void AssignCandidatesToLookups(Batch batch, IEnumerable<Candidate> candidates)
Expand Down
28 changes: 26 additions & 2 deletions src/sdk/USStreetApi/Lookup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SmartyStreets.USStreetApi
using System.Runtime.CompilerServices;

namespace SmartyStreets.USStreetApi
{
using System;
using System.Collections.Generic;
Expand All @@ -13,7 +15,13 @@ public class Lookup : ILookup
public const string ENHANCED = "enhanced";
public const string INVALID = "invalid";
public const string RANGE = "range"; // Deprecated


public enum Format
{
Default,
ProjectUsa,
}

public List<Candidate> Result { get; private set; }

[DataMember(Name = "input_id")]
Expand Down Expand Up @@ -52,6 +60,9 @@ public class Lookup : ILookup
[DataMember(Name = "match")]
public string MatchStrategy { get; set; }

[DataMember(Name = "format")]
public Format OutputFormat { get; set; }

public int MaxCandidates
{
get => this.maxCandidates;
Expand Down Expand Up @@ -85,5 +96,18 @@ public void AddToResult(Candidate newCandidate)
{
this.Result.Add(newCandidate);
}

public string GetFormatString()
{
switch (this.OutputFormat)
{
case Format.Default:
return "default";
case Format.ProjectUsa:
return "project-usa";
default:
return "";
}
}
}
}
28 changes: 28 additions & 0 deletions src/tests/USStreetApi/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,35 @@ public void TestSendingSingleFullyPopulatedLookup()
Assert.AreEqual("?input_id=1234&street=1&street2=3&secondary=2&city=5&state=6&zipcode=7&" +
"lastline=8&addressee=0&urbanization=4&match=enhanced&candidates=5", sender.Request.GetUrl());
}

[Test]
public void TestSendingSingleFullyPopulatedLookupWithFormatOutput()
{
var sender = new RequestCapturingSender();
var serializer = new FakeSerializer(null);
var client = new Client(sender, serializer);
var lookup = new Lookup
{
InputId = "1234",
Addressee = "0",
Street = "1",
Secondary = "2",
Street2 = "3",
Urbanization = "4",
City = "5",
State = "6",
ZipCode = "7",
Lastline = "8",
MatchStrategy = "enhanced",
OutputFormat = Lookup.Format.ProjectUsa
};

client.Send(lookup);

Assert.AreEqual("?input_id=1234&street=1&street2=3&secondary=2&city=5&state=6&zipcode=7&" +
"lastline=8&addressee=0&urbanization=4&match=enhanced&candidates=5&format=project-usa", sender.Request.GetUrl());
}

#endregion

#region [ Batch Lookup ]
Expand Down

0 comments on commit da543fe

Please sign in to comment.