/// <summary> /// get people in all legislatures for a given state /// </summary> /// <param name="state"></param> /// <returns></returns> public async Task <LegeSet> GetStatePeopleAsync(string state) { LegeSet inf = null; try { var graphQLRequest = new GraphQLRequest(); string queryJurisdictionFixed = FixQueryQuotes(QsStateLeges); // // note: GraphQL "query variable" feature should be able to be used // but I havent got that working yet. Maybe it's not implemented yet // for OpenStates. queryJurisdictionFixed = queryJurisdictionFixed.Replace("$state", state); graphQLRequest.Query = queryJurisdictionFixed; var response = await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false); int NumLege = response.Data.jurisdiction.organizations.edges.Count; inf = new LegeSet(state); for (int i = 0; i < NumLege; i++) { string OneLegeName = response.Data.jurisdiction.organizations.edges[i].node.name.ToString(); string OneLegeId = response.Data.jurisdiction.organizations.edges[i].node.id.ToString(); int q = response.Data.jurisdiction.organizations.edges[i].node.children.edges.Count; for (int k = 0; k < q; k++) { string OneName = response.Data.jurisdiction.organizations.edges[i].node.children.edges[k].node.name; string OneID = response.Data.jurisdiction.organizations.edges[i].node.children.edges[k].node.id; Newtonsoft.Json.Linq.JArray peeps = await GetPeopleByOrgIDAllAsync(OneID, null, null); List <OnePerson> PeopleNames; if (peeps != null) { int m = peeps.Count; PeopleNames = new List <OnePerson>(m); for (int j = 0; j < m; j++) { string NomJ = peeps[j]["node"]["name"].ToString(); OnePerson p = new OnePerson(NomJ); PeopleNames.Add(p); } } else { PeopleNames = new List <OnePerson>(); } inf.AddLege(OneName, OneID, PeopleNames); } } } catch (System.Exception) { } return(inf); }
public async Task <string> SummarizeStateLeges(string state) { try { LegeSet lset = await GetStatePeopleAsync(state); string Summary = lset.SummarizeLeges(); return(Summary); } catch (System.Exception) { } return(""); }