Skip to content

Commit

Permalink
Added Bill Cosponsor endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
babelshift committed Feb 17, 2017
1 parent d600290 commit d0836a3
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 3 deletions.
14 changes: 14 additions & 0 deletions ProPublicaCongressAPI/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ public static void Initialize()
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestMajorAction))
.ForMember(dest => dest.DateSenatePassageVote,
opts => opts.ResolveUsing<NullableDateTimeResolver, string>(s => s.DateSenatePassageVote));

x.CreateMap<InternalModels.BillCosponsor, Contracts.BillCosponsor>()
.ForMember(dest => dest.DateCosponsored,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateCosponsored));
x.CreateMap<InternalModels.BillCosponsorPartySummary, Contracts.BillCosponsorPartySummary>();
x.CreateMap<InternalModels.BillCosponsorContainer, Contracts.BillCosponsorContainer>()
.ForMember(dest => dest.DateIntroduced,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateIntroduced))
.ForMember(dest => dest.DateHousePassageVote,
opts => opts.ResolveUsing<NullableDateTimeResolver, string>(s => s.DateHousePassageVote))
.ForMember(dest => dest.DateLatestMajorAction,
opts => opts.ResolveUsing<DateTimeResolver, string>(s => s.DateLatestMajorAction))
.ForMember(dest => dest.DateSenatePassageVote,
opts => opts.ResolveUsing<NullableDateTimeResolver, string>(s => s.DateSenatePassageVote));
});
}

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

namespace ProPublicaCongressAPI.Contracts
{
public class BillCosponsor
{
public string CosponsorMemberId { get; set; }
public string CosponsorMemberName { get; set; }
public DateTime DateCosponsored { get; set; }
}
}
24 changes: 24 additions & 0 deletions ProPublicaCongressAPI/Contracts/BillCosponsorContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;

namespace ProPublicaCongressAPI.Contracts
{
public class BillCosponsorContainer
{
public int Congress { get; set; }
public string BillNumber { get; set; }
public string BillUrlNumber { get; set; }
public string BillTitle { get; set; }
public string SponsorMemberName { get; set; }
public string SponsorMemberId { get; set; }
public DateTime DateIntroduced { get; set; }
public int CosponsorCount { get; set; }
public string Committees { get; set; }
public DateTime DateLatestMajorAction { get; set; }
public string LatestMajorAction { get; set; }
public DateTime? DateHousePassageVote { get; set; }
public DateTime? DateSenatePassageVote { get; set; }
public IReadOnlyCollection<BillCosponsorPartySummary> PartySummaries { get; set; }
public IReadOnlyCollection<BillCosponsor> Cosponsors { get; set; }
}
}
8 changes: 8 additions & 0 deletions ProPublicaCongressAPI/Contracts/BillCosponsorPartySummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ProPublicaCongressAPI.Contracts
{
public class BillCosponsorPartySummary
{
public string PartyId { get; set; }
public int SponsorCount { get; set; }
}
}
16 changes: 16 additions & 0 deletions ProPublicaCongressAPI/InternalModels/BillCosponsor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace ProPublicaCongressAPI.InternalModels
{
internal class BillCosponsor
{
[JsonProperty("cosponsor_id")]
public string CosponsorMemberId { get; set; }

[JsonProperty("name")]
public string CosponsorMemberName { get; set; }

[JsonProperty("date")]
public string DateCosponsored { get; set; }
}
}
53 changes: 53 additions & 0 deletions ProPublicaCongressAPI/InternalModels/BillCosponsorContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace ProPublicaCongressAPI.InternalModels
{
internal class BillCosponsorContainer
{
[JsonProperty("congress")]
public int Congress { get; set; }

[JsonProperty("bill")]
public string BillNumber { get; set; }

[JsonProperty("url_number")]
public string BillUrlNumber { get; set; }

[JsonProperty("title")]
public string BillTitle { get; set; }

[JsonProperty("sponsor")]
public string SponsorMemberName { get; set; }

[JsonProperty("sponsor_id")]
public string SponsorMemberId { get; set; }

[JsonProperty("introduced_date")]
public string DateIntroduced { get; set; }

[JsonProperty("number_of_cosponsors")]
public int CosponsorCount { get; set; }

[JsonProperty("committees")]
public string Committees { get; set; }

[JsonProperty("latest_major_action_date")]
public string DateLatestMajorAction { get; set; }

[JsonProperty("latest_major_action")]
public string LatestMajorAction { get; set; }

[JsonProperty("house_passage_vote")]
public string DateHousePassageVote { get; set; }

[JsonProperty("senate_passage_vote")]
public string DateSenatePassageVote { get; set; }

[JsonProperty("cosponsors_by_party")]
public IReadOnlyCollection<BillCosponsorPartySummary> PartySummaries { get; set; }

[JsonProperty("cosponsors")]
public IReadOnlyCollection<BillCosponsor> Cosponsors { get; set; }
}
}
13 changes: 13 additions & 0 deletions ProPublicaCongressAPI/InternalModels/BillCosponsorPartySummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

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

[JsonProperty("sponsors")]
public int SponsorCount { get; set; }
}
}
6 changes: 6 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutoMapperConfiguration.cs" />
<Compile Include="Contracts\BillCosponsor.cs" />
<Compile Include="Contracts\BillCosponsorContainer.cs" />
<Compile Include="Contracts\BillCosponsorPartySummary.cs" />
<Compile Include="Contracts\Chamber.cs" />
<Compile Include="Contracts\CosponsorBillType.cs" />
<Compile Include="Contracts\CurrentMember.cs" />
Expand Down Expand Up @@ -88,6 +91,9 @@
<Compile Include="Contracts\VoteByDateContainer.cs" />
<Compile Include="Contracts\VoteByTypeContainer.cs" />
<Compile Include="Contracts\VoteByTypeMember.cs" />
<Compile Include="InternalModels\BillCosponsor.cs" />
<Compile Include="InternalModels\BillCosponsorContainer.cs" />
<Compile Include="InternalModels\BillCosponsorPartySummary.cs" />
<Compile Include="InternalModels\CurrentMember.cs" />
<Compile Include="InternalModels\RecentBill.cs" />
<Compile Include="InternalModels\RecentBillByMember.cs" />
Expand Down
18 changes: 15 additions & 3 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<Contracts.BillCosponsorContainer> GetBillCosponsors(int congress, string billId)
{
string url = apiBaseUrl + String.Format(billCosponsorsUrl, congress, billId);

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

return contract;
}

public async Task<Contracts.SpecificBillDetail> GetSpecificBillDetail(int congress, string billId, SpecificBillDetailType billDetailType)
{
string url = apiBaseUrl + String.Format(specificBillDetailsUrl, congress, billId, billDetailType.ToString().ToLower());
Expand Down Expand Up @@ -328,9 +340,9 @@ private async Task<ApiResponse<IReadOnlyCollection<T>>> GetMultipleResultDataAsy
Debug.Assert(!String.IsNullOrWhiteSpace(url));
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-API-Key", apiKey);
var membersJson = await httpClient.GetStringAsync(url);
var resultInterface = JsonConvert.DeserializeObject<ApiResponse<IReadOnlyCollection<T>>>(membersJson);
return resultInterface;
var json = await httpClient.GetStringAsync(url);
var result = JsonConvert.DeserializeObject<ApiResponse<IReadOnlyCollection<T>>>(json);
return result;
}
}
}

0 comments on commit d0836a3

Please sign in to comment.