diff options
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/api.rb | 28 | ||||
-rw-r--r-- | web/lib/api/v4/josm.rb | 20 | ||||
-rw-r--r-- | web/lib/api/v4/key.rb | 86 | ||||
-rw-r--r-- | web/lib/api/v4/keys.rb | 64 | ||||
-rw-r--r-- | web/lib/api/v4/search.rb | 28 | ||||
-rw-r--r-- | web/lib/api/v4/site.rb | 28 | ||||
-rw-r--r-- | web/lib/api/v4/tag.rb | 75 | ||||
-rw-r--r-- | web/lib/api/v4/tags.rb | 24 | ||||
-rw-r--r-- | web/lib/api/v4/wiki.rb | 18 | ||||
-rw-r--r-- | web/lib/utils.rb | 16 |
10 files changed, 214 insertions, 173 deletions
diff --git a/web/lib/api.rb b/web/lib/api.rb index 7b82bff..d2ce590 100644 --- a/web/lib/api.rb +++ b/web/lib/api.rb @@ -71,10 +71,36 @@ class API sort.map{ |s| "<tt>#{s}</tt>" }.join(', ') end + def stack_results(level, stack, result) + result.each do |r| + stack.push({ + :level => level, + :name => "#{r[0]}:", + :type => r[1].to_s.gsub(/_/, ' '), + :desc => r[2] + }) + if r[3] + stack_results(level+1, stack, r[3]) + end + end + end + def show_result return '<span class="empty">unknown</span>' if result.nil? + return result if result.is_a?(String) - '<pre>' + JSON.pretty_generate(result).gsub(/"(STRING|INT|FLOAT|BOOL|ARRAY_OF_STRINGS)"/, '\1') + '</pre>' + + # old way of documenting now only used for old API versions + # this can be removed when all API calls <v4 are removed + if result.is_a?(Hash) + return '<pre>' + JSON.pretty_generate(result).gsub(/"(STRING|INT|FLOAT|BOOL|ARRAY_OF_STRINGS)"/, '\1') + '</pre>' + end + + stack = [] + stack_results(0, stack, result) + return '<table class="apiresults">' + + stack.map{ |s| "<tr><td>#{ ' ' * s[:level] }<tt>#{ s[:name] }</tt></td><td>#{ s[:type] }</td><td>#{ s[:desc] }</td></tr>" }.join("\n") + + '</table>' end def deprecated? diff --git a/web/lib/api/v4/josm.rb b/web/lib/api/v4/josm.rb index 18d3b04..9561bb0 100644 --- a/web/lib/api/v4/josm.rb +++ b/web/lib/api/v4/josm.rb @@ -8,16 +8,16 @@ class Taginfo < Sinatra::Base :query => 'Only show results where the key or value matches this query (substring match, optional).' }, :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING, - :value_bool => :STRING, - :rule => :STRING, - :area_color => :STRING, - :line_color => :STRING, - :line_width => :INT, - :icon => :STRING - }, + :result => paging_results([ + [:key, :STRING, ''], + [:value, :STRING, ''], + [:value_bool, :STRING, ''], + [:rule, :STRING, ''], + [:area_color, :STRING, ''], + [:line_color, :STRING, ''], + [:line_width, :INT, ''], + [:icon, :STRING, ''] + ]), :example => { :style => 'standard', :page => 1, :rp => 10}, :ui => '/reports/josm_styles' }) do diff --git a/web/lib/api/v4/key.rb b/web/lib/api/v4/key.rb index 5da3bbd..7374628 100644 --- a/web/lib/api/v4/key.rb +++ b/web/lib/api/v4/key.rb @@ -4,12 +4,12 @@ class Taginfo < Sinatra::Base api(4, 'key/stats', { :description => 'Show some database statistics for given key.', :parameters => { :key => 'Tag key (required).' }, - :result => { - :type => :STRING, - :count => :INT, - :count_fraction => :FLOAT, - :values => :INT - }, + :result => no_paging_results([ + [:type, :STRING, 'Object type ("all", "nodes", "ways", or "relations")'], + [:count, :INT, 'Number of objects with this type and key.'], + [:count_fraction, :FLOAT, 'Number of objects in relation to all objects.'], + [:values, :INT, 'Number of different values for this key.'] + ]), :example => { :key => 'amenity' }, :ui => '/keys/amenity#overview' }) do @@ -91,12 +91,12 @@ class Taginfo < Sinatra::Base :relations => { :doc => 'Only values on tags used on relations.' } }, :sort => %w( value count_all count_nodes count_ways count_relations ), - :result => { - :value => :STRING, - :count => :INT, - :fraction => :FLOAT, - :description => :STRING - }, + :result => paging_results([ + [:value, :STRING, 'Value'], + [:count, :INT, 'Number of times this key/value is in the OSM database.'], + [:fraction, :FLOAT, 'Number of times in relation to number of times this key is in the OSM database.'], + [:description, :STRING, 'Description of the tag from the wiki.'] + ]), :example => { :key => 'highway', :page => 1, :rp => 10, :sortname => 'count_ways', :sortorder => 'desc' }, :ui => '/keys/highway#values' }) do @@ -175,12 +175,12 @@ class Taginfo < Sinatra::Base :relations => { :doc => 'Only values on tags used on relations.' } }, :sort => %w( together_count other_key from_fraction ), - :result => { - :other_key => :STRING, - :together_count => :INT, - :to_fraction => :FLOAT, - :from_fraction => :FLOAT - }, + :result => paging_results([ + [:other_key, :STRING, ''], + [:together_count, :INT, ''], + [:to_fraction, :FLOAT, ''], + [:from_fraction, :FLOAT, ''] + ]), :example => { :key => 'highway', :page => 1, :rp => 10, :sortname => 'together_count', :sortorder => 'desc' }, :ui => '/keys/highway#keys' }) do @@ -232,21 +232,21 @@ class Taginfo < Sinatra::Base :description => 'Get list of wiki pages in different languages describing a key.', :parameters => { :key => 'Tag key (required)' }, :paging => :no, - :result => { - :lang => :STRING, - :language => :STRING, - :language_en => :STRING, - :title => :STRING, - :description => :STRING, - :image => :STRING, - :on_node => :BOOL, - :on_way => :BOOL, - :on_area => :BOOL, - :on_relation => :BOOL, - :tags_implies => :ARRAY_OF_STRINGS, - :tags_combination => :ARRAY_OF_STRINGS, - :tags_linked => :ARRAY_OF_STRINGS - }, + :result => no_paging_results([ + [:lang, :STRING, ''], + [:language, :STRING, ''], + [:language_en, :STRING, ''], + [:title, :STRING, ''], + [:description, :STRING, ''], + [:image, :STRING, ''], + [:on_node, :BOOL, ''], + [:on_way, :BOOL, ''], + [:on_area, :BOOL, ''], + [:on_relation, :BOOL, ''], + [:tags_implies, :ARRAY_OF_STRINGS, ''], + [:tags_combination, :ARRAY_OF_STRINGS, ''], + [:tags_linked, :ARRAY_OF_STRINGS, ''] + ]), :example => { :key => 'highway' }, :ui => '/keys/highway#wiki' }) do @@ -265,16 +265,16 @@ class Taginfo < Sinatra::Base :query => 'Only show results where the value matches this query (substring match, optional).' }, :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING, - :value_bool => :STRING, - :rule => :STRING, - :area_color => :STRING, - :line_color => :STRING, - :line_width => :INT, - :icon => :STRING - }, + :result => paging_results([ + [:key, :STRING, ''], + [:value, :STRING, ''], + [:value_bool, :STRING, ''], + [:rule, :STRING, ''], + [:area_color, :STRING, ''], + [:line_color, :STRING, ''], + [:line_width, :INT, ''], + [:icon, :STRING, ''] + ]), :example => { :style => 'standard', :key => 'highway', :page => 1, :rp => 10}, :ui => '/keys/highway#josm' }) do diff --git a/web/lib/api/v4/keys.rb b/web/lib/api/v4/keys.rb index 3762c96..0d3f023 100644 --- a/web/lib/api/v4/keys.rb +++ b/web/lib/api/v4/keys.rb @@ -14,22 +14,22 @@ class Taginfo < Sinatra::Base :paging => :optional, :filter => @@filters, :sort => %w( key count_all count_nodes count_ways count_relations values_all users_all in_wiki in_josm in_potlatch length ), - :result => { - :key => :STRING, - :count_all => :INT, - :count_all_fraction => :FLOAT, - :count_nodes => :INT, - :count_nodes_fraction => :FLOAT, - :count_ways => :INT, - :count_ways_fraction => :FLOAT, - :count_relations => :INT, - :count_relations_fraction => :FLOAT, - :values_all => :INT, - :users_all => :INT, - :in_wiki => :BOOL, - :in_josm => :BOOL, - :in_potlatch => :BOOL - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:count_all, :INT, 'Number of objects in the OSM database with this key.'], + [:count_all_fraction, :FLOAT, 'Number of objects in relation to all objects.'], + [:count_nodes, :INT, 'Number of nodes in the OSM database with this key.'], + [:count_nodes_fraction, :FLOAT, 'Number of nodes in relation to all tagged nodes.'], + [:count_ways, :INT, 'Number of ways in the OSM database with this key.'], + [:count_ways_fraction, :FLOAT, 'Number of ways in relation to all ways.'], + [:count_relations, :INT, 'Number of relations in the OSM database with this key.'], + [:count_relations_fraction, :FLOAT, 'Number of relations in relation to all relations.'], + [:values_all, :INT, ''], + [:users_all, :INT, ''], + [:in_wiki, :BOOL, ''], + [:in_josm, :BOOL, ''], + [:in_potlatch, :BOOL, ''], + ]), :example => { :page => 1, :rp => 10, :filter => 'in_wiki', :sortname => 'key', :sortorder => 'asc' }, :ui => '/keys' }) do @@ -142,10 +142,10 @@ class Taginfo < Sinatra::Base :parameters => { :query => 'Only show keys matching this query (substring match, optional).' }, :paging => :optional, :sort => %w( key ), - :result => { - :key => :STRING, - :lang => "Hash with language codes as keys and values showing what type of wiki page is available" - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:lang, :HASH, 'Hash with language codes as keys and values showing what type of wiki pages are available.'] + ]), :example => { :page => 1, :rp => 10, :sortname => 'key', :sortorder => 'asc' }, :ui => '/reports/language_comparison_table_for_keys_in_the_wiki' }) do @@ -189,18 +189,18 @@ class Taginfo < Sinatra::Base }, :paging => :optional, :sort => %w( key count_all values_all users_all ), - :result => { - :key => :STRING, - :count_all => :INT, - :count_all_fraction => :FLOAT, - :values_all => :INT, - :users_all => :INT, - :prevalent_values => [{ - :value => :STRING, - :count => :INT, - :fraction => :FLOAT - }] - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:count_all, :INT, 'Number of occurances in database.'], + [:count_all_fraction, :FLOAT, ''], + [:values_all, :INT, 'Number of different values for this key.'], + [:users_all, :INT, 'Number of different users who own objects with this key.'], + [:prevalent_values, :HASH, 'Often used values.', [ + [:value, :STRING, 'Value'], + [:count, :INT, 'Number of occurances of this value.'], + [:fraction, :FLOAT, ''] + ]] + ]), :example => { :min_count => 1000, :english => '1', :page => 1, :rp => 10, :sortname => 'count_all', :sortorder => 'desc' }, :ui => '/reports/frequently_used_keys_without_wiki_page' }) do diff --git a/web/lib/api/v4/search.rb b/web/lib/api/v4/search.rb index a8ca2c0..e41165d 100644 --- a/web/lib/api/v4/search.rb +++ b/web/lib/api/v4/search.rb @@ -6,11 +6,11 @@ class Taginfo < Sinatra::Base :parameters => { :query => 'Value to search for (substring search, required).' }, :sort => %w( count_all key value ), :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING, - :count_all => :INT - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:value, :STRING, 'Value'], + [:count_all, :INT, 'Number of objects in the database with this tag.'] + ]), :example => { :query => 'foo', :page => 1, :rp => 10 }, :ui => '/search?q=foo#values' }) do @@ -47,11 +47,11 @@ class Taginfo < Sinatra::Base :parameters => { :query => 'Value to search for (substring search, required).' }, :sort => %w( count_all key value ), :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING, - :count_all => :INT - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:value, :STRING, 'Value'], + [:count_all, :INT, 'Number of objects in the database with this tag.'] + ]), :example => { :query => 'highway%3Dresidential', :page => 1, :rp => 10 }, :ui => '/search?q=highway%3Dresidential' }) do @@ -95,10 +95,10 @@ class Taginfo < Sinatra::Base :parameters => { :query => 'Value to search for (substring search, required).' }, :sort => %w( count_all key value ), :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:value, :STRING, 'Value'] + ]), :example => { :query => 'fire', :page => 1, :rp => 10 }, :ui => '/search?q=fire#fulltext' }) do diff --git a/web/lib/api/v4/site.rb b/web/lib/api/v4/site.rb index 303e9c1..7db0173 100644 --- a/web/lib/api/v4/site.rb +++ b/web/lib/api/v4/site.rb @@ -3,14 +3,14 @@ class Taginfo < Sinatra::Base api(4, 'site/info', { :description => 'Get information about this taginfo site.', - :result => { - :url => :STRING, - :name => :STRING, - :description => :STRING, - :icon => :STRING, - :contact => :STRING, - :area => :STRING - }, + :result => [ + [:url, :STRING, 'URL'], + [:name, :STRING, 'Name'], + [:description, :STRING, 'Description'], + [:icon, :STRING, 'Path to icon which appears on the lop left corner of all pages.'], + [:contact, :STRING, 'Contact information to admin.'], + [:area, :STRING, 'Description of area covered.'] + ], :example => { } }) do data = {} @@ -22,12 +22,12 @@ class Taginfo < Sinatra::Base api(4, 'site/sources', { :description => 'Get information about the data sources used.', - :result => { - :name => :STRING, - :data_until => :STRING, - :update_start => :STRING, - :update_end => :STRING - }, + :result => [ + [:name , :STRING, 'Name'], + [:data_until , :STRING, 'All changes in the source until this date are reflected in taginfo.'], + [:update_start, :STRING, 'Date/Timestamp when last update was started.'], + [:update_end , :STRING, 'Date/Timestamp when last update was finished.'] + ], :example => { }, :ui => '/sources' }) do diff --git a/web/lib/api/v4/tag.rb b/web/lib/api/v4/tag.rb index 4b5d731..f15b202 100644 --- a/web/lib/api/v4/tag.rb +++ b/web/lib/api/v4/tag.rb @@ -7,12 +7,11 @@ class Taginfo < Sinatra::Base :key => 'Tag key (required).', :value => 'Tag value (required).' }, - :result => { - :type => :STRING, - :count => :INT, - :count_fraction => :FLOAT, - :values => :INT - }, + :result => no_paging_results([ + [:type, :STRING, 'Object type ("all", "nodes", "ways", or "relations")'], + [:count, :INT, 'Number of objects with this type and tag.'], + [:count_fraction, :FLOAT, 'Number of objects in relation to all objects.'] + ]), :example => { :key => 'amenity', :value => 'school' }, :ui => '/tags/amenity=school#overview' }) do @@ -59,13 +58,13 @@ class Taginfo < Sinatra::Base :relations => { :doc => 'Only values on tags used on relations.' } }, :sort => %w( together_count other_tag from_fraction ), - :result => { - :other_key => :STRING, - :other_value => :STRING, - :together_count => :INT, - :to_fraction => :FLOAT, - :from_fraction => :FLOAT - }, + :result => paging_results([ + [:other_key, :STRING, ''], + [:other_value, :STRING, ''], + [:together_count, :INT, ''], + [:to_fraction, :FLOAT, ''], + [:from_fraction, :FLOAT, ''] + ]), :example => { :key => 'highway', :value => 'residential', :page => 1, :rp => 10, :sortname => 'together_count', :sortorder => 'desc' }, :ui => '/tags/highway=residential#combinations' }) do @@ -130,21 +129,21 @@ class Taginfo < Sinatra::Base :description => 'Get list of wiki pages in different languages describing a tag.', :parameters => { :key => 'Tag key (required)', :value => 'Tag value (required).' }, :paging => :no, - :result => { - :lang => :STRING, - :language => :STRING, - :language_en => :STRING, - :title => :STRING, - :description => :STRING, - :image => :STRING, - :on_node => :BOOL, - :on_way => :BOOL, - :on_area => :BOOL, - :on_relation => :BOOL, - :tags_implies => :ARRAY_OF_STRINGS, - :tags_combination => :ARRAY_OF_STRINGS, - :tags_linked => :ARRAY_OF_STRINGS - }, + :result => no_paging_results([ + [:lang, :STRING, ''], + [:language, :STRING, ''], + [:language_en, :STRING, ''], + [:title, :STRING, ''], + [:description, :STRING, ''], + [:image, :STRING, ''], + [:on_node, :BOOL, ''], + [:on_way, :BOOL, ''], + [:on_area, :BOOL, ''], + [:on_relation, :BOOL, ''], + [:tags_implies, :ARRAY_OF_STRINGS, ''], + [:tags_combination, :ARRAY_OF_STRINGS, ''], + [:tags_linked, :ARRAY_OF_STRINGS, ''] + ]), :example => { :key => 'highway', :value => 'residential' }, :ui => '/tags/highway=residential#wiki' }) do @@ -164,16 +163,16 @@ class Taginfo < Sinatra::Base :value => 'Tag value (required).' }, :paging => :optional, - :result => { - :key => :STRING, - :value => :STRING, - :value_bool => :STRING, - :rule => :STRING, - :area_color => :STRING, - :line_color => :STRING, - :line_width => :INT, - :icon => :STRING - }, + :result => paging_results([ + [:key, :STRING, ''], + [:value, :STRING, ''], + [:value_bool, :STRING, ''], + [:rule, :STRING, ''], + [:area_color, :STRING, ''], + [:line_color, :STRING, ''], + [:line_width, :INT, ''], + [:icon, :STRING, ''] + ]), :example => { :style => 'standard', :key => 'highway', :value => 'residential', :page => 1, :rp => 10}, :ui => '/tags/highway=residential#josm' }) do diff --git a/web/lib/api/v4/tags.rb b/web/lib/api/v4/tags.rb index f9ed196..9830e7a 100644 --- a/web/lib/api/v4/tags.rb +++ b/web/lib/api/v4/tags.rb @@ -6,18 +6,18 @@ class Taginfo < Sinatra::Base :parameters => { :query => 'Only show tags matching this query (substring match in key and value, optional).' }, :paging => :optional, :sort => %w( tag count_all count_nodes count_ways count_relations ), - :result => { - :key => :STRING, - :value => :STRING, - :count_all => :INT, - :count_all_fraction => :FLOAT, - :count_nodes => :INT, - :count_nodes_fraction => :FLOAT, - :count_ways => :INT, - :count_ways_fraction => :FLOAT, - :count_relations => :INT, - :count_relations_fraction => :FLOAT, - }, + :result => paging_results([ + [:key, :STRING, 'Key'], + [:value, :STRING, 'Value'], + [:count_all, :INT, 'Number of objects in the OSM database with this tag.'], + [:count_all_fraction, :FLOAT, 'Number of objects in relation to all objects.'], + [:count_nodes, :INT, 'Number of nodes in the OSM database with this tag.'], + [:count_nodes_fraction, :FLOAT, 'Number of nodes in relation to all tagged nodes.'], + [:count_ways, :INT, 'Number of ways in the OSM database with this tag.'], + [:count_ways_fraction, :FLOAT, 'Number of ways in relation to all ways.'], + [:count_relations, :INT, 'Number of relations in the OSM database with this tag.'], + [:count_relations_fraction, :FLOAT, 'Number of relations in relation to all relations.'] + ]), :example => { :page => 1, :rp => 10, :sortname => 'tag', :sortorder => 'asc' }, :ui => '/tags' }) do diff --git a/web/lib/api/v4/wiki.rb b/web/lib/api/v4/wiki.rb index dbc6b26..45f85b8 100644 --- a/web/lib/api/v4/wiki.rb +++ b/web/lib/api/v4/wiki.rb @@ -4,15 +4,15 @@ class Taginfo < Sinatra::Base api(4, 'wiki/languages', { :description => 'List languages taginfo knows about and how many wiki pages describing keys and tags there are in these languages.', :paging => :no, - :result => { - :code => :STRING, - :native_name => :STRING, - :english_name => :STRING, - :wiki_key_pages => :INT, - :wiki_key_pages_fraction => :FLOAT, - :wiki_tag_pages => :INT, - :wiki_tag_pages_fraction => :FLOAT - }, + :result => no_paging_results([ + [:code , :STRING, 'Language code.'], + [:native_name , :STRING, 'Name of language in this language.'], + [:english_name , :STRING, 'Name of language in English.'], + [:wiki_key_pages , :INT, 'Number of "Key" wiki pages in this language.'], + [:wiki_key_pages_fraction, :FLOAT, 'Number of "Key" wiki pages in this language in relation to the number of keys described in any language in the wiki.'], + [:wiki_tag_pages , :INT, 'Number of "Tag" wiki pages in this language.'], + [:wiki_tag_pages_fraction, :FLOAT, 'Number of "Tag" wiki pages in this language in relation to the number of tags described in any language in the wiki.'] + ]), :sort => %w( code native_name english_name wiki_key_pages wiki_tag_pages ), :example => { :sortname => 'wiki_key_pages', :sortorder => 'desc' }, :ui => '/reports/languages' diff --git a/web/lib/utils.rb b/web/lib/utils.rb index 3a9e8e6..db80787 100644 --- a/web/lib/utils.rb +++ b/web/lib/utils.rb @@ -215,3 +215,19 @@ def get_josm_style_rules_result(total, res) }.to_json end +def paging_results(array) + return [ + [ :total, :INT, 'Total number of results.' ], + [ :page, :INT, 'Result page number (first has page number 1).' ], + [ :rp, :INT, 'Results per page.' ], + [ :data, :ARRAY_OF_HASHES, 'Array with results.', array ] + ]; +end + +def no_paging_results(array) + return [ + [ :total, :INT, 'Total number of results.' ], + [ :data, :ARRAY_OF_HASHES, 'Array with results.', array ] + ]; +end + |