From 0e0d83c7eb9405cf94221d16d339673d51ba9bfa Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 23 Feb 2013 12:21:27 -0500 Subject: [PATCH] add legacy artist json api --- app/models/artist.rb | 12 ++++++++++++ app/views/legacy/artists.json.erb | 1 + config/routes.rb | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 app/views/legacy/artists.json.erb diff --git a/app/models/artist.rb b/app/models/artist.rb index 55d15a8e1..75f472737 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -284,6 +284,18 @@ class Artist < ActiveRecord::Base end end + def legacy_api_hash + return { + :id => id, + :name => name, + :other_names => other_names, + :group_name => group_name, + :urls => artist_urls.map {|x| x.url}, + :is_active => is_active?, + :updater_id => 0 + } + end + def initialize_creator self.creator_id = CurrentUser.user.id end diff --git a/app/views/legacy/artists.json.erb b/app/views/legacy/artists.json.erb new file mode 100644 index 000000000..f7b4addaa --- /dev/null +++ b/app/views/legacy/artists.json.erb @@ -0,0 +1 @@ +[<%= raw @artists.map(&:to_json).join(",") %>] diff --git a/config/routes.rb b/config/routes.rb index a3dc2fe14..88b77e07d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -201,7 +201,8 @@ Danbooru::Application.routes.draw do # legacy aliases match "/artist" => redirect {|params, req| "/artists?page=#{req.params[:page]}"} - match "/artist/index.xml", :controller => "legacy", :action => "artists" + match "/artist/index.xml", :controller => "legacy", :action => "artists", :format => "xml" + match "/artist/index.json", :controller => "legacy", :action => "artists", :format => "json" match "/artist/index" => redirect {|params, req| "/artists?page=#{req.params[:page]}"} match "/artist/show/:id" => redirect("/artists/%{id}") match "/artist/show" => redirect {|params, req| "/artists?name=#{CGI::escape(req.params[:name])}"}