Skip to content

Commit

Permalink
Merge pull request #48 from smartystreets/eric/add-custom-parameter
Browse files Browse the repository at this point in the history
Eric/add custom parameter
  • Loading branch information
RyanLCox1 authored Nov 6, 2024
2 parents 157d785 + 5df0877 commit a82d636
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/examples/InternationalAutocompleteExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static void Run()
Locality = "Paris",
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("max_results", "3");

try
{
client.Send(lookup);
Expand Down
3 changes: 3 additions & 0 deletions src/examples/InternationalStreetExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static void Run()
Country = "Brazil",
PostalCode = "02516-050"
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("input_id", "ID-8675309");

try
{
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USAutocompleteProExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public static void Run()
lookup.PreferRatio = 4;
lookup.Source = "all";

//uncomment the below line to add a custom parameter
//lookup.AddCustomParameter("source", "all");

try
{
client.Send(lookup);
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USEnrichmentGeoReferenceExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static void Run()
componentsLookup.SetState("NJ");
componentsLookup.SetZipcode("08876");

//uncomment the below line to add a custom parameter
//componentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the line below
var freeformLookup = new SmartyStreets.USEnrichmentApi.GeoReference.Lookup();
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
Expand Down
6 changes: 6 additions & 0 deletions src/examples/USEnrichmentPropertyExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public static void Run()
componentsLookup.SetState("NJ");
componentsLookup.SetZipcode("08876");

//uncomment the below line to add a custom parameter
//componentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the line below
var freeformLookup = new SmartyStreets.USEnrichmentApi.Property.Principal.Lookup();
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
Expand Down Expand Up @@ -83,6 +86,9 @@ public static void Run()
financialComponentsLookup.SetState("NJ");
financialComponentsLookup.SetZipcode("08876");

//uncomment the below line to add a custom parameter
//financialComponentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the line below
var financialFreeformLookup = new SmartyStreets.USEnrichmentApi.Property.Financial.Lookup();
financialFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
Expand Down
6 changes: 6 additions & 0 deletions src/examples/USEnrichmentSecondaryExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static void Run()
componentsLookup.SetState("NJ");
componentsLookup.SetZipcode("08876");

//uncomment the below line to add a custom parameter
//componentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the line below
var freeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Lookup();
freeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
Expand Down Expand Up @@ -95,6 +98,9 @@ public static void Run()
countComponentsLookup.SetState("NJ");
countComponentsLookup.SetZipcode("08876");

//uncomment the below line to add a custom parameter
//countComponentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the line below
var countFreeformLookup = new SmartyStreets.USEnrichmentApi.Secondary.Count.Lookup();
countFreeformLookup.SetFreeform("56 Union Ave Somerville NJ 08876");
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USEnrichmentUniversalExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static void Run()
componentsLookup.SetState("NJ");
componentsLookup.SetZipcode("08876");

//uncomment the line below to add a custom parameter
//componentsLookup.AddCustomParameter("zipcode", "08876");

// Create a lookup with a single line address using the lines below
var freeformLookup = new SmartyStreets.USEnrichmentApi.Universal.Lookup();
freeformLookup.SetDatasetName("property");
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USExtractExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static void Run()
AddressesHaveLineBreaks = false,
AddressesPerLine = 1
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("addr_line_breaks", "false");

try
{
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USReverseGeoExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static void Run()

var lookup = new Lookup(40.111111, -111.111111);

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("source", "all");

try
{
client.Send(lookup);
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USStreetLookupsWithMatchStrategyExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static void Run()
MatchStrategy = Lookup.STRICT
};

//uncomment the line below to add a custom parameter
//addressWithStrictStrategy.AddCustomParameter("city", "provo");

var addressWithEnhancedStrategy = new Lookup
{
Street = "693 W 1150 S",
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USStreetMultipleAddressesExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public static void Run()
// Refer to the documentation for additional MatchStrategy options.
};

//uncomment the line below to add a custom parameter
//address1.AddCustomParameter("InputId", "24601");

var address2 = new Lookup("1 Rosedale, Baltimore, Maryland")
{
Street = "1 Rosedale",
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USStreetSingleAddressEndpointExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static void Run()
// Refer to the documentation for additional MatchStrategy options.
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("InputId", "24601");

try
{
client.Send(lookup);
Expand Down
4 changes: 4 additions & 0 deletions src/examples/USStreetSingleAddressExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ public static void Run()
City = "Mountain View",
State = "CA",
ZipCode = "21229",
CountySource = Lookup.GEOGRAPHIC,
MaxCandidates = 3,
MatchStrategy = Lookup.ENHANCED // "invalid" is the most permissive match,
// this will always return at least one result even if the address is invalid.
// Refer to the documentation for additional MatchStrategy options.
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("county_source", "geographic");

try
{
client.Send(lookup);
Expand Down
4 changes: 4 additions & 0 deletions src/examples/USZipCodeMultipleLookupsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public static void Run()
ZipCode = "12345"
};

//uncomment the lines below to add custom parameters
// lookup1.AddCustomParameter("city", "Schenectady");
// lookup1.AddCustomParameter("state", "NY");

var lookup2 = new Lookup
{
City = "Phoenix",
Expand Down
3 changes: 3 additions & 0 deletions src/examples/USZipCodeSingleLookupExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static void Run()
ZipCode = "94039"
};

//uncomment the line below to add a custom parameter
//lookup.AddCustomParameter("zipcode", "94039");

try
{
client.Send(lookup);
Expand Down
5 changes: 5 additions & 0 deletions src/sdk/InternationalAutcompleteApi/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.IO;
using System.Collections.Generic;

/// <summary>
/// This client sends lookups to the SmartyStreets US Autocomplete API,
Expand Down Expand Up @@ -58,6 +59,10 @@ private static Request BuildRequest(Lookup lookup)
request.SetParameter("max_results", lookup.MaxSuggestionsString);
request.SetParameter("include_only_locality", lookup.Locality);
request.SetParameter("include_only_postal_code", lookup.PostalCode);

foreach (KeyValuePair<string, string> line in lookup.CustomParamDict) {
request.SetParameter(line.Key, line.Value);
}

return request;
}
Expand Down
5 changes: 5 additions & 0 deletions src/sdk/InternationalAutcompleteApi/Lookup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace SmartyStreets.InternationalAutocompleteApi
{
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// In addition to holding all of the input data for this lookup, this class also
Expand All @@ -22,6 +23,7 @@ public class Lookup
public int MaxResults { get; set; }
public string Locality { get; set; }
public string PostalCode { get; set; }
public Dictionary<string, string> CustomParamDict = new Dictionary<string, string>{};

#endregion

Expand All @@ -46,5 +48,8 @@ public Lookup(string search) : this()

internal string MaxSuggestionsString => this.MaxResults.ToString();

public void AddCustomParameter(string parameter, string value) {
CustomParamDict.Add(parameter, value);
}
}
}
4 changes: 4 additions & 0 deletions src/sdk/InternationalStreetApi/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ private static Request BuildRequest(Lookup lookup)
request.SetParameter("administrative_area", lookup.AdministrativeArea);
request.SetParameter("postal_code", lookup.PostalCode);

foreach (KeyValuePair<string, string> line in lookup.CustomParamDict) {
request.SetParameter(line.Key, line.Value);
}

return request;
}

Expand Down
5 changes: 5 additions & 0 deletions src/sdk/InternationalStreetApi/Lookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Lookup : ILookup
public string Locality { get; set; }
public string AdministrativeArea { get; set; }
public string PostalCode { get; set; }
public Dictionary<string, string> CustomParamDict = new Dictionary<string, string>{};

#endregion

Expand Down Expand Up @@ -118,5 +119,9 @@ public void AddToResult(Candidate newCandidate)
{
this.Result.Add(newCandidate);
}

public void AddCustomParameter(string parameter, string value) {
CustomParamDict.Add(parameter, value);
}
}
}
5 changes: 5 additions & 0 deletions src/sdk/USAutocompleteProApi/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.IO;
using System.Collections.Generic;

/// <summary>
/// This client sends lookups to the SmartyStreets US Autocomplete API,
Expand Down Expand Up @@ -57,6 +58,10 @@ private static Request BuildRequest(Lookup lookup)
request.SetParameter("selected", lookup.Selected);
request.SetParameter("source", lookup.Source);

foreach (KeyValuePair<string, string> line in lookup.CustomParamDict) {
request.SetParameter(line.Key, line.Value);
}

return request;
}

Expand Down
6 changes: 6 additions & 0 deletions src/sdk/USAutocompleteProApi/Lookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SmartyStreets.USAutocompleteProApi
{
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// In addition to holding all of the input data for this lookup, this class also
Expand Down Expand Up @@ -31,6 +32,7 @@ public class Lookup
public string PreferGeolocation { get; set; }
public string Selected { get; set; }
public string Source { get; set; }
public Dictionary<string, string> CustomParamDict = new Dictionary<string, string>{};

#endregion

Expand Down Expand Up @@ -112,5 +114,9 @@ public void AddPreferZIP(string zipcode)
this.PreferGeolocation = GeolocateType.NONE;
this.PreferZIPCodes.Add(zipcode);
}

public void AddCustomParameter(string parameter, string value) {
CustomParamDict.Add(parameter, value);
}
}
}
5 changes: 5 additions & 0 deletions src/sdk/USEnrichmentApi/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace SmartyStreets.USEnrichmentApi
{
using System;
using System.IO;
using System.Collections.Generic;

public class Client //: IUSEnrichmentClient
{
Expand Down Expand Up @@ -150,6 +151,10 @@ private SmartyStreets.Request BuildRequest(Lookup lookup)
request.SetHeader("Etag", lookup.GetEtag());
}

foreach (KeyValuePair<string, string> line in lookup.CustomParamDict) {
request.SetParameter(line.Key, line.Value);
}

return request;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/sdk/USEnrichmentApi/Lookup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace SmartyStreets.USEnrichmentApi
{
using System;
Expand All @@ -15,6 +17,7 @@ public abstract class Lookup
private string zipcode;
private string includeFields;
private string excludeFields;
public Dictionary<string, string> CustomParamDict = new Dictionary<string, string>{};
private string eTag;

public Lookup(string smartyKey = null, string datasetName = null, string dataSubsetName = null, string freeform = null, string street = null,
Expand Down Expand Up @@ -141,6 +144,10 @@ public void SetZipcode(string zipcode)
}

public abstract void DeserializeAndSetResults(SmartyStreets.ISerializer serializer, Stream payload);

public void AddCustomParameter(string parameter, string value) {
CustomParamDict.Add(parameter, value);
}
}

}
8 changes: 7 additions & 1 deletion src/sdk/USExtractApi/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SmartyStreets.USExtractApi
using System.Collections.Generic;

