Skip to content

Commit

Permalink
more code cleanup in the hopes that it's enough to get this app runni…
Browse files Browse the repository at this point in the history
…ng on heroku
  • Loading branch information
abelmartin committed May 10, 2011
1 parent a0c1317 commit cb9ca24
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 45 deletions.
1 change: 0 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require './cotm'

run Sinatra::Application
#run CotM.new
82 changes: 38 additions & 44 deletions cotm.rb
Original file line number Diff line number Diff line change
@@ -1,65 +1,59 @@
require 'rubygems' if RUBY_VERSION < '1.9'
#require 'sinatra/base'
require 'sinatra'
require 'haml'
require 'net/http'
require 'date'

# You want your API key in a proxy call of some sort so it's not publicly visible.
# I'm placing my actaul API key in a seperate file OUTSIDE of source control.
#require './my_api_key'
# require './my_api_key'

#class CotM < Sinatra::Base
# Our Sinatra backend:
get '/' do
@current_month = Date.today.month
haml :index
end

get '/' do
@current_month = Date.today.month
haml :index
end
get '/proxy' do
# We take the value from our select control in the param string
# We'll construct the date range based on that

get '/proxy' do
# We take the value from our select control in the param string
# We'll construct the date range based on that
# Let's create a default value just incase we attempt to call
# the API without the param we're expecting.

default_date = "#{Date.today.year}-#{"%02d" % Date.today.month}"

year_month = params[:year_month] || default_date
puts year_month

# Let's create a default value just incase we attempt to call
# the API without the param we're expecting.

default_date = "#{Date.today.year}-#{"%02d" % Date.today.month}"

year_month = params[:year_month] || default_date
puts year_month
# The start of the month is ALWAYS 01
start_date = "#{year_month}-01"

# The start of the month is ALWAYS 01
start_date = "#{year_month}-01"
# End of the month requires a little massaging
ymArray = year_month.split("-")
year = ymArray[0].to_i
month = ymArray[1].to_i

# End of the month requires a little massaging
ymArray = year_month.split("-")
year = ymArray[0].to_i
month = ymArray[1].to_i
# Ruby has a ton of neat little quirks. Here's an easy way to get the last day of a month
end_date = Date.new(year, month, -1)

# Ruby has a ton of neat little quirks. Here's an easy way to get the last day of a month
end_date = Date.new(year, month, -1)
# Core URL
api_url = "http://api.nytimes.com/svc/movies/v2/reviews/search.json?"

# Core URL
api_url = "http://api.nytimes.com/svc/movies/v2/reviews/search.json?"
# Your params
api_url += "&opening-date=#{start_date};#{end_date}"

# Your params
api_url += "&opening-date=#{start_date};#{end_date}"
# Default Sort by openning day
api_url += "&order=by-opening-date"

# Default Sort by openning day
api_url += "&order=by-opening-date"
# The API from 'my_api_key.rb'
api_url += "&api-key=#{API_KEY}"

puts api_url

# The API from 'my_api_key.rb'
api_url += "&api-key=#{API_KEY}"

puts api_url
Net::HTTP.get URI.parse(api_url)

Net::HTTP.get URI.parse(api_url)
end

end

# Adding declarations for static content. This includes our stylesheet and backbone app .js files
set :public, File.dirname(__FILE__) + '/public'
#end

# Run This App
# CotM.run!
# Adding declarations for static content. This includes our stylesheet and backbone app .js files
set :public, File.dirname(__FILE__) + '/public'

0 comments on commit cb9ca24

Please sign in to comment.