pemilu 1.0.0 → 1.0.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 +4 -4
- data/.coveralls.yml +2 -0
- data/Gemfile +1 -0
- data/README.md +2 -1
- data/lib/pemilu/api.rb +12 -5
- data/lib/pemilu/version.rb +1 -1
- data/pemilu.gemspec +1 -1
- data/spec/pemilu/api_spec.rb +65 -0
- data/spec/spec_helper.rb +2 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52da03fb22c27f319ca7881f9dcc789e74b83ddc
|
4
|
+
data.tar.gz: 16060f73360b8b61cf52e3d29440855364528893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c95d4014c7e7774325fe7f1e004bd821d2c2907f51e634bd35362041b98fcfa838854063df6b87f67d1d3a8dda517aa5ee1130c12d4578b4bbd3feb7e9b79cd
|
7
|
+
data.tar.gz: 05244afbb48328477ed7c8574dd4a4413eeeaec9c830c26cd156ff5a24083b260a9cf4818838323fa349aec4fb5740db7a0f2d3c9c7ea61012d0d66c9b94d967
|
data/.coveralls.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# pemilu [](http://badge.fury.io/rb/pemilu) [](https://travis-ci.org/pyk/pemilu)
|
1
|
+
# pemilu [](http://badge.fury.io/rb/pemilu) [](https://travis-ci.org/pyk/pemilu) [](https://gemnasium.com/pyk/pemilu) [](https://codeclimate.com/github/pyk/pemilu) [](https://coveralls.io/r/pyk/pemilu)
|
2
|
+
|
2
3
|
A beautiful Ruby interface of [Pemilu APIs](http://pemiluapi.org)
|
3
4
|
|
4
5
|
## Contents
|
data/lib/pemilu/api.rb
CHANGED
@@ -26,6 +26,7 @@ module Pemilu
|
|
26
26
|
params.delete_if{ |k,v| v.nil? }
|
27
27
|
uri.query = URI.encode_www_form(params)
|
28
28
|
respond = Net::HTTP.get_response(uri)
|
29
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
29
30
|
result = []
|
30
31
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
31
32
|
@total_candidate = data["data"]["results"]["total"]
|
@@ -66,8 +67,9 @@ module Pemilu
|
|
66
67
|
params = { apiKey: @key }
|
67
68
|
uri.query = URI.encode_www_form(params)
|
68
69
|
respond = Net::HTTP.get_response(uri)
|
70
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
71
|
+
return "Can't get Candidate with id: #{id}" if respond.is_a?(Net::HTTPInternalServerError)
|
69
72
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
70
|
-
return "Cann't get candidate with id: #{id}" if data.nil?
|
71
73
|
candidate = data["data"]["results"]["caleg"][0]
|
72
74
|
return Pemilu::Candidate.new(
|
73
75
|
id: candidate["id"],
|
@@ -109,6 +111,7 @@ module Pemilu
|
|
109
111
|
uri.query = URI.encode_www_form(params)
|
110
112
|
respond = Net::HTTP.get_response(uri)
|
111
113
|
result = []
|
114
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
112
115
|
|
113
116
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
114
117
|
@total_parties = data["data"]["results"]["count"]
|
@@ -131,10 +134,10 @@ module Pemilu
|
|
131
134
|
params = { apiKey: @key }
|
132
135
|
uri.query = URI.encode_www_form(params)
|
133
136
|
respond = Net::HTTP.get_response(uri)
|
134
|
-
|
137
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
138
|
+
return "Can't get Party with id: #{id}" if respond.is_a?(Net::HTTPBadRequest)
|
135
139
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
136
140
|
party = data["data"]["results"]["partai"][0]
|
137
|
-
return "Cann't get party with id: #{id}" if party.nil?
|
138
141
|
return Pemilu::Party.new(
|
139
142
|
id: party["id"].to_i,
|
140
143
|
nick_name: party["nama"],
|
@@ -150,6 +153,7 @@ module Pemilu
|
|
150
153
|
params = { apiKey: @key }
|
151
154
|
uri.query = URI.encode_www_form(params)
|
152
155
|
respond = Net::HTTP.get_response(uri)
|
156
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
153
157
|
result = []
|
154
158
|
|
155
159
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
@@ -172,9 +176,10 @@ module Pemilu
|
|
172
176
|
params = { apiKey: @key }
|
173
177
|
uri.query = URI.encode_www_form(params)
|
174
178
|
respond = Net::HTTP.get_response(uri)
|
179
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
180
|
+
return "Can't get Province with id: #{id}" if respond.is_a?(Net::HTTPBadRequest)
|
175
181
|
|
176
182
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
177
|
-
return "Cann't get province with id: #{id}" if data.nil?
|
178
183
|
province = data["data"]["results"]["provinsi"][0]
|
179
184
|
return Pemilu::Province.new(
|
180
185
|
id: province["id"].to_i,
|
@@ -198,6 +203,7 @@ module Pemilu
|
|
198
203
|
params.delete_if{ |k,v| v.nil? }
|
199
204
|
uri.query = URI.encode_www_form(params)
|
200
205
|
respond = Net::HTTP.get_response(uri)
|
206
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
201
207
|
result = []
|
202
208
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
203
209
|
@total_election_districts = data["data"]["results"]["count"]
|
@@ -223,9 +229,10 @@ module Pemilu
|
|
223
229
|
params = { apiKey: @key }
|
224
230
|
uri.query = URI.encode_www_form(params)
|
225
231
|
respond = Net::HTTP.get_response(uri)
|
232
|
+
return "Invalid request error. Please check your API key" if respond.is_a?(Net::HTTPUnauthorized)
|
233
|
+
return "Can't get Electoral District with id: #{id}" if respond.is_a?(Net::HTTPInternalServerError)
|
226
234
|
|
227
235
|
data = JSON.parse(respond.body) if respond.is_a?(Net::HTTPSuccess)
|
228
|
-
return "Cann't get province with id: #{id}" if data.nil?
|
229
236
|
ed = data["data"]["results"]["dapil"][0]
|
230
237
|
return Pemilu::ElectoralDistrict.new(
|
231
238
|
id: ed["id"],
|
data/lib/pemilu/version.rb
CHANGED
data/pemilu.gemspec
CHANGED
data/spec/pemilu/api_spec.rb
CHANGED
@@ -28,6 +28,12 @@ module Pemilu
|
|
28
28
|
expect(candidate.class).to eq(Pemilu::Candidate)
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
33
|
+
|
34
|
+
it "should return invalid request error " do
|
35
|
+
expect(pemilu_invalid.candidates).to eq("Invalid request error. Please check your API key")
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
describe "#candidate(id)" do
|
@@ -62,6 +68,16 @@ module Pemilu
|
|
62
68
|
expect(caleg.jobs.class).to eq(Array)
|
63
69
|
expect(caleg.organizations.class).to eq(Array)
|
64
70
|
end
|
71
|
+
|
72
|
+
it "should return Can't get Candidate with id: 1" do
|
73
|
+
expect(pemilu.candidate(1)).to eq( "Can't get Candidate with id: 1" )
|
74
|
+
end
|
75
|
+
|
76
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
77
|
+
|
78
|
+
it "should return invalid request error " do
|
79
|
+
expect(pemilu_invalid.candidate("1101-00-0000-0102")).to eq("Invalid request error. Please check your API key")
|
80
|
+
end
|
65
81
|
end
|
66
82
|
|
67
83
|
describe "#parties" do
|
@@ -73,6 +89,12 @@ module Pemilu
|
|
73
89
|
expect(party.class).to eq(Pemilu::Party)
|
74
90
|
end
|
75
91
|
end
|
92
|
+
|
93
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
94
|
+
|
95
|
+
it "should return invalid request error " do
|
96
|
+
expect(pemilu_invalid.parties).to eq("Invalid request error. Please check your API key")
|
97
|
+
end
|
76
98
|
end
|
77
99
|
|
78
100
|
describe "#party(id)" do
|
@@ -88,6 +110,16 @@ module Pemilu
|
|
88
110
|
expect(party.facebook).to eq("https://www.facebook.com/pages/Partai-Nasdem/135724689838285")
|
89
111
|
expect(party.twitter).to eq("https://twitter.com/NasDem")
|
90
112
|
end
|
113
|
+
|
114
|
+
it "should return Can't get Party with id: S" do
|
115
|
+
expect(pemilu.party("S")).to eq( "Can't get Party with id: S" )
|
116
|
+
end
|
117
|
+
|
118
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
119
|
+
|
120
|
+
it "should return invalid request error " do
|
121
|
+
expect(pemilu_invalid.party(1)).to eq("Invalid request error. Please check your API key")
|
122
|
+
end
|
91
123
|
end
|
92
124
|
|
93
125
|
describe "#provinces" do
|
@@ -99,6 +131,12 @@ module Pemilu
|
|
99
131
|
expect(province.class).to eq(Pemilu::Province)
|
100
132
|
end
|
101
133
|
end
|
134
|
+
|
135
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
136
|
+
|
137
|
+
it "should return invalid request error " do
|
138
|
+
expect(pemilu_invalid.provinces).to eq("Invalid request error. Please check your API key")
|
139
|
+
end
|
102
140
|
end
|
103
141
|
|
104
142
|
describe "#province(id)" do
|
@@ -115,6 +153,16 @@ module Pemilu
|
|
115
153
|
expect(province.population).to eq(5015234)
|
116
154
|
province.electoral_district.should be_a(Array)
|
117
155
|
end
|
156
|
+
|
157
|
+
it "should return Can't get Province with id: S" do
|
158
|
+
expect(pemilu.province("S")).to eq( "Can't get Province with id: S" )
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
162
|
+
|
163
|
+
it "should return invalid request error " do
|
164
|
+
expect(pemilu_invalid.province(11)).to eq("Invalid request error. Please check your API key")
|
165
|
+
end
|
118
166
|
end
|
119
167
|
|
120
168
|
describe "#electoral_districts" do
|
@@ -126,6 +174,12 @@ module Pemilu
|
|
126
174
|
expect(ed.class).to eq(Pemilu::ElectoralDistrict)
|
127
175
|
end
|
128
176
|
end
|
177
|
+
|
178
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
179
|
+
|
180
|
+
it "should return invalid request error " do
|
181
|
+
expect(pemilu_invalid.electoral_districts).to eq("Invalid request error. Please check your API key")
|
182
|
+
end
|
129
183
|
end
|
130
184
|
|
131
185
|
describe "#electoral_district(id)" do
|
@@ -143,6 +197,17 @@ module Pemilu
|
|
143
197
|
expect(electoral_district.province.id).to eq(11)
|
144
198
|
expect(electoral_district.province.name).to eq("Aceh")
|
145
199
|
end
|
200
|
+
|
201
|
+
it "should return Can't get Electoral District with id: S" do
|
202
|
+
expect(pemilu.electoral_district("S")).to eq( "Can't get Electoral District with id: S" )
|
203
|
+
end
|
204
|
+
|
205
|
+
let(:pemilu_invalid) { Pemilu::API.new(key:"xxx") }
|
206
|
+
|
207
|
+
it "should return invalid request error " do
|
208
|
+
expect(pemilu_invalid.electoral_district("1101-00-0000")).to eq("Invalid request error. Please check your API key")
|
209
|
+
end
|
210
|
+
|
146
211
|
end
|
147
212
|
|
148
213
|
end
|
data/spec/spec_helper.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.1
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.14'
|
55
55
|
description: A beautiful Ruby interface for Pemilu APIs
|
56
56
|
email:
|
57
57
|
- bayualdiyansyah@gmail.com
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".coveralls.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".rspec"
|
64
65
|
- ".travis.yml"
|