A beautiful Ruby interface of Pemilu APIs
Developer Pemilu APIs has published a bunch of new excellent API endpoints, my planning is to released pemilu gem v2.0.0 to support all those APIs. so far i already implemented Pertanyaan API V1, see here. for the other APIs are in proccess. If you already extend this gem to support all those APIs, feel free to submit pull request.
- About PEMILU APIs 2014
- Installation
- How to use pemilu gem
- Configure API key
- APIs
- Candidate APIs
- Party APIs
- Province APIs
- Electoral District APIs
- Exception Handling
- Changelog
- Author
- License
As many as 180 million people are registered to vote in Indonesia's 2014 elections. An estimated 67 million of those people will be voting for the first time. Voters need answers. Am I registered? Where do candidates stand on the issues that are important to me? How do I mark the ballot? What can I do if I'm having trouble voting? To answer those questions, and many more, we're helping to build an open repository of information for Indonesian voters in 2014 — an elections API. - PEMILU APIs 2014
Add this line to your application's Gemfile:
gem 'pemilu'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pemilu
Before accessing all available APIs make sure Configure your API key first.
require "pemilu"
pemilu = Pemilu::API.new(key: "YOUR API KEY")
List of available attribute to each candidate that you can get some information
about candidate itself. For example candidate.id
will display id of candidate.
Attribute | Return | Description | #candidates |
#candidate |
---|---|---|---|---|
id |
String | ID of Candidate | x | x |
name |
String | Name of Candidate | x | x |
gender |
String | Gender of Candidate | x | x |
religion |
String | Religion of Candidate | x | x |
birthplace |
String | Birthplace of Candidate | x | x |
date_of_birth |
String | Date of Candidate birth | x | x |
marital_status |
String | Marital status of Candidate | x | x |
name_of_couples |
String | Name of Candidate couples | x | x |
number_of_children |
Integer | Number of Candidate children | x | x |
village |
String | Village where Candidate live | x | x |
sub_district |
String | Sub district where Candidate live | x | x |
district |
String | District where Candidate live | x | x |
province |
Hash | Province where Candidate live | x | x |
electoral_district |
Hash | Electoral district where Candidate running on | x | x |
election_year |
Integer | Election year where Candidate running on | x | x |
legislative_body |
String | Legislative body where Candidate running on (ex. DPR) | x | x |
party |
String | Party of Candidate | x | - |
party |
Hash | Party of Candidate | - | x |
ordinal |
Integer | Ordinal of Candidate | x | x |
picture |
String | URL of Candidate picture | x | x |
educations |
Array | List of Candidate education history | - | x |
jobs |
Array | List of Candidate job history | - | x |
organizations |
Array | List of Candidate organization history | - | x |
description:
x
mark is sign this attribute available when return from#candidates
or#candidate
-
mark is sign this attributenil
when return from#candidates
or#candidate
Return an array of Pemilu::Candidate
object that filtered by declared option.
pemilu.candidates(options = {})
Option | Value | Default | Description | Return |
---|---|---|---|---|
name |
String | nil |
String full or partial name of the candidate | Only all candidates that matching with name |
party |
String | nil |
Name of the available party | Only all candidates on the party |
electoral_district |
String | nil |
ID of electoral district (daerah pilihan) | Only all candidates that running on electoral district |
election_year |
Integer | nil |
Election year (tahun pemilihan)of candidate | Only all candidates that running on election year |
province |
String | nil |
ID of the Province | Only all candidates that running on province |
gender |
String | nil |
"L" for man and "W" for woman |
Only all candidates has gender specified |
religion |
String | nil |
Religion of the candidate | Only all candidates that have religion specified |
legislative_body |
String | nil |
Legislative body that the candidate is running for | Only all candidates that running on that legislative body |
limit |
Integer | 100 |
Number of records to return | All candidates on specific limit number |
offset |
Integer | nil |
Number the offset | All candidates from beginning of the offset number |
# get 10 man candidates
pemilu.candidates(limit: 10, gender: "L")
# print some information about 2 candidates with Islam religion
candidates = pemilu.candidates(limit:2, religion: "ISLAM")
candidates.each do |candidate|
puts "Name: #{candidate.name}"
puts "Regligion: #{candidate.religion}"
end
Return an object of Pemilu::Candidate
with an id
specified.
pemilu.candidate("ID CANDIDATE")
ID Candidate must be String. like this "1101-00-0000-0102"
# print some information about Candidate with id=1101-00-0000-0102
candidate = pemilu.candidate("1101-00-0000-0102")
puts "Name: #{candidate.name}"
List of available attribute to each Party that you can use for get some information
about party itself. For example party.id
will display id of party.
Attribute | Return | Decription | #parties |
#party |
---|---|---|---|---|
id |
Integer | ID of Party | x | x |
nick_name |
String | Nick name or abbreviation of Party | x | x |
full_name |
String | Full name of Party | x | x |
url |
String | URL to Party homepage | x | x |
facebook |
String | URL to Party facebook page | x | x |
twitter |
String | URL to Party twitter page | x | x |
description:
x
mark is sign this attribute available when return from#parties
or#party
-
mark is sign this attributenil
when return from#parties
or#party
Return an array of Pemilu::Party
object.
# get all parties
pemilu.parties
#=> [#<Pemilu::Party:0xb833bfcc....]
# print name and facebook url each for each party
pemilu.parties.each do |party|
puts "Party name: #{party.full_name}"
puts "Party facebook: #{party.facebook}"
end
Return one object of Pemilu::Party specified by ID.
pemilu.party("ID PARTY")
ID PARTY
must be an Integer.
# print information about Partai Demokrasi Indonesia Perjuangan
pdip = pemilu.party(4)
puts pdip.id #=> 4
puts pdip.nick_name #=> PDI-P
puts pdip.full_name #=> Partai Demokrasi Indonesia Perjuangan
puts pdip.facebook #=> https://www.facebook.com/DPP.PDI.Perjuangan
puts pdip.twitter #=> https://twitter.com/pdi_perjuangan
List of available attribute to each Province that you can use for get some information
about province itself. For example province.id
will display id of province.
Attribute | Return | Decription | #provinces |
#province |
---|---|---|---|---|
id |
Integer | ID of Province | x | x |
name |
String | Nick Name of Province | x | x |
full_name |
String | Full Name of Province | x | x |
international_name |
String | International Name (English) of Province | x | x |
available_chairs |
Integer | Availalble chairs for Candidates | x | x |
population |
Integer | Population of Province | x | x |
electoral_district |
Array | List of Electoral District on Province | - | x |
description:
x
mark is sign this attribute available when return from#provinces
or#province
-
mark is sign this attributenil
when return from#provinces
or#province
Return an array of Pemilu::Province
object.
# get all provinces
pemilu.provinces
#=> [#<Pemilu::Province:0xb8c4ceb8....]
# print id and international name of each province
pemilu.provinces.each do |province|
puts "ID: #{province.id}"
puts "Internatioal Name: #{province.international_name}"
end
Return one object of Pemilu::Province specified by ID.
pemilu.province("ID PROVINCE")
ID PROVINCE
must be an Integer.
# print information about Special Region of Aceh
aceh = pemilu.province(11)
puts aceh.id #=> 11
puts aceh.name #=> Aceh
puts aceh.international_name #=> Special Region of Aceh
List of available attribute to each Electoral District that you can use for get some information
about Electoral District itself. For example ed.id
will display id of Electoral District.
Attribute | Return | Decription | #electoral_districts |
#electoral_district |
---|---|---|---|---|
id |
String | ID of Electoral District | x | x |
name |
String | Name or Electoral District | x | x |
legislative_body |
String | Legislative body of Electoral District | x | x |
available_chairs |
Integer | Number of available chairs in Electoral District | x | x |
population |
Integer | Population in Electoral District | x | x |
province |
Hash | Province of Electoral District | x | X |
province.id |
Integer | Province id of Electoral District | x | x |
province.name |
String | Province name of Electoral District | x | x |
description:
x
mark is sign this attribute available when return from#parties
or#party
-
mark is sign this attributenil
when return from#parties
or#party
Return an array of Pemilu::ElectoralDistrict
object that filtered by declared option.
pemilu.electoral_districts(options = {})
Option | Value | Default | Description | Return |
---|---|---|---|---|
province |
String | nil |
Name of province | Only all electoral district in province |
legislative_body |
String | nil |
Legislative body of Electoral District | Only all electoral district that have specified legislative body |
# get electoral district on Aceh province
pemilu.electoral_districts(province: "Aceh")
Return one object of Pemilu::ElectoralDistrict specified by ID.
pemilu.electoral_district("ID ELETORAL DISTRICT")
ID ELECTORAL DISTRICT
should be String. Like this "1101-00-0000"
# print information about Aceh I electoral district
ed = pemilu.electoral_district("1101-00-0000")
puts ed.id #=> 1101-00-0000
puts ed.legislative_body #=> DPR
puts ed.available_chairs #=> 7
puts ed.population #=> 2642760
If you are using Invalid API key, all your request will return
Invalid request error. Please check your API key
If you are requesting ID for Candidate, Party, Province or Electoral District that didn't exist, your request will return
Can't get OBJECT with id: ID
note: OBJECT
and ID
are depend on your request. if you are requesting party(s)
the return will like this
Can't get Party with id: s
- add Handling Exception for Invalid APIs & ID object Didn't exist
- initial relase
- support all available APIs on Pemilu APIs
- pre-release
- only support Candidate APIs
Author |
---|
Bayu Aldi Yansyah |
S1 Matematika, 2013, Universitas Airlangga |
@peeyek |
MIT (c) 2014 Bayu Aldi Yansyah