Class: CivicAide::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
HTTParty
Defined in:
lib/civic_aide/client.rb

Constant Summary collapse

API_ENDPOINT =
'https://www.googleapis.com/civicinfo/'.freeze
API_VERSION =
'us_v1'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, official_only = nil) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
# File 'lib/civic_aide/client.rb', line 19

def initialize(api_key=nil, official_only=nil)
  @api_key, @official_only = api_key, official_only
  @api_key ||= CivicAide.api_key
  @official_only ||= CivicAide.official_only
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



16
17
18
# File 'lib/civic_aide/client.rb', line 16

def api_key
  @api_key
end

#official_onlyObject

Returns the value of attribute official_only.



17
18
19
# File 'lib/civic_aide/client.rb', line 17

def official_only
  @official_only
end

Instance Method Details

#elections(election_id = nil) ⇒ Object Also known as: election



39
40
41
# File 'lib/civic_aide/client.rb', line 39

def elections(election_id=nil)
  CivicAide::Elections.new(self, election_id)
end

#get(url, query = {}) ⇒ Object



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

def get(url, query={})
  response = self.class.get(url, :query => query.merge(self.default_query))
  format_response(response.body)
end

#post(url, query = {}, body = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/civic_aide/client.rb', line 30

def post(url, query={}, body={})
  response = self.class.post(url,
      :query => query.merge(self.default_query),
      :body => body.to_json
    )
  check_response_status(response['status'])
  format_response(response.body)
end

#representativesObject



44
45
46
# File 'lib/civic_aide/client.rb', line 44

def representatives
  CivicAide::Representatives.new(self)
end