Skip to content

Commit

Permalink
Added Senate Nomination Votes endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
babelshift committed Feb 17, 2017
1 parent 27a3e79 commit ea7c7e6
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ProPublicaCongressAPI/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ public static void Initialize()
return dateTimeVoted;
}));
x.CreateMap<InternalModels.VoteByDateContainer, Contracts.VoteByDateContainer>();
x.CreateMap<InternalModels.SenateNominationVote, Contracts.SenateNominationVote>()
.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<InternalModels.SenateNominationVoteContainer, Contracts.SenateNominationVoteContainer>();
});
}

Expand Down
34 changes: 34 additions & 0 deletions ProPublicaCongressAPI/Contracts/SenateNominationVote.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
14 changes: 14 additions & 0 deletions ProPublicaCongressAPI/Contracts/SenateNominationVoteContainer.cs
Original file line number Diff line number Diff line change
@@ -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<SenateNominationVote> Votes { get; set; }
}
}
2 changes: 1 addition & 1 deletion ProPublicaCongressAPI/Contracts/VoteByDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
49 changes: 49 additions & 0 deletions ProPublicaCongressAPI/InternalModels/SenateNominationVote.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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<SenateNominationVote> Votes { get; set; }
}
}
2 changes: 1 addition & 1 deletion ProPublicaCongressAPI/InternalModels/VoteByDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 4 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<Compile Include="Contracts\RollCallVoteSummaryIndependent.cs" />
<Compile Include="Contracts\RollCallVoteSummaryRepublican.cs" />
<Compile Include="Contracts\RollCallVoteSummaryTotal.cs" />
<Compile Include="Contracts\SenateNominationVote.cs" />
<Compile Include="Contracts\SenateNominationVoteContainer.cs" />
<Compile Include="Contracts\Session.cs" />
<Compile Include="Contracts\VoteAggregateCategory.cs" />
<Compile Include="Contracts\VoteByDate.cs" />
Expand All @@ -91,6 +93,8 @@
<Compile Include="InternalModels\RollCallVotesContainer.cs" />
<Compile Include="InternalModels\RollCallVotePosition.cs" />
<Compile Include="InternalModels\RollCallVoteSummaryTotal.cs" />
<Compile Include="InternalModels\SenateNominationVote.cs" />
<Compile Include="InternalModels\SenateNominationVoteContainer.cs" />
<Compile Include="InternalModels\VoteByDate.cs" />
<Compile Include="InternalModels\VoteByDateContainer.cs" />
<Compile Include="InternalModels\VoteByTypeContainer.cs" />
Expand Down
12 changes: 12 additions & 0 deletions ProPublicaCongressAPI/ProPublicaCongressApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public ProPublicaCongressApiClient(string apiKey)
AutoMapperConfiguration.Initialize();
}

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

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

return contract;
}

public async Task<Contracts.VoteByDateContainer> GetVotesByDate(Chamber chamber, int year, int month)
{
string url = apiBaseUrl + String.Format(votesByDateUrl, chamber.ToString().ToLower(), year, month);
Expand Down

0 comments on commit ea7c7e6

Please sign in to comment.