pemilu 0.5.1 → 1.0.0
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 +4 -4
- data/.travis.yml +4 -0
- data/README.md +324 -77
- data/lib/pemilu/api.rb +164 -30
- data/lib/pemilu/electoral_district.rb +17 -0
- data/lib/pemilu/party.rb +14 -0
- data/lib/pemilu/province.rb +17 -0
- data/lib/pemilu/version.rb +1 -1
- data/lib/pemilu.rb +3 -0
- data/spec/pemilu/api_spec.rb +86 -12
- data/spec/pemilu/candidate_spec.rb +13 -12
- data/spec/pemilu/electoral_district_spec.rb +30 -0
- data/spec/pemilu/party_spec.rb +26 -0
- data/spec/pemilu/province_spec.rb +26 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6c0e7caedcb15b71e2a0baf61421bb95c0227dd
|
4
|
+
data.tar.gz: d4ed5955fc4615e25666434bcd43910a86eb4e25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef63effe307e8bce81f0e392f56969a93d6480e463b6ea3592e591c4f84d6f435b0a602628afc72c158f2516c71842ba3f0a566128830adb436670228ea9c50
|
7
|
+
data.tar.gz: 3e19059d2b0f3fbeaae60c9169c09b6ea161433ea8899ccc0f4327be73710e94993714e066bf80374c0df1ce644cc892be5352b27f9f8b7bc3876ad3f33dccd9
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,56 +1,96 @@
|
|
1
|
-
# pemilu
|
1
|
+
# pemilu [](http://badge.fury.io/rb/pemilu) [](https://travis-ci.org/pyk/pemilu)
|
2
2
|
A beautiful Ruby interface of [Pemilu APIs](http://pemiluapi.org)
|
3
3
|
|
4
4
|
## Contents
|
5
|
-
- [Installation]
|
6
|
-
- [How to use pemilu gem]
|
7
|
-
- [Configure API key]
|
8
|
-
- [APIs]
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
|
28
|
-
[
|
29
|
-
[
|
30
|
-
[
|
5
|
+
- [Installation][in]
|
6
|
+
- [How to use pemilu gem][ht]
|
7
|
+
- [Configure API key][c]
|
8
|
+
- [APIs][a]
|
9
|
+
- **Candidate APIs**
|
10
|
+
- [List of Candidate attributes][ca]
|
11
|
+
- [Get list of all Candidates][g]
|
12
|
+
- [#candidates usage example][cux]
|
13
|
+
- [Get details of Candidate][gdoc]
|
14
|
+
- [#candidate usage example][cue]
|
15
|
+
- **Party APIs**
|
16
|
+
- [List of Party attributes][lop]
|
17
|
+
- [Get list of all Parties][gloap]
|
18
|
+
- [#parties usage example][psue]
|
19
|
+
- [Get details of Party][gdop]
|
20
|
+
- [#party(id) usage example][pue]
|
21
|
+
- **Province APIs**
|
22
|
+
- [List of Province attributes][lopa]
|
23
|
+
- [Get list of all Provinces][gloapv]
|
24
|
+
- [#provinces usage example][pvue]
|
25
|
+
- [Get details of Province][gopv]
|
26
|
+
- [#province(id) usage example][pvue]
|
27
|
+
- **Electoral District APIs**
|
28
|
+
- [List of Electoral District attributes][loeda]
|
29
|
+
- [Get list of all Electoral Districts][adom1]
|
30
|
+
- [#electoral_districts usage example][adom2]
|
31
|
+
- [Get details of Electoral District][adom3]
|
32
|
+
- [#electoral_district(id) usage example][adom4]
|
33
|
+
- [Exception Handling][eh]
|
34
|
+
- [Author][auth]
|
35
|
+
- [License][licn]
|
36
|
+
|
37
|
+
[in]: https://github.com/pyk/pemilu#installation
|
38
|
+
[ht]: https://github.com/pyk/pemilu#how-to-use-pemilu-gem
|
39
|
+
[c]: https://github.com/pyk/pemilu#configure
|
40
|
+
[a]: https://github.com/pyk/pemilu#apis
|
41
|
+
[ca]: https://github.com/pyk/pemilu#list-of-candidate-attributes-object
|
42
|
+
[g]: https://github.com/pyk/pemilu#get-list-of-all-candidates
|
43
|
+
[cux]: https://github.com/pyk/pemilu#candidate-usage-example
|
44
|
+
[gdoc]: https://github.com/pyk/pemilu#get-details-of-candidate
|
45
|
+
[cue]: https://github.com/pyk/pemilu#candidate-usage-example
|
46
|
+
[si]: https://github.com/pyk/pemilu#still-in-active-development
|
47
|
+
[lop]: https://github.com/pyk/pemilu#list-of-party-attributes-object
|
48
|
+
[gloap]: https://github.com/pyk/pemilu#get-list-of-all-parties
|
49
|
+
[psue]: https://github.com/pyk/pemilu#parties-usage-example
|
50
|
+
[gdop]: https://github.com/pyk/pemilu#get-details-of-party
|
51
|
+
[pue]: https://github.com/pyk/pemilu#partyid-usage-example
|
52
|
+
[lopa]: https://github.com/pyk/pemilu#list-of-province-attributes-object
|
53
|
+
[gloapv]: https://github.com/pyk/pemilu#get-list-of-all-provinces
|
54
|
+
[pvue]: https://github.com/pyk/pemilu#provinceid-usage-example
|
55
|
+
[gopv]: https://github.com/pyk/pemilu#get-details-of-province
|
56
|
+
[loeda]: https://github.com/pyk/pemilu#list-of-electoral-district-attribute
|
57
|
+
[adom1]: https://github.com/pyk/pemilu#get-list-of-all-electoral-district
|
58
|
+
[adom2]: https://github.com/pyk/pemilu#electoral_districts-usage-example
|
59
|
+
[adom3]: https://github.com/pyk/pemilu#get-details-of-electoral-district
|
60
|
+
[adom4]: https://github.com/pyk/pemilu#electoral_districtid-usage-example
|
61
|
+
[eh]: https://github.com/pyk/pemilu#exception-handling
|
62
|
+
[auth]: https://github.com/pyk/pemilu#author
|
63
|
+
[licn]: https://github.com/pyk/pemilu#license
|
31
64
|
|
32
65
|
## Installation
|
33
66
|
Add this line to your application's Gemfile:
|
34
67
|
|
35
|
-
|
68
|
+
```ruby
|
69
|
+
gem 'pemilu'
|
70
|
+
```
|
36
71
|
|
37
72
|
And then execute:
|
38
73
|
|
74
|
+
```shell
|
39
75
|
$ bundle
|
76
|
+
```
|
40
77
|
|
41
78
|
Or install it yourself as:
|
42
79
|
|
43
|
-
|
44
|
-
|
80
|
+
```shell
|
81
|
+
$ gem install pemilu
|
82
|
+
```
|
45
83
|
|
46
84
|
## How to use pemilu gem
|
47
85
|
|
48
86
|
### Configure
|
49
|
-
Before accessing all available [APIs](
|
87
|
+
Before accessing all available [APIs](#contents) make sure Configure your API key first.
|
50
88
|
|
89
|
+
``` ruby
|
51
90
|
require "pemilu"
|
52
91
|
|
53
92
|
pemilu = Pemilu::API.new(key: "YOUR API KEY")
|
93
|
+
```
|
54
94
|
|
55
95
|
### APIs
|
56
96
|
|
@@ -58,54 +98,60 @@ Before accessing all available [APIs](a) make sure Configure your API key first.
|
|
58
98
|
List of available attribute to each candidate that you can get some information
|
59
99
|
about candidate itself. For example `candidate.id` will display id of candidate.
|
60
100
|
|
61
|
-
|Attribute|Return|Description
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
101
|
+
| Attribute | Return | Description | `#candidates` | `#candidate` |
|
102
|
+
| --------- | ------ | ----------- | ------------- | ------------ |
|
103
|
+
| `id` | String | ID of Candidate | x | x |
|
104
|
+
| `name` | String | Name of Candidate | x | x |
|
105
|
+
| `gender` | String | Gender of Candidate | x | x |
|
106
|
+
| `religion`| String | Religion of Candidate | x | x |
|
107
|
+
| `birthplace` | String | Birthplace of Candidate | x | x |
|
108
|
+
| `date_of_birth` | String | Date of Candidate birth | x | x |
|
109
|
+
| `marital_status`| String | Marital status of Candidate | x | x |
|
110
|
+
| `name_of_couples`| String | Name of Candidate couples | x | x |
|
111
|
+
| `number_of_children` | Integer | Number of Candidate children | x | x |
|
112
|
+
| `village` | String | Village where Candidate live | x | x |
|
113
|
+
| `sub_district` | String | Sub district where Candidate live | x | x |
|
114
|
+
| `district`| String | District where Candidate live | x | x |
|
115
|
+
| `province`| Hash | Province where Candidate live | x | x |
|
116
|
+
| `electoral_district` | Hash | Electoral district where Candidate running on | x | x |
|
117
|
+
| `election_year`| Integer | Election year where Candidate running on | x | x |
|
118
|
+
| `legislative_body` | String | Legislative body where Candidate running on (ex. DPR) | x | x |
|
119
|
+
| `party` | String | Party of Candidate | x | - |
|
120
|
+
| `party` | Hash | Party of Candidate | - | x |
|
121
|
+
| `ordinal` | Integer | Ordinal of Candidate | x | x |
|
122
|
+
| `picture` | String | URL of Candidate picture | x | x |
|
123
|
+
| `educations` | Array | List of Candidate education history | - | x |
|
124
|
+
| `jobs` | Array | List of Candidate job history | - | x |
|
125
|
+
| `organizations` | Array | List of Candidate organization history | - | x |
|
126
|
+
|
127
|
+
description:
|
128
|
+
- `x` mark is sign this attribute available when return from `#candidates` or `#candidate`
|
129
|
+
- `-` mark is sign this attribute `nil` when return from `#candidates` or `#candidate`
|
86
130
|
|
87
131
|
#### Get list of all candidates
|
88
132
|
Return an array of `Pemilu::Candidate` object that filtered by declared option.
|
89
133
|
|
134
|
+
```ruby
|
90
135
|
pemilu.candidates(options = {})
|
91
|
-
|
136
|
+
```
|
92
137
|
##### Available options
|
93
138
|
|
94
|
-
|Option|Value|Default|Description|Return|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
139
|
+
| Option | Value | Default | Description | Return |
|
140
|
+
| ------ | ----- | ------- | ----------- | ------ |
|
141
|
+
| `name` | String | `nil`| String full or partial name of the candidate | Only all candidates that matching with `name` |
|
142
|
+
| `party` | String | `nil` | Name of the available party | Only all candidates on the `party` |
|
143
|
+
| `electoral_district` | String | `nil`| ID of electoral district (daerah pilihan) | Only all candidates that running on electoral district |
|
144
|
+
| `election_year` | Integer | `nil` | Election year (tahun pemilihan)of candidate | Only all candidates that running on election year|
|
145
|
+
| `province` | String | `nil` | ID of the Province | Only all candidates that running on `province` |
|
146
|
+
| `gender` | String | `nil` | `"L"` for man and `"W"` for woman|Only all candidates has `gender` specified |
|
147
|
+
| `religion` | String | `nil` | Religion of the candidate | Only all candidates that have religion specified |
|
148
|
+
| `legislative_body` | String | `nil` | Legislative body that the candidate is running for | Only all candidates that running on that legislative body |
|
149
|
+
| `limit` | Integer | `100` | Number of records to return | All candidates on specific limit number |
|
150
|
+
| `offset` | Integer | `nil` | Number the offset | All candidates from beginning of the offset number |
|
106
151
|
|
107
152
|
#### `#candidates` usage example
|
108
153
|
|
154
|
+
```ruby
|
109
155
|
# get 10 man candidates
|
110
156
|
pemilu.candidates(limit: 10, gender: "L")
|
111
157
|
|
@@ -115,24 +161,225 @@ Return an array of `Pemilu::Candidate` object that filtered by declared option.
|
|
115
161
|
puts "Name: #{candidate.name}"
|
116
162
|
puts "Regligion: #{candidate.religion}"
|
117
163
|
end
|
118
|
-
|
164
|
+
```
|
119
165
|
|
120
166
|
#### Get details of Candidate
|
121
167
|
Return an object of `Pemilu::Candidate` with an `id` specified.
|
122
168
|
|
169
|
+
```ruby
|
123
170
|
pemilu.candidate("ID CANDIDATE")
|
171
|
+
```
|
172
|
+
|
173
|
+
ID Candidate must be String. like this `"1101-00-0000-0102"`
|
124
174
|
|
125
175
|
#### `#candidate` usage example
|
126
176
|
|
177
|
+
```ruby
|
127
178
|
# print some information about Candidate with id=1101-00-0000-0102
|
128
179
|
candidate = pemilu.candidate("1101-00-0000-0102")
|
129
180
|
puts "Name: #{candidate.name}"
|
181
|
+
```
|
182
|
+
|
183
|
+
#### List of Party attributes object
|
184
|
+
List of available attribute to each Party that you can use for get some information
|
185
|
+
about party itself. For example `party.id` will display id of party.
|
186
|
+
|
187
|
+
| Attribute | Return | Decription | `#parties` | `#party` |
|
188
|
+
| --------- | ------ | ---------- | ---------- | -------- |
|
189
|
+
| `id` | Integer | ID of Party | x | x |
|
190
|
+
| `nick_name` | String | Nick name or abbreviation of Party | x | x |
|
191
|
+
| `full_name` | String | Full name of Party | x | x |
|
192
|
+
| `url` | String | URL to Party homepage | x | x |
|
193
|
+
| `facebook` | String | URL to Party facebook page | x | x |
|
194
|
+
| `twitter` | String | URL to Party twitter page | x | x |
|
195
|
+
|
196
|
+
description:
|
197
|
+
- `x` mark is sign this attribute available when return from `#parties` or
|
198
|
+
`#party`
|
199
|
+
- `-` mark is sign this attribute `nil` when return from `#parties` or `#party`
|
200
|
+
|
201
|
+
#### Get list of all Parties
|
202
|
+
Return an array of `Pemilu::Party` object.
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
# get all parties
|
206
|
+
pemilu.parties
|
207
|
+
#=> [#<Pemilu::Party:0xb833bfcc....]
|
208
|
+
```
|
209
|
+
|
210
|
+
#### `#parties` usage example
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
# print name and facebook url each for each party
|
214
|
+
pemilu.parties.each do |party|
|
215
|
+
puts "Party name: #{party.full_name}"
|
216
|
+
puts "Party facebook: #{party.facebook}"
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
#### Get details of Party
|
221
|
+
Return one object of Pemilu::Party specified by ID.
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
pemilu.party("ID PARTY")
|
225
|
+
```
|
226
|
+
|
227
|
+
`ID PARTY` must be an Integer.
|
228
|
+
|
229
|
+
#### `#party(id)` usage example
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
# print information about Partai Demokrasi Indonesia Perjuangan
|
233
|
+
pdip = pemilu.party(4)
|
234
|
+
|
235
|
+
puts pdip.id #=> 4
|
236
|
+
puts pdip.nick_name #=> PDI-P
|
237
|
+
puts pdip.full_name #=> Partai Demokrasi Indonesia Perjuangan
|
238
|
+
puts pdip.facebook #=> https://www.facebook.com/DPP.PDI.Perjuangan
|
239
|
+
puts pdip.twitter #=> https://twitter.com/pdi_perjuangan
|
240
|
+
```
|
241
|
+
|
242
|
+
#### List of Province attributes object
|
243
|
+
List of available attribute to each Province that you can use for get some information
|
244
|
+
about province itself. For example `province.id` will display id of province.
|
245
|
+
|
246
|
+
| Attribute | Return | Decription | `#provinces` | `#province` |
|
247
|
+
| --------- | ------ | ---------- | ---------- | -------- |
|
248
|
+
| `id` | Integer | ID of Province | x | x |
|
249
|
+
| `name` | String | Nick Name of Province | x | x |
|
250
|
+
| `full_name` | String | Full Name of Province | x | x |
|
251
|
+
| `international_name` | String | International Name (English) of Province | x | x |
|
252
|
+
| `available_chairs` | Integer | Availalble chairs for Candidates | x | x |
|
253
|
+
| `population` | Integer | Population of Province | x | x |
|
254
|
+
| `electoral_district` | Array | List of Electoral District on Province | - | x |
|
255
|
+
|
256
|
+
description:
|
257
|
+
- `x` mark is sign this attribute available when return from `#provinces` or
|
258
|
+
`#province`
|
259
|
+
- `-` mark is sign this attribute `nil` when return from `#provinces` or `#province`
|
260
|
+
|
261
|
+
#### Get list of all Provinces
|
262
|
+
Return an array of `Pemilu::Province` object.
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
# get all provinces
|
266
|
+
pemilu.provinces
|
267
|
+
#=> [#<Pemilu::Province:0xb8c4ceb8....]
|
268
|
+
```
|
269
|
+
|
270
|
+
#### `#provinces` usage example
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
# print id and international name of each province
|
274
|
+
pemilu.provinces.each do |province|
|
275
|
+
puts "ID: #{province.id}"
|
276
|
+
puts "Internatioal Name: #{province.international_name}"
|
277
|
+
end
|
278
|
+
```
|
279
|
+
|
280
|
+
#### Get details of Province
|
281
|
+
Return one object of Pemilu::Province specified by ID.
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
pemilu.province("ID PROVINCE")
|
285
|
+
```
|
286
|
+
|
287
|
+
`ID PROVINCE` must be an Integer.
|
288
|
+
|
289
|
+
#### `#province(id)` usage example
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
# print information about Special Region of Aceh
|
293
|
+
aceh = pemilu.province(11)
|
294
|
+
|
295
|
+
puts aceh.id #=> 11
|
296
|
+
puts aceh.name #=> Aceh
|
297
|
+
puts aceh.international_name #=> Special Region of Aceh
|
298
|
+
```
|
299
|
+
|
300
|
+
#### List of Electoral District attribute
|
301
|
+
List of available attribute to each Electoral District that you can use for get some information
|
302
|
+
about Electoral District itself. For example `ed.id` will display id of Electoral District.
|
303
|
+
|
304
|
+
| Attribute | Return | Decription | `#electoral_districts` | `#electoral_district` |
|
305
|
+
| --------- | ------ | ---------- | ---------- | -------- |
|
306
|
+
| `id` | String | ID of Electoral District | x | x |
|
307
|
+
| `name` | String | Name or Electoral District | x | x |
|
308
|
+
| `legislative_body` | String | Legislative body of Electoral District | x | x |
|
309
|
+
| `available_chairs` | Integer | Number of available chairs in Electoral District| x | x |
|
310
|
+
| `population` | Integer | Population in Electoral District | x | x |
|
311
|
+
| `province` | Hash | Province of Electoral District | x | X |
|
312
|
+
| `province.id` | Integer | Province id of Electoral District | x | x |
|
313
|
+
| `province.name` | String | Province name of Electoral District | x | x |
|
314
|
+
|
315
|
+
|
316
|
+
description:
|
317
|
+
- `x` mark is sign this attribute available when return from `#parties` or
|
318
|
+
`#party`
|
319
|
+
- `-` mark is sign this attribute `nil` when return from `#parties` or `#party`
|
320
|
+
|
321
|
+
### Get list of all electoral district
|
322
|
+
Return an array of `Pemilu::ElectoralDistrict` object that filtered by declared option.
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
pemilu.electoral_districts(options = {})
|
326
|
+
```
|
327
|
+
##### Available options
|
328
|
+
|
329
|
+
| Option | Value | Default | Description | Return |
|
330
|
+
| ------ | ----- | ------- | ----------- | ------ |
|
331
|
+
| `province` | String | `nil`| Name of province | Only all electoral district in `province` |
|
332
|
+
| `legislative_body` | String | `nil` | Legislative body of Electoral District | Only all electoral district that have specified legislative body |
|
333
|
+
|
334
|
+
#### `#electoral_districts` usage example
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
# get electoral district on Aceh province
|
338
|
+
pemilu.electoral_districts(province: "Aceh")
|
339
|
+
```
|
340
|
+
|
341
|
+
#### Get details of Electoral District
|
342
|
+
Return one object of Pemilu::ElectoralDistrict specified by ID.
|
343
|
+
|
344
|
+
```ruby
|
345
|
+
pemilu.electoral_district("ID ELETORAL DISTRICT")
|
346
|
+
```
|
347
|
+
|
348
|
+
`ID ELECTORAL DISTRICT` should be String. Like this `"1101-00-0000"`
|
349
|
+
|
350
|
+
#### `#electoral_district(id)` usage example
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
# print information about Aceh I electoral district
|
354
|
+
ed = pemilu.electoral_district("1101-00-0000")
|
355
|
+
|
356
|
+
puts ed.id #=> 1101-00-0000
|
357
|
+
puts ed.legislative_body #=> DPR
|
358
|
+
puts ed.available_chairs #=> 7
|
359
|
+
puts ed.population #=> 2642760
|
360
|
+
```
|
361
|
+
|
362
|
+
### Exception Handling
|
363
|
+
When get details of specific information about Candidate, Party, Province and Electoral District using ID that doesn't exist it will raised error like this:
|
364
|
+
|
365
|
+
|
366
|
+
```shell
|
367
|
+
NoMethodError: undefined method `[]' for nil:NilClass
|
368
|
+
```
|
369
|
+
|
370
|
+
but, with exception handling feature now every return object that didn't exist return like this:
|
371
|
+
|
372
|
+
|
373
|
+
```shell
|
374
|
+
"Cann't get party with id: 100"
|
375
|
+
```
|
130
376
|
|
131
|
-
##
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
377
|
+
## Author
|
378
|
+
| Author |
|
379
|
+
| ---------------- |
|
380
|
+
|Bayu Aldi Yansyah |
|
381
|
+
|S1 Matematika, 2013, Universitas Airlangga |
|
382
|
+
|[@peeyek](https://twitter.com/peeyek) |
|
136
383
|
|
137
|
-
|
138
|
-
|
384
|
+
## License
|
385
|
+
MIT (c) 2014 Bayu Aldi Yansyah
|
data/lib/pemilu/api.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "pp"
|
2
1
|
module Pemilu
|
3
2
|
class API
|
4
3
|
|
@@ -28,40 +27,36 @@ module Pemilu
|
|
28
27
|
uri.query = URI.encode_www_form(params)
|
29
28
|
respond = Net::HTTP.get_response(uri)
|
30
29
|
result = []
|
31
|
-
if respond.is_a?(Net::HTTPSuccess)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
candidates.each do |caleg|
|
30
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
31
|
+
@total_candidate = data["data"]["results"]["total"]
|
32
|
+
candidates = data["data"]["results"]["caleg"]
|
33
|
+
candidates.each do |caleg|
|
36
34
|
result << Pemilu::Candidate.new(
|
37
35
|
id: caleg["id"],
|
38
36
|
name: caleg["nama"],
|
39
37
|
gender: caleg["jenis_kelamin"],
|
40
38
|
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"],
|
39
|
+
birthplace: caleg["tempat_lahir"],
|
40
|
+
date_of_birth: caleg["tanggal_lahir"],
|
41
|
+
marital_status: caleg["status_perkawinan"],
|
42
|
+
name_of_couples: caleg["nama_pasangan"],
|
43
|
+
number_of_children: caleg["jumlah_anak"],
|
44
|
+
village: caleg["kelurahan_tinggal"],
|
45
|
+
sub_district: caleg["kecamatan_tinggal"],
|
46
|
+
district: caleg["kab_kota_tinggal"],
|
49
47
|
province: {
|
50
|
-
"id" => caleg["provinsi"]["id"],
|
48
|
+
"id" => caleg["provinsi"]["id"],
|
51
49
|
"name" => caleg["provinsi"]["nama"]
|
52
50
|
},
|
53
51
|
electoral_district: {
|
54
52
|
"id" => caleg["dapil"]["id"],
|
55
53
|
"nama" => caleg["dapil"]["nama"]
|
56
54
|
},
|
57
|
-
election_year: caleg["tahun"],
|
55
|
+
election_year: caleg["tahun"],
|
58
56
|
legislative_body: caleg["lembaga"],
|
59
57
|
party: caleg["partai"],
|
60
58
|
ordinal: caleg["urutan"],
|
61
59
|
picture: caleg["foto_url"])
|
62
|
-
end
|
63
|
-
else
|
64
|
-
return "Can't reach the http://api.pemiluapi.org"
|
65
60
|
end
|
66
61
|
return result
|
67
62
|
end
|
@@ -72,32 +67,33 @@ module Pemilu
|
|
72
67
|
uri.query = URI.encode_www_form(params)
|
73
68
|
respond = Net::HTTP.get_response(uri)
|
74
69
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
70
|
+
return "Cann't get candidate with id: #{id}" if data.nil?
|
75
71
|
candidate = data["data"]["results"]["caleg"][0]
|
76
72
|
return Pemilu::Candidate.new(
|
77
73
|
id: candidate["id"],
|
78
74
|
name: candidate["nama"],
|
79
75
|
gender: candidate["jenis_kelamin"],
|
80
76
|
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"],
|
77
|
+
birthplace: candidate["tempat_lahir"],
|
78
|
+
date_of_birth: candidate["tanggal_lahir"],
|
79
|
+
marital_status: candidate["status_perkawinan"],
|
80
|
+
name_of_couples: candidate["nama_pasangan"],
|
81
|
+
number_of_children: candidate["jumlah_anak"].to_i,
|
82
|
+
village: candidate["kelurahan_tinggal"],
|
83
|
+
sub_district: candidate["kecamatan_tinggal"],
|
84
|
+
district: candidate["kab_kota_tinggal"],
|
89
85
|
province: {
|
90
|
-
"id" => candidate["provinsi"]["id"],
|
86
|
+
"id" => candidate["provinsi"]["id"],
|
91
87
|
"name" => candidate["provinsi"]["nama"]
|
92
88
|
},
|
93
89
|
electoral_district: {
|
94
90
|
"id" => candidate["dapil"]["id"],
|
95
91
|
"name" => candidate["dapil"]["nama"]
|
96
92
|
},
|
97
|
-
election_year: candidate["tahun"],
|
93
|
+
election_year: candidate["tahun"],
|
98
94
|
legislative_body: candidate["lembaga"],
|
99
95
|
party: {
|
100
|
-
"id" => candidate["partai"]["id"].to_i,
|
96
|
+
"id" => candidate["partai"]["id"].to_i,
|
101
97
|
"name" => candidate["partai"]["nama"]
|
102
98
|
},
|
103
99
|
ordinal: candidate["urutan"],
|
@@ -106,5 +102,143 @@ module Pemilu
|
|
106
102
|
jobs: candidate["riwayat_pekerjaan"],
|
107
103
|
organizations: candidate["riwayat_organisasi"])
|
108
104
|
end
|
105
|
+
|
106
|
+
def parties
|
107
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/partai")
|
108
|
+
params = { apiKey: @key }
|
109
|
+
uri.query = URI.encode_www_form(params)
|
110
|
+
respond = Net::HTTP.get_response(uri)
|
111
|
+
result = []
|
112
|
+
|
113
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
114
|
+
@total_parties = data["data"]["results"]["count"]
|
115
|
+
parties = data["data"]["results"]["partai"]
|
116
|
+
parties.each do |party|
|
117
|
+
result << Pemilu::Party.new(
|
118
|
+
id: party["id"].to_i,
|
119
|
+
nick_name: party["nama"],
|
120
|
+
full_name: party["nama_lengkap"],
|
121
|
+
url: party["url_situs"],
|
122
|
+
facebook: party["url_facebook"],
|
123
|
+
twitter: party["url_twitter"]
|
124
|
+
)
|
125
|
+
end
|
126
|
+
return result
|
127
|
+
end
|
128
|
+
|
129
|
+
def party(id)
|
130
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/partai/#{id}")
|
131
|
+
params = { apiKey: @key }
|
132
|
+
uri.query = URI.encode_www_form(params)
|
133
|
+
respond = Net::HTTP.get_response(uri)
|
134
|
+
|
135
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
136
|
+
party = data["data"]["results"]["partai"][0]
|
137
|
+
return "Cann't get party with id: #{id}" if party.nil?
|
138
|
+
return Pemilu::Party.new(
|
139
|
+
id: party["id"].to_i,
|
140
|
+
nick_name: party["nama"],
|
141
|
+
full_name: party["nama_lengkap"],
|
142
|
+
url: party["url_situs"],
|
143
|
+
facebook: party["url_facebook"],
|
144
|
+
twitter: party["url_twitter"]
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
def provinces
|
149
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/provinsi")
|
150
|
+
params = { apiKey: @key }
|
151
|
+
uri.query = URI.encode_www_form(params)
|
152
|
+
respond = Net::HTTP.get_response(uri)
|
153
|
+
result = []
|
154
|
+
|
155
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
156
|
+
@total_provinsi = data["data"]["results"]["count"]
|
157
|
+
provinces = data["data"]["results"]["provinsi"]
|
158
|
+
provinces.each do |province|
|
159
|
+
result << Pemilu::Province.new(
|
160
|
+
id: province["id"].to_i,
|
161
|
+
name: province["nama"],
|
162
|
+
full_name: province["nama_lengkap"],
|
163
|
+
international_name: province["nama_inggris"],
|
164
|
+
available_chairs: province["jumlah_kursi"],
|
165
|
+
population: province["jumlah_penduduk"])
|
166
|
+
end
|
167
|
+
return result
|
168
|
+
end
|
169
|
+
|
170
|
+
def province(id)
|
171
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/provinsi/#{id}")
|
172
|
+
params = { apiKey: @key }
|
173
|
+
uri.query = URI.encode_www_form(params)
|
174
|
+
respond = Net::HTTP.get_response(uri)
|
175
|
+
|
176
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
177
|
+
return "Cann't get province with id: #{id}" if data.nil?
|
178
|
+
province = data["data"]["results"]["provinsi"][0]
|
179
|
+
return Pemilu::Province.new(
|
180
|
+
id: province["id"].to_i,
|
181
|
+
name: province["nama"],
|
182
|
+
full_name: province["nama_lengkap"],
|
183
|
+
international_name: province["nama_inggris"],
|
184
|
+
available_chairs: province["jumlah_kursi"],
|
185
|
+
electoral_district: province["dapil"],
|
186
|
+
population: province["jumlah_penduduk"])
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
def electoral_districts(province: nil, legislative_body: nil)
|
191
|
+
|
192
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/dapil")
|
193
|
+
params = {
|
194
|
+
apiKey: @key,
|
195
|
+
lembaga: legislative_body,
|
196
|
+
provinsi: province
|
197
|
+
}
|
198
|
+
params.delete_if{ |k,v| v.nil? }
|
199
|
+
uri.query = URI.encode_www_form(params)
|
200
|
+
respond = Net::HTTP.get_response(uri)
|
201
|
+
result = []
|
202
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
203
|
+
@total_election_districts = data["data"]["results"]["count"]
|
204
|
+
eds = data["data"]["results"]["dapil"]
|
205
|
+
eds.each do |ed|
|
206
|
+
result << Pemilu::ElectoralDistrict.new(
|
207
|
+
id: ed["id"],
|
208
|
+
name: ed["nama"],
|
209
|
+
full_name: ed["nama_lengkap"],
|
210
|
+
legislative_body: ed["nama_lembaga"],
|
211
|
+
available_chairs: ed["jumlah_kursi"],
|
212
|
+
population: ed["jumlah_penduduk"],
|
213
|
+
province: {
|
214
|
+
"id" => ed["provinsi"]["id"],
|
215
|
+
"name" => ed["provinsi"]["nama"]
|
216
|
+
})
|
217
|
+
end
|
218
|
+
return result
|
219
|
+
end
|
220
|
+
|
221
|
+
def electoral_district(id)
|
222
|
+
uri = URI("http://api.pemiluapi.org/candidate/api/dapil/#{id}")
|
223
|
+
params = { apiKey: @key }
|
224
|
+
uri.query = URI.encode_www_form(params)
|
225
|
+
respond = Net::HTTP.get_response(uri)
|
226
|
+
|
227
|
+
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
228
|
+
return "Cann't get province with id: #{id}" if data.nil?
|
229
|
+
ed = data["data"]["results"]["dapil"][0]
|
230
|
+
return Pemilu::ElectoralDistrict.new(
|
231
|
+
id: ed["id"],
|
232
|
+
name: ed["nama"],
|
233
|
+
full_name: ed["nama_lengkap"],
|
234
|
+
legislative_body: ed["nama_lembaga"],
|
235
|
+
available_chairs: ed["jumlah_kursi"],
|
236
|
+
population: ed["jumlah_penduduk"],
|
237
|
+
province: {
|
238
|
+
"id" => ed["provinsi"]["id"],
|
239
|
+
"name" => ed["provinsi"]["nama"]
|
240
|
+
})
|
241
|
+
end
|
242
|
+
|
109
243
|
end
|
110
244
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Pemilu
|
2
|
+
class ElectoralDistrict
|
3
|
+
|
4
|
+
attr_reader :id, :name, :full_name, :legislative_body, :available_chairs, :population, :province
|
5
|
+
|
6
|
+
def initialize(id: nil, name: nil, full_name: nil, legislative_body: nil, available_chairs: nil, population: nil, province: nil)
|
7
|
+
@id = id
|
8
|
+
@name = name
|
9
|
+
@full_name = full_name
|
10
|
+
@legislative_body = legislative_body
|
11
|
+
@available_chairs = available_chairs
|
12
|
+
@population = population
|
13
|
+
@province = province
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/pemilu/party.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pemilu
|
2
|
+
class Party
|
3
|
+
attr_reader :id, :nick_name, :full_name, :url, :facebook, :twitter
|
4
|
+
def initialize(id: nil, nick_name: nil, full_name: nil, url: nil, facebook: nil, twitter: nil)
|
5
|
+
@id = id
|
6
|
+
@nick_name = nick_name
|
7
|
+
@full_name = full_name
|
8
|
+
@url = url
|
9
|
+
@facebook = facebook
|
10
|
+
@twitter = twitter
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Pemilu
|
2
|
+
class Province
|
3
|
+
|
4
|
+
attr_reader :id, :name, :full_name, :international_name, :available_chairs, :population, :electoral_district
|
5
|
+
|
6
|
+
def initialize(id: nil, name: nil, full_name: nil, international_name: nil, available_chairs: nil, population: nil, electoral_district: nil)
|
7
|
+
@id = id
|
8
|
+
@name = name
|
9
|
+
@full_name = full_name
|
10
|
+
@international_name = international_name
|
11
|
+
@available_chairs = available_chairs
|
12
|
+
@population = population
|
13
|
+
@electoral_district = electoral_district
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/pemilu/version.rb
CHANGED
data/lib/pemilu.rb
CHANGED
data/spec/pemilu/api_spec.rb
CHANGED
@@ -6,7 +6,7 @@ module Pemilu
|
|
6
6
|
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
7
7
|
|
8
8
|
it "should an object" do
|
9
|
-
pemilu.
|
9
|
+
pemilu.should be_a(Object)
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -22,27 +22,20 @@ module Pemilu
|
|
22
22
|
describe "#candidates" do
|
23
23
|
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
24
24
|
|
25
|
-
it "should return an array" do
|
26
|
-
pemilu.candidates.should be_a(Array)
|
27
|
-
end
|
28
|
-
|
29
25
|
it "should return an array of Pemilu::Candidate object" do
|
26
|
+
pemilu.candidates.should be_a(Array)
|
30
27
|
pemilu.candidates.each do |candidate|
|
31
28
|
expect(candidate.class).to eq(Pemilu::Candidate)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
36
|
-
describe "#candidate" do
|
33
|
+
describe "#candidate(id)" do
|
37
34
|
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
38
35
|
|
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
|
36
|
+
it "should return one Pemilu::Candidate object and correct details" do
|
45
37
|
caleg = pemilu.candidate("1101-00-0000-0102")
|
38
|
+
caleg.should be_a(Pemilu::Candidate)
|
46
39
|
expect(caleg.id).to eq("1101-00-0000-0102")
|
47
40
|
expect(caleg.name).to eq("Drs. H. T. PRIBADI")
|
48
41
|
expect(caleg.gender).to eq("L")
|
@@ -71,5 +64,86 @@ module Pemilu
|
|
71
64
|
end
|
72
65
|
end
|
73
66
|
|
67
|
+
describe "#parties" do
|
68
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
69
|
+
|
70
|
+
it "should return an array of Pemilu::Party object" do
|
71
|
+
pemilu.parties.should be_a(Array)
|
72
|
+
pemilu.parties.each do |party|
|
73
|
+
expect(party.class).to eq(Pemilu::Party)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#party(id)" do
|
79
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
80
|
+
|
81
|
+
it "should return Pemilu::Party object and have correct details" do
|
82
|
+
party = pemilu.party(1)
|
83
|
+
party.should be_a(Pemilu::Party)
|
84
|
+
expect(party.id).to eq(1)
|
85
|
+
expect(party.nick_name).to eq("Partai NasDem")
|
86
|
+
expect(party.full_name).to eq("Partai NasDem")
|
87
|
+
expect(party.url).to eq("http://www.partainasdem.org/")
|
88
|
+
expect(party.facebook).to eq("https://www.facebook.com/pages/Partai-Nasdem/135724689838285")
|
89
|
+
expect(party.twitter).to eq("https://twitter.com/NasDem")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#provinces" do
|
94
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
95
|
+
|
96
|
+
it "should return an array of Pemilu::Province object" do
|
97
|
+
pemilu.provinces.should be_a(Array)
|
98
|
+
pemilu.provinces.each do |province|
|
99
|
+
expect(province.class).to eq(Pemilu::Province)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#province(id)" do
|
105
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
106
|
+
|
107
|
+
it "should return Pemilu::Province object and have correct details" do
|
108
|
+
province = pemilu.province(11)
|
109
|
+
province.should be_a(Pemilu::Province)
|
110
|
+
expect(province.id).to eq(11)
|
111
|
+
expect(province.name).to eq("Aceh")
|
112
|
+
expect(province.full_name).to eq("Aceh")
|
113
|
+
expect(province.international_name).to eq("Special Region of Aceh")
|
114
|
+
expect(province.available_chairs).to eq(13)
|
115
|
+
expect(province.population).to eq(5015234)
|
116
|
+
province.electoral_district.should be_a(Array)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#electoral_districts" do
|
121
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
122
|
+
|
123
|
+
it "should return an array of Pemilu::ElectoralDistrict object" do
|
124
|
+
pemilu.electoral_districts.should be_a(Array)
|
125
|
+
pemilu.electoral_districts.each do |ed|
|
126
|
+
expect(ed.class).to eq(Pemilu::ElectoralDistrict)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#electoral_district(id)" do
|
132
|
+
let(:pemilu) { Pemilu::API.new(key: "06ec082d057daa3d310b27483cc3962e") }
|
133
|
+
|
134
|
+
it "should return Pemilu::ElectoralDistrict object and have correct details" do
|
135
|
+
electoral_district = pemilu.electoral_district("1101-00-0000")
|
136
|
+
electoral_district.should be_a(Pemilu::ElectoralDistrict)
|
137
|
+
expect(electoral_district.id).to eq("1101-00-0000")
|
138
|
+
expect(electoral_district.name).to eq("Aceh I")
|
139
|
+
expect(electoral_district.legislative_body).to eq("DPR")
|
140
|
+
expect(electoral_district.available_chairs).to eq(7)
|
141
|
+
expect(electoral_district.population).to eq(2642760)
|
142
|
+
electoral_district.province.should be_a(Hash)
|
143
|
+
expect(electoral_district.province.id).to eq(11)
|
144
|
+
expect(electoral_district.province.name).to eq("Aceh")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
74
148
|
end
|
75
149
|
end
|
@@ -8,23 +8,23 @@ module Pemilu
|
|
8
8
|
name: "bayu aldi yansyah",
|
9
9
|
gender: "L",
|
10
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",
|
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
19
|
province: {
|
20
|
-
"id" => 2,
|
20
|
+
"id" => 2,
|
21
21
|
"name" => "Jawa Timur"
|
22
22
|
},
|
23
23
|
electoral_district: {
|
24
24
|
"id" => 20,
|
25
25
|
"name" => "Sidoarjo"
|
26
26
|
},
|
27
|
-
election_year: 2014,
|
27
|
+
election_year: 2014,
|
28
28
|
legislative_body: "DPR",
|
29
29
|
party: "Partai Asolole jos!",
|
30
30
|
ordinal: 1,
|
@@ -42,7 +42,8 @@ module Pemilu
|
|
42
42
|
"ringkasan" => "Test"
|
43
43
|
}] ) }
|
44
44
|
|
45
|
-
it "should return
|
45
|
+
it "should return Pemilu::Candidate object and have correct details" do
|
46
|
+
candidate.should be_a(Pemilu::Candidate)
|
46
47
|
expect(candidate.id).to eq(1)
|
47
48
|
expect(candidate.name).to eq("bayu aldi yansyah")
|
48
49
|
expect(candidate.gender).to eq("L")
|
@@ -72,4 +73,4 @@ module Pemilu
|
|
72
73
|
|
73
74
|
end
|
74
75
|
end
|
75
|
-
end
|
76
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Pemilu
|
4
|
+
describe ElectoralDistrict do
|
5
|
+
describe "new" do
|
6
|
+
let(:ed) { Pemilu::ElectoralDistrict.new(
|
7
|
+
id: 1,
|
8
|
+
full_name: "test",
|
9
|
+
legislative_body: "test",
|
10
|
+
available_chairs: 1,
|
11
|
+
population: 1,
|
12
|
+
province: {
|
13
|
+
"id" => 1,
|
14
|
+
"name" => "test"
|
15
|
+
})}
|
16
|
+
|
17
|
+
it "should become Pemilu::ElectoralDistrict object and have correct details" do
|
18
|
+
ed.should be_a(Pemilu::ElectoralDistrict)
|
19
|
+
expect(ed.id).to eq(1)
|
20
|
+
expect(ed.full_name).to eq("test")
|
21
|
+
expect(ed.legislative_body).to eq("test")
|
22
|
+
expect(ed.available_chairs).to eq(1)
|
23
|
+
expect(ed.population).to eq(1)
|
24
|
+
ed.province.should be_a(Hash)
|
25
|
+
expect(ed.province.id).to eq(1)
|
26
|
+
expect(ed.province.name).to eq("test")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Pemilu
|
4
|
+
describe Party do
|
5
|
+
describe "new" do
|
6
|
+
let(:party) { Pemilu::Party.new(
|
7
|
+
id: 1,
|
8
|
+
nick_name: "ASOLOLE",
|
9
|
+
full_name: "ASOLOLE JOS!",
|
10
|
+
url: "test",
|
11
|
+
facebook: "test",
|
12
|
+
twitter: "test"
|
13
|
+
) }
|
14
|
+
|
15
|
+
it "should return Pemilu::Party object and have correct details" do
|
16
|
+
party.should be_a(Pemilu::Party)
|
17
|
+
expect(party.id).to eq(1)
|
18
|
+
expect(party.nick_name).to eq("ASOLOLE")
|
19
|
+
expect(party.full_name).to eq("ASOLOLE JOS!")
|
20
|
+
expect(party.url).to eq("test")
|
21
|
+
expect(party.facebook).to eq("test")
|
22
|
+
expect(party.twitter).to eq("test")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Pemilu
|
4
|
+
describe Province do
|
5
|
+
describe "new" do
|
6
|
+
let(:province) { Pemilu::Province.new(
|
7
|
+
id: 1,
|
8
|
+
name: "Sidoarjo",
|
9
|
+
full_name: "Sidoarjo",
|
10
|
+
international_name: "Sidoarjo jos!",
|
11
|
+
available_chairs: 1,
|
12
|
+
population: 100000
|
13
|
+
) }
|
14
|
+
|
15
|
+
it "should an object of Pemilu::Province and return correct details" do
|
16
|
+
expect(province.class).to eq(Pemilu::Province)
|
17
|
+
expect(province.id).to eq(1)
|
18
|
+
expect(province.name).to eq("Sidoarjo")
|
19
|
+
expect(province.full_name).to eq("Sidoarjo")
|
20
|
+
expect(province.international_name).to eq("Sidoarjo jos!")
|
21
|
+
expect(province.available_chairs).to eq(1)
|
22
|
+
expect(province.population).to eq(100000)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pemilu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bayu Aldi Yansyah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
@@ -68,11 +69,17 @@ files:
|
|
68
69
|
- lib/pemilu.rb
|
69
70
|
- lib/pemilu/api.rb
|
70
71
|
- lib/pemilu/candidate.rb
|
72
|
+
- lib/pemilu/electoral_district.rb
|
71
73
|
- lib/pemilu/hash_extension.rb
|
74
|
+
- lib/pemilu/party.rb
|
75
|
+
- lib/pemilu/province.rb
|
72
76
|
- lib/pemilu/version.rb
|
73
77
|
- pemilu.gemspec
|
74
78
|
- spec/pemilu/api_spec.rb
|
75
79
|
- spec/pemilu/candidate_spec.rb
|
80
|
+
- spec/pemilu/electoral_district_spec.rb
|
81
|
+
- spec/pemilu/party_spec.rb
|
82
|
+
- spec/pemilu/province_spec.rb
|
76
83
|
- spec/spec_helper.rb
|
77
84
|
homepage: https://github.com/pyk/pemilu
|
78
85
|
licenses:
|
@@ -101,4 +108,7 @@ summary: A beautiful Ruby interface for Pemilu APIs (pemiluapi.org)
|
|
101
108
|
test_files:
|
102
109
|
- spec/pemilu/api_spec.rb
|
103
110
|
- spec/pemilu/candidate_spec.rb
|
111
|
+
- spec/pemilu/electoral_district_spec.rb
|
112
|
+
- spec/pemilu/party_spec.rb
|
113
|
+
- spec/pemilu/province_spec.rb
|
104
114
|
- spec/spec_helper.rb
|