Election results in the London Borough of Sutton.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

app.rb 1.7 KiB

il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
il y a 14 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'json'
  4. require 'rest_client'
  5. get '/' do
  6. @wards = %w{ Cheam Sutton Stonecot }
  7. haml :home
  8. end
  9. get '/wards' do
  10. @postcode = params[:postcode].strip.upcase
  11. url = "http://www.uk-postcodes.com/postcode/" + @postcode.gsub(/ /, '') + '.json'
  12. result = RestClient.get(url)
  13. result_ary = JSON.parse(result)
  14. @district_name = result_ary['administrative']['district']['title']
  15. @ward_name = result_ary['administrative']['ward']['title']
  16. haml :wards
  17. end
  18. __END__
  19. @@layout
  20. !!!
  21. %html
  22. %head
  23. %title Find My Candidates
  24. %link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' }
  25. %body
  26. #header
  27. %h1 Find My Candidates
  28. #main
  29. = yield
  30. #footer
  31. %hr/
  32. %p
  33. Made by
  34. %a{ :href => "http://adrianshort.co.uk/" } Adrian Short
  35. -#
  36. with
  37. %a{ :href => "http://www.ordnancesurvey.co.uk/oswebsite/products/code-point-open/" } Ordnance Survey
  38. and
  39. %a{ :href => "http://www.sutton.gov.uk/" } Sutton Council
  40. data,
  41. %a{ :href => "http://uk-postcodes.com" } UK Postcodes API
  42. and
  43. %a{ :href => "http://sinatrarb.com" } Sinatra.
  44. %p
  45. Hosted by
  46. %a{ :href => "http://heroku.com" } Heroku.
  47. Source at
  48. %a{ :href => "http://github.com/adrianshort" } Github.
  49. @@home
  50. %form{ :method => 'get', :action => '/wards' }
  51. %label{ :for => "postcode" } Postcode
  52. %input{ :type => 'text', :name => 'postcode', :size => 8, :maxlength => 8 }
  53. %input{ :type => 'submit', :value => "Find" }
  54. -#
  55. - for ward in @wards
  56. %p= ward
  57. @@wards
  58. %h2 #{@postcode} is in #{@ward_name} Ward in #{@district_name}