Implement "fields" parameter from the YouTube Data API (#429)

* Implement fields handling
This commit is contained in:
afrmtbl
2019-03-30 21:18:34 -04:00
committed by Omar Roth
parent 1b78001201
commit a7723e6ded
2 changed files with 258 additions and 0 deletions

View File

@@ -97,6 +97,16 @@ class APIHandler < Kemal::Handler
if env.response.headers["Content-Type"]?.try &.== "application/json"
response = JSON.parse(response)
if env.params.query["fields"]?
fields_text = env.params.query["fields"]
begin
JSONFilter.filter(response, fields_text)
rescue ex
env.response.status_code = 400
response = {"error" => ex.message}
end
end
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
response = response.to_pretty_json
else