add API commands to view a single Channel

This commit is contained in:
Lee Lawlor
2014-08-15 21:56:02 -04:00
parent 83fd941c10
commit 32dac9c9c7
11 changed files with 204 additions and 6 deletions

View File

@ -152,7 +152,6 @@ class ChannelsController < ApplicationController
end
def show
@channel = Channel.find(params[:id]) if params[:id]
@title = @channel.name
@ -164,6 +163,15 @@ class ChannelsController < ApplicationController
api_index @channel.id
# if owner of channel
get_channel_data if @mychannel
# if a json or xml request
if request.format == :json || request.format == :xml
# authenticate the channel if the user owns the channel
authenticated = (@mychannel) || (User.find_by_api_key(get_apikey) == @channel.user)
# set options correctly
options = authenticated ? Channel.private_options : Channel.public_options
end
respond_to do |format|
format.html do
if @mychannel
@ -174,7 +182,8 @@ class ChannelsController < ApplicationController
session[:errors] = nil
end
end
format.json { render :json => @channel.as_json(Channel.public_options) }
format.json { render :json => @channel.as_json(options) }
format.xml { render :xml => @channel.to_xml(options) }
end
end