Class: GovKit::CA::Represent
- Inherits:
-
Object
- Object
- GovKit::CA::Represent
- Defined in:
- lib/gov_kit-ca/represent.rb
Overview
A Ruby wrapper for the Represent API.
Instance Method Summary collapse
-
#boundaries(opts = {}) ⇒ Object
Get boundaries.
-
#boundary_sets(opts = {}) ⇒ Object
Get boundary sets.
-
#candidates(opts = {}) ⇒ Object
Get candidates.
-
#elections(opts = {}) ⇒ Object
Get elections.
-
#initialize(connection = nil) ⇒ Represent
constructor
A new instance of Represent.
-
#postcodes(postcode, opts = {}) ⇒ Object
Get boundaries and representatives by postal code.
-
#representative_sets(opts = {}) ⇒ Object
Get representative sets.
-
#representatives(opts = {}) ⇒ Object
Get representatives.
Constructor Details
#initialize(connection = nil) ⇒ Represent
Returns a new instance of Represent.
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.
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.
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.
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.
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.
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.
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.
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 |