Class: Barton::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Barton::App
- Defined in:
- lib/barton/app.rb
Instance Method Summary collapse
-
#prepare_response(args = nil) ⇒ Object
Prepares and array of results for the API response.
Instance Method Details
#prepare_response(args = nil) ⇒ Object
Prepares and array of results for the API response
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/barton/app.rb', line 71 def prepare_response( args=nil ) # add generic API meta data response = {} response[:name] = "Barton API" response[:disclaimer] = "This data is crowded sourced and provided free of charge for informational purposes only. No guarantees regarding data quality are made whatsoever apart from it's rather considerable coolness." response[:license] = "MIT License http://www.opensource.org/licenses/mit-license.php" unless args.nil? response[:result_count] = args.length response[:results] = args status 404 if args.length == 0 end response[:resources] = { :home => Barton.api_url, :api => "#{Barton.api_url}/api", :electorates => "#{Barton.api_url}/api/electorates", :members => "#{Barton.api_url}/api/members" } response[:examples] = { :id => "#{Barton.api_url}/api/members/0db2ec", :geo => "#{Barton.api_url}/api/electorates?geo=151.2054563,-33.8438383", :tags => "#{Barton.api_url}/api/members?tags=sydney,local", :mixed => "#{Barton.api_url}/api/electorates?geo=151.2054563,-33.8438383&tags=federal", } # format content_type 'application/json;charset=utf-8' JSON.pretty_generate( response ) end |