-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more code cleanup in the hopes that it's enough to get this app runni…
…ng on heroku
- Loading branch information
1 parent
a0c1317
commit cb9ca24
Showing
2 changed files
with
38 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require './cotm' | ||
|
||
run Sinatra::Application | ||
#run CotM.new |
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
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' |