openstates/openstates.go

37 lines
729 B
Go
Raw Normal View History

2019-04-07 11:23:12 +00:00
package openstates
2019-04-08 12:23:51 +00:00
import (
"context"
"log"
"github.com/machinebox/graphql"
)
2019-04-07 11:23:12 +00:00
type OpenStatesApi struct {
ApiKey string
Client *graphql.Client
}
func NewOpenStatesApi(key string) *OpenStatesApi {
o := OpenStatesApi{
ApiKey: key,
}
o.Client = graphql.NewClient("https://openstates.org/graphql")
2019-04-08 12:23:51 +00:00
return &o
2019-04-07 11:23:12 +00:00
}
2019-04-08 12:23:51 +00:00
func (o *OpenStatesApi) TurnOnLogging() {
o.Client.Log = func(s string) { log.Println(s) }
}
2019-04-07 11:23:12 +00:00
2019-04-08 12:23:51 +00:00
func (o *OpenStatesApi) MakeRequest(req *graphql.Request, res interface{}) {
ctx := context.Background()
req.Header.Add("X-API-KEY", o.ApiKey)
if err := o.Client.Run(ctx, req, &res); err != nil {
log.Fatal(err)
}
2019-04-07 11:23:12 +00:00
}
2019-04-08 12:23:51 +00:00
//func (o *OpenStatesApi) GetLegislatorsForArea(lat float, long float) []PersonNode {
//}