Skip to content

Commit

Permalink
Added recent bill endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
babelshift committed Feb 17, 2017
1 parent ea7c7e6 commit 5f32ef2
Show file tree
Hide file tree
Showing 13 changed files with 287 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 @@ -123,6 +123,12 @@ public static void Initialize()
return dateTimeVoted;
}));
x.CreateMap<InternalModels.SenateNominationVoteContainer, Contracts.SenateNominationVoteContainer>();

x.CreateMap<InternalModels.RecentBill, Contracts.RecentBill>();
x.CreateMap<InternalModels.RecentBillsContainer, Contracts.RecentBillsContainer>();

x.CreateMap<InternalModels.RecentBillByMember, Contracts.RecentBillByMember>();
x.CreateMap<InternalModels.RecentBillsByMemberContainer, Contracts.RecentBillsByMemberContainer>();
});
}

Expand Down
25 changes: 25 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ProPublicaCongressAPI.Contracts
{
public class RecentBill
{
public string BillNumber { get; set; }

public string BillDetailUrl { get; set; }

public string BillTitle { get; set; }

public string SponsorMemberDetailUrl { get; set; }

public string DateIntroduced { get; set; }

public int CosponsorCount { get; set; }

public string Committees { get; set; }

public string PrimarySubject { get; set; }

public string DateLatestMajorAction { get; set; }

public string LatestMajorAction { get; set; }
}
}
27 changes: 27 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBillByMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace ProPublicaCongressAPI.Contracts
{
public class RecentBillByMember
{
public int Congress { get; set; }

public string BillNumber { get; set; }

public string BillDetailUrl { get; set; }

public string BillTitle { get; set; }

public string SponsorMemberId { get; set; }

public string DateIntroduced { get; set; }

public int CosponsorCount { get; set; }

public string Committees { get; set; }

public string PrimarySubject { get; set; }

public string DateLatestMajorAction { get; set; }

public string LatestMajorAction { get; set; }
}
}
9 changes: 9 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBillByMemberType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ProPublicaCongressAPI.Contracts
{
public enum RecentBillByMemberType
{
Unknown,
Introduced,
Updated
}
}
11 changes: 11 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBillType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ProPublicaCongressAPI.Contracts
{
public enum RecentBillType
{
Unknown,
Introduced,
Updated,
Passed,
Major
}
}
19 changes: 19 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBillsByMemberContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace ProPublicaCongressAPI.Contracts
{
public class RecentBillsByMemberContainer
{
public string MemberId { get; set; }

public string MemberDetailUrl { get; set; }

public string MemberName { get; set; }

public int NumberOfResults { get; set; }

public int Offset { get; set; }

public IReadOnlyCollection<RecentBillByMember> Bills { get; set; }
}
}
17 changes: 17 additions & 0 deletions ProPublicaCongressAPI/Contracts/RecentBillsContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;

namespace ProPublicaCongressAPI.Contracts
{
public class RecentBillsContainer
{
public int Congress { get; set; }

public string Chamber { get; set; }

public int NumberOfResults { get; set; }

public int Offset { get; set; }

public IReadOnlyCollection<RecentBill> Bills { get; set; }
}
}
37 changes: 37 additions & 0 deletions ProPublicaCongressAPI/InternalModels/RecentBill.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;

namespace ProPublicaCongressAPI.InternalModels
{
internal class RecentBill
{
[JsonProperty("number")]
public string BillNumber { get; set; }

[JsonProperty("bill_uri")]
public string BillDetailUrl { get; set; }

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

[JsonProperty("sponsor_uri")]
public string SponsorMemberDetailUrl { get; set; }

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

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

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

[JsonProperty("primary_subject")]
public string PrimarySubject { get; set; }

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

[JsonProperty("latest_major_action")]
public string LatestMajorAction { get; set; }
}
}
40 changes: 40 additions & 0 deletions ProPublicaCongressAPI/InternalModels/RecentBillByMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Newtonsoft.Json;

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

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

[JsonProperty("bill_uri")]
public string BillDetailUrl { get; set; }

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

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

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

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

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

[JsonProperty("primary_subject")]
public string PrimarySubject { get; set; }

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

