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

@ -12,7 +12,7 @@
}
#bootstrap-sidebar li a {
padding: 1px 8px;
padding: 0 8px;
font-size: 15px;
}

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

View File

@ -20,6 +20,7 @@
<li class="subitem"><a href="#get_field">Get Channel Field Feed</a></li>
<li class="subitem"><a href="#get_status">Get Status Updates</a></li>
<li class="subitem"><a href="#index">List Channels</a></li>
<li class="subitem"><a href="#show">View a Channel</a></li>
<li class="subitem"><a href="#create">Create a Channel</a></li>
<li class="subitem"><a href="#update">Update a Channel</a></li>
<li class="subitem"><a href="#clear">Clear a Channel</a></li>

View File

@ -116,6 +116,9 @@
<hr />
<%= render 'docs/channels/index' %>
<hr />
<%= render 'docs/channels/show' %>
<hr />
<%= render 'docs/channels/create' %>

View File

@ -0,0 +1,72 @@
<div>
<%= render 'response' %>
<h2 id="show">View a Channel</h2>
</div>
<br>
To view a specific Channel, send an HTTP GET to
<br>
<code><%= @ssl_api_domain %>channels/<span class="customcode">CHANNEL_ID</span><span class="format format-json">.json</span><span class="format format-xml">.xml</span></code> .
<br><br>
Valid parameters:
<ul>
<li><b>api_key</b> (string) - User's API Key; please note that this is different than a Channel API key, and can be found in <a href="/account">your account details</a>. If this key is provided, the Channel's private details (such as the Channel's API keys) will also be shown. (optional).</li>
</ul>
<br>
Example GET:
<pre>GET <span class="str"><%= @ssl_api_domain %>channels/1417<span class="format format-json">.json</span><span class="format format-xml">.xml</span></span></pre>
<br>
<div class="format format-block-xxxl format-text">
The response will be a webpage that shows the Channel.
</div>
<div class="format format-block-xxxl format-json">
The response will be a JSON object of the Channel, for example:
<pre class="prettyprint">
{
"id": 4,
"name": "My New Channel",
"description": null,
"metadata": null,
"latitude": null,
"longitude": null,
"created_at": "2014-03-25T13:12:50-04:00",
"elevation": null,
"last_entry_id": null,
"ranking": 15,
"username": "hans",
"tags": []
}
</pre>
</div>
<div class="format format-block-xxxl format-xml">
The response will be an XML object of public Channels, for example:
<pre class="prettyprint">
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;channel>
&lt;id type="integer">4&lt;/id>
&lt;name>My New Channel&lt;/name>
&lt;description nil="true" />
&lt;metadata nil="true" />
&lt;latitude type="decimal" nil="true" />
&lt;longitude type="decimal" nil="true" />
&lt;created-at type="dateTime">2014-03-25T20:17:44-04:00&lt;/created-at>
&lt;elevation nil="true" />
&lt;last-entry-id type="integer" nil="true" />
&lt;ranking type="integer">15&lt;/ranking>
&lt;username>hans&lt;/username>
&lt;tags type="array" />
&lt;/channel>
</pre>
</div>