Skip to content

Instantly share code, notes, and snippets.

@djadriano
Created March 13, 2014 03:53
Show Gist options
  • Select an option

  • Save djadriano/9521649 to your computer and use it in GitHub Desktop.

Select an option

Save djadriano/9521649 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'net/http'
require 'open-uri'
require 'json'
require 'pp'
set :views, File.dirname(__FILE__) + '/views'
set :public_folder, File.dirname(__FILE__) + '/public'
get '/*' do
if params.has_key?('_escaped_fragment_')
url_params = params[ :_escaped_fragment_ ]
arr_url_params = url_params.split( '=' )
arr_url_params_section = arr_url_params[ 0 ].split( '/' )
section_name = arr_url_params_section[ 1 ]
if arr_url_params_section.length == 2
puts '-------------- é a home de alguma seção --------------'
verifiy_section(section_name, '')
elsif arr_url_params_section.length > 2
puts '-------------- tem parametro --------------'
verifiy_section(section_name, arr_url_params_section[ 2 ])
end
else
send_file File.join(settings.public_folder, 'index.html')
end
end
# get '/' do
# uri = URI('http://api.soundcloud.com/users/djadrianofernandes/tracks.json?client_id=cd001908211e3eaa05d2f9212497182d')
# res = Net::HTTP.get_response(uri)
# json_array = JSON.parse(res.body)
# @doidao = json_array
# erb :index
# end
# get '/*' do
# url_params = params[ :_escaped_fragment_ ]
# url_params.length
# if url_params == ''
# send_file File.join(settings.public_folder, 'index.html')
# else
# erb :radio
# end
# if params
# url_params = params[ :_escaped_fragment_ ]
# arr_url_params = url_params.split( '=' )
# arr_url_params_section = arr_url_params[ 0 ].split( '/' )
# section_name = arr_url_params_section[ 1 ]
# puts get_artists()
# if arr_url_params_section.length == 0
# puts '-------------- é a index --------------'
# erb :index
# elsif arr_url_params_section.length == 2
# puts '-------------- é a home de alguma seção --------------'
# if section_name == 'artists'
# erb :artists
# elsif section_name == 'podcasts'
# erb :podcasts
# elsif section_name == 'radio'
# erb :radio
# end
# elsif arr_url_params_section.length > 2
# puts '-------------- tem parametro --------------'
# erb :artists
# end
# else
# erb :podasts
# end
# end
def verifiy_section(section_name, section_param)
if section_param.empty?
if section_name == 'artists'
erb :artists
elsif section_name == 'podcasts'
erb :podcasts
elsif section_name == 'radio'
erb :radio
end
else
"Sei la"
end
end
def get_artist
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment