Skip to content

Commit

Permalink
Merge pull request #3 from pavpen/I-0002_support_custom_fields
Browse files Browse the repository at this point in the history
Support Custom Fields
  • Loading branch information
pavpen committed Feb 12, 2016
2 parents 46cb418 + 6c4b131 commit f185783
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 68 deletions.
4 changes: 3 additions & 1 deletion NationBuilderAPI.1.3.0.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Changes since v. 1.2.0:

## Improvements

* Added alpha support for custom fields.

* Added convenience methods for working with a person's e-mail IDs.

* Added deserialization of `validation_errors` in Nation Builder remote exceptions.
Expand Down Expand Up @@ -97,7 +99,7 @@ Changes since v. 1.0.0:

* Added data structures for receiving webhook HTTP requests from Nation Builder in .NET WCF services.
</releaseNotes>
<copyright>Copyright 2014-2015 Pavel M. Penev.</copyright>
<copyright>Copyright 2014-2016 Pavel M. Penev.</copyright>
<dependencies>
</dependencies>
</metadata>
Expand Down
Binary file modified NationBuilderAPI.v12.suo
Binary file not shown.
4 changes: 2 additions & 2 deletions NationBuilderAPI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
4 changes: 2 additions & 2 deletions NationBuilderAPI/V1/Donations/DonationTransportObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace NationBuilderAPI.V1
{
[DataContract]
class DonationTransportObject
class DonationTransportObject<DonationType>
{
[DataMember]
public Donation donation;
public DonationType donation;
}
}
4 changes: 2 additions & 2 deletions NationBuilderAPI/V1/People/PersonResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace NationBuilderAPI.V1
{
[DataContract]
public class PersonResponse : MemberwiseCloneableComparable
public class PersonResponse<PersonType> : MemberwiseCloneableComparable
{
[DataMember]
public Person person;
public PersonType person;

[DataMember]
public Precinct precinct;
Expand Down
4 changes: 2 additions & 2 deletions NationBuilderAPI/V1/People/PersonTransportObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace NationBuilderAPI.V1
{
[DataContract]
class PersonTransportObject
class PersonTransportObject<PersonType>
{
[DataMember]
public Person person;
public PersonType person;
}
}
2 changes: 1 addition & 1 deletion NationBuilderAPI/V1/Session/Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// The index endpoint provides a paginated view of the contacts made to a person.
Expand Down
25 changes: 15 additions & 10 deletions NationBuilderAPI/V1/Session/Donations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession : NationBuilderHttpTransport
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// The index endpoint provides a paginated view of the donations in a nation.
/// </summary>
/// <param name="limit">Number of results to show on each page of results (max 100).</param>
/// <returns>The requested page of results, and result information.</returns>
public ResultsPageResponse<Donation> GetDonations(int limit = 100)
public ResultsPageResponse<DonationType> GetDonations(int limit = 100)
{
StringBuilder reqUrlBuilder = RequestUrlBuilderAppendQuery(
MakeRequestUrlBuilder("donations"),
"&limit=", limit.ToString());
var req = MakeHttpRequest(reqUrlBuilder);
var res = DeserializeHttpResponse<ResultsPageResponse<Donation>>(req);
var res = DeserializeHttpResponse<ResultsPageResponse<DonationType>>(req);

return res;
}
Expand All @@ -29,7 +29,7 @@ public ResultsPageResponse<Donation> GetDonations(int limit = 100)
/// </summary>
/// <param name="limit">Number of results to retrieve on each page of results (max 100).</param>
/// <returns>All the donations in the nation.</returns>
public IEnumerable<Donation> GetDonationsResults(int limit = 100)
public IEnumerable<DonationType> GetDonationsResults(int limit = 100)
{
return AllResultsFrom(GetDonations(limit));
}
Expand All @@ -53,11 +53,13 @@ public IEnumerable<Donation> GetDonationsResults(int limit = 100)
/// </summary>
/// <param name="donation">The resource of the donation to be created.</param>
/// <returns>The newly-created donation.</returns>
public Donation CreateDonation(Donation donation)
public DonationType CreateDonation(DonationType donation)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("donations");
var req = MakeHttpPostRequest<DonationTransportObject>(reqUrlBuilder, new DonationTransportObject() { donation = donation });
DonationTransportObject res = DeserializeHttpResponse<DonationTransportObject>(req);
var req = MakeHttpPostRequest<DonationTransportObject<DonationType>>(
reqUrlBuilder,
new DonationTransportObject<DonationType>() { donation = donation });
var res = DeserializeHttpResponse<DonationTransportObject<DonationType>>(req);

return res.donation;
}
Expand All @@ -70,11 +72,14 @@ public Donation CreateDonation(Donation donation)
/// <param name="id">ID of the donation to update.</param>
/// <param name="donation">The resource attributes of the donation to change.</param>
/// <returns>A full representation of the updated donation.</returns>
public Donation UpdateDonation(long id, Donation donation)
public DonationType UpdateDonation(long id, DonationType donation)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("donations/", id.ToString());
var req = MakeHttpPostRequest<DonationTransportObject>(reqUrlBuilder, new DonationTransportObject() { donation = donation }, "PUT");
DonationTransportObject res = DeserializeHttpResponse<DonationTransportObject>(req);
var req = MakeHttpPostRequest<DonationTransportObject<DonationType>>(
reqUrlBuilder,
new DonationTransportObject<DonationType>() { donation = donation },
"PUT");
DonationTransportObject<DonationType> res = DeserializeHttpResponse<DonationTransportObject<DonationType>>(req);

return res.donation;
}
Expand Down
8 changes: 4 additions & 4 deletions NationBuilderAPI/V1/Session/Lists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// The index endpoint shows a paginated list of custom lists.
Expand Down Expand Up @@ -41,13 +41,13 @@ public IEnumerable<List> GetListsResults(int limit = 100)
/// <param name="listId">ID of the list to get people from.</param>
/// <param name="limit">Maximum number of results to show in one page of results. (Default: 10, max: 100.)</param>
/// <returns>A page of <see cref="List"/>s.</returns>
public ResultsPageResponse<Person> GetPeopleInList(long listId, int limit = 10)
public ResultsPageResponse<PersonType> GetPeopleInList(long listId, int limit = 10)
{
StringBuilder reqUrlBuilder = RequestUrlBuilderAppendQuery(
MakeRequestUrlBuilder("lists/", listId.ToString(), "/people"),
"&limit=", limit.ToString());
var req = MakeHttpRequest(reqUrlBuilder);
var res = DeserializeHttpResponse<ResultsPageResponse<Person>>(req);
var res = DeserializeHttpResponse<ResultsPageResponse<PersonType>>(req);

return res;
}
Expand All @@ -58,7 +58,7 @@ public ResultsPageResponse<Person> GetPeopleInList(long listId, int limit = 10)
/// <param name="listId">ID of the list to get people from.</param>
/// <param name="limit">The number of result to fetch in each HTTP request. The maximum is 100.</param>
/// <returns>An enumeration of all the people in the given list.</returns>
public IEnumerable<Person> GetPeopleInListResults(long listId, int limit = 100)
public IEnumerable<PersonType> GetPeopleInListResults(long listId, int limit = 100)
{
return AllResultsFrom(GetPeopleInList(listId, limit));
}
Expand Down
23 changes: 22 additions & 1 deletion NationBuilderAPI/V1/Session/NationBuilderSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,29 @@ namespace NationBuilderAPI.V1
{
/// <summary>
/// A session object used to access a nation's API.
///
/// <param name="Person">
/// The type of <c>Person</c> objects returned by Nation Builder for the accessed nation.
///
/// Use this to access custom `Person` fields.
/// </param>
///
/// <param name="Donation">
/// The type of <c>Donation</c> objects returned by Nation Builder for the accessed nation.
///
/// Use this to access custom `Donation` fields.
/// </param>
/// </summary>
public partial class NationBuilderSession : NationBuilderHttpTransport, IDisposable
public class NationBuilderSession : NationBuilderSession<Person, Donation>
{
public NationBuilderSession(string slug, string accessToken) : base(slug, accessToken)
{ }
}

/// <summary>
/// A session object used to access a nation's API.
/// </summary>
public partial class NationBuilderSession<PersonType, DonationType> : NationBuilderHttpTransport, IDisposable
{
/// <summary>
/// Create a new Nation Builder session for accessing a nation's API.
Expand Down
44 changes: 25 additions & 19 deletions NationBuilderAPI/V1/Session/People.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// The index endpoint provides a paginated view of the people in a nation. Each person's data is abbreviated for the Index view.
Expand Down Expand Up @@ -47,7 +47,7 @@ public IEnumerable<AbbreviatedPerson> GetPeopleResults(int limit = 100)
/// <param name="id">ID of the person to retrieve.</param>
/// <param name="idType">Type of ID to use, set to <c>"external"</c> to show the person based on their external ID. Leave as <c>null</c> to use NationBuilder's ID.</param>
/// <returns>The full person information.</returns>
public PersonResponse ShowPerson(long id, string idType = null)
public PersonResponse<PersonType> ShowPerson(long id, string idType = null)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people/", id.ToString());
if (null != idType)
Expand All @@ -56,7 +56,7 @@ public PersonResponse ShowPerson(long id, string idType = null)
}

var req = MakeHttpRequest(reqUrlBuilder);
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req);
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req);