[JsonProperty("latest_major_action")]
public string LatestMajorAction { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using System.Collections.Generic;

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

[JsonProperty("member_uri")]
public string MemberDetailUrl { get; set; }

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

[JsonProperty("num_results")]
public int NumberOfResults { get; set; }

[JsonProperty("offset")]
public int Offset { get; set; }

[JsonProperty("bills")]
public IReadOnlyCollection<RecentBillByMember> Bills { get; set; }
}
}
23 changes: 23 additions & 0 deletions ProPublicaCongressAPI/InternalModels/RecentBillsContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Newtonsoft.Json;
using System.Collections.Generic;

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

[JsonProperty("chamber")]
public string Chamber { get; set; }

[JsonProperty("num_results")]
public int NumberOfResults { get; set; }

[JsonProperty("offset")]
public int Offset { get; set; }

[JsonProperty("bills")]
public IReadOnlyCollection<RecentBill> Bills { get; set; }
}
}
10 changes: 10 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<Compile Include="Contracts\MemberVotesContainer.cs" />
<Compile Include="Contracts\NewMember.cs" />
<Compile Include="Contracts\NewMembersContainer.cs" />
<Compile Include="Contracts\RecentBill.cs" />
<Compile Include="Contracts\RecentBillByMember.cs" />
<Compile Include="Contracts\RecentBillsByMemberContainer.cs" />
<Compile Include="Contracts\RecentBillsContainer.cs" />
<Compile Include="Contracts\RecentBillByMemberType.cs" />
<Compile Include="Contracts\RecentBillType.cs" />
<Compile Include="Contracts\RollCallVote.cs" />
<Compile Include="Contracts\RollCallVoteContainer.cs" />
<Compile Include="Contracts\RollCallVotesContainer.cs" />
Expand All @@ -75,6 +81,10 @@
<Compile Include="Contracts\VoteByTypeContainer.cs" />
<Compile Include="Contracts\VoteByTypeMember.cs" />
<Compile Include="InternalModels\CurrentMember.cs" />
<Compile Include="InternalModels\RecentBill.cs" />
<Compile Include="InternalModels\RecentBillByMember.cs" />
<Compile Include="InternalModels\RecentBillsByMemberContainer.cs" />
<Compile Include="InternalModels\RecentBillsContainer.cs" />
<Compile Include="InternalModels\RollCallVoteContainer.cs" />
<Compile Include="InternalModels\RollCallVoteSummaryDemocratic.cs" />
<Compile Include="InternalModels\RollCallVoteSummaryIndependent.cs" />
Expand Down
37 changes: 37 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,50 @@ public class ProPublicaCongressApiClient
private const string nomineesByStateUrl = "v1/{0}/nominees/state/{1}.json"; // 0 = congress, 1 = state
private const string statePartyCountUrl = "v1/states/members/party.json";
private const string committeesUrl = "v1/{0}/{1}/committees/{2}.json"; // 0 = congress, 1 = chamber, 2 = committee-id
private const string offsetParameter = "?offset={0}";

public ProPublicaCongressApiClient(string apiKey)
{
this.apiKey = apiKey;
AutoMapperConfiguration.Initialize();
}

public async Task<Contracts.RecentBillsByMemberContainer> GetRecentBillsByMember(string memberId, RecentBillByMemberType billType, int? offset = null)
{
string url = apiBaseUrl + String.Format(recentBillsByMemberUrl, memberId, billType.ToString().ToLower());

// we can offset the results to page through them since this endpoint only returns 20 at a time
if (offset.HasValue && offset.Value > 0)
{
url += String.Format(offsetParameter, offset.Value);
}

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

return contract;
}

public async Task<Contracts.RecentBillsContainer> GetRecentBills(int congress, Chamber chamber, RecentBillType billType, int? offset = null)
{
string url = apiBaseUrl + String.Format(recentBillsUrl, congress, chamber.ToString().ToLower(), billType.ToString().ToLower());

// we can offset the results to page through them since this endpoint only returns 20 at a time
if(offset.HasValue && offset.Value > 0)
{
url += String.Format(offsetParameter, offset.Value);
}

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

return contract;
}

public async Task<Contracts.SenateNominationVoteContainer> GetSenateNominationVotes(int congress)
{
string url = apiBaseUrl + String.Format(senateNominationsUrl, congress);
Expand Down

0 comments on commit 5f32ef2

Please sign in to comment.