From d56ccc469a106e0a811f3166efa587526b0cf5d7 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 8 Apr 2019 07:23:51 -0500 Subject: [PATCH] All Nodes Represented --- .gitignore | 1 + _example/api_key.go.example | 1 + _example/main.go | 24 +++++--- action_types.go | 33 ++++++++++ bill_node.go | 117 ++++++++++++++++++++++++++++++++++++ contact_detail_node.go | 8 +++ division_node.go | 15 +++++ entity_types.go | 8 +++ identifier_node.go | 6 ++ jurisdiction_node.go | 10 +++ legislative_session_node.go | 15 +++++ link_node.go | 6 ++ membership_node.go | 16 +++++ name_node.go | 8 +++ openstates.go | 24 ++++++-- organization_node.go | 20 ++++++ person_node.go | 35 ----------- post_node.go | 14 +++++ vote_types.go | 11 ++++ 19 files changed, 323 insertions(+), 49 deletions(-) create mode 100644 action_types.go create mode 100644 bill_node.go create mode 100644 contact_detail_node.go create mode 100644 division_node.go create mode 100644 entity_types.go create mode 100644 identifier_node.go create mode 100644 jurisdiction_node.go create mode 100644 legislative_session_node.go create mode 100644 link_node.go create mode 100644 membership_node.go create mode 100644 name_node.go create mode 100644 organization_node.go create mode 100644 post_node.go create mode 100644 vote_types.go diff --git a/.gitignore b/.gitignore index 20efd6f..c55f96e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ _example/api_key.go +_example/_example _example/example diff --git a/_example/api_key.go.example b/_example/api_key.go.example index fbf255f..2f221a1 100644 --- a/_example/api_key.go.example +++ b/_example/api_key.go.example @@ -1,4 +1,5 @@ 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 index 594f846..7f4aec5 100644 --- a/_example/main.go +++ b/_example/main.go @@ -1,22 +1,30 @@ package main import ( - "context" "encoding/json" "fmt" - "log" + "git.bullercodeworks.com/brian/openstates" "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 { + id name + sortName + familyName + givenName + image + birthDate + deathDate + createdAt + updatedAt + extras } } } @@ -26,13 +34,9 @@ func main() { 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) - } + o := openstates.NewOpenStatesApi(ApiKey) + o.TurnOnLogging() + o.MakeRequest(req, &res) j, _ := json.Marshal(res) fmt.Println(string(j)) } diff --git a/action_types.go b/action_types.go new file mode 100644 index 0000000..23a77ed --- /dev/null +++ b/action_types.go @@ -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" +) diff --git a/bill_node.go b/bill_node.go new file mode 100644 index 0000000..98782ea --- /dev/null +++ b/bill_node.go @@ -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 +} diff --git a/contact_detail_node.go b/contact_detail_node.go new file mode 100644 index 0000000..2c13d04 --- /dev/null +++ b/contact_detail_node.go @@ -0,0 +1,8 @@ +package openstates + +type ContactDetailNode struct { + Type string + Value string + Note string + Label string +} diff --git a/division_node.go b/division_node.go new file mode 100644 index 0000000..36b0aff --- /dev/null +++ b/division_node.go @@ -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" +) diff --git a/entity_types.go b/entity_types.go new file mode 100644 index 0000000..7425361 --- /dev/null +++ b/entity_types.go @@ -0,0 +1,8 @@ +package openstates + +type EntityType string + +const ( + EntityOrganization = "organization" + EntityPerson = "person" +) diff --git a/identifier_node.go b/identifier_node.go new file mode 100644 index 0000000..1c2b37a --- /dev/null +++ b/identifier_node.go @@ -0,0 +1,6 @@ +package openstates + +type IdentifierNode struct { + Identifier string + Scheme string +} diff --git a/jurisdiction_node.go b/jurisdiction_node.go new file mode 100644 index 0000000..dc11cff --- /dev/null +++ b/jurisdiction_node.go @@ -0,0 +1,10 @@ +package openstates + +type JurisdictionNode struct { + Id string + Name string + Url string + // FeatureFlags -- Reserved for future user + LegislativeSessions []LegislativeSessionNode + Organizations []OrganizationNode +} diff --git a/legislative_session_node.go b/legislative_session_node.go new file mode 100644 index 0000000..2c835cc --- /dev/null +++ b/legislative_session_node.go @@ -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" +) diff --git a/link_node.go b/link_node.go new file mode 100644 index 0000000..5c699b8 --- /dev/null +++ b/link_node.go @@ -0,0 +1,6 @@ +package openstates + +type LinkNode struct { + Url string + Text string +} diff --git a/membership_node.go b/membership_node.go new file mode 100644 index 0000000..3434cdf --- /dev/null +++ b/membership_node.go @@ -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 +} diff --git a/name_node.go b/name_node.go new file mode 100644 index 0000000..50ba4d0 --- /dev/null +++ b/name_node.go @@ -0,0 +1,8 @@ +package openstates + +type NameNode struct { + Name string + Note string + StartDate string + EndDate string +} diff --git a/openstates.go b/openstates.go index e1ec214..bf1a119 100644 --- a/openstates.go +++ b/openstates.go @@ -1,6 +1,11 @@ package openstates -import "github.com/machinebox/graphql" +import ( + "context" + "log" + + "github.com/machinebox/graphql" +) type OpenStatesApi struct { ApiKey string @@ -12,9 +17,20 @@ func NewOpenStatesApi(key string) *OpenStatesApi { ApiKey: key, } 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 { +//} diff --git a/organization_node.go b/organization_node.go new file mode 100644 index 0000000..6c8833d --- /dev/null +++ b/organization_node.go @@ -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 +} diff --git a/person_node.go b/person_node.go index 37d9d76..8b1ddc1 100644 --- a/person_node.go +++ b/person_node.go @@ -20,38 +20,3 @@ type PersonNode struct { 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 -} diff --git a/post_node.go b/post_node.go new file mode 100644 index 0000000..cf5a8a2 --- /dev/null +++ b/post_node.go @@ -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 +} diff --git a/vote_types.go b/vote_types.go new file mode 100644 index 0000000..570571b --- /dev/null +++ b/vote_types.go @@ -0,0 +1,11 @@ +package openstates + +type VoteType string + +const ( + VotePassage = "passage" + VoteAmendment = "amendment" + VoteReading1 = "reading:1" + VoteReading2 = "reading:2" + VoteOther = "other" +)