namespace SmartyStreets.USExtractApi
{
using System;
using System.IO;
Expand Down Expand Up @@ -52,6 +54,10 @@ private static Request BuildRequest(Lookup lookup)
if ((lookup.MatchStrategy != "") && (lookup.MatchStrategy != Lookup.STRICT))
request.SetParameter("match", lookup.MatchStrategy);

foreach (KeyValuePair<string, string> line in lookup.CustomParamDict) {
request.SetParameter(line.Key, line.Value);
}

return request;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/sdk/USExtractApi/Lookup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace SmartyStreets.USExtractApi
using System.Collections.Generic;

namespace SmartyStreets.USExtractApi

{
/// <summary>
/// In addition to holding all of the input data for this lookup, this class also
Expand All @@ -20,6 +23,7 @@ public class Lookup
public int AddressesPerLine { get; set; }
public string MatchStrategy { get; set; }
public string Text { get; set; }
public Dictionary<string, string> CustomParamDict = new Dictionary<string, string>{};

#endregion

Expand Down Expand Up @@ -51,5 +55,9 @@ public void SpecifyHtmlInput(bool html)
{
this.html = html.ToString().ToLower();
}

public void AddCustomParameter(string parameter, string value) {
CustomParamDict.Add(parameter, value);
}
}
}
Loading

0 comments on commit a82d636

Please sign in to comment.