From db7d2a4cc2139f3246af2cf618a8658f1f75d1ab Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 16 Jun 2016 11:22:03 -0500 Subject: [PATCH] Initial Commit --- example/.gitignore | 5 + example/example.go | 27 ++ openstates/bill_structs.go | 96 +++++ openstates/bills.go | 107 ++++++ openstates/legislator_structs.go | 7 + openstates/legislators.go | 34 ++ openstates/openstates.go | 99 ++++++ openstates/os_structs.go | 54 +++ openstates/states/states.go | 579 +++++++++++++++++++++++++++++++ sunlight.go | 1 + 10 files changed, 1009 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/example.go create mode 100644 openstates/bill_structs.go create mode 100644 openstates/bills.go create mode 100644 openstates/legislator_structs.go create mode 100644 openstates/legislators.go create mode 100644 openstates/openstates.go create mode 100644 openstates/os_structs.go create mode 100644 openstates/states/states.go create mode 100644 sunlight.go diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..7ccba9c --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,5 @@ +# So I can "example `cat api-key`" on the cli +api-key + +# Binary +example \ No newline at end of file diff --git a/example/example.go b/example/example.go new file mode 100644 index 0000000..4ec355e --- /dev/null +++ b/example/example.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "os" + + "github.com/br0xen/sunlight-api/openstates" +) + +func main() { + var apiKey string + if len(os.Args) > 1 { + apiKey = os.Args[1] + } else { + fmt.Println("Usage: example ") + return + } + o := openstates.Create(apiKey) + //d, err := o.StateMetadata(states.Kansas) + d, err := o.GetBillDetailFromID("KSB00002165") + //d, err := o.GetBillDetail(states.Kansas, "2013-2014", "HR 6020") + if err != nil { + fmt.Println(err.Error()) + return + } + fmt.Printf("%+v\n", d) +} diff --git a/openstates/bill_structs.go b/openstates/bill_structs.go new file mode 100644 index 0000000..58759fe --- /dev/null +++ b/openstates/bill_structs.go @@ -0,0 +1,96 @@ +package openstates + +import "time" + +// Bill is a Bill +type Bill struct { + Title string `json:"title"` + CreatedAtStr string `json:"created_at"` + CreatedAt time.Time `json:"-"` + UpdatedAtStr string `json:"updated_at"` + UpdatedAt time.Time `json:"-"` + Chamber string `json:"chamber"` + State string `json:"state"` + Session string `json:"session"` + Subjects []string `json:"subjects"` + Type []string `json:"type"` + ID string `json:"id"` + BillID string `json:"bill_id"` + HasDetail bool `json:"-"` + ActionDates *ActionDates `json:"action_dates"` + Actions []Action `json:"actions"` + AlternateTitles []string `json:"alternate_titles"` + Documents []string `json:"documents"` + Level string `json:"level"` + ScrapedSubjects []string `json:"scraped_subjects"` + Sources []Source `json:"sources"` + Sponsors []Sponsor `json:"sponsors"` + Versions []Version `json:"versions"` + Votes []Vote `json:"votes"` +} + +// ActionDates are the dates that actions happened on the bill +type ActionDates struct { + PassedUpperStr string `json:"passed_upper"` + PassedUpper time.Time `json:"-"` + PassedLowerStr string `json:"passed_lower"` + PassedLower time.Time `json:"-"` + LastStr string `json:"last"` + Last time.Time `json:"-"` + SignedStr string `json:"signed"` + Signed time.Time `json:"-"` + FirstStr string `json:"first"` + First time.Time `json:"-"` +} + +// Action on a bill +type Action struct { + Date time.Time + DateStr string `json:"date"` + Action string `json:"action"` + Type []string `json:"type"` + Actor string `json:"actor"` +} + +// Source is a source in a bill +type Source struct { + URL string `json:"url"` +} + +// Sponsor is a sponsor on a bill +type Sponsor struct { + LegID string `json:"leg_id"` + Type string `json:"type"` + Name string `json:"name"` +} + +// Version is a version of a bill +type Version struct { + URL string `json:"url"` + MimeType string `json:"mimetype"` + DocID string `json:"doc_id"` + Name string `json:"name"` +} + +// Vote is a vote on a bill +type Vote struct { + OtherCount int `json:"other_count"` + Threshold string `json:"+threshold"` + OtherVotes []Legislator `json:"other_votes"` + YesCount int `json:"yes_count"` + YesVotes []Legislator `json:"yes_votes"` + NoCount int `json:"no_count"` + NoVotes []Legislator `json:"no_votes"` + Motion string `json:"motion"` + Chamber string `json:"chamber"` + State string `json:"state"` + Session string `json:"session"` + Sources []Source `json:"sources"` + Passed bool `json:"passed"` + DateStr string `json:"date"` + Date time.Time `json:"-"` + VoteID string `json:"vote_id"` + Type string `json:"type"` + ID string `json:"id"` + BillID string `json:"bill_id"` +} diff --git a/openstates/bills.go b/openstates/bills.go new file mode 100644 index 0000000..d78879b --- /dev/null +++ b/openstates/bills.go @@ -0,0 +1,107 @@ +package openstates + +import ( + "encoding/json" + "fmt" + "net/url" + "strconv" + "time" + + "github.com/br0xen/sunlight-api/openstates/states" +) + +// GetBillsWithParams returns all bills with parameters 'v' +func (o *OpenStates) GetBillsWithParams(v url.Values) ([]Bill, error) { + var ret []Bill + var err error + var getVal []byte + if getVal, err = o.call("bills", v); err != nil { + return ret, err + } + err = json.Unmarshal(getVal, &ret) + if err == nil { + for i := range ret { + ret[i].CreatedAt, err = time.Parse("2006-01-02 15:04:05", ret[i].CreatedAtStr) + if err != nil { + fmt.Println("Error on idx: " + strconv.Itoa(i)) + return ret, err + } + ret[i].UpdatedAt, err = time.Parse("2006-01-02 15:04:05", ret[i].UpdatedAtStr) + if err != nil { + fmt.Println("Error on idx: " + strconv.Itoa(i)) + return ret, err + } + } + } + return ret, err +} + +// GetBillsForState gets all bills for state st +func (o *OpenStates) GetBillsForState(st string) ([]Bill, error) { + st, err := states.ScrubToAbbr(st) + if err != nil { + return []Bill{}, err + } + vals := url.Values{} + vals.Set("state", st) + return o.GetBillsWithParams(vals) +} + +// QueryBillsForState Does a search for bills with text 'q' in state 'st +func (o *OpenStates) QueryBillsForState(st string, q string) ([]Bill, error) { + st, err := states.ScrubToAbbr(st) + if err != nil { + return []Bill{}, err + } + vals := url.Values{} + vals.Set("state", st) + vals.Set("q", q) + return o.GetBillsWithParams(vals) +} + +func (o *OpenStates) getBillDetailForEndpoint(ep string) (*Bill, error) { + var ret *Bill + var err error + var getVal []byte + v := url.Values{} + if getVal, err = o.call(ep, v); err != nil { + return ret, err + } + fmt.Println(string(getVal)) + err = json.Unmarshal(getVal, &ret) + ret.HasDetail = true + if err == nil { + if err = UnmarshalTimeString(ret.CreatedAtStr, &ret.CreatedAt); err != nil { + return ret, err + } + if err = UnmarshalTimeString(ret.UpdatedAtStr, &ret.UpdatedAt); err != nil { + return ret, err + } + UnmarshalTimeString(ret.ActionDates.PassedUpperStr, &ret.ActionDates.PassedUpper) + UnmarshalTimeString(ret.ActionDates.PassedLowerStr, &ret.ActionDates.PassedLower) + UnmarshalTimeString(ret.ActionDates.LastStr, &ret.ActionDates.Last) + UnmarshalTimeString(ret.ActionDates.SignedStr, &ret.ActionDates.Signed) + UnmarshalTimeString(ret.ActionDates.FirstStr, &ret.ActionDates.First) + for i := range ret.Actions { + UnmarshalTimeString(ret.Actions[i].DateStr, &ret.Actions[i].Date) + } + for i := range ret.Votes { + UnmarshalTimeString(ret.Votes[i].DateStr, &ret.Votes[i].Date) + } + } + return ret, err +} + +// GetBillDetail Gets bill detail from state, session, and name +func (o *OpenStates) GetBillDetail(st, sess, name string) (*Bill, error) { + st, err := states.ScrubToAbbr(st) + if err != nil { + return nil, err + } + return o.getBillDetailForEndpoint("bills/" + st + "/" + sess + "/" + name) +} + +// GetBillDetailFromID ... +func (o *OpenStates) GetBillDetailFromID(id string) (*Bill, error) { + return o.getBillDetailForEndpoint("bills/" + id) +} diff --git a/openstates/legislator_structs.go b/openstates/legislator_structs.go new file mode 100644 index 0000000..ad6e474 --- /dev/null +++ b/openstates/legislator_structs.go @@ -0,0 +1,7 @@ +package openstates + +// Legislator is a legislator +type Legislator struct { + LegID string `json:"leg_id"` + NameOnBill string `json:"name"` // Shows up when pulling bill detail +} diff --git a/openstates/legislators.go b/openstates/legislators.go new file mode 100644 index 0000000..3f9f093 --- /dev/null +++ b/openstates/legislators.go @@ -0,0 +1,34 @@ +package openstates + +import ( + "encoding/json" + "net/url" +) + +// SearchLegislators retrieves a list of legislators based on a number of +// parameters, the results do not include the `roles` or `old_roles` items +// by default +// Valid Parameters: +// * state - Filter by state +// * first_name - Filter by first name +// * last_name - Filter by last name +// * chamber - Only legislators with a role in the specified chamber +// * active - 'true' (default) to only include current legislators +// * term - Only legislators that have a role in a certain term +// * district - Only legislators that have represented the specified district +// * party - Only legislators that have been associated with a specified +// party +func (o *OpenStates) SearchLegislators(v url.Values) ([]Legislator, error) { + var ret []Legislator + var err error + var getVal []byte + if getVal, err = o.call("legislators", v); err != nil { + return ret, err + } + err = json.Unmarshal(getVal, &ret) + if err == nil { + //for i := range ret { + //} + } + return ret, err +} diff --git a/openstates/openstates.go b/openstates/openstates.go new file mode 100644 index 0000000..1561ae5 --- /dev/null +++ b/openstates/openstates.go @@ -0,0 +1,99 @@ +package openstates + +import ( + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "strconv" + "time" + + "github.com/br0xen/sunlight-api/openstates/states" +) + +// Create returns a new OpenStates object +func Create(key string) *OpenStates { + o := OpenStates{APIVersion: 1, APIKey: key} + return &o +} + +// SetAPIVersion changes the api version +func (o *OpenStates) SetAPIVersion(i int) { + o.APIVersion = i +} + +func (o *OpenStates) call(endpoint string, values url.Values) ([]byte, error) { + var ret []byte + url := "http://openstates.org/api/v" + strconv.Itoa(o.APIVersion) + "/" + endpoint + "?apikey=" + o.APIKey + if len(values) > 0 { + url += "&" + values.Encode() + } + resp, err := http.Get(url) + if err != nil { + return ret, err + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + return body, err +} + +// AllMetadata returns all state's metadata +func (o *OpenStates) AllMetadata() ([]StateMeta, error) { + var ret []StateMeta + var getVal []byte + var err error + vals := url.Values{} + if getVal, err = o.call("metadata", vals); err != nil { + return ret, err + } + err = json.Unmarshal(getVal, &ret) + return ret, err +} + +// StateMetadata pulls metadata for a specific state +func (o *OpenStates) StateMetadata(st string) (*StateMeta, error) { + var ret *StateMeta + var err error + orig := st + if states.IsValidName(st) { + st, err = states.NameToAbbr(st) + } + if !states.IsValidAbbr(st) { + return ret, errors.New("Invalid State: " + orig) + } + var getVal []byte + vals := url.Values{} + if getVal, err = o.call("metadata/"+st, vals); err != nil { + return ret, err + } + fmt.Println(string(getVal)) + err = json.Unmarshal(getVal, &ret) + return ret, err +} + +// UnmarshalTimeString Takes a time string and a pointer to a time object +// and populates the time object with the value from the string +func UnmarshalTimeString(s string, t *time.Time) error { + var err error + // Check if 's' is empty + if s == "" { + return errors.New("Invalid Time Value") + } + *t, err = time.Parse("2006-01-02 15:04:05", s) + return err +} + +/* + resp, err := http.Get("http://openstates.org/api/v1/legislators/geo/?apikey=" + site.OpenStatesKey + "&lat=" + lat + "&long=" + lng) + if err != nil { + fmt.Fprint(w, "{\"status\":\"error\"}") + return + } + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + fmt.Fprint(w, string(body)) + // http://openstates.org/api/v1/legislators/geo/?lat=35.79&long=-78.78 + // https://sunlightlabs.github.io/openstates-api/legislators.html#examples/geo-lookup +*/ diff --git a/openstates/os_structs.go b/openstates/os_structs.go new file mode 100644 index 0000000..f17c70b --- /dev/null +++ b/openstates/os_structs.go @@ -0,0 +1,54 @@ +package openstates + +import "time" + +// OpenStates is the Wrapper for the OpenStates API +type OpenStates struct { + APIVersion int + APIKey string +} + +// StateMeta is all of the metadata for a state +type StateMeta struct { + Name string `json:"name"` + Abbr string `json:"abbreviation"` + Chambers map[string]StateChamber `json:"chambers"` + FeatureFlags []string `json:"feature_flags"` + CapitolTimezone time.Location `json:"-"` + CapitolTimezoneStr string `json:"capitol_timezone"` + ID string `json:"id"` + LatestCSVDate time.Time `json:"-"` + LatestCSVDateStr string `json:"latest_csv_date"` + LatestCSVURL string `json:"latest_csv_url"` + LatestJSONDate time.Time `json:"-"` + LatestJSONDateStr string `json:"latest_json_date"` + LatestJSONURL string `json:"latest_json_url"` + LatestUpdate time.Time `json:"-"` + LatestUpdateStr string `json:"latest_update"` + LegislatureName string `json:"legislature_name"` + LegislatureURL string `json:"legislature_url"` + SessionDetails map[string]SessionDetail `json:"session_details"` + Terms []Term `json:"terms"` +} + +// StateChamber is a Chamber in the state's government +type StateChamber struct { + Name string `json:"name"` // The Chamber name + Title string `json:"title"` // Title of a person in this chamber +} + +// SessionDetail are details about a specific session +type SessionDetail struct { + Type string `json:"type"` + DisplayName string `json:"display_name"` + StartDate time.Time `json:"-"` + StartDateStr string `json:"start_date"` +} + +// Term is a state term +type Term struct { + EndYear int `json:"end_year"` + StartYear int `json:"start_year"` + Name string `json:"name"` + Sessions []string `json:"sessions"` +} diff --git a/openstates/states/states.go b/openstates/states/states.go new file mode 100644 index 0000000..be553f2 --- /dev/null +++ b/openstates/states/states.go @@ -0,0 +1,579 @@ +package states + +import ( + "errors" + "strings" +) + +// ScrubToAbbr takes a name or abbr and returns an abbr +func ScrubToAbbr(nm string) (string, error) { + var err error + orig := nm + if IsValidName(nm) { + nm, err = NameToAbbr(nm) + } + if !IsValidAbbr(nm) { + return "", errors.New("Invalid State: " + orig) + } + return nm, err +} + +// IsValidName returns whether the given string is a valid name +func IsValidName(nm string) bool { + nm = strings.Title(nm) + switch nm { + case Alabama: + return true + case Alaska: + return true + case Arizona: + return true + case Arkansas: + return true + case California: + return true + case Colorado: + return true + case Connecticut: + return true + case Delaware: + return true + case DistrictOfColumbia: + return true + case Florida: + return true + case Georgia: + return true + case Hawaii: + return true + case Idaho: + return true + case Illinois: + return true + case Indiana: + return true + case Iowa: + return true + case Kansas: + return true + case Kentucky: + return true + case Louisiana: + return true + case Maine: + return true + case Maryland: + return true + case Massachusetts: + return true + case Michigan: + return true + case Minnesota: + return true + case Mississippi: + return true + case Missouri: + return true + case Montana: + return true + case Nebraska: + return true + case Nevada: + return true + case NewHampshire: + return true + case NewJersey: + return true + case NewMexico: + return true + case NewYork: + return true + case NorthCarolina: + return true + case NorthDakota: + return true + case Ohio: + return true + case Oklahoma: + return true + case Oregon: + return true + case Pennsylvania: + return true + case PuertoRico: + return true + case RhodeIsland: + return true + case SouthCarolina: + return true + case SouthDakota: + return true + case Tennessee: + return true + case Texas: + return true + case Utah: + return true + case Vermont: + return true + case Virginia: + return true + case Washington: + return true + case WestVirginia: + return true + case Wisconsin: + return true + case Wyoming: + return true + } + return false +} + +// IsValidAbbr return whether it was passed a valid abbreviation +func IsValidAbbr(a string) bool { + a = strings.ToLower(a) + switch a { + case AlabamaAbbr: + return true + case AlaskaAbbr: + return true + case ArizonaAbbr: + return true + case ArkansasAbbr: + return true + case CaliforniaAbbr: + return true + case ColoradoAbbr: + return true + case ConnecticutAbbr: + return true + case DelawareAbbr: + return true + case DistrictOfColumbiaAbbr: + return true + case FloridaAbbr: + return true + case GeorgiaAbbr: + return true + case HawaiiAbbr: + return true + case IdahoAbbr: + return true + case IllinoisAbbr: + return true + case IndianaAbbr: + return true + case IowaAbbr: + return true + case KansasAbbr: + return true + case KentuckyAbbr: + return true + case LouisianaAbbr: + return true + case MaineAbbr: + return true + case MarylandAbbr: + return true + case MassachusettsAbbr: + return true + case MichiganAbbr: + return true + case MinnesotaAbbr: + return true + case MississippiAbbr: + return true + case MissouriAbbr: + return true + case MontanaAbbr: + return true + case NebraskaAbbr: + return true + case NevadaAbbr: + return true + case NewHampshireAbbr: + return true + case NewJerseyAbbr: + return true + case NewMexicoAbbr: + return true + case NewYorkAbbr: + return true + case NorthCarolinaAbbr: + return true + case NorthDakotaAbbr: + return true + case OhioAbbr: + return true + case OklahomaAbbr: + return true + case OregonAbbr: + return true + case PennsylvaniaAbbr: + return true + case PuertoRicoAbbr: + return true + case RhodeIslandAbbr: + return true + case SouthCarolinaAbbr: + return true + case SouthDakotaAbbr: + return true + case TennesseeAbbr: + return true + case TexasAbbr: + return true + case UtahAbbr: + return true + case VermontAbbr: + return true + case VirginiaAbbr: + return true + case WashingtonAbbr: + return true + case WestVirginiaAbbr: + return true + case WisconsinAbbr: + return true + case WyomingAbbr: + return true + } + return false +} + +// NameToAbbr converts a state name to it's abbreviation +func NameToAbbr(nm string) (string, error) { + nm = strings.Title(nm) + switch nm { + case Alabama: + return AlabamaAbbr, nil + case Alaska: + return AlaskaAbbr, nil + case Arizona: + return ArizonaAbbr, nil + case Arkansas: + return ArkansasAbbr, nil + case California: + return CaliforniaAbbr, nil + case Colorado: + return ColoradoAbbr, nil + case Connecticut: + return ConnecticutAbbr, nil + case Delaware: + return DelawareAbbr, nil + case DistrictOfColumbia: + return DistrictOfColumbiaAbbr, nil + case Florida: + return FloridaAbbr, nil + case Georgia: + return GeorgiaAbbr, nil + case Hawaii: + return HawaiiAbbr, nil + case Idaho: + return IdahoAbbr, nil + case Illinois: + return IllinoisAbbr, nil + case Indiana: + return IndianaAbbr, nil + case Iowa: + return IowaAbbr, nil + case Kansas: + return KansasAbbr, nil + case Kentucky: + return KentuckyAbbr, nil + case Louisiana: + return LouisianaAbbr, nil + case Maine: + return MaineAbbr, nil + case Maryland: + return MarylandAbbr, nil + case Massachusetts: + return MassachusettsAbbr, nil + case Michigan: + return MichiganAbbr, nil + case Minnesota: + return MinnesotaAbbr, nil + case Mississippi: + return MississippiAbbr, nil + case Missouri: + return MissouriAbbr, nil + case Montana: + return MontanaAbbr, nil + case Nebraska: + return NebraskaAbbr, nil + case Nevada: + return NevadaAbbr, nil + case NewHampshire: + return NewHampshireAbbr, nil + case NewJersey: + return NewJerseyAbbr, nil + case NewMexico: + return NewMexicoAbbr, nil + case NewYork: + return NewYorkAbbr, nil + case NorthCarolina: + return NorthCarolinaAbbr, nil + case NorthDakota: + return NorthDakotaAbbr, nil + case Ohio: + return OhioAbbr, nil + case Oklahoma: + return OklahomaAbbr, nil + case Oregon: + return OregonAbbr, nil + case Pennsylvania: + return PennsylvaniaAbbr, nil + case PuertoRico: + return PuertoRicoAbbr, nil + case RhodeIsland: + return RhodeIslandAbbr, nil + case SouthCarolina: + return SouthCarolinaAbbr, nil + case SouthDakota: + return SouthDakotaAbbr, nil + case Tennessee: + return TennesseeAbbr, nil + case Texas: + return TexasAbbr, nil + case Utah: + return UtahAbbr, nil + case Vermont: + return VermontAbbr, nil + case Virginia: + return VirginiaAbbr, nil + case Washington: + return WashingtonAbbr, nil + case WestVirginia: + return WestVirginiaAbbr, nil + case Wisconsin: + return WisconsinAbbr, nil + case Wyoming: + return WyomingAbbr, nil + } + return "", errors.New("Invalid State Name") +} + +// AbbrToName converts a state abbreviation to it's name +func AbbrToName(nm string) (string, error) { + nm = strings.ToLower(nm) + switch nm { + case AlabamaAbbr: + return Alabama, nil + case AlaskaAbbr: + return Alaska, nil + case ArizonaAbbr: + return Arizona, nil + case ArkansasAbbr: + return Arkansas, nil + case CaliforniaAbbr: + return California, nil + case ColoradoAbbr: + return Colorado, nil + case ConnecticutAbbr: + return Connecticut, nil + case DelawareAbbr: + return Delaware, nil + case DistrictOfColumbiaAbbr: + return DistrictOfColumbia, nil + case FloridaAbbr: + return Florida, nil + case GeorgiaAbbr: + return Georgia, nil + case HawaiiAbbr: + return Hawaii, nil + case IdahoAbbr: + return Idaho, nil + case IllinoisAbbr: + return Illinois, nil + case IndianaAbbr: + return Indiana, nil + case IowaAbbr: + return Iowa, nil + case KansasAbbr: + return Kansas, nil + case KentuckyAbbr: + return Kentucky, nil + case LouisianaAbbr: + return Louisiana, nil + case MaineAbbr: + return Maine, nil + case MarylandAbbr: + return Maryland, nil + case MassachusettsAbbr: + return Massachusetts, nil + case MichiganAbbr: + return Michigan, nil + case MinnesotaAbbr: + return Minnesota, nil + case MississippiAbbr: + return Mississippi, nil + case MissouriAbbr: + return Missouri, nil + case MontanaAbbr: + return Montana, nil + case NebraskaAbbr: + return Nebraska, nil + case NevadaAbbr: + return Nevada, nil + case NewHampshireAbbr: + return NewHampshire, nil + case NewJerseyAbbr: + return NewJersey, nil + case NewMexicoAbbr: + return NewMexico, nil + case NewYorkAbbr: + return NewYork, nil + case NorthCarolinaAbbr: + return NorthCarolina, nil + case NorthDakotaAbbr: + return NorthDakota, nil + case OhioAbbr: + return Ohio, nil + case OklahomaAbbr: + return Oklahoma, nil + case OregonAbbr: + return Oregon, nil + case PennsylvaniaAbbr: + return Pennsylvania, nil + case PuertoRicoAbbr: + return PuertoRico, nil + case RhodeIslandAbbr: + return RhodeIsland, nil + case SouthCarolinaAbbr: + return SouthCarolina, nil + case SouthDakotaAbbr: + return SouthDakota, nil + case TennesseeAbbr: + return Tennessee, nil + case TexasAbbr: + return Texas, nil + case UtahAbbr: + return Utah, nil + case VermontAbbr: + return Vermont, nil + case VirginiaAbbr: + return Virginia, nil + case WashingtonAbbr: + return Washington, nil + case WestVirginiaAbbr: + return WestVirginia, nil + case WisconsinAbbr: + return Wisconsin, nil + case WyomingAbbr: + return Wyoming, nil + } + return "", errors.New("Invalid State Abbreviation") +} + +// State Name Constants +const ( + Alabama = "Alabama" + Alaska = "Alaska" + Arizona = "Arizona" + Arkansas = "Arkansas" + California = "California" + Colorado = "Colorado" + Connecticut = "Connecticut" + Delaware = "Delaware" + DistrictOfColumbia = "District of Columbia" + Florida = "Florida" + Georgia = "Georgia" + Hawaii = "Hawaii" + Idaho = "Idaho" + Illinois = "Illinois" + Indiana = "Indiana" + Iowa = "Iowa" + Kansas = "Kansas" + Kentucky = "Kentucky" + Louisiana = "Louisiana" + Maine = "Maine" + Maryland = "Maryland" + Massachusetts = "Massachusetts" + Michigan = "Michigan" + Minnesota = "Minnesota" + Mississippi = "Mississippi" + Missouri = "Missouri" + Montana = "Montana" + Nebraska = "Nebraska" + Nevada = "Nevada" + NewHampshire = "New Hampshire" + NewJersey = "New Jersey" + NewMexico = "New Mexico" + NewYork = "New York" + NorthCarolina = "North Carolina" + NorthDakota = "North Dakota" + Ohio = "Ohio" + Oklahoma = "Oklahoma" + Oregon = "Oregon" + Pennsylvania = "Pennsylvania" + PuertoRico = "Puerto Rico" + RhodeIsland = "Rhode Island" + SouthCarolina = "South Carolina" + SouthDakota = "South Dakota" + Tennessee = "Tennessee" + Texas = "Texas" + Utah = "Utah" + Vermont = "Vermont" + Virginia = "Virginia" + Washington = "Washington" + WestVirginia = "West Virginia" + Wisconsin = "Wisconsin" + Wyoming = "Wyoming" +) + +// State Abbreviation Constants +const ( + AlabamaAbbr = "al" + AlaskaAbbr = "ak" + ArizonaAbbr = "az" + ArkansasAbbr = "ar" + CaliforniaAbbr = "ca" + ColoradoAbbr = "co" + ConnecticutAbbr = "ct" + DelawareAbbr = "de" + DistrictOfColumbiaAbbr = "dc" + FloridaAbbr = "fl" + GeorgiaAbbr = "ga" + HawaiiAbbr = "hi" + IdahoAbbr = "id" + IllinoisAbbr = "il" + IndianaAbbr = "in" + IowaAbbr = "io" + KansasAbbr = "ks" + KentuckyAbbr = "ky" + LouisianaAbbr = "la" + MaineAbbr = "me" + MarylandAbbr = "md" + MassachusettsAbbr = "ma" + MichiganAbbr = "mi" + MinnesotaAbbr = "mn" + MississippiAbbr = "ms" + MissouriAbbr = "mo" + MontanaAbbr = "mt" + NebraskaAbbr = "ne" + NevadaAbbr = "nv" + NewHampshireAbbr = "nh" + NewJerseyAbbr = "nj" + NewMexicoAbbr = "nm" + NewYorkAbbr = "ny" + NorthCarolinaAbbr = "nc" + NorthDakotaAbbr = "nd" + OhioAbbr = "oh" + OklahomaAbbr = "ok" + OregonAbbr = "or" + PennsylvaniaAbbr = "pa" + PuertoRicoAbbr = "pr" + RhodeIslandAbbr = "ri" + SouthCarolinaAbbr = "sc" + SouthDakotaAbbr = "sd" + TennesseeAbbr = "tn" + TexasAbbr = "tx" + UtahAbbr = "ut" + VermontAbbr = "vt" + VirginiaAbbr = "va" + WashingtonAbbr = "wa" + WestVirginiaAbbr = "wv" + WisconsinAbbr = "wi" + WyomingAbbr = "wy" +) diff --git a/sunlight.go b/sunlight.go new file mode 100644 index 0000000..36e66e0 --- /dev/null +++ b/sunlight.go @@ -0,0 +1 @@ +package sunlightApi