Permalink
Browse files

Adding support for JSON in the API

  • Loading branch information...
robbyrussell committed Sep 2, 2008
1 parent e755425 commit 36bcd0716a0a86fdaaf352d7760653b886877f2e
Showing with 16 additions and 9 deletions.
  1. +12 −9 app/controllers/api/links_controller.rb
  2. +4 −0 app/models/link.rb
@@ -1,15 +1,18 @@
class Api::LinksController < Api::BaseController
def create
respond_to do |format|
format.xml do
@link = Link.find_or_create_by_website_url( params[:link][:website_url] )
@link.ip_address = request.remote_ip if @link.new_record?
if @link.save
render :xml => @link.to_api_xml
else
render :xml => xml_error_response( "Unable to generate a RubyURL for you" )
end
@link = Link.find_or_create_by_website_url( params[:link][:website_url] )
@link.ip_address = request.remote_ip if @link.new_record?
if @link.save
respond_to do |format|
format.xml { render :xml => @link.to_api_xml }
format.json { render :json => @link.to_api_json }
end
else
respond_to do |format|
format.xml { render :xml => xml_error_response( "Unable to generate a RubyURL for you" ) }
format.json { render :json => "Unable to generate a RubyURL for you".to_json }
end
end
end
end
View
@@ -29,6 +29,10 @@ def to_api_xml
end
end
def to_api_json
self.to_json( :only => [ :website_url, :permalink ] )
end
private
def generate_token

0 comments on commit 36bcd07

Please sign in to comment.