Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Forked from gunn/directory_web_service.rb
Created January 29, 2011 17:35
Show Gist options
  • Save rafaelss/802024 to your computer and use it in GitHub Desktop.
Save rafaelss/802024 to your computer and use it in GitHub Desktop.
require 'mechanize'
require 'sinatra'
get '/:psuid' do
find_name params[:psuid]
end
def find_name(psuid)
page = Mechanize.new.get('http://psu.edu/ph')
search_result = page.form_with(:name => 'search') do |search|
search.uid = psuid
end.submit
word = search_result.parser.at('html body form table tr td b').text
word[21, word.length].split(" ").map do |n|
n.downcase.capitalize
end.join(" ")
rescue
"There was an error trying to fetch ID: '#{psuid}'"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment