Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting multiple API versions #2353

Closed
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -368,4 +368,10 @@ def get_auth_data

# override to stop oauth plugin sending errors
def invalid_oauth_response; end

# The latest version of the API that's deployed. Useful for links to raw XML e.g. on browse pages
def latest_api_version
@browse_api_version = Settings.api_versions.map(&:to_f).max.to_s
end
helper_method :latest_api_version
end
8 changes: 4 additions & 4 deletions app/views/browse/changeset.html.erb
Expand Up @@ -17,9 +17,9 @@
<div class="buttons clearfix subscribe-buttons">
<form action="#">
<% if @changeset.subscribers.exists?(current_user.id) %>
<input class="action-button" type="submit" name="unsubscribe" value="<%= t("javascripts.changesets.show.unsubscribe") %>" data-method="POST" data-url="<%= changeset_unsubscribe_url(@changeset) %>" />
<input class="action-button" type="submit" name="unsubscribe" value="<%= t("javascripts.changesets.show.unsubscribe") %>" data-method="POST" data-url="<%= v06_changeset_unsubscribe_url(@changeset) %>" />
<% else %>
<input class="action-button" type="submit" name="subscribe" value="<%= t("javascripts.changesets.show.subscribe") %>" data-method="POST" data-url="<%= changeset_subscribe_url(@changeset) %>" />
<input class="action-button" type="submit" name="subscribe" value="<%= t("javascripts.changesets.show.subscribe") %>" data-method="POST" data-url="<%= v06_changeset_subscribe_url(@changeset) %>" />
<% end %>
</form>
</div>
Expand Down Expand Up @@ -137,7 +137,7 @@
<% end %>

<div class='secondary-actions'>
<%= link_to(t(".changesetxml"), :controller => "api/changesets", :action => "show") %>
<%= link_to(t(".changesetxml"), :controller => "api/changesets", :action => "show", :api_version => latest_api_version) %>
&middot;
<%= link_to(t(".osmchangexml"), :controller => "api/changesets", :action => "download") %>
<%= link_to(t(".osmchangexml"), :controller => "api/changesets", :action => "download", :api_version => latest_api_version) %>
</div>
4 changes: 2 additions & 2 deletions app/views/changesets/index.atom.builder
Expand Up @@ -17,10 +17,10 @@ atom_feed(:language => I18n.locale, :schema_date => 2009,
@changesets.each do |changeset|
feed.entry(changeset, :updated => changeset.closed_at, :id => changeset_url(changeset.id, :only_path => false)) do |entry|
entry.link :rel => "alternate",
:href => changeset_show_url(changeset, :only_path => false),
:href => v06_changeset_show_url(changeset, :only_path => false),
:type => "application/osm+xml"
entry.link :rel => "alternate",
:href => changeset_download_url(changeset, :only_path => false),
:href => v06_changeset_download_url(changeset, :only_path => false),
:type => "application/osmChange+xml"

if !changeset.tags.empty? && changeset.tags.key?("comment")
Expand Down
7 changes: 4 additions & 3 deletions config/routes.rb
Expand Up @@ -31,9 +31,6 @@ def v_string(version)
put "changeset/:id" => "changesets#update", :id => /\d+/
put "changeset/:id/close" => "changesets#close", :id => /\d+/
get "changesets" => "changesets#query"
post "changeset/:id/comment" => "changeset_comments#create", :as => :changeset_comment, :id => /\d+/
post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
end
end
end
Expand All @@ -56,6 +53,10 @@ def v_string(version)

# TODO: refactor these too
scope "api/0.6" do
post "changeset/:id/comment" => "api/changeset_comments#create", :as => :changeset_comment, :id => /\d+/
post "changeset/comment/:id/hide" => "api/changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "api/changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/

put "node/create" => "api/nodes#create"
get "node/:id/ways" => "api/ways#ways_for_node", :id => /\d+/
get "node/:id/relations" => "api/relations#relations_for_node", :id => /\d+/
Expand Down