return res;
}
Expand All @@ -68,13 +68,13 @@ public PersonResponse ShowPerson(long id, string idType = null)
/// </summary>
/// <param name="externalId">The external ID of the person to retrieve.</param>
/// <returns>The full person information.</returns>
public PersonResponse ShowPersonWithExternalId(string externalId)
public PersonResponse<PersonType> ShowPersonWithExternalId(string externalId)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people/", WebUtility.UrlEncode(externalId));
reqUrlBuilder = RequestUrlBuilderAppendQuery(reqUrlBuilder, "&id_type=external");

var req = MakeHttpRequest(reqUrlBuilder);
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req);
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req);

return res;
}
Expand Down Expand Up @@ -213,14 +213,14 @@ public IEnumerable<AbbreviatedPerson> SearchPeopleResults(string first_name = nu
/// <param name="distance">The radius in miles for which to include results. (Optional, default: 1 mile.)</param>
/// <param name="limit">Number of results to show per page. (Default: 10, max: 100.)</param>
/// <returns>The specified page of people in the specified search radius.</returns>
public ResultsPageResponse<Person> NearbyPeople(string location, double distance = 1.0, int limit = 10)
public ResultsPageResponse<PersonType> NearbyPeople(string location, double distance = 1.0, int limit = 10)
{
StringBuilder reqUrlBuilder = RequestUrlBuilderAppendMethodNonNullParameters(
MakeRequestUrlBuilder("people/nearby"),
MethodBase.GetCurrentMethod().GetParameters(),
location, distance.ToString(), limit.ToString());
var req = MakeHttpRequest(reqUrlBuilder);
var res = DeserializeHttpResponse<ResultsPageResponse<Person>>(req);
var res = DeserializeHttpResponse<ResultsPageResponse<PersonType>>(req);

return res;
}
Expand All @@ -232,7 +232,7 @@ public ResultsPageResponse<Person> NearbyPeople(string location, double distance
/// <param name="distance">The radius in miles for which to include results. (optional, default: 1 mile)</param>
/// <param name="limit">Number of results to retireve per page. (default: 100, max: 100)</param>
/// <returns>The people in the specified search radius.</returns>
public IEnumerable<Person> NearbyPeopleResults(string location, double distance = 1.0, int limit = 100)
public IEnumerable<PersonType> NearbyPeopleResults(string location, double distance = 1.0, int limit = 100)
{
return AllResultsFrom(NearbyPeople(location, distance, limit));
}
Expand All @@ -249,11 +249,11 @@ public IEnumerable<Person> NearbyPeopleResults(string location, double distance
/// If a person you create does not meet these criteria you will receive an error for a field called identity.
/// </param>
/// <returns>The person created.</returns>
public PersonResponse CreatePerson(Person person)
public PersonResponse<PersonType> CreatePerson(PersonType person)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people");
var req = MakeHttpPostRequest<PersonTransportObject>(reqUrlBuilder, new PersonTransportObject() { person = person });
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req, HttpStatusCode.Created);
var req = MakeHttpPostRequest<PersonTransportObject<PersonType>>(reqUrlBuilder, new PersonTransportObject<PersonType>() { person = person });
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req, HttpStatusCode.Created);

return res;
}
Expand All @@ -266,11 +266,14 @@ public PersonResponse CreatePerson(Person person)
/// <param name="id">ID of the person to update.</param>
/// <param name="person">The resource attributes of the person to change.</param>
/// <returns>The updated person.</returns>
public PersonResponse UpdatePerson(long id, Person person)
public PersonResponse<PersonType> UpdatePerson(long id, PersonType person)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people/", id.ToString());
var req = MakeHttpPostRequest<PersonTransportObject>(reqUrlBuilder, new PersonTransportObject() { person = person }, HttpMethodNames.Put);
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req);
var req = MakeHttpPostRequest<PersonTransportObject<PersonType>>(
reqUrlBuilder,
new PersonTransportObject<PersonType>() { person = person },
HttpMethodNames.Put);
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req);

