Class: OpenAustralia::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/openaustralia/api.rb

Overview

Ruby wrapper for the openaustralia.org API

You’ll need an API key: get one at openaustralia.org/api

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Api

create an API instance with the specified key Get your key from openaustralia.org/api



24
25
26
27
# File 'lib/openaustralia/api.rb', line 24

def initialize(key)
  @key = key
  @xml_getter = XmlGetter.new #replaced for unit tests
end

Instance Method Details

#get_comments(search_params = {}) ⇒ Object

Fetch comments left on OpenAustralia.

With no arguments, returns most recent comments in reverse date order. Arguments

date (optional)

Fetch the comments for this date.

search (optional)

Fetch the comments that contain this term.

user_id (optional)

Fetch the comments by a particular user ID.

pid

Fetch the comments made on a particular person ID (Representative/Senator).

page (optional)

Page of results to return.

num (optional)

Number of results to return.


201
202
203
204
# File 'lib/openaustralia/api.rb', line 201

def get_comments(search_params = {})
  xml = do_request('getComments', search_params)
  CommentsSearch.load_from_xml xml
end

#get_debates(search_params = {}) ⇒ Object

Fetch Debates.

This includes Oral Questions. Arguments

Note you can only supply one of the following search terms at present.

type (required)

One of "representatives" or "senate".

date

Fetch the debates for this date.

search

Fetch the debates that contain this term.

person

Fetch the debates by a particular person ID.

gid

Fetch the speech or debate that matches this GID.

order (optional, when using search or person)

d for date ordering, r for relevance ordering.

page (optional, when using search or person)

Page of results to return.

num (optional, when using search or person)

Number of results to return.


158
159
160
161
# File 'lib/openaustralia/api.rb', line 158

def get_debates(search_params = {})
  xml = do_request('getDebates', search_params)
  DebateSearch.load_from_xml xml.root
end

#get_divisions(search_params = {}) ⇒ Object

get_divisions returns a list of electoral divisions

supported search parameters:

postcode (optional)
  Fetch the list of electoral divisions that are within the given
  postcode (there can be more than one)
date (optional)
  Fetch the list of electoral divisions as it was on this date.
search (optional)
  Fetch the list of electoral divisions that match this search string.

example:

get_disivions :postcode => 3022

NB: at the time of writing, only the postcode parameter seems to actually work.



45
46
47
48
# File 'lib/openaustralia/api.rb', line 45

def get_divisions(search_params = {})
  xml = do_request('getDivisions', search_params)
  DivisionResult.load_from_xml xml
end

#get_hansard(search_params = {}) ⇒ Object

Fetch all Hansard. Arguments

Note you can only supply one of the following at present.

search

Fetch the data that contain this term.

person

Fetch the data by a particular person ID.

order (optional, when using search or person, defaults to date)

d for date ordering, r for relevance ordering, p for use by person.

page (optional, when using search or person)

Page of results to return.

num (optional, when using search or person)

Number of results to return.


179
180
181
182
# File 'lib/openaustralia/api.rb', line 179

def get_hansard(search_params = {})
  xml = do_request('getHansard', search_params)
  HansardSearch.load_from_xml xml.root
end

#get_representative(search_params = {}) ⇒ Object

Fetch a particular member of the House of Representatives.

Arguments

id (optional)

If you know the person ID for the member you want (returned from
getRepresentatives or elsewhere), this will return data for
that person.

division (optional)

The name of an electoral division; we will try and work it out from
whatever you give us. :)

always_return (optional)

For the division option, sets whether to always try and return a
Representative, even if the seat is currently vacant.

example:

get_representative :id => 10001


68
69
70
71
72
# File 'lib/openaustralia/api.rb', line 68

def get_representative(search_params = {})
  xml = do_request('getRepresentative', search_params)
  result = RepresentativeResult.load_from_xml xml
  result.matches.first
end

#get_representatives(search_params = {}) ⇒ Object

Fetch a list of members of the House of Representatives. Arguments

postcode (optional)

Fetch the list of Representatives whose electoral division lies within
the postcode (there may be more than one)

date (optional)

Fetch the list of members of the House of Representatives as it was on
this date.

party (optional)

Fetch the list of Representatives from the given party.

search (optional)

Fetch the list of Representatives that match this search string in
their name.

example

api.get_representatives :postcode => 2000

NB: if more than one representative is returned, then the ‘office’ array

will be empty.


94
95
96
97
98
# File 'lib/openaustralia/api.rb', line 94

def get_representatives(search_params = {})
  xml = do_request('getRepresentatives', search_params)
  result = RepresentativeResult.load_from_xml xml
  result.matches
end

#get_senator(search_params = {}) ⇒ Object

Fetch a particular Senator. Arguments

id (required)

If you know the person ID for the Senator you want, this will return data for that person.

example

api.get_senator :id => 10214


108
109
110
111
112
# File 'lib/openaustralia/api.rb', line 108

def get_senator(search_params = {})
  xml = do_request('getSenator', search_params)
  result = SenatorResult.load_from_xml xml
  result.matches.first
end

#get_senators(search_params = {}) ⇒ Object

Fetch a list of Senators. Arguments

date (optional)

Fetch the list of Senators as it was on this date.

party (optional)

Fetch the list of Senators from the given party.

state (optional)

Fetch the list of Senators from the given state.

search (optional)

Fetch the list of Senators that match this search string in their name.

example

api.get_senators :search => 'brown'


129
130
131
132
133
# File 'lib/openaustralia/api.rb', line 129

def get_senators(search_params = {})
  xml = do_request('getSenators', search_params)
  result = SenatorSearchResult.load_from_xml xml
  result.matches
end