Class: GovKit::CA::Represent

Inherits:
Object
  • Object
show all
Defined in:
lib/gov_kit-ca/represent.rb

Overview

A Ruby wrapper for the Represent API.

Instance Method Summary collapse

Constructor Details

#initialize(connection = nil) ⇒ Represent

Returns a new instance of Represent.

Parameters:

  • connection (Faraday::Connection) (defaults to: nil)

    a Faraday connection



7
8
9
# File 'lib/gov_kit-ca/represent.rb', line 7

def initialize(connection = nil)
  @client = connection || Faraday
end

Instance Method Details

#boundaries(opts = {}) ⇒ Object

Get boundaries.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :boundary_set (String)

    a boundary set

  • :boundary (String)

    a boundary

  • :representatives (Boolean)
  • :sets (Array<String>, String)

    comma-separated list of boundary sets

  • :contains (Array<Float>, String)

    comma-separated latitude and longitude

  • :touches (String)

    a boundary

  • :intersects (String)

    a boundary

  • :limit (Integer)
  • :offset (Integer)

See Also:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gov_kit-ca/represent.rb', line 35

def boundaries(opts = {})
  if Array === opts[:sets]
    opts[:sets] = opts[:sets].join(',')
  end
  if Array === opts[:contains]
    opts[:contains] = opts[:contains].join(',')
  end
  if opts.has_key?(:boundary) && !opts.has_key?(:boundary_set)
    raise ArgumentError, ':boundary_set must be set if :boundary is set'
  end
  if opts[:representatives] && !(opts.has_key?(:boundary) && opts.has_key?(:boundary_set))
    raise ArgumentError, ':boundary_set and :boundary must be set if :representatives is true'
  end
  request(['boundaries', opts.delete(:boundary_set), opts.delete(:boundary), opts.delete(:representatives) && 'representatives'], opts)
end

#boundary_sets(opts = {}) ⇒ Object

Get boundary sets.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :boundary_set (String)

    a boundary set

  • :limit (Integer)
  • :offset (Integer)

See Also:



18
19
20
# File 'lib/gov_kit-ca/represent.rb', line 18

def boundary_sets(opts = {})
  request(['boundary-sets', opts.delete(:boundary_set)], opts)
end

#candidates(opts = {}) ⇒ Object

Get candidates.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :election (String)

    an election

  • :point (Array<Float>, String)

    a comma-separated latitude and longitude

  • :districts (Array<Strong>, String)

    a comma-separated list of boundaries

  • :limit (Integer)
  • :offset (Integer)

See Also:



115
116
117
118
119
120
121
122
123
# File 'lib/gov_kit-ca/represent.rb', line 115

def candidates(opts = {})
  if Array === opts[:point]
    opts[:point] = opts[:point].join(',')
  end
  if Array === opts[:districts]
    opts[:districts] = opts[:districts].join(',')
  end
  request(['candidates', opts.delete(:election)], opts)
end

#elections(opts = {}) ⇒ Object

Get elections.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :election (String)

    an election

  • :limit (Integer)
  • :offset (Integer)

See Also:



83
84
85
# File 'lib/gov_kit-ca/represent.rb', line 83

def elections(opts = {})
  request ['elections', opts.delete(:election)], opts
end

#postcodes(postcode, opts = {}) ⇒ Object

Get boundaries and representatives by postal code.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :sets (Array<String>, String)

    comma-separated list of boundary sets

  • :limit (Integer)
  • :offset (Integer)

See Also:



58
59
60
61
62
63
# File 'lib/gov_kit-ca/represent.rb', line 58

def postcodes(postcode, opts = {})
  if Array === opts[:sets]
    opts[:sets] = opts[:sets].join(',')
  end
  request(['postcodes', PostalCode.format_postal_code(postcode)], opts)
end

#representative_sets(opts = {}) ⇒ Object

Get representative sets.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :representative_set (String)

    a representative set

  • :limit (Integer)
  • :offset (Integer)

See Also:



72
73
74
# File 'lib/gov_kit-ca/represent.rb', line 72

def representative_sets(opts = {})
  request ['representative-sets', opts.delete(:representative_set)], opts
end

#representatives(opts = {}) ⇒ Object

Get representatives.

Parameters:

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :representative_set (String)

    a representative set

  • :point (Array<Float>, String)

    a comma-separated latitude and longitude

  • :districts (Array<Strong>, String)

    a comma-separated list of boundaries

  • :limit (Integer)
  • :offset (Integer)

See Also:



96
97
98
99
100
101
102
103
104
# File 'lib/gov_kit-ca/represent.rb', line 96

def representatives(opts = {})
  if Array === opts[:point]
    opts[:point] = opts[:point].join(',')
  end
  if Array === opts[:districts]
    opts[:districts] = opts[:districts].join(',')
  end
  request(['representatives', opts.delete(:representative_set)], opts)
end