Skip to content

Commit

Permalink
adding location api
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Valverde committed Aug 25, 2015
1 parent 0d69fbe commit b39dd61
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 12 deletions.
4 changes: 3 additions & 1 deletion FullContactDotNet/Company/Address.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace FullContactDotNet.Company
using FullContactDotNet.Shared;

namespace FullContactDotNet.Company
{
public class Address
{
Expand Down
3 changes: 2 additions & 1 deletion FullContactDotNet/Company/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using FullContactDotNet.Shared;
using System.Collections.Generic;

namespace FullContactDotNet.Company
{
Expand Down
13 changes: 9 additions & 4 deletions FullContactDotNet/FullContactDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@
<Compile Include="Account\Metric.cs" />
<Compile Include="Casing.cs" />
<Compile Include="Company\Address.cs" />
<Compile Include="Company\Asset.cs" />
<Compile Include="Location\EnrichedLocationResponse.cs" />
<Compile Include="Location\Location.cs" />
<Compile Include="Shared\Asset.cs" />
<Compile Include="Company\CompanyResponse.cs" />
<Compile Include="Company\ContactInfo.cs" />
<Compile Include="Company\EmailAddress.cs" />
<Compile Include="Company\NameAndCode.cs" />
<Compile Include="Shared\NameAndCode.cs" />
<Compile Include="Company\Organization.cs" />
<Compile Include="Company\PhoneNumber.cs" />
<Compile Include="Company\Ranking.cs" />
<Compile Include="Person\DeducedName.cs" />
<Compile Include="Person\DeducedNameAndCode.cs" />
<Compile Include="FullContactLocationApi.cs" />
<Compile Include="IFullContactLocationApi.cs" />
<Compile Include="Location\NormalizedLocationResponse.cs" />
<Compile Include="Shared\DeducedName.cs" />
<Compile Include="Shared\DeducedNameAndCode.cs" />
<Compile Include="Shared\SocialProfile.cs" />
<Compile Include="Company\Traffic.cs" />
<Compile Include="FullContactAccountApi.cs" />
Expand Down
78 changes: 78 additions & 0 deletions FullContactDotNet/FullContactLocationApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using FullContactDotNet.Location;
using RestSharp;
using System;

namespace FullContactDotNet
{
public class FullContactLocationApi : FullContactApi, IFullContactLocationApi
{
/// <summary>
/// Initializes a new instance of the <see cref="FullContactLocationApi"/> class.
/// </summary>
public FullContactLocationApi() : base(FullContactConfiguration.ApiKey) { }

/// <summary>
/// Initializes a new instance of the <see cref="FullContactLocationApi"/> class.
/// </summary>
/// <param name="apiKey">The API key.</param>
public FullContactLocationApi(string apiKey) : base(apiKey) { }

/// <summary>
/// Gets the normalized location.
/// </summary>
/// <param name="place">The place.</param>
/// <param name="includeZeroPopulation">The include zero population.</param>
/// <param name="casing">The casing.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">An email address is required to lookup a person by email.</exception>
public NormalizedLocationResponse GetNormalizedLocation(string place, bool? includeZeroPopulation = null, Casing? casing = null)
{
if (string.IsNullOrWhiteSpace(place)) throw new ArgumentNullException("A place is required to get a normalized location.");

var request = GetLocationRequest("locationNormalizer", includeZeroPopulation, casing);
request.AddParameter("place", place);
return Execute<NormalizedLocationResponse>(request);
}

/// <summary>
/// Gets the enriched location.
/// </summary>
/// <param name="place">The place.</param>
/// <param name="includeZeroPopulation">The include zero population.</param>
/// <param name="casing">The casing.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">A place is required to get a normalized location.</exception>
public EnrichedLocationResponse GetEnrichedLocation(string place, bool? includeZeroPopulation = null, Casing? casing = null)
{
if (string.IsNullOrWhiteSpace(place)) throw new ArgumentNullException("A place is required to get a enriched location.");

var request = GetLocationRequest("locationEnrichment", includeZeroPopulation, casing);
request.AddParameter("place", place);
return Execute<EnrichedLocationResponse>(request);
}

/// <summary>
/// Gets the location request.
/// </summary>
/// <param name="resource">The resource.</param>
/// <param name="includeZeroPopulation">The include zero population.</param>
/// <param name="casing">The casing.</param>
/// <returns></returns>
private RestRequest GetLocationRequest(string resource, bool? includeZeroPopulation = null, Casing? casing = null)
{
var request = new RestRequest(string.Format("/address/{0}.json", resource), Method.GET);

if (includeZeroPopulation.HasValue)
{
request.AddParameter("includeZeroPopulation", includeZeroPopulation.Value);
}

if (casing.HasValue)
{
request.AddParameter("casing", casing.Value);
}

return request;
}
}
}
30 changes: 30 additions & 0 deletions FullContactDotNet/IFullContactLocationApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using FullContactDotNet.Location;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FullContactDotNet
{
public interface IFullContactLocationApi
{
/// <summary>
/// Gets the normalized location.
/// </summary>
/// <param name="place">The place.</param>
/// <param name="includeZeroPopulation">The include zero population.</param>
/// <param name="casing">The casing.</param>
/// <returns></returns>
NormalizedLocationResponse GetNormalizedLocation(string place, bool? includeZeroPopulation = null, Casing? casing = null);

/// <summary>
/// Gets the enriched location.
/// </summary>
/// <param name="place">The place.</param>
/// <param name="includeZeroPopulation">The include zero population.</param>
/// <param name="casing">The casing.</param>
/// <returns></returns>
EnrichedLocationResponse GetEnrichedLocation(string place, bool? includeZeroPopulation = null, Casing? casing = null);
}
}
15 changes: 15 additions & 0 deletions FullContactDotNet/Location/EnrichedLocationResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace FullContactDotNet.Location
{
public class EnrichedLocationResponse : FullContactResponse
{
/// <summary>
/// Gets or sets the locations.
/// </summary>
/// <value>
/// The locations.
/// </value>
public List<Location> Locations { get; set; }
}
}
63 changes: 63 additions & 0 deletions FullContactDotNet/Location/Location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using FullContactDotNet.Shared;

namespace FullContactDotNet.Location
{
public class Location
{
/// <summary>
/// Gets or sets the city.
/// </summary>
/// <value>
/// The city.
/// </value>
public string City { get; set; }

/// <summary>
/// Gets or sets the county.
/// </summary>
/// <value>
/// The county.
/// </value>
public string County { get; set; }

/// <summary>
/// Gets or sets the state.
/// </summary>
/// <value>
/// The state.
/// </value>
public NameAndCode State { get; set; }

/// <summary>
/// Gets or sets the country.
/// </summary>
/// <value>
/// The country.
/// </value>
public NameAndCode Country { get; set; }

/// <summary>
/// Gets or sets the continent.
/// </summary>
/// <value>
/// The continent.
/// </value>
public string Continent { get; set; }

/// <summary>
/// Gets or sets the population.
/// </summary>
/// <value>
/// The population.
/// </value>
public string Population { get; set; }

/// <summary>
/// Gets or sets the normalized location.
/// </summary>
/// <value>
/// The normalized location.
/// </value>
public string NormalizedLocation { get; set; }
}
}
63 changes: 63 additions & 0 deletions FullContactDotNet/Location/NormalizedLocationResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using FullContactDotNet.Shared;

namespace FullContactDotNet.Location
{
public class NormalizedLocationResponse : FullContactResponse
{
/// <summary>
/// Gets or sets the city.
/// </summary>
/// <value>
/// The city.
/// </value>
public string City { get; set; }

/// <summary>
/// Gets or sets the state.
/// </summary>
/// <value>
/// The state.
/// </value>
public NameAndCode State { get; set; }

/// <summary>
/// Gets or sets the county.
/// </summary>
/// <value>
/// The county.
/// </value>
public string County { get; set; }

/// <summary>
/// Gets or sets the country.
/// </summary>
/// <value>
/// The country.
/// </value>
public NameAndCode Country { get; set; }

/// <summary>
/// Gets or sets the continent.
/// </summary>
/// <value>
/// The continent.
/// </value>
public string Continent { get; set; }

/// <summary>
/// Gets or sets the likelihood.
/// </summary>
/// <value>
/// The likelihood.
/// </value>
public string Likelihood { get; set; }

/// <summary>
/// Gets or sets the normalized location.
/// </summary>
/// <value>
/// The normalized location.
/// </value>
public string NormalizedLocation { get; set; }
}
}
4 changes: 3 additions & 1 deletion FullContactDotNet/Person/LocationDeduced.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace FullContactDotNet.Person
using FullContactDotNet.Shared;

namespace FullContactDotNet.Person
{
public class LocationDeduced
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FullContactDotNet.Company
namespace FullContactDotNet.Shared
{
public class Asset
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FullContactDotNet.Person
namespace FullContactDotNet.Shared
{
public class DeducedName
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FullContactDotNet.Person
namespace FullContactDotNet.Shared
{
public class DeducedNameAndCode : DeducedName
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FullContactDotNet.Company
namespace FullContactDotNet.Shared
{
public class NameAndCode
{
Expand Down
46 changes: 46 additions & 0 deletions UnitTests/FullContactLocationApiUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FullContactDotNet;

namespace UnitTests
{
[TestClass]
public class FullContactLocationApiUnitTests
{
[TestMethod]
[ExpectedException(typeof(ArgumentNullException),
"FullContactApi was allowed to query location normalization with a null place.")]
public void FullContactLocationApiGetNormalizedLocationNullPlace()
{
var fullContactLocationApi = new FullContactLocationApi();
var actual = fullContactLocationApi.GetNormalizedLocation(null);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException),
"FullContactApi was allowed to query location normalization with a blank place.")]
public void FullContactLocationApiGetNormalizedLocationEmptyPlace()
{
var fullContactLocationApi = new FullContactLocationApi();
var actual = fullContactLocationApi.GetNormalizedLocation(" ");
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException),
"FullContactApi was allowed to query location enrichment with a null place.")]
public void FullContactLocationApiGetEnrichedLocationNullPlace()
{
var fullContactLocationApi = new FullContactLocationApi();
var actual = fullContactLocationApi.GetEnrichedLocation(null);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException),
"FullContactApi was allowed to query location enrichment with a blank place.")]
public void FullContactLocationApiGetEnrichedLocationEmptyPlace()
{
var fullContactLocationApi = new FullContactLocationApi();
var actual = fullContactLocationApi.GetEnrichedLocation(" ");
}
}
}
5 changes: 4 additions & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="FullContactLocationApiUnitTests.cs" />
<Compile Include="FullContactPersonApiUnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down

0 comments on commit b39dd61

Please sign in to comment.