From ea7c7e6efad70d4d47c071b5dcc01ef8a70edc1d Mon Sep 17 00:00:00 2001 From: Justin Skiles Date: Thu, 16 Feb 2017 21:47:46 -0500 Subject: [PATCH] Added Senate Nomination Votes endpoint. --- .../AutoMapperConfiguration.cs | 18 +++++++ .../Contracts/SenateNominationVote.cs | 34 +++++++++++++ .../SenateNominationVoteContainer.cs | 14 ++++++ ProPublicaCongressAPI/Contracts/VoteByDate.cs | 2 +- .../InternalModels/SenateNominationVote.cs | 49 +++++++++++++++++++ .../SenateNominationVoteContainer.cs | 17 +++++++ .../InternalModels/VoteByDate.cs | 2 +- .../ProPublicaCongressAPI.csproj | 4 ++ .../ProPublicaCongressApiClient.cs | 12 +++++ 9 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 ProPublicaCongressAPI/Contracts/SenateNominationVote.cs create mode 100644 ProPublicaCongressAPI/Contracts/SenateNominationVoteContainer.cs create mode 100644 ProPublicaCongressAPI/InternalModels/SenateNominationVote.cs create mode 100644 ProPublicaCongressAPI/InternalModels/SenateNominationVoteContainer.cs diff --git a/ProPublicaCongressAPI/AutoMapperConfiguration.cs b/ProPublicaCongressAPI/AutoMapperConfiguration.cs index c36d601..0b78963 100644 --- a/ProPublicaCongressAPI/AutoMapperConfiguration.cs +++ b/ProPublicaCongressAPI/AutoMapperConfiguration.cs @@ -105,6 +105,24 @@ public static void Initialize() return dateTimeVoted; })); x.CreateMap(); + + + x.CreateMap() + .ForMember(dest => dest.DateTimeVoted, opts => opts.ResolveUsing(source => + { + string rawDateTimeVoted = source.DateVoted; + + if (!String.IsNullOrWhiteSpace(source.TimeVoted)) + { + rawDateTimeVoted += " " + source.TimeVoted; + } + + DateTime dateTimeVoted; + DateTime.TryParse(rawDateTimeVoted, out dateTimeVoted); + + return dateTimeVoted; + })); + x.CreateMap(); }); } diff --git a/ProPublicaCongressAPI/Contracts/SenateNominationVote.cs b/ProPublicaCongressAPI/Contracts/SenateNominationVote.cs new file mode 100644 index 0000000..e7cf1f6 --- /dev/null +++ b/ProPublicaCongressAPI/Contracts/SenateNominationVote.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; +using System; + +namespace ProPublicaCongressAPI.Contracts +{ + public class SenateNominationVote + { + public int Congress { get; set; } + + public int Session { get; set; } + + public int RollCallNumber { get; set; } + + public string Question { get; set; } + + public string Description { get; set; } + + public string VoteType { get; set; } + + public DateTime DateTimeVoted { get; set; } + + public string Result { get; set; } + + public string NomineeDetailUrl { get; set; } + + public RollCallVoteSummaryDemocratic DemocraticVoteSummary { get; set; } + + public RollCallVoteSummaryRepublican RepublicanVoteSummary { get; set; } + + public RollCallVoteSummaryIndependent IndependentVoteSummary { get; set; } + + public RollCallVoteSummaryTotal TotalVoteSummary { get; set; } + } +} \ No newline at end of file diff --git a/ProPublicaCongressAPI/Contracts/SenateNominationVoteContainer.cs b/ProPublicaCongressAPI/Contracts/SenateNominationVoteContainer.cs new file mode 100644 index 0000000..a5fec9d --- /dev/null +++ b/ProPublicaCongressAPI/Contracts/SenateNominationVoteContainer.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace ProPublicaCongressAPI.Contracts +{ + public class SenateNominationVoteContainer + { + public int TotalVotes { get; set; } + + public int Offset { get; set; } + + public IReadOnlyCollection Votes { get; set; } + } +} \ No newline at end of file diff --git a/ProPublicaCongressAPI/Contracts/VoteByDate.cs b/ProPublicaCongressAPI/Contracts/VoteByDate.cs index 0e0de24..82c20b2 100644 --- a/ProPublicaCongressAPI/Contracts/VoteByDate.cs +++ b/ProPublicaCongressAPI/Contracts/VoteByDate.cs @@ -9,7 +9,7 @@ public class VoteByDate public int Session { get; set; } - public int RollCall { get; set; } + public int RollCallNumber { get; set; } public string VoteDetailUrl { get; set; } diff --git a/ProPublicaCongressAPI/InternalModels/SenateNominationVote.cs b/ProPublicaCongressAPI/InternalModels/SenateNominationVote.cs new file mode 100644 index 0000000..c1bc64f --- /dev/null +++ b/ProPublicaCongressAPI/InternalModels/SenateNominationVote.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; + +namespace ProPublicaCongressAPI.InternalModels +{ + internal class SenateNominationVote + { + [JsonProperty("congress")] + public int Congress { get; set; } + + [JsonProperty("session")] + public int Session { get; set; } + + [JsonProperty("roll_call")] + public int RollCallNumber { get; set; } + + [JsonProperty("question")] + public string Question { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("vote_type")] + public string VoteType { get; set; } + + [JsonProperty("date")] + public string DateVoted { get; set; } + + [JsonProperty("time")] + public string TimeVoted { get; set; } + + [JsonProperty("result")] + public string Result { get; set; } + + [JsonProperty("nominee_uri")] + public string NomineeDetailUrl { get; set; } + + [JsonProperty("democratic")] + public RollCallVoteSummaryDemocratic DemocraticVoteSummary { get; set; } + + [JsonProperty("republican")] + public RollCallVoteSummaryRepublican RepublicanVoteSummary { get; set; } + + [JsonProperty("independent")] + public RollCallVoteSummaryIndependent IndependentVoteSummary { get; set; } + + [JsonProperty("total")] + public RollCallVoteSummaryTotal TotalVoteSummary { get; set; } + } +} \ No newline at end of file diff --git a/ProPublicaCongressAPI/InternalModels/SenateNominationVoteContainer.cs b/ProPublicaCongressAPI/InternalModels/SenateNominationVoteContainer.cs new file mode 100644 index 0000000..7d2dd42 --- /dev/null +++ b/ProPublicaCongressAPI/InternalModels/SenateNominationVoteContainer.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace ProPublicaCongressAPI.InternalModels +{ + internal class SenateNominationVoteContainer + { + [JsonProperty("total_votes")] + public int TotalVotes { get; set; } + + [JsonProperty("offset")] + public int Offset { get; set; } + + [JsonProperty("votes")] + public IReadOnlyCollection Votes { get; set; } + } +} \ No newline at end of file diff --git a/ProPublicaCongressAPI/InternalModels/VoteByDate.cs b/ProPublicaCongressAPI/InternalModels/VoteByDate.cs index 40efe4a..ff87694 100644 --- a/ProPublicaCongressAPI/InternalModels/VoteByDate.cs +++ b/ProPublicaCongressAPI/InternalModels/VoteByDate.cs @@ -12,7 +12,7 @@ internal class VoteByDate public int Session { get; set; } [JsonProperty("roll_call")] - public int RollCall { get; set; } + public int RollCallNumber { get; set; } [JsonProperty("vote_uri")] public string VoteDetailUrl { get; set; } diff --git a/ProPublicaCongressAPI/ProPublicaCongressAPI.csproj b/ProPublicaCongressAPI/ProPublicaCongressAPI.csproj index 3eec665..299f88c 100644 --- a/ProPublicaCongressAPI/ProPublicaCongressAPI.csproj +++ b/ProPublicaCongressAPI/ProPublicaCongressAPI.csproj @@ -66,6 +66,8 @@ + + @@ -91,6 +93,8 @@ + + diff --git a/ProPublicaCongressAPI/ProPublicaCongressApiClient.cs b/ProPublicaCongressAPI/ProPublicaCongressApiClient.cs index c67fdea..b086a5c 100644 --- a/ProPublicaCongressAPI/ProPublicaCongressApiClient.cs +++ b/ProPublicaCongressAPI/ProPublicaCongressApiClient.cs @@ -44,6 +44,18 @@ public ProPublicaCongressApiClient(string apiKey) AutoMapperConfiguration.Initialize(); } + public async Task GetSenateNominationVotes(int congress) + { + string url = apiBaseUrl + String.Format(senateNominationsUrl, congress); + + var internalModel = await GetMultipleResultDataAsync(url); + var contract = AutoMapperConfiguration.Mapper.Map< + InternalModels.SenateNominationVoteContainer, + Contracts.SenateNominationVoteContainer>(internalModel.Results.ElementAt(0)); + + return contract; + } + public async Task GetVotesByDate(Chamber chamber, int year, int month) { string url = apiBaseUrl + String.Format(votesByDateUrl, chamber.ToString().ToLower(), year, month);