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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6c0e7caedcb15b71e2a0baf61421bb95c0227dd
4
- data.tar.gz: d4ed5955fc4615e25666434bcd43910a86eb4e25
3
+ metadata.gz: 52da03fb22c27f319ca7881f9dcc789e74b83ddc
4
+ data.tar.gz: 16060f73360b8b61cf52e3d29440855364528893
5
5
  SHA512:
6
- metadata.gz: 9ef63effe307e8bce81f0e392f56969a93d6480e463b6ea3592e591c4f84d6f435b0a602628afc72c158f2516c71842ba3f0a566128830adb436670228ea9c50
7
- data.tar.gz: 3e19059d2b0f3fbeaae60c9169c09b6ea161433ea8899ccc0f4327be73710e94993714e066bf80374c0df1ce644cc892be5352b27f9f8b7bc3876ad3f33dccd9
6
+ metadata.gz: 2c95d4014c7e7774325fe7f1e004bd821d2c2907f51e634bd35362041b98fcfa838854063df6b87f67d1d3a8dda517aa5ee1130c12d4578b4bbd3feb7e9b79cd
7
+ data.tar.gz: 05244afbb48328477ed7c8574dd4a4413eeeaec9c830c26cd156ff5a24083b260a9cf4818838323fa349aec4fb5740db7a0f2d3c9c7ea61012d0d66c9b94d967
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: HH7XvLd17GpTfIbOtIN1AccfBuQrbrUqp
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'coveralls', require: false
3
4
  # Specify your gem's dependencies in pemilu.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # pemilu [![Gem Version](https://badge.fury.io/rb/pemilu.png)](http://badge.fury.io/rb/pemilu) [![Build Status](https://travis-ci.org/pyk/pemilu.png?branch=master)](https://travis-ci.org/pyk/pemilu)
1
+ # pemilu [![Gem Version](https://badge.fury.io/rb/pemilu.png)](http://badge.fury.io/rb/pemilu) [![Build Status](https://travis-ci.org/pyk/pemilu.png?branch=master)](https://travis-ci.org/pyk/pemilu) [![Dependency Status](https://gemnasium.com/pyk/pemilu.png)](https://gemnasium.com/pyk/pemilu) [![Code Climate](https://codeclimate.com/github/pyk/pemilu.png)](https://codeclimate.com/github/pyk/pemilu) [![Coverage Status](https://coveralls.io/repos/pyk/pemilu/badge.png)](https://coveralls.io/r/pyk/pemilu)
2
+
2
3
  A beautiful Ruby interface of [Pemilu APIs](http://pemiluapi.org)
3
4
 
4
5
  ## Contents
@@ -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"],
@@ -1,3 +1,3 @@
1
1
  module Pemilu
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
24
  end
@@ -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
@@ -1,3 +1,5 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
1
3
  require "pemilu"
2
4
  # This file was generated by the `rspec --init` command. Conventionally, all
3
5
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
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.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-02 00:00:00.000000000 Z
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: '0'
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: '0'
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"