diff --git a/docs/00_overview.md b/docs/00_overview.md new file mode 100644 index 00000000..f05ab353 --- /dev/null +++ b/docs/00_overview.md @@ -0,0 +1,7 @@ +# Overview + +... some general docs here ... + +## Media Types + +The API is currently JSON only. \ No newline at end of file diff --git a/docs/01_cross_origin.md b/docs/01_cross_origin.md new file mode 100644 index 00000000..031f7209 --- /dev/null +++ b/docs/01_cross_origin.md @@ -0,0 +1,23 @@ +# Web Clients + +When write an in-browsers client, you have to circumvent the browser's +[same origin policy](http://en.wikipedia.org/wiki/Same_origin_policy). +Generally, we offer two different approaches for this: +[Cross-Origin Resource Sharing](http://en.wikipedia.org/wiki/CORS) (aka CORS) +and [JSONP](http://en.wikipedia.org/wiki/JSONP). If you don't have any good +reason for using JSONP, we recommend you use CORS. + +## Cross-Origin Resource Sharing + +... some general docs here ... + +In contrast to JSONP, CORS does not lead to any execution of untrusted code. + +Most JavaScript frameworks, like [jQuery](http://jquery.com), take care of CORS +requests for you under the hood, so you can just do a normal *ajax* request. + +Our current setup allows the headers `Content-Type`, `Authorization`, `Accept` and the HTTP methods `HEAD`, `GET`, `POST`, `PATCH`, `PUT`, `DELETE`. + +## JSONP + +... some docs here ... diff --git a/lib/travis/api/app/endpoint/documentation.rb b/lib/travis/api/app/endpoint/documentation.rb index e38262d1..5f56edac 100644 --- a/lib/travis/api/app/endpoint/documentation.rb +++ b/lib/travis/api/app/endpoint/documentation.rb @@ -11,7 +11,12 @@ class Travis::Api::App get '/' do content_type :html endpoints = Endpoints.endpoints - erb :index, {}, :endpoints => endpoints.keys.sort.map { |k| endpoints[k] } + erb :index, {}, endpoints: endpoints.keys.sort.map { |k| endpoints[k] } + end + + get '/x' do + content_type :html + general_docs end helpers do @@ -38,6 +43,29 @@ class Travis::Api::App gsub(/<\/?code>/, ''). gsub(/TODO:?/, 'TODO') end + + private + + def general_docs + @@general_docs ||= doc_files.map do |file| + header, content = File.read(file).split("\n", 2) + content = markdown(content) + subheaders = [] + + content.gsub!(/

(.*)<\/h2>/) do + subheaders << $1 + "

#{$1}

" + end + + header.gsub! /^#* */, '' + { id: header, title: header, content: content, subheaders: subheaders } + end + end + + def doc_files + pattern = File.expand_path('../../../../../../docs/*.md', __FILE__) + Dir[pattern].sort + end end end end @@ -118,6 +146,13 @@ __END__
+ +@@ endpoint_content +<% unless endpoint['doc'].to_s.empty? %> + <%= docs_for endpoint %> +
+<% end %> +<% endpoint['routes'].each do |route| %> +
+

<%= route['verb'] %> <%= route['uri'] %>

+ <% if route['scope'] %> +

+

Required autorization scope: <%= route['scope'] %>
+

+ <% end %> + <%= docs_for route %> +
+<% end %> + +@@ entry +
+ + <%= content %> +
+