From 6a0ab94f77dda584061c72c93ca92bf362f25244 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sun, 7 Apr 2019 06:23:12 -0500 Subject: [PATCH] Initial Commit --- .gitignore | 2 ++ _example/api_key.go.example | 4 +++ _example/main.go | 51 +++++++++++++++++++++++++++++++++ openstates.go | 20 +++++++++++++ person_node.go | 57 +++++++++++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 .gitignore create mode 100644 _example/api_key.go.example create mode 100644 _example/main.go create mode 100644 openstates.go create mode 100644 person_node.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20efd6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +_example/api_key.go +_example/example diff --git a/_example/api_key.go.example b/_example/api_key.go.example new file mode 100644 index 0000000..fbf255f --- /dev/null +++ b/_example/api_key.go.example @@ -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 = "" diff --git a/_example/main.go b/_example/main.go new file mode 100644 index 0000000..594f846 --- /dev/null +++ b/_example/main.go @@ -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 +} diff --git a/openstates.go b/openstates.go new file mode 100644 index 0000000..e1ec214 --- /dev/null +++ b/openstates.go @@ -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 { + +} diff --git a/person_node.go b/person_node.go new file mode 100644 index 0000000..37d9d76 --- /dev/null +++ b/person_node.go @@ -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 +}