Initial Commit
This commit is contained in:
commit
6a0ab94f77
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
_example/api_key.go
|
||||
_example/example
|
4
_example/api_key.go.example
Normal file
4
_example/api_key.go.example
Normal file
@ -0,0 +1,4 @@
|
||||
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 = ""
|
51
_example/main.go
Normal file
51
_example/main.go
Normal file
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"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 {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
req.Var("lat", 37.700824)
|
||||
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)
|
||||
}
|
||||
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
|
||||
}
|
20
openstates.go
Normal file
20
openstates.go
Normal file
@ -0,0 +1,20 @@
|
||||
package openstates
|
||||
|
||||
import "github.com/machinebox/graphql"
|
||||
|
||||
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")
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *OpenStatesApi) GetLegislatorsForArea(lat float, long float) []PersonNode {
|
||||
|
||||
}
|
57
person_node.go
Normal file
57
person_node.go
Normal file
@ -0,0 +1,57 @@
|
||||
package openstates
|
||||
|
||||
type PersonNode struct {
|
||||
Id string
|
||||
Name string
|
||||
SortName string
|
||||
FamilyName string
|
||||
GivenName string
|
||||
Image string
|
||||
BirthDate string
|
||||
DeathDate string
|
||||
Identifiers []IdentifierNode
|
||||
OtherNames []NameNode
|
||||
Links []LinkNode
|
||||
ContactDetails []ContactDetailNode
|
||||
CurrentMemberships []MembershipNode
|
||||
OldMemberships []MembershipNode
|
||||
Sources []LinkNode
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
Extras string
|
||||
}
|
||||
|
||||
type IdentifierNode struct {
|
||||
Identifier string
|
||||
Scheme string
|
||||
}
|
||||
type NameNode struct {
|
||||
Name string
|
||||
Note string
|
||||
StartDate string
|
||||
EndDate string
|
||||
}
|
||||
type ContactDetailNode struct {
|
||||
Type string
|
||||
Value string
|
||||
Note string
|
||||
Label string
|
||||
}
|
||||
type MembershipNode struct {
|
||||
Id string
|
||||
PersonName string
|
||||
Person *PersonNode
|
||||
Organization *OrganizationNode
|
||||
Post *PostNode
|
||||
Label string
|
||||
Role string
|
||||
StartDate string
|
||||
EndDate string
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
Extras string
|
||||
}
|
||||
type LinkNode struct {
|
||||
Url string
|
||||
Text string
|
||||
}
|
Loading…
Reference in New Issue
Block a user