Wednesday, November 28, 2018

pyk/pemilu: A beautiful Ruby interface of Pemilu APIs

A beautiful Ruby interface of Pemilu APIs



IMPORTANT : This gem is no longer maintaned by me.
Feel Free to fork and send PR



Update 9 Mar 2014


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.


Contents


  • About PEMILU APIs 2014

  • Installation

  • How to use pemilu gem
    • Configure API key

    • APIs
      • Candidate APIs
        • List of Candidate attributes

        • Get list of all Candidates

        • #candidates usage example

        • Get details of Candidate

        • #candidate usage example


      • Party APIs
        • List of Party attributes

        • Get list of all Parties

        • #parties usage example

        • Get details of Party

        • #party(id) usage example


      • Province APIs
        • List of Province attributes

        • Get list of all Provinces

        • #provinces usage example

        • Get details of Province

        • #province(id) usage example


      • Electoral District APIs
        • List of Electoral District attributes

        • Get list of all Electoral Districts

        • #electoral_districts usage example

        • Get details of Electoral District

        • #electoral_district(id) usage example



    • Exception Handling
      • Invalid API key

      • ID Didn't exist



  • Changelog

  • Author

  • License

PEMILU APIs 2014



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



Installation


Add this line to your application's Gemfile:



And then execute:



Or install it yourself as:



How to use pemilu gem


Configure


Before accessing all available APIs make sure Configure your API key first.


require "pemilu"

pemilu = Pemilu::API.new(key: "YOUR API KEY")

APIs


List of Candidate attributes object


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.


























































































































AttributeReturnDescription#candidates#candidate
idStringID of Candidatexx
nameStringName of Candidatexx
genderStringGender of Candidatexx
religionStringReligion of Candidatexx
birthplaceStringBirthplace of Candidatexx
date_of_birthStringDate of Candidate birthxx
marital_statusStringMarital status of Candidatexx
name_of_couplesStringName of Candidate couplesxx
number_of_childrenIntegerNumber of Candidate childrenxx
villageStringVillage where Candidate livexx
sub_districtStringSub district where Candidate livexx
districtStringDistrict where Candidate livexx
provinceHashProvince where Candidate livexx
electoral_districtHashElectoral district where Candidate running onxx
election_yearIntegerElection year where Candidate running onxx
legislative_bodyStringLegislative body where Candidate running on (ex. DPR)xx
partyStringParty of Candidatex-
partyHashParty of Candidate-x
ordinalIntegerOrdinal of Candidatexx
pictureStringURL of Candidate picturexx
educationsArrayList of Candidate education history-x
jobsArrayList of Candidate job history-x
organizationsArrayList of Candidate organization history-x

description:


  • x mark is sign this attribute available when return from #candidates or #candidate

  • - mark is sign this attribute nil when return from #candidates or #candidate

Get list of all candidates


Return an array of Pemilu::Candidate object that filtered by declared option.


pemilu.candidates(options = )
Available options
























































OptionValueDefaultDescriptionReturn
nameStringnilString full or partial name of the candidateOnly all candidates that matching with name
partyStringnilName of the available partyOnly all candidates on the party
electoral_districtStringnilID of electoral district (daerah pilihan)Only all candidates that running on electoral district
election_yearIntegernilElection year (tahun pemilihan)of candidateOnly all candidates that running on election year
provinceStringnilID of the ProvinceOnly all candidates that running on province
genderStringnil"L" for man and "W" for womanOnly all candidates has gender specified
religionStringnilReligion of the candidateOnly all candidates that have religion specified
legislative_bodyStringnilLegislative body that the candidate is running forOnly all candidates that running on that legislative body
limitInteger100Number of records to returnAll candidates on specific limit number
offsetIntegernilNumber the offsetAll candidates from beginning of the offset number

#candidates usage example


# 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: #"
puts "Regligion: #"
end

Get details of Candidate


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"


#candidate usage example


