openstates/_example/main.go

46 lines
997 B
Go
Raw Permalink Normal View History

2019-04-07 11:23:12 +00:00
package main
import (
"encoding/json"
"fmt"
"log"
2019-04-07 11:23:12 +00:00
2019-04-08 12:23:51 +00:00
"git.bullercodeworks.com/brian/openstates"
2019-04-07 11:23:12 +00:00
)
func main() {
//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 links}}}}`)
//req.Var("lat", 37.700824)
//req.Var("long")
2019-04-07 11:23:12 +00:00
var res response
2019-04-08 12:23:51 +00:00
o := openstates.NewOpenStatesApi(ApiKey)
o.SetLogger(func(s string) { log.Println(s) })
props := make(map[string]interface{})
props["lat"] = 37.700824
props["long"] = -97.352906
o.MakeRequest(&res, props)
//o.MakeRequest(req, &res)
//fmt.Println("= Fields =")
//for _, v := range res.People.Edges {
// v.Node.GetFields()
// break
//}
fmt.Println("= Result =")
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 openstates.PersonNode
2019-04-07 11:23:12 +00:00
}
type node struct {
Name string
}