Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/common/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class Constants
puducherry punjab rajasthan sikkim tamil_nadu telangana
tripura uttarakhand uttaranchal uttar_pradesh west_bengal
)

# All possible years for MPs
MP_YEARS = %w(2004 2009 2014 2019)

end
9 changes: 3 additions & 6 deletions my_neta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

# Main app class
class MyNeta < Roda
# All possible years for MPs
YEARS = %w(2004 2009 2014 2019)

plugin :json, serializer: proc { |o| JSON.pretty_generate(o) }

route do |r|
Expand All @@ -25,7 +22,7 @@ class MyNeta < Roda
mps: {
endpoint: '/mps',
sample: '/mps[/year][/state or union_territory]',
examples: %W(/mps/#{YEARS.sample} /mps/2014/#{Constants::MP_STATES.sample})
examples: %W(/mps/#{Constants::MP_YEARS.sample} /mps/2014/#{Constants::MP_STATES.sample})
},
mlas: {
endpoint: '/mlas',
Expand Down Expand Up @@ -59,7 +56,7 @@ class MyNeta < Roda
end

r.on :year do |year|
if YEARS.member?(year)
if Constants::MP_YEARS.member?(year)
r.is do
ret[:count] = MP.filter(year: year).count
ret[:mps] = MP.filter(year: year).order_by(:state_or_ut, :constituency)
Expand All @@ -83,7 +80,7 @@ class MyNeta < Roda
else
response.status = 400
ret[:error] = 'That is not a valid year'
ret[:valid_years] = YEARS
ret[:valid_years] = Constants::MP_YEARS
ret
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/mps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def app

# Test the number of MPs
When(:json) { JSON.parse(resp.body) }
Then { json['valid_years'].eql? MyNeta::YEARS }
Then { json['valid_years'].eql? Constants::MP_YEARS }

end

Expand Down