Created
October 3, 2013 22:05
-
-
Save spencereldred/6817851 to your computer and use it in GitHub Desktop.
Spencer's movie.rb file of routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'sinatra/reloader' | |
require 'typhoeus' | |
require 'json' | |
# @query = "Star Wars" | |
# movie_list_request = Typhoeus.get( | |
# "http://www.omdbapi.com", | |
# :params => { :s => @query } | |
# ) | |
# @movie_list = JSON.parse(movie_list_request.body) | |
# puts @movie_list | |
# @id = "tt0076759" | |
# movie_info_request = Typhoeus.get( | |
# "http://www.omdbapi.com", | |
# :params => { :i => @id } | |
# ) | |
# @movie_info = JSON.parse(movie_info_request.body) | |
# puts @movie_info | |
get '/' do | |
# redirect to form to get movie | |
@method = "get" | |
@action = "/movie" | |
erb :form | |
end | |
get "/movie/:id" do | |
# show a particular movie | |
# p "The id: #{params[:captures]}" | |
@id = params[:captures][0] | |
p "@id = #{@id}" | |
movie_info_request = Typhoeus.get( | |
"http://www.omdbapi.com", | |
:params => { :i => @id } | |
) | |
@movie_info = JSON.parse(movie_info_request.body) | |
puts @movie_info | |
erb :newfile | |
end | |
# Receives 'new' movie symbol | |
get '/movie' do | |
@query = params[:query]; | |
puts @query | |
movie_list_request = Typhoeus.get( | |
"http://www.omdbapi.com", | |
:params => { :s => @query } | |
) | |
@movie_list = JSON.parse(movie_list_request.body) | |
@movies = @movie_list.map { |k,v| v } | |
@movies.flatten! | |
# p @movies | |
@movies.each {|movie| p movie["Title"]} | |
@movies | |
erb :index | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment