pemilu 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +1 -0
- data/lib/pemilu/api.rb +110 -0
- data/lib/pemilu/candidate.rb +31 -0
- data/lib/pemilu/hash_extension.rb +9 -0
- data/lib/pemilu/version.rb +3 -0
- data/lib/pemilu.rb +10 -0
- data/pemilu.gemspec +24 -0
- data/spec/pemilu/api_spec.rb +75 -0
- data/spec/pemilu/candidate_spec.rb +75 -0
- data/spec/spec_helper.rb +18 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b972a663d36270f5cb44ac23f67912c49dab9275
|
4
|
+
data.tar.gz: 1688f1637c95559c5cf1e8d3b614d6315f83058e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 304c05b90f80d5cad9e671c39869657f8410938ac58457b3c0d82f659f5f8f15cd7629ebf05deb31463fcad2c980ab067df4d1ebc99c96df898f2e7edc5e108a
|
7
|
+
data.tar.gz: db067f0cd237b00a26b90efb6ba6e07e2fc49e17eea8b36a398d1251b4e1d960c28b3710a4ea2415b6c59619a18ad2f8d20f2f6dd277205809298e2f325c6e49
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bayu Aldi Yansyah
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# pemilu
|
2
|
+
A beautiful Ruby interface of [Pemilu APIs](http://pemiluapi.org)
|
3
|
+
|
4
|
+
## Contents
|
5
|
+
- [Installation](in)
|
6
|
+
- [How to use pemilu gem](ht)
|
7
|
+
- [Configure API key](c)
|
8
|
+
- [APIs](a)
|
9
|
+
- [List of Candidate attributes](ca)
|
10
|
+
- [Get list of all Candidates (`#candidates`)](g)
|
11
|
+
- [`#candidates` usage example](cux)
|
12
|
+
- [Get details of Candidate (`#candidate`)](gdoc)
|
13
|
+
- [`#candidate` usage example](cue)
|
14
|
+
- Get list of all Parties [**wait for the next release**](si)
|
15
|
+
- Get details of Party [**wait for the next release**](si)
|
16
|
+
- Get list of all Provinces [**wait for the next release**](si)
|
17
|
+
- Get details of Province [**wait for the next release**](si)
|
18
|
+
- Get list of all Electoral Districts [**wait for the next release**](si)
|
19
|
+
- Get details of Electoral District [**wait for the next release**](si)
|
20
|
+
|
21
|
+
[in]: http
|
22
|
+
[ht]: http
|
23
|
+
[c]: http
|
24
|
+
[a]: http
|
25
|
+
[ca]: http
|
26
|
+
[g]: http
|
27
|
+
[cux]: http
|
28
|
+
[gdoc]: http
|
29
|
+
[cue]: http
|
30
|
+
[si]: http
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem 'test'
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install test
|
44
|
+
|
45
|
+
|
46
|
+
## How to use pemilu gem
|
47
|
+
|
48
|
+
### Configure
|
49
|
+
Before accessing all available [APIs](a) make sure Configure your API key first.
|
50
|
+
|
51
|
+
require "pemilu"
|
52
|
+
|
53
|
+
pemilu = Pemilu::API.new(key: "YOUR API KEY")
|
54
|
+
|
55
|
+
### APIs
|
56
|
+
|
57
|
+
#### List of Candidate attributes object
|
58
|
+
List of available attribute to each candidate that you can get some information
|
59
|
+
about candidate itself. For example `candidate.id` will display id of candidate.
|
60
|
+
|
61
|
+
|Attribute|Return|Description|`#candidates`|`#candidate`|
|
62
|
+
---------------------------------------------------------
|
63
|
+
|`id`|String|ID of Candidate|x|x|
|
64
|
+
|`name`|String|Name of Candidate|x|x|
|
65
|
+
|`gender`|String|Gender of Candidate|x|x|
|
66
|
+
|`religion`|String|Religion of Candidate|x|x|
|
67
|
+
|`birthplace`|String|Birthplace of Candidate|x|x|
|
68
|
+
|`date_of_birth`|String|Date of Candidate birth|x|x|
|
69
|
+
|`marital_status`|String|Marital status of Candidate|x|x|
|
70
|
+
|`name_of_couples`|String|Name of Candidate couples|x|x|
|
71
|
+
|`number_of_children`|Integer|Number of Candidate children|x|x|
|
72
|
+
|`village`|String|Village where Candidate live|x|x|
|
73
|
+
|`sub_district`|String|Sub district where Candidate live|x|x|
|
74
|
+
|`district`|String|District where Candidate live|x|x|
|
75
|
+
|`province`|Hash|Province where Candidate live|x|x|
|
76
|
+
|`electoral_district`|Hash|Electoral district where Candidate running on|x|x|
|
77
|
+
|`election_year`|Integer|Election year where Candidate running on|x|x|
|
78
|
+
|`legislative_body`|String|Legislative body where Candidate running on (ex. DPR)|x|x|
|
79
|
+
|`party`|String|Party of Candidate|x|-|
|
80
|
+
|`party`|Hash|Party of Candidate|-|x|
|
81
|
+
|`ordinal`|Integer|Ordinal of Candidate|x|x|
|
82
|
+
|`picture`|String|URL of Candidate picture|x|x|
|
83
|
+
|`educations`|Array|List of Candidate education history|-|x|
|
84
|
+
|`jobs`|Array|List of Candidate job history|-|x|
|
85
|
+
|`organizations`|Array|List of Candidate organization history|-|x|
|
86
|
+
|
87
|
+
#### Get list of all candidates
|
88
|
+
Return an array of `Pemilu::Candidate` object that filtered by declared option.
|
89
|
+
|
90
|
+
pemilu.candidates(options = {})
|
91
|
+
|
92
|
+
##### Available options
|
93
|
+
|
94
|
+
|Option|Value|Default|Description|Return|
|
95
|
+
-----------------------------------------
|
96
|
+
|`name`|String|`nil`|String full or partial name of the candidate|Only all candidates that matching with `name`|
|
97
|
+
|`party`|String|`nil`|Name of the available party|Only all candidates on the `party`|
|
98
|
+
|`electoral_district`|String|`nil`|ID of electoral district (daerah pilihan)|Only all candidates that running on electoral district|
|
99
|
+
|`election_year`|Integer|`nil`|Election year (tahun pemilihan)of candidate|Only all candidates that running on election year|
|
100
|
+
|`province`|String|`nil`|ID of the Province|Only all candidates that running on `province`|
|
101
|
+
|`gender`|String|`nil`|`"L"` for man and `"W"` for woman|Only all candidates has `gender` specified|
|
102
|
+
|`religion`|String|`nil`|Religion of the candidate|Only all candidates that have religion specified|
|
103
|
+
|`legislative_body`|String|`nil`|Legislative body that the candidate is running for|Only all candidates that running on that legislative body|
|
104
|
+
|`limit`|Integer|`100`| Number of records to return| All candidates on specific limit number|
|
105
|
+
|`offset`|Integer|`nil`|Number the offset|All candidates from beginning of the offset number|
|
106
|
+
|
107
|
+
#### `#candidates` usage example
|
108
|
+
|
109
|
+
# get 10 man candidates
|
110
|
+
pemilu.candidates(limit: 10, gender: "L")
|
111
|
+
|
112
|
+
# print some information about 2 candidates with Islam religion
|
113
|
+
candidates = pemilu.candidates(limit:2, religion: "ISLAM")
|
114
|
+
candidates.each do |candidate|
|
115
|
+
puts "Name: #{candidate.name}"
|
116
|
+
puts "Regligion: #{candidate.religion}"
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
#### Get details of Candidate
|
121
|
+
Return an object of `Pemilu::Candidate` with an `id` specified.
|
122
|
+
|
123
|
+
pemilu.candidate("ID CANDIDATE")
|
124
|
+
|
125
|
+
#### `#candidate` usage example
|
126
|
+
|
127
|
+
# print some information about Candidate with id=1101-00-0000-0102
|
128
|
+
candidate = pemilu.candidate("1101-00-0000-0102")
|
129
|
+
puts "Name: #{candidate.name}"
|
130
|
+
|
131
|
+
## Still in active development
|
132
|
+
23:32 Saturday, 1 March 2014.
|
133
|
+
Sorry this gem is still under development. Actually you can use it on production
|
134
|
+
because this gem is [well tested](wt). But, you don't get full feature yet.
|
135
|
+
Please wait for the next release. You can give me a shot at [@peeyek](pyk) on twitter.
|
136
|
+
|
137
|
+
[wt]: http://linktospec
|
138
|
+
[pyk] : http:/twitterlink
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/pemilu/api.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require "pp"
|
2
|
+
module Pemilu
|
3
|
+
class API
|
4
|
+
|
5
|
+
attr_reader :key
|
6
|
+
|
7
|
+
def initialize(key: nil)
|
8
|
+
@key = key
|
9
|
+
end
|
10
|
+
|
11
|
+
def candidates(name: nil, party: nil, electoral_district: nil, election_year: nil, province: nil, gender: nil, religion: nil, legislative_body: nil, limit: 100, offset: nil)
|
12
|
+
|
13
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/caleg")
|
14
|
+
params = {
|
15
|
+
apiKey: @key,
|
16
|
+
nama: name,
|
17
|
+
partai: party,
|
18
|
+
dapil: electoral_district,
|
19
|
+
tahun: election_year,
|
20
|
+
provinsi: province,
|
21
|
+
jenis_kelamin: gender,
|
22
|
+
agama: religion,
|
23
|
+
lembaga: legislative_body,
|
24
|
+
limit: limit,
|
25
|
+
offset: offset
|
26
|
+
}
|
27
|
+
params.delete_if{ |k,v| v.nil? }
|
28
|
+
uri.query = URI.encode_www_form(params)
|
29
|
+
respond = Net::HTTP.get_response(uri)
|
30
|
+
result = []
|
31
|
+
if respond.is_a?(Net::HTTPSuccess)
|
32
|
+
data = JSON.parse(respond.body)
|
33
|
+
@total_candidate = data["data"]["results"]["total"]
|
34
|
+
candidates = data["data"]["results"]["caleg"]
|
35
|
+
candidates.each do |caleg|
|
36
|
+
result << Pemilu::Candidate.new(
|
37
|
+
id: caleg["id"],
|
38
|
+
name: caleg["nama"],
|
39
|
+
gender: caleg["jenis_kelamin"],
|
40
|
+
religion: caleg["agama"],
|
41
|
+
birthplace: caleg["tempat_lahir"],
|
42
|
+
date_of_birth: caleg["tanggal_lahir"],
|
43
|
+
marital_status: caleg["status_perkawinan"],
|
44
|
+
name_of_couples: caleg["nama_pasangan"],
|
45
|
+
number_of_children: caleg["jumlah_anak"],
|
46
|
+
village: caleg["kelurahan_tinggal"],
|
47
|
+
sub_district: caleg["kecamatan_tinggal"],
|
48
|
+
district: caleg["kab_kota_tinggal"],
|
49
|
+
province: {
|
50
|
+
"id" => caleg["provinsi"]["id"],
|
51
|
+
"name" => caleg["provinsi"]["nama"]
|
52
|
+
},
|
53
|
+
electoral_district: {
|
54
|
+
"id" => caleg["dapil"]["id"],
|
55
|
+
"nama" => caleg["dapil"]["nama"]
|
56
|
+
},
|
57
|
+
election_year: caleg["tahun"],
|
58
|
+
legislative_body: caleg["lembaga"],
|
59
|
+
party: caleg["partai"],
|
60
|
+
ordinal: caleg["urutan"],
|
61
|
+
picture: caleg["foto_url"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
return "Can't reach the http://api.pemiluapi.org"
|
65
|
+
end
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
def candidate(id)
|
70
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/caleg/#{id}")
|
71
|
+
params = { apiKey: @key }
|
72
|
+
uri.query = URI.encode_www_form(params)
|
73
|
+
respond = Net::HTTP.get_response(uri)
|
74
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
75
|
+
candidate = data["data"]["results"]["caleg"][0]
|
76
|
+
return Pemilu::Candidate.new(
|
77
|
+
id: candidate["id"],
|
78
|
+
name: candidate["nama"],
|
79
|
+
gender: candidate["jenis_kelamin"],
|
80
|
+
religion: candidate["agama"],
|
81
|
+
birthplace: candidate["tempat_lahir"],
|
82
|
+
date_of_birth: candidate["tanggal_lahir"],
|
83
|
+
marital_status: candidate["status_perkawinan"],
|
84
|
+
name_of_couples: candidate["nama_pasangan"],
|
85
|
+
number_of_children: candidate["jumlah_anak"].to_i,
|
86
|
+
village: candidate["kelurahan_tinggal"],
|
87
|
+
sub_district: candidate["kecamatan_tinggal"],
|
88
|
+
district: candidate["kab_kota_tinggal"],
|
89
|
+
province: {
|
90
|
+
"id" => candidate["provinsi"]["id"],
|
91
|
+
"name" => candidate["provinsi"]["nama"]
|
92
|
+
},
|
93
|
+
electoral_district: {
|
94
|
+
"id" => candidate["dapil"]["id"],
|
95
|
+
"name" => candidate["dapil"]["nama"]
|
96
|
+
},
|
97
|
+
election_year: candidate["tahun"],
|
98
|
+
legislative_body: candidate["lembaga"],
|
99
|
+
party: {
|
100
|
+
"id" => candidate["partai"]["id"].to_i,
|
101
|
+
"name" => candidate["partai"]["nama"]
|
102
|
+
},
|
103
|
+
ordinal: candidate["urutan"],
|
104
|
+
picture: candidate["foto_url"],
|
105
|
+
educations: candidate["riwayat_pendidikan"],
|
106
|
+
jobs: candidate["riwayat_pekerjaan"],
|
107
|
+
organizations: candidate["riwayat_organisasi"])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Pemilu
|
2
|
+
class Candidate
|
3
|
+
attr_reader :id, :name, :gender, :religion, :birthplace, :date_of_birth, :marital_status, :name_of_couples, :number_of_children, :village, :sub_district, :district, :province, :electoral_district, :election_year, :legislative_body, :party, :ordinal, :picture, :educations, :jobs, :organizations
|
4
|
+
|
5
|
+
def initialize( id: nil, name: nil, gender: nil, religion: nil, birthplace: nil, date_of_birth: nil, marital_status: nil, name_of_couples: nil, number_of_children: nil, village: nil, sub_district: nil, district: nil, province: nil, electoral_district: nil, election_year: nil, legislative_body: nil, party: nil, ordinal: nil, picture: nil, educations: nil, jobs: nil, organizations: nil)
|
6
|
+
|
7
|
+
@id = id
|
8
|
+
@name = name
|
9
|
+
@gender = gender
|
10
|
+
@religion = religion
|
11
|
+
@birthplace = birthplace
|
12
|
+
@date_of_birth = date_of_birth
|
13
|
+
@marital_status = marital_status
|
14
|
+
@name_of_couples = name_of_couples
|
15
|
+
@number_of_children = number_of_children
|
16
|
+
@village = village
|
17
|
+
@sub_district = sub_district
|
18
|
+
@district = district
|
19
|
+
@province = province
|
20
|
+
@electoral_district = electoral_district
|
21
|
+
@election_year = election_year
|
22
|
+
@legislative_body = legislative_body
|
23
|
+
@party = party
|
24
|
+
@ordinal = ordinal
|
25
|
+
@picture = picture
|
26
|
+
@educations = educations
|
27
|
+
@jobs = jobs
|
28
|
+
@organizations = organizations
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/pemilu.rb
ADDED
data/pemilu.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pemilu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pemilu"
|
8
|
+
spec.version = Pemilu::VERSION
|
9
|
+
spec.authors = ["Bayu Aldi Yansyah"]
|
10
|
+
spec.email = ["bayualdiyansyah@gmail.com"]
|
11
|
+
spec.summary = %q{A beautiful Ruby interface for Pemilu APIs (pemiluapi.org)}
|
12
|
+
spec.description = %q{A beautiful Ruby interface for Pemilu APIs}
|
13
|
+
spec.homepage = "https://github.com/pyk/pemilu"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Pemilu
|
4
|
+
describe API do
|
5
|
+
describe "new" do
|
6
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
7
|
+
|
8
|
+
it "should an object" do
|
9
|
+
pemilu.class.should be_a(Object)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#key" do
|
15
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
16
|
+
|
17
|
+
it "should return 06ec082d057daa3d310b27483cc3962e" do
|
18
|
+
expect(pemilu.key).to eq("06ec082d057daa3d310b27483cc3962e")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#candidates" do
|
23
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
24
|
+
|
25
|
+
it "should return an array" do
|
26
|
+
pemilu.candidates.should be_a(Array)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return an array of Pemilu::Candidate object" do
|
30
|
+
pemilu.candidates.each do |candidate|
|
31
|
+
expect(candidate.class).to eq(Pemilu::Candidate)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#candidate" do
|
37
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
38
|
+
|
39
|
+
it "should return one Pemilu::Candidate object" do
|
40
|
+
caleg = pemilu.candidate("1101-00-0000-0102")
|
41
|
+
expect(caleg.class).to eq(Pemilu::Candidate)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return details of candidate" do
|
45
|
+
caleg = pemilu.candidate("1101-00-0000-0102")
|
46
|
+
expect(caleg.id).to eq("1101-00-0000-0102")
|
47
|
+
expect(caleg.name).to eq("Drs. H. T. PRIBADI")
|
48
|
+
expect(caleg.gender).to eq("L")
|
49
|
+
expect(caleg.religion).to eq("ISLAM")
|
50
|
+
expect(caleg.birthplace).to eq("BANDA ACEH")
|
51
|
+
expect(caleg.date_of_birth).to eq("1950-01-19")
|
52
|
+
expect(caleg.marital_status).to eq("KAWIN")
|
53
|
+
expect(caleg.name_of_couples).to eq("CUT MUSRI")
|
54
|
+
expect(caleg.number_of_children).to eq(3)
|
55
|
+
expect(caleg.village).to eq("GEUCEU INIEM")
|
56
|
+
expect(caleg.sub_district).to eq("BANDA RAYA")
|
57
|
+
expect(caleg.district).to eq("KOTA BANDA ACEH")
|
58
|
+
expect(caleg.province.id).to eq(11)
|
59
|
+
expect(caleg.province.name).to eq("Aceh")
|
60
|
+
expect(caleg.electoral_district.id).to eq("1101-00-0000")
|
61
|
+
expect(caleg.electoral_district.name).to eq("Aceh I")
|
62
|
+
expect(caleg.election_year).to eq(2014)
|
63
|
+
expect(caleg.legislative_body).to eq("DPR")
|
64
|
+
expect(caleg.party.id).to eq(1)
|
65
|
+
expect(caleg.party.name).to eq("Partai NasDem")
|
66
|
+
expect(caleg.ordinal).to eq(2)
|
67
|
+
expect(caleg.picture).to eq("http://dct.kpu.go.id/images/foto/DPR/1101.%20ACEH%20I/01.%20NASDEM/02.%20DRS.%20H.T.%20PRIBADI.JPG")
|
68
|
+
expect(caleg.educations.class).to eq(Array)
|
69
|
+
expect(caleg.jobs.class).to eq(Array)
|
70
|
+
expect(caleg.organizations.class).to eq(Array)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Pemilu
|
4
|
+
describe Candidate do
|
5
|
+
describe "new" do
|
6
|
+
let(:candidate) { Pemilu::Candidate.new(
|
7
|
+
id: 1,
|
8
|
+
name: "bayu aldi yansyah",
|
9
|
+
gender: "L",
|
10
|
+
religion: "ISLAM",
|
11
|
+
birthplace: "Nganjuk",
|
12
|
+
date_of_birth: "07 Oktober 1996",
|
13
|
+
marital_status: "Di PHPin",
|
14
|
+
name_of_couples: "Pevita Pearce",
|
15
|
+
number_of_children: 100,
|
16
|
+
village: "Keloposepuluh",
|
17
|
+
sub_district: "Sukodono",
|
18
|
+
district: "Sidoarjo",
|
19
|
+
province: {
|
20
|
+
"id" => 2,
|
21
|
+
"name" => "Jawa Timur"
|
22
|
+
},
|
23
|
+
electoral_district: {
|
24
|
+
"id" => 20,
|
25
|
+
"name" => "Sidoarjo"
|
26
|
+
},
|
27
|
+
election_year: 2014,
|
28
|
+
legislative_body: "DPR",
|
29
|
+
party: "Partai Asolole jos!",
|
30
|
+
ordinal: 1,
|
31
|
+
picture: "hhtp://foto.jpg",
|
32
|
+
educations: [{
|
33
|
+
"id" => 9,
|
34
|
+
"ringkasan" => "Test"
|
35
|
+
}],
|
36
|
+
jobs: [{
|
37
|
+
"id" => 9,
|
38
|
+
"ringkasan" => "Test"
|
39
|
+
}],
|
40
|
+
organizations: [{
|
41
|
+
"id" => 9,
|
42
|
+
"ringkasan" => "Test"
|
43
|
+
}] ) }
|
44
|
+
|
45
|
+
it "should return a correct candidate details" do
|
46
|
+
expect(candidate.id).to eq(1)
|
47
|
+
expect(candidate.name).to eq("bayu aldi yansyah")
|
48
|
+
expect(candidate.gender).to eq("L")
|
49
|
+
expect(candidate.religion).to eq("ISLAM")
|
50
|
+
expect(candidate.birthplace).to eq("Nganjuk")
|
51
|
+
expect(candidate.date_of_birth).to eq("07 Oktober 1996")
|
52
|
+
expect(candidate.marital_status).to eq("Di PHPin")
|
53
|
+
expect(candidate.name_of_couples).to eq("Pevita Pearce")
|
54
|
+
expect(candidate.number_of_children).to eq(100)
|
55
|
+
expect(candidate.number_of_children).to eq(100)
|
56
|
+
expect(candidate.village).to eq("Keloposepuluh")
|
57
|
+
expect(candidate.sub_district).to eq("Sukodono")
|
58
|
+
expect(candidate.district).to eq("Sidoarjo")
|
59
|
+
expect(candidate.province.id).to eq(2)
|
60
|
+
expect(candidate.province.name).to eq("Jawa Timur")
|
61
|
+
expect(candidate.electoral_district.id).to eq(20)
|
62
|
+
expect(candidate.electoral_district.name).to eq("Sidoarjo")
|
63
|
+
expect(candidate.election_year).to eq(2014)
|
64
|
+
expect(candidate.legislative_body).to eq("DPR")
|
65
|
+
expect(candidate.party).to eq("Partai Asolole jos!")
|
66
|
+
expect(candidate.ordinal).to eq(1)
|
67
|
+
expect(candidate.picture).to eq("hhtp://foto.jpg")
|
68
|
+
expect(candidate.educations.class).to eq(Array)
|
69
|
+
expect(candidate.jobs.class).to eq(Array)
|
70
|
+
expect(candidate.organizations.class).to eq(Array)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "pemilu"
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
5
|
+
# loaded once.
|
6
|
+
#
|
7
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pemilu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bayu Aldi Yansyah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A beautiful Ruby interface for Pemilu APIs
|
56
|
+
email:
|
57
|
+
- bayualdiyansyah@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/pemilu.rb
|
69
|
+
- lib/pemilu/api.rb
|
70
|
+
- lib/pemilu/candidate.rb
|
71
|
+
- lib/pemilu/hash_extension.rb
|
72
|
+
- lib/pemilu/version.rb
|
73
|
+
- pemilu.gemspec
|
74
|
+
- spec/pemilu/api_spec.rb
|
75
|
+
- spec/pemilu/candidate_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/pyk/pemilu
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A beautiful Ruby interface for Pemilu APIs (pemiluapi.org)
|
101
|
+
test_files:
|
102
|
+
- spec/pemilu/api_spec.rb
|
103
|
+
- spec/pemilu/candidate_spec.rb
|
104
|
+
- spec/spec_helper.rb
|