Ruby gem for easy access to Canadian civic data around the web
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
tasks
.gitignore
.rspec
.travis.yml
.yardopts
Gemfile
LICENSE
README.md
Rakefile
govkit-ca.gemspec

README.md

GovKit-CA

Gem Version Build Status Dependency Status Coverage Status Code Climate

GovKit-CA is a Ruby gem that provides easy access to Canadian civic information around the web.

Installation

gem install govkit-ca

Represent API

GovKit-CA provides a Represent API client. First, create a client:

require 'govkit-ca'

client = GovKit::CA::Represent.new

Send a request to the /postcodes/ endpoint:

client.postcodes('A1A1A1')

Send a request to the /representative-sets/ endpoint:

client.representative_sets(limit: 0)

Send a request to the /representatives/ endpoint:

client.representatives(representative_set: 'toronto-city-council')

Send a request to the /boundary-sets/ endpoint:

client.boundary_sets(limit: 0)

Send a request to the /boundaries/ endpoint:

client.boundaries(boundary_set: 'toronto-wards')

Send a request to the /elections/ endpoint:

client.elections(limit: 0)

Send a request to the /candidates/ endpoint:

client.candidates(election: 'house-of-commons')

Read the full documentation on RubyDoc.info.

Postal code to electoral district lookup

GovKit-CA provides an API for free postal code to electoral district lookups, using the sources:

These sources can be unstable or incorrect.

require 'govkit-ca'

# Register the sources to use.
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::ElectionsCa)
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::LiberalCa)
GovKit::CA::PostalCode::StrategySet.register(GovKit::CA::PostalCode::Strategy::NDPCa)

GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('A1A1A1') # [10007]
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('K0A1K0') # [35076]
GovKit::CA::PostalCode.find_electoral_districts_by_postal_code('H0H0H0') # raises GovKit::CA::ResourceNotFound

GovKit::CA::PostalCode.find_province_by_postal_code('A1A1A1') # "Newfoundland and Labrador"
GovKit::CA::PostalCode.find_province_by_postal_code('K0A1K0') # "Ontario"
GovKit::CA::PostalCode.find_province_by_postal_code('H0H0H0') # "Quebec"

Postal codes may contain lowercase letters. Spaces and non-alphanumeric characters are removed before processing.

GovKit-CA will raise GovKit::CA::ResourceNotFound if the electoral districts within a postal code cannot be determined, and GovKit::CA::InvalidRequest if a postal code is not properly formatted.

Acknowledgements

GovKit-CA interoperates with the Participatory Politics Foundation's GovKit. GovKit-CA is not affiliated with the Participatory Politics Foundation or GovKit.

Copyright (c) 2011 Open North Inc., released under the MIT license