From 0e406b3ed1b1b2c43588b436410d1ddac6466651 Mon Sep 17 00:00:00 2001 From: Hiro Asari Date: Fri, 15 Nov 2013 09:19:25 -0500 Subject: [PATCH] Accept `pretty` parameter for pretty formatting If the parameter is equal to `true` (in any case--`TRUE`, `True`) or a positive integer, return pretty formatted JSON data. No tests are necessary. --- lib/travis/api/app/helpers/respond_with.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/travis/api/app/helpers/respond_with.rb b/lib/travis/api/app/helpers/respond_with.rb index 18df03ad..66751047 100644 --- a/lib/travis/api/app/helpers/respond_with.rb +++ b/lib/travis/api/app/helpers/respond_with.rb @@ -10,7 +10,13 @@ class Travis::Api::App def respond_with(resource, options = {}) result = respond(resource, options) - result = JSON.pretty_generate(result) if result && response.content_type =~ /application\/json/ + if result && response.content_type =~ /application\/json/ + if params[:pretty].downcase == 'true' || params[:pretty].to_i > 0 + JSON.pretty_generate(result) + else + result.to_json + end + end halt result || 404 end