All Nodes Represented

This commit is contained in:
Brian Buller 2019-04-08 07:23:51 -05:00
parent 6a0ab94f77
commit d56ccc469a
19 changed files with 323 additions and 49 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
_example/api_key.go _example/api_key.go
_example/_example
_example/example _example/example

View File

@ -1,4 +1,5 @@
package main package main
// Copy this file to "api_key.go" and then populate the line below in that file with your api key // 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) // ("api_key.go" is in the .gitignore)
var ApiKey = "" var ApiKey = ""

View File

@ -1,22 +1,30 @@
package main package main
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"git.bullercodeworks.com/brian/openstates"
"github.com/machinebox/graphql" "github.com/machinebox/graphql"
) )
func main() { func main() {
client := graphql.NewClient("https://openstates.org/graphql")
req := graphql.NewRequest(` req := graphql.NewRequest(`
query Reps($lat: Float, $long: Float) { query Reps($lat: Float, $long: Float) {
people(latitude: $lat, longitude: $long, first: 100) { people(latitude: $lat, longitude: $long, first: 100) {
edges { edges {
node { node {
id
name name
sortName
familyName
givenName
image
birthDate
deathDate
createdAt
updatedAt
extras
} }
} }
} }
@ -26,13 +34,9 @@ func main() {
req.Var("long", -97.352906) req.Var("long", -97.352906)
var res response var res response
ctx := context.Background() o := openstates.NewOpenStatesApi(ApiKey)
// This line enables logging... Probably don't want it for production :) o.TurnOnLogging()
client.Log = func(s string) { log.Println(s) } o.MakeRequest(req, &res)
req.Header.Add("X-API-KEY", ApiKey)
if err := client.Run(ctx, req, &res); err != nil {
log.Fatal(err)
}
j, _ := json.Marshal(res) j, _ := json.Marshal(res)
fmt.Println(string(j)) fmt.Println(string(j))
} }

33
action_types.go Normal file
View File

@ -0,0 +1,33 @@
package openstates
type ActionType string
const (
ActionBillIntroduced = "bill:introduced"
ActionBillPassed = "bill:passed"
ActionBillFailed = "bill:failed"
ActionBillWithdrawn = "bill:withdrawn"
ActionBillVetoOverridePassed = "bill:veto_override:passed"
ActionBillVetoOverrideFailed = "bill:veto_override:failed"
ActionBillReading1 = "bill:reading:1"
ActionBillReading2 = "bill:reading:2"
ActionBillReading3 = "bill:reading:3"
ActionBillFiled = "bill:filed"
ActionBillSubstituted = "bill:substituted"
ActionGovernorReceived = "governor:received"
ActionGovernorSigned = "governor:signed"
ActionGovernorVetoed = "governor:vetoed"
ActionGovernorVetoedLineItem = "governor:vetoed:line-item"
ActionAmendmentIntroduced = "amendment:introduced"
ActionAmendmentPassed = "amendment:passed"
ActionAmendmentFailed = "amendment:failed"
ActionAmendmentAmended = "amendment:amended"
ActionAmendmentWithdrawn = "amendment:withdrawn"
ActionAmendmentTabled = "amendment:tabled"
ActionCommitteeReferred = "committee:referred"
ActionCommitteePassed = "committee:passed"
ActionCommitteePassedFavorable = "committee:passed:favorable"
ActionCommitteePassedUnfavorable = "committee:passed:unfavorable"
ActionCommitteeFailed = "committee:failed"
ActionOther = "other"
)

117
bill_node.go Normal file
View File

@ -0,0 +1,117 @@
package openstates
type BillNode struct {
Id string
LegislativeSession *LegislativeSessionNode
Identifier string
Title string
FromOrganization string
Classification []string
Subject []string
Abstracts []BillAbstractNode
OtherTitles []BillTitleNode
OtherIdentifiers []BillIdentifierNode
Actions []BillActionNode
Sponsorships []BillSponsorshipNode
RelatedBills []RelatedBillNode
Versions []BillDocumentNode
Documents []BillDocumentNode
Votes []VoteEventNode
Sources []LinkNode
OpenStatesUrl string
CreatedAt string
UpdatedAt string
Extras string
}
type BillAbstractNode struct {
Abstract string
Note string
Date string
}
type BillTitleNode struct {
Title string
Note string
}
type BillIdentifierNode struct {
Identifier string
Scheme string
Note string
}
type BillActionNode struct {
Organization *OrganizationNode
Description string
Date string
Classification []ActionType
Order int
Extras string
Vote *VoteEventNode
RelatedEntities []RelatedEntityNode
}
type RelatedEntityNode struct {
Name string
EntityType EntityType
Organization *OrganizationNode
Person *PersonNode
}
type BillSponsorshipNode struct {
Name string
EntityType EntityType
Organization *OrganizationNode
Person *PersonNode
Primary bool
Classification string
}
type RelatedBillNode struct {
Identifier string
LegislativeSession string
RelationType string
RelatedBill *BillNode
}
type BillDocumentNode struct {
Note string
Date string
Links []MimetypeLinkNode
}
type MimetypeLinkNode struct {
MediaType string
Url string
Text string
}
type VoteEventNode struct {
Id string
Identifier string
MotionText string
MotionClassification []string
StartDate string
Result string
Organization *OrganizationNode
BillAction *BillActionNode
Votes []PersonVoteNode
Counts []VoteCountNode
Sources []string
CreatedAt string
UpdatedAt string
Extras string
}
type PersonVoteNode struct {
Option string
VoterName string
Voter *PersonNode
Note string
}
type VoteCountNode struct {
Option string
Value int
}

8
contact_detail_node.go Normal file
View File

@ -0,0 +1,8 @@
package openstates
type ContactDetailNode struct {
Type string
Value string
Note string
Label string
}

15
division_node.go Normal file
View File

@ -0,0 +1,15 @@
package openstates
type DivisionNode struct {
Id string
Name string
Redirect string
Country string
CreatedAt string
UpdatedAt string
Extras string
}
const (
CountryUS = "us"
)

8
entity_types.go Normal file
View File

@ -0,0 +1,8 @@
package openstates
type EntityType string
const (
EntityOrganization = "organization"
EntityPerson = "person"
)

6
identifier_node.go Normal file
View File

@ -0,0 +1,6 @@
package openstates
type IdentifierNode struct {
Identifier string
Scheme string
}

10
jurisdiction_node.go Normal file
View File

@ -0,0 +1,10 @@
package openstates
type JurisdictionNode struct {
Id string
Name string
Url string
// FeatureFlags -- Reserved for future user
LegislativeSessions []LegislativeSessionNode
Organizations []OrganizationNode
}

View File

@ -0,0 +1,15 @@
package openstates
type LegislativeSessionNode struct {
Jurisdiction *JurisdictionNode
Identifier string
Name string
Classification string
StartDate string
EndDate string
}
const (
ClassificationPrimary = "primary"
ClassificationSpecial = "special"
)

6
link_node.go Normal file
View File

@ -0,0 +1,6 @@
package openstates
type LinkNode struct {
Url string
Text string
}

16
membership_node.go Normal file
View File

@ -0,0 +1,16 @@
package openstates
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
}

8
name_node.go Normal file
View File

@ -0,0 +1,8 @@
package openstates
type NameNode struct {
Name string
Note string
StartDate string
EndDate string
}

View File

@ -1,6 +1,11 @@
package openstates package openstates
import "github.com/machinebox/graphql" import (
"context"
"log"
"github.com/machinebox/graphql"
)
type OpenStatesApi struct { type OpenStatesApi struct {
ApiKey string ApiKey string
@ -12,9 +17,20 @@ func NewOpenStatesApi(key string) *OpenStatesApi {
ApiKey: key, ApiKey: key,
} }
o.Client = graphql.NewClient("https://openstates.org/graphql") o.Client = graphql.NewClient("https://openstates.org/graphql")
return o return &o
} }
func (o *OpenStatesApi) GetLegislatorsForArea(lat float, long float) []PersonNode { func (o *OpenStatesApi) TurnOnLogging() {
o.Client.Log = func(s string) { log.Println(s) }
} }
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)
}
}
//func (o *OpenStatesApi) GetLegislatorsForArea(lat float, long float) []PersonNode {
//}

20
organization_node.go Normal file
View File

@ -0,0 +1,20 @@
package openstates
type OrganizationNode struct {
Id string
Name string
Image string
Classification string
FoundingDate string
DissolutionDate string
Parent *OrganizationNode
Children []OrganizationNode
CurrentMemberships []MembershipNode
Identifiers []IdentifierNode
OtherNames []NameNode
Links []LinkNode
Sources []string
CreatedAt string
UpdatedAt string
Extras string
}

View File

@ -20,38 +20,3 @@ type PersonNode struct {
UpdatedAt string UpdatedAt string
Extras 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
}

14
post_node.go Normal file
View File

@ -0,0 +1,14 @@
package openstates
type PostNode struct {
Id string
Label string
Role string
Division *DivisionNode
StartDate string
EndDate string
MaximumMberships int
CreatedAt string
UpdatedAt string
Extras string
}

11
vote_types.go Normal file
View File

@ -0,0 +1,11 @@
package openstates
type VoteType string
const (
VotePassage = "passage"
VoteAmendment = "amendment"
VoteReading1 = "reading:1"
VoteReading2 = "reading:2"
VoteOther = "other"
)