Skip to content

Commit

Permalink
Add Get Nominees by State endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
babelshift committed Feb 17, 2017
1 parent f9ac512 commit 07089d8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ProPublicaCongressAPI/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ public static void Initialize()
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateReceived))
.ForMember(dest => dest.DateLatestAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestAction));

x.CreateMap<InternalModels.NomineeByState, Contracts.NomineeByState>()
.ForMember(dest => dest.DateLatestAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestAction))
.ForMember(dest => dest.DateReceived,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateReceived));
});
}

Expand Down
15 changes: 15 additions & 0 deletions ProPublicaCongressAPI/Contracts/NomineeByState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace ProPublicaCongressAPI.Contracts
{
public class NomineeByState
{
public string NomineeId { get; set; }
public string NomineeDetailUrl { get; set; }
public DateTime DateReceived { get; set; }
public string Description { get; set; }
public string NomineeState { get; set; }
public DateTime DateLatestAction { get; set; }
public string Status { get; set; }
}
}
28 changes: 28 additions & 0 deletions ProPublicaCongressAPI/InternalModels/NomineeByState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Newtonsoft.Json;

namespace ProPublicaCongressAPI.InternalModels
{
internal class NomineeByState
{
[JsonProperty("id")]
public string NomineeId { get; set; }

[JsonProperty("uri")]
public string NomineeDetailUrl { get; set; }

[JsonProperty("date_received")]
public string DateReceived { get; set; }

[JsonProperty("description")]
public string Description { get; set; }

[JsonProperty("nominee_state")]
public string NomineeState { get; set; }

[JsonProperty("latest_action_date")]
public string DateLatestAction { get; set; }

[JsonProperty("status")]
public string Status { get; set; }
}
}
2 changes: 2 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="Contracts\MemberVotesContainer.cs" />
<Compile Include="Contracts\NewMember.cs" />
<Compile Include="Contracts\NewMembersContainer.cs" />
<Compile Include="Contracts\NomineeByState.cs" />
<Compile Include="Contracts\RecentBill.cs" />
<Compile Include="Contracts\RecentBillByMember.cs" />
<Compile Include="Contracts\RecentBillsByMemberContainer.cs" />
Expand Down Expand Up @@ -100,6 +101,7 @@
<Compile Include="InternalModels\BillCosponsorContainer.cs" />
<Compile Include="InternalModels\BillCosponsorPartySummary.cs" />
<Compile Include="InternalModels\CurrentMember.cs" />
<Compile Include="InternalModels\NomineeByState.cs" />
<Compile Include="InternalModels\RecentBill.cs" />
<Compile Include="InternalModels\RecentBillByMember.cs" />
<Compile Include="InternalModels\RecentBillsByMemberContainer.cs" />
Expand Down
12 changes: 12 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public ProPublicaCongressApiClient(string apiKey)
AutoMapperConfiguration.Initialize();
}

public async Task<IReadOnlyCollection<Contracts.NomineeByState>> GetNomineesByState(int congress, string state)
{
string url = apiBaseUrl + String.Format(nomineesByStateUrl, congress, state);

var internalModel = await GetMultipleResultDataAsync<InternalModels.NomineeByState>(url);
var contract = AutoMapperConfiguration.Mapper.Map<
IReadOnlyCollection<InternalModels.NomineeByState>,
IReadOnlyCollection<Contracts.NomineeByState>>(internalModel.Results);

return contract;
}

public async Task<Contracts.SpecificNomination> GetSpecificNomination(int congress, string nominationId)
{
string url = apiBaseUrl + String.Format(specificNominationUrl, congress, nominationId);
Expand Down

0 comments on commit 07089d8

Please sign in to comment.