All Nodes Represented

This commit is contained in:
2019-04-08 07:23:51 -05:00
parent 6a0ab94f77
commit d56ccc469a
19 changed files with 323 additions and 49 deletions

View File

@@ -1,4 +1,5 @@
package main
// Copy this file to "api_key.go" and then populate the line below in that file with your api key
// ("api_key.go" is in the .gitignore)
var ApiKey = ""

View File

@@ -1,22 +1,30 @@
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"git.bullercodeworks.com/brian/openstates"
"github.com/machinebox/graphql"
)
func main() {
client := graphql.NewClient("https://openstates.org/graphql")
req := graphql.NewRequest(`
query Reps($lat: Float, $long: Float) {
people(latitude: $lat, longitude: $long, first: 100) {
edges {
node {
id
name
sortName
familyName
givenName
image
birthDate
deathDate
createdAt
updatedAt
extras
}
}
}
@@ -26,13 +34,9 @@ func main() {
req.Var("long", -97.352906)
var res response
ctx := context.Background()
// This line enables logging... Probably don't want it for production :)
client.Log = func(s string) { log.Println(s) }
req.Header.Add("X-API-KEY", ApiKey)
if err := client.Run(ctx, req, &res); err != nil {
log.Fatal(err)
}
o := openstates.NewOpenStatesApi(ApiKey)
o.TurnOnLogging()
o.MakeRequest(req, &res)
j, _ := json.Marshal(res)
fmt.Println(string(j))
}