diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-06 12:26:56 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-06 12:28:43 +0100 |
commit | 94cf8b600b3b59e3bad066b6a4b7bf010007e84e (patch) | |
tree | 87d02818a7812b9e03f15d838dd6f25a9bc6d7fd | |
parent | 71577075ff777cf2a6f3b4e7b6c8fd37d206d960 (diff) | |
download | taginfo-94cf8b600b3b59e3bad066b6a4b7bf010007e84e.tar taginfo-94cf8b600b3b59e3bad066b6a4b7bf010007e84e.tar.gz |
Started work on API version 4.
-rw-r--r-- | web/lib/api.rb | 8 | ||||
-rw-r--r-- | web/lib/api/main.rb | 1 | ||||
-rw-r--r-- | web/lib/api/site.rb | 23 | ||||
-rwxr-xr-x | web/taginfo.rb | 4 | ||||
-rw-r--r-- | web/views/taginfo/apidoc.erb | 22 | ||||
-rw-r--r-- | web/views/taginfo/index.erb | 2 |
6 files changed, 53 insertions, 7 deletions
diff --git a/web/lib/api.rb b/web/lib/api.rb index 9b3e2ba..7b82bff 100644 --- a/web/lib/api.rb +++ b/web/lib/api.rb @@ -77,6 +77,14 @@ class API '<pre>' + JSON.pretty_generate(result).gsub(/"(STRING|INT|FLOAT|BOOL|ARRAY_OF_STRINGS)"/, '\1') + '</pre>' end + def deprecated? + return !@superseded_by.nil? + end + + def superseded_by + return '/api/' + @superseded_by + end + end class APIParameters diff --git a/web/lib/api/main.rb b/web/lib/api/main.rb index 4819972..836340c 100644 --- a/web/lib/api/main.rb +++ b/web/lib/api/main.rb @@ -2,6 +2,7 @@ class Taginfo < Sinatra::Base api(2, 'site', { + :superseded_by => '4/site', :description => 'Get information about this taginfo site.', :result => { :url => :STRING, diff --git a/web/lib/api/site.rb b/web/lib/api/site.rb new file mode 100644 index 0000000..36f989c --- /dev/null +++ b/web/lib/api/site.rb @@ -0,0 +1,23 @@ +# web/lib/api/site.rb +class Taginfo < Sinatra::Base + + api(4, 'site', { + :description => 'Get information about this taginfo site.', + :result => { + :url => :STRING, + :name => :STRING, + :description => :STRING, + :icon => :STRING, + :contact => :STRING, + :area => :STRING + }, + :example => { } + }) do + data = {} + [:url, :name, :description, :icon, :contact, :area].each do |k| + data[k] = TaginfoConfig.get("instance.#{k}") + end + return data.to_json + end + +end diff --git a/web/taginfo.rb b/web/taginfo.rb index 6beadb7..13bcc2f 100755 --- a/web/taginfo.rb +++ b/web/taginfo.rb @@ -185,6 +185,7 @@ class Taginfo < Sinatra::Base #-------------------------------------------------------------------------- + # old deprecated API (version 2 and 3) load 'lib/api/db.rb' load 'lib/api/josm.rb' load 'lib/api/main.rb' @@ -193,6 +194,9 @@ class Taginfo < Sinatra::Base load 'lib/api/wiki.rb' load 'lib/api/langtag.rb' + # current API (version 4) + load 'lib/api/site.rb' + load 'lib/ui/embed.rb' load 'lib/ui/keys_tags.rb' load 'lib/ui/reports.rb' diff --git a/web/views/taginfo/apidoc.erb b/web/views/taginfo/apidoc.erb index 3dab6d2..864dacc 100644 --- a/web/views/taginfo/apidoc.erb +++ b/web/views/taginfo/apidoc.erb @@ -2,6 +2,12 @@ <p>See <a href="http://wiki.openstreetmap.org/wiki/Taginfo/API">the OSM wiki</a> for general information about the API.</p> +<% if params[:show_deprecated] %> +<p><span class="button"><a href="/taginfo/apidoc">Do not show deprecated API calls</a></span></p> +<% else %> +<p><span class="button"><a href="/taginfo/apidoc?show_deprecated=true">Also show deprecated API calls</a></span></p> +<% end %> + <h2>Table of Contents</h2> <p style="color: red;">This list of API calls and their descriptions are not complete!</p> @@ -9,17 +15,20 @@ <ul> <% API.paths.keys.sort.each do |version| API.paths[version].keys.sort.each do |path| - doc = API.paths[version][path] %> - <li><a href="#<%= doc.complete_path.tr('/', '_')[1,1000] %>"><%= doc.complete_path %></li> -<% end + doc = API.paths[version][path] + if !doc.deprecated? || params[:show_deprecated] %> + <li><a href="#<%= doc.complete_path.tr('/', '_')[1,1000] %>"><%= doc.complete_path %></a><%= doc.deprecated? ? " <span class='bad'>Deprecated. Use <a href='##{ doc.superseded_by.tr('/', '_')[1,1000] }'>#{ doc.superseded_by }</a> instead.</span>" : '' %></li> +<% end + end end %> </ul> <% API.paths.keys.sort.each do |version| API.paths[version].keys.sort.each do |path| - doc = API.paths[version][path] %> + doc = API.paths[version][path] + if !doc.deprecated? || params[:show_deprecated] %> <a name="<%= doc.complete_path.tr('/', '_')[1,1000] %>"></a> -<h2><%= doc.complete_path %></h2> +<h2><%= doc.complete_path %><%= doc.deprecated? ? " <span class='bad'>Deprecated. Use <a href='##{ doc.superseded_by.tr('/', '_')[1,1000] }'>#{ doc.superseded_by }</a> instead.</span>" : '' %></h2> <table class="desc"> </tr> <tr> @@ -60,5 +69,6 @@ <td><a href="<%= doc.show_ui %>" target="_blank"><%= doc.show_ui %></a></td> </tr> </table> -<% end +<% end + end end %> diff --git a/web/views/taginfo/index.erb b/web/views/taginfo/index.erb index 893bfe9..40f4790 100644 --- a/web/views/taginfo/index.erb +++ b/web/views/taginfo/index.erb @@ -15,5 +15,5 @@ <tr><td><%= k %></td><td><%= TaginfoConfig.get("instance.#{k}") %></td></tr> <% end %> </table> - <p>These config settings are also available from the <tt>/api/2/site</tt> <a href="/taginfo/apidoc#api_2_site">API call</a>.</p> + <p style="margin-top: 10px;">These config settings are also available from the <tt>/api/4/site</tt> <a href="/taginfo/apidoc#api_4_site">API call</a>.</p> </div> |