return res;
}
Expand All @@ -281,11 +284,14 @@ public PersonResponse UpdatePerson(long id, Person person)
/// </summary>
/// <param name="person">The resource attributes of the person to push.</param>
/// <returns>The new, or updated person.</returns>
public PersonResponse PushPerson(Person person)
public PersonResponse<PersonType> PushPerson(PersonType person)
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people/push");
var req = MakeHttpPostRequest<PersonTransportObject>(reqUrlBuilder, new PersonTransportObject() { person = person }, HttpMethodNames.Put);
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req);
var req = MakeHttpPostRequest<PersonTransportObject<PersonType>>(
reqUrlBuilder,
new PersonTransportObject<PersonType>() { person = person },
HttpMethodNames.Put);
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req);

return res;
}
Expand Down Expand Up @@ -321,11 +327,11 @@ public RegisterResponse RegisterPerson(long id)
/// This endpoint returns the access token's resource owner's representation.
/// </summary>
/// <returns></returns>
public PersonResponse PersonMe()
public PersonResponse<PersonType> PersonMe()
{
StringBuilder reqUrlBuilder = MakeRequestUrlBuilder("people/me");
var req = MakeHttpRequest(reqUrlBuilder);
PersonResponse res = DeserializeHttpResponse<PersonResponse>(req);
var res = DeserializeHttpResponse<PersonResponse<PersonType>>(req);

return res;
}
Expand Down
8 changes: 4 additions & 4 deletions NationBuilderAPI/V1/Session/PeopleTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// Show the tags that have been used before in a nation.
Expand Down Expand Up @@ -40,15 +40,15 @@ public IEnumerable<Tag> GetPeopleTagsResults(int limit = 100)
/// <param name="tagName">The tag to search by.</param>
/// <param name="limit">Max number of results to show in one page of results. (Default: 10, max: 100.)</param>
/// <returns>A results page of people tagged with the given tag.</returns>
public ResultsPageResponse<Person> GetPeopleWithTag(string tagName, int limit = 10)
public ResultsPageResponse<PersonType> GetPeopleWithTag(string tagName, int limit = 10)
{
StringBuilder reqUrlBuilder = RequestUrlBuilderAppendQuery(
// <c>WebUtility.UrlEncode(tagName)</c> does not work here for .NET 4.5, since the Nation Builder service
// requires spaces to be encoded as '%20', and not '+'.
MakeRequestUrlBuilder("tags/", Uri.EscapeDataString(tagName), "/people"),
"&limit=", limit.ToString());
var req = MakeHttpRequest(reqUrlBuilder);
var res = DeserializeHttpResponse<ResultsPageResponse<Person>>(req);
var res = DeserializeHttpResponse<ResultsPageResponse<PersonType>>(req);

return res;
}
Expand All @@ -59,7 +59,7 @@ public ResultsPageResponse<Person> GetPeopleWithTag(string tagName, int limit =
/// <param name="tagName">The tag to search by.</param>
/// <param name="limit">The number of result to fetch in each HTTP request. The maximum is 100.</param>
/// <returns>An enumeration of all the people with a given tag.</returns>
public IEnumerable<Person> GetPeopleWithTagResults(string tagName, int limit = 100)
public IEnumerable<PersonType> GetPeopleWithTagResults(string tagName, int limit = 100)
{
return AllResultsFrom(GetPeopleWithTag(tagName, limit));
}
Expand Down
2 changes: 1 addition & 1 deletion NationBuilderAPI/V1/Session/Webhooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NationBuilderAPI.V1
{
public partial class NationBuilderSession : Http.NationBuilderHttpTransport
public partial class NationBuilderSession<PersonType, DonationType>
{
/// <summary>
/// Returns a paginated list of the webhooks the nation has already registered with this endpoint.
Expand Down
Loading

0 comments on commit f185783

Please sign in to comment.