diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api_controller.rb | 20 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 8 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 6 |
3 files changed, 29 insertions, 5 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 6f83d89d6..8d7de3140 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -203,14 +203,28 @@ class ApiController < ApplicationController if since_date_str begin - since_date = Date.strptime(since_date_str, "%Y-%m-%d") + since_date = Date.strptime(since_date_str, "%Y-%m-%d") rescue ArgumentError + render :json => {"errors" => [ + "Parameter since_date must be in format yyyy-mm-dd (not '#{since_date_str}')" ] }, + :status => 500 + return + end + @events = @events.where("info_request_events.created_at >= ?", since_date) + end + + # We take a "since" parameter that allows the client + # to restrict to events more recent than a certain other event + if since_event_id + begin + event = InfoRequestEvent.find(since_event_id) + rescue ActiveRecord::RecordNotFound render :json => {"errors" => [ - "Parameter since_date must be in format yyyy-mm-dd (not '#{since_date_str}')" ] }, + "Event ID #{since_event_id} not found" ] }, :status => 500 return end - @events = @events.where("info_request_events.created_at >= ?", since_date) + @events = @events.where("info_request_events.created_at > ?", event.created_at) end # We take a "since" parameter that allows the client diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 635ba8f58..0ee82d30c 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -278,9 +278,15 @@ class InfoRequestEvent < ActiveRecord::Base end self.params_yaml = params.to_yaml end + def params - YAML.load(self.params_yaml) + param_hash = YAML.load(params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end + def params_yaml_as_html ret = '' # split out parameters into old/new diffs, and other ones diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 8049349d0..59160381c 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -71,7 +71,11 @@ class PostRedirect < ActiveRecord::Base end def reason_params - YAML.load(reason_params_yaml) + param_hash = YAML.load(reason_params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end # Extract just local path part, without domain or # |