return API key when creating a channel via API

This commit is contained in:
Lee Lawlor 2014-03-31 14:16:20 -04:00
parent 6d48aaa8fc
commit 6e5883bb80
4 changed files with 28 additions and 4 deletions

View File

@ -206,8 +206,8 @@ class ChannelsController < ApplicationController
channel.add_write_api_key
@channel_id = channel.id
respond_to do |format|
format.json { render :json => channel.to_json(Channel.public_options) }
format.xml { render :xml => channel.to_xml(Channel.public_options) }
format.json { render :json => channel.to_json(Channel.private_options) }
format.xml { render :xml => channel.to_xml(Channel.private_options) }
format.any { redirect_to channel_path(@channel_id, :anchor => "channelsettings") }
end
end

View File

@ -172,6 +172,19 @@ class Channel < ActiveRecord::Base
}
end
# used when creating a channel
def self.private_options
{
:root => false,
:only => [:id, :name, :description, :latitude, :longitude, :last_entry_id, :elevation, :created_at, :ranking],
:methods => :username,
:include => {
:tags => {:only => [:id, :name]},
:api_keys => {:only => [:api_key, :write_flag]}
}
}
end
# login name of the user who created the channel
def username; self.user.try(:login); end

View File

@ -58,7 +58,11 @@ POST <span class="str"><%= @ssl_api_domain %>channels<span class="format format-
"last_entry_id": null,
"ranking": 15,
"username": "hans",
"tags": []
"tags": [],
"api_keys": [{
"api_key": "XXXXXXXXXXXXXXXX",
"write_flag": true
}]
}
</pre>
@ -81,6 +85,12 @@ POST <span class="str"><%= @ssl_api_domain %>channels<span class="format format-
&lt;ranking type="integer">15&lt;/ranking>
&lt;username>hans&lt;/username>
&lt;tags type="array" />
&lt;api-keys type="array">
&lt;api-key>
&lt;api-key>XXXXXXXXXXXXXXXX&lt;/api-key>
&lt;write-flag type="boolean">true&lt;/write-flag>
&lt;/api-key>
&lt;/api-keys>
&lt;/channel>
</pre>

View File

@ -4,7 +4,8 @@
</div>
<br>
To update a Channel feed, send an HTTP GET or POST to <code><%= @ssl_api_domain %>update<span class="format format-json">.json</span><span class="format format-xml">.xml</span></code> .
To update a Channel feed, send an HTTP GET or POST to<br>
<code><%= @ssl_api_domain %>update<span class="format format-json">.json</span><span class="format format-xml">.xml</span></code> .
<br><br>
Valid parameters: