Class: OpenCivicData::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/open_civic_data/client.rb

Constant Summary collapse

@@key_required =

rubocop:disable ClassVars

true
@@endpoint =

rubocop:disable ClassVars

'http://api.opencivicdata.org'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#get

Constructor Details

#initialize(key) ⇒ Client

Returns a new instance of Client.



14
15
16
17
# File 'lib/open_civic_data/client.rb', line 14

def initialize(key)
  fail ArgumentError, 'API key required' if key.nil? && @@key_required
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/open_civic_data/client.rb', line 9

def key
  @key
end

Class Method Details

.endpointObject



114
115
116
# File 'lib/open_civic_data/client.rb', line 114

def endpoint
  @@endpoint
end

.endpoint=(endpoint) ⇒ Object



110
111
112
# File 'lib/open_civic_data/client.rb', line 110

def endpoint=(endpoint)
  @@endpoint = endpoint
end

.key_requiredBoolean

Check if key is required.

Examples:

if OpenCivicData.key_required
  OpenCivicData.key = SUNLIGHT_KEY

Returns:

  • (Boolean)


106
107
108
# File 'lib/open_civic_data/client.rb', line 106

def key_required
  @@key_required
end

.key_required=(bool) ⇒ Object

Disable ArgumentError if no api key is provided. Useful for using different endpoints.

Examples:

OpenCivicData.key_required(false)
OpenCivicData.jurisdictions

Parameters:

  • (Boolean)


96
97
98
# File 'lib/open_civic_data/client.rb', line 96

def key_required=(bool)
  @@key_required = bool # rubocop:disable ClassVars
end

Instance Method Details

#bills(options = {}) ⇒ Hashie::Rash

Fetches legislative documents and their history

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.bills

Returns:

  • (Hashie::Rash)

    Bill's type, legislative body, session, name, chamber, title, type, subject and summary.



75
76
77
# File 'lib/open_civic_data/client.rb', line 75

def bills(options = {})
  get('/bills/', options)
end

#divisions(options = {}) ⇒ Hashie::Rash

Fetches political geographies such as a state, county or congressional district

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.divisions

Returns:

  • (Hashie::Rash)

    Division's geometries and list of child jurisdiction ids.



35
36
37
# File 'lib/open_civic_data/client.rb', line 35

def divisions(options = {})
  get('/divisions/', options)
end

#events(options = {}) ⇒ Hashie::Rash

Fetches legislative event, such as a meeting or hearing

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.events

Returns:

  • (Hashie::Rash)

    Event's type, name, description, when, end, status, location, and linked entities.



65
66
67
# File 'lib/open_civic_data/client.rb', line 65

def events(options = {})
  get('/events/', options)
end

#jurisdictions(options = {}) ⇒ Hashie::Rash

Fetches governing bodies that exist within a division

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.jurisdictions

Returns:

  • (Hashie::Rash)

    Jurisdiction's name, url, chambers, terms, and session details.



25
26
27
# File 'lib/open_civic_data/client.rb', line 25

def jurisdictions(options = {})
  get('/jurisdictions/', options)
end

#organizations(options = {}) ⇒ Hashie::Rash

Fetches groups of people, such as a city council, state senate or committee

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.organizations

Returns:

  • (Hashie::Rash)

    Organization's name, classification, parent id, contact details, links and posts.



55
56
57
# File 'lib/open_civic_data/client.rb', line 55

def organizations(options = {})
  get('/organizations/', options)
end

#people(options = {}) ⇒ Hashie::Rash

Fetches people, typically politicians or gov officials

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.people

Returns:

  • (Hashie::Rash)

    Person's name, image, contact details, and links.



45
46
47
# File 'lib/open_civic_data/client.rb', line 45

def people(options = {})
  get('/people/', options)
end

#votes(options = {}) ⇒ Hashie::Rash

Fetches the record of vote taken on motions

Examples:

OpenCivicData.key = YOUR_SUNLIGHT_API_KEY
OpenCivicData.votes

Returns:

  • (Hashie::Rash)

    Vote's organization, session, chamber, date, motion, type and passed or not.



85
86
87
# File 'lib/open_civic_data/client.rb', line 85

def votes(options = {})
  get('/votes/', options)
end