openstates/_example/main.go

56 lines
857 B
Go
Raw Normal View History

2019-04-07 11:23:12 +00:00
package main
import (
"encoding/json"
"fmt"
2019-04-08 12:23:51 +00:00
"git.bullercodeworks.com/brian/openstates"
2019-04-07 11:23:12 +00:00
"github.com/machinebox/graphql"
)
func main() {
req := graphql.NewRequest(`
query Reps($lat: Float, $long: Float) {
people(latitude: $lat, longitude: $long, first: 100) {
edges {
node {
2019-04-08 12:23:51 +00:00
id
2019-04-07 11:23:12 +00:00
name
2019-04-08 12:23:51 +00:00
sortName
familyName
givenName
image
birthDate
deathDate
createdAt
updatedAt
extras
2019-04-07 11:23:12 +00:00
}
}
}
}
`)
req.Var("lat", 37.700824)
req.Var("long", -97.352906)
var res response
2019-04-08 12:23:51 +00:00
o := openstates.NewOpenStatesApi(ApiKey)
o.TurnOnLogging()
o.MakeRequest(req, &res)
2019-04-07 11:23:12 +00:00
j, _ := json.Marshal(res)
fmt.Println(string(j))
}
type response struct {
People people
}
type people struct {
Edges []edge
}
type edge struct {
Node node
}
type node struct {
Name string
}