commit 27173076c96dcdf0ed27a33e6990a23d85772f68 Author: Adrian Short Date: Mon Apr 12 21:33:37 2010 +0100 Initial commit diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..84b746b --- /dev/null +++ b/app.rb @@ -0,0 +1,53 @@ +require 'rubygems' +require 'sinatra' +require 'json' +require 'rest_client' + +get '/' do + @wards = %w{ Cheam Sutton Stonecot } + haml :home +end + +get '/wards' do + @postcode = params[:postcode].strip.upcase + + url = "http://www.uk-postcodes.com/postcode/" + @postcode.gsub(/ /, '') + '.json' + + result = RestClient.get(url) + result_ary = JSON.parse(result) + @district_name = result_ary['administrative']['district']['title'] + @ward_name = result_ary['administrative']['ward']['title'] + haml :wards +end + +__END__ + +@@layout +!!! +%html + %head + %title Find My Candidates + %body + #main + %h1 Find My Candidates + = yield + #footer + %hr/ + %p Design by Adrian Short + +@@home +%form{ :method => 'get', :action => '/wards' } + %label{ :for => "postcode" } + Postcode + %input{ :type => 'text', :name => 'postcode', :size => 10 } + %input{ :type => 'submit', :value => "Find" } +- for ward in @wards + %p= ward + + +@@wards +%h2 + #{@ward_name} Ward in #{@district_name} +%p + Your postcode is #{@postcode} + \ No newline at end of file