MY CODE >> Ruby BBYOpen Store Search
<!DOCTYPE html>
<!-- 
    index.html.erb 
    Tommy Martin
    December 2013
    
    This is a basic html.erb web page that gets data from the user.
    -->
    
<html lang = "en">
	<head>
		<title> Search Form </title>
	</head>

	<body>
		
		<h1>Smart Homes</h1>
		
		<br />
		
		<form name="input" action="search_form/results" method="get">
			Zip Code: <input type="text" name="zip"> <br />
			Search Radius: <input type="text" name="dist"> <br />
			<input type="submit" value="Submit">
		</form>
		
	</body>
	
</html>
<!-- 
    results.html.erb 
    Tommy Martin
    December 2013
    
    This is a basic html.erb web page that displays the rendered and formatted XML from
    Ruby.
    -->
    
<h1>Store finder results</h1>
<br />
<%= @xmlVar.html_safe %> <br />
# search_form_controller.rb
# Tommy Martin
# December 2013
# This Ruby code accepts user data from the index.html.erb page and uses that data to make
# a request on the BBYOpen Server.  XML is returned by the server and is formatted for the
# results.html.erb to display.

class SearchFormController < ApplicationController
  def index
  end

  def results
	require 'net/http'
	require 'rexml/document'
	require 'uri'
	
	@zip = params[:zip]
	@dist = params[:dist]
	
	url = 'http://api.remix.bestbuy.com/v1/stores(area('+ @zip +','+ @dist +'))
	    ?show=storeId,name,distance,lat,lng&apiKey=fuzgmrj4nv8v9ummatn78m3k'

	# get the XML data as a string
	xml_data = Net::HTTP.get_response(URI.parse(url)).body
	
	# extract event information
	doc = REXML::Document.new(xml_data)
	titles = []
	links = []
	doc.elements.each('stores/store/name') do |ele|
	   titles << ele.text
	end
	doc.elements.each('stores/store/distance') do |ele|
	   links << ele.text
	end

	@xmlVar = "<b>Results:</b> <br /><br />"
	# print all events
	titles.each_with_index do |title, idx|
	   @xmlVar += "<b>Store: </b>#{title} <br /> 
	       <b>Distance: </b> #{links[idx]} <br /><br />"
	end
  end
end