Ver a proveniência

Initial commit

tags/last-sinatra-version
Adrian Short há 14 anos
cometimento
27173076c9
1 ficheiros alterados com 53 adições e 0 eliminações
  1. +53
    -0
      app.rb

+ 53
- 0
app.rb Ver ficheiro

@@ -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}

Carregando…
Cancelar
Guardar