# print some information about Candidate with id=1101-00-0000-0102
candidate = pemilu.candidate("1101-00-0000-0102")
puts "Name: #"

List of Party attributes object


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.





































AttributeReturnDecription#parties#party
idIntegerID of Partyxx
nick_nameStringNick name or abbreviation of Partyxx
full_nameStringFull name of Partyxx
urlStringURL to Party homepagexx
facebookStringURL to Party facebook pagexx
twitterStringURL to Party twitter pagexx

description:


  • x mark is sign this attribute available when return from #parties or
    #party

  • - mark is sign this attribute nil when return from #parties or #party

Get list of all Parties


Return an array of Pemilu::Party object.


# get all parties
pemilu.parties
#=> [#<Pemilu::Party:0xb833bfcc....]

#parties usage example


# print name and facebook url each for each party
pemilu.parties.each do |party|
puts "Party name: #"
puts "Party facebook: #"
end

Get details of Party


Return one object of Pemilu::Party specified by ID.



ID PARTY must be an Integer.


#party(id) usage example


# 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 Province attributes object


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.










































AttributeReturnDecription#provinces#province
idIntegerID of Provincexx
nameStringNick Name of Provincexx
full_nameStringFull Name of Provincexx
international_nameStringInternational Name (English) of Provincexx
available_chairsIntegerAvailalble chairs for Candidatesxx
populationIntegerPopulation of Provincexx
electoral_districtArrayList of Electoral District on Province-x

description:


  • x mark is sign this attribute available when return from #provinces or
    #province

  • - mark is sign this attribute nil when return from #provinces or #province

Get list of all Provinces


Return an array of Pemilu::Province object.


# get all provinces
pemilu.provinces
#=> [#<Pemilu::Province:0xb8c4ceb8....]

#provinces usage example


# print id and international name of each province
pemilu.provinces.each do |province|
puts "ID: #"
puts "Internatioal Name: #"
end

Get details of Province


Return one object of Pemilu::Province specified by ID.


pemilu.province("ID PROVINCE")

ID PROVINCE must be an Integer.


#province(id) usage example


# 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 Electoral District attribute


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.















































AttributeReturnDecription#electoral_districts#electoral_district
idStringID of Electoral Districtxx
nameStringName or Electoral Districtxx
legislative_bodyStringLegislative body of Electoral Districtxx
available_chairsIntegerNumber of available chairs in Electoral Districtxx
populationIntegerPopulation in Electoral Districtxx
provinceHashProvince of Electoral DistrictxX
province.idIntegerProvince id of Electoral Districtxx
province.nameStringProvince name of Electoral Districtxx

description:


  • x mark is sign this attribute available when return from #parties or
    #party

  • - mark is sign this attribute nil when return from #parties or #party

Get list of all electoral district


Return an array of Pemilu::ElectoralDistrict object that filtered by declared option.


pemilu.electoral_districts(options = )
Available options
















OptionValueDefaultDescriptionReturn
provinceStringnilName of provinceOnly all electoral district in province
legislative_bodyStringnilLegislative body of Electoral DistrictOnly all electoral district that have specified legislative body

#electoral_districts usage example


# get electoral district on Aceh province
pemilu.electoral_districts(province: "Aceh")

Get details of Electoral District


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"


#electoral_district(id) usage example


# 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

Exception Handling


Invalid API key


If you are using Invalid API key, all your request will return


Invalid request error. Please check your API key

ID Didn't exist

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

Changelog


1.0.1 March 3, 2014

  • add Handling Exception for Invalid APIs & ID object Didn't exist

1.0.0 March 2, 2014

  • initial relase

  • support all available APIs on Pemilu APIs

0.5.1 March 1, 2014

  • pre-release

  • only support Candidate APIs

Author






Author
Bayu Aldi Yansyah
S1 Matematika, 2013, Universitas Airlangga
@peeyek

License


MIT (c) 2014 Bayu Aldi Yansyah


Analytics




Source

No comments:

Post a Comment