Skip to content

Commit

Permalink
fixing format parameter to be backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
kylethefeared committed Dec 18, 2009
1 parent 389382a commit 12cc3c4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions timeapi.rb
Expand Up @@ -4,6 +4,7 @@
require 'date'
require 'time'
require 'active_support'
require 'cgi'
require 'json'

module TimeAPI
Expand Down Expand Up @@ -81,18 +82,18 @@ def prefers_json?
def json?
prefers_json? \
|| /\.json$/.match((params[:zone] || '').downcase) \
|| /\.json$/.match((params[:time] || '').downcase) \
|| request.params.map { |k,v| k.downcase }.include?('json')
|| /\.json$/.match((params[:time] || '').downcase)
end

def jsonp?
json? && callback.present?
end

def format
(request.params['format'] || jsonp? ? '%B %d, %Y %H:%M:%S GMT%z' : '') \
.gsub('%20', ' ') \
.gsub('\\', '%')
format = (request.params.select { |k,v| v.blank? }.first || [nil]).first \
|| request.params['format'] \
|| (jsonp? ? '%B %d, %Y %H:%M:%S GMT%z' : '')
CGI.unescape(format).gsub('\\', '%')
end

get '/' do
Expand Down

0 comments on commit 12cc3c4

Please sign in to comment.