From 6e5883bb8011ceaf788c013329c8b00b68c199c8 Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Mon, 31 Mar 2014 14:16:20 -0400 Subject: [PATCH] return API key when creating a channel via API --- app/controllers/channels_controller.rb | 4 ++-- app/models/channel.rb | 13 +++++++++++++ app/views/docs/channels/_create.html.erb | 12 +++++++++++- app/views/docs/channels/_update.html.erb | 3 ++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index d66607c..97a60cd 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -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 diff --git a/app/models/channel.rb b/app/models/channel.rb index e3c7fb5..25cc02c 100644 --- a/app/models/channel.rb +++ b/app/models/channel.rb @@ -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 diff --git a/app/views/docs/channels/_create.html.erb b/app/views/docs/channels/_create.html.erb index e98fb82..010b13b 100644 --- a/app/views/docs/channels/_create.html.erb +++ b/app/views/docs/channels/_create.html.erb @@ -58,7 +58,11 @@ POST <%= @ssl_api_domain %>channels @@ -81,6 +85,12 @@ POST <%= @ssl_api_domain %>channels15</ranking> <username>hans</username> <tags type="array" /> + <api-keys type="array"> + <api-key> + <api-key>XXXXXXXXXXXXXXXX</api-key> + <write-flag type="boolean">true</write-flag> + </api-key> + </api-keys> </channel> diff --git a/app/views/docs/channels/_update.html.erb b/app/views/docs/channels/_update.html.erb index 4a2e8c1..3755bba 100644 --- a/app/views/docs/channels/_update.html.erb +++ b/app/views/docs/channels/_update.html.erb @@ -4,7 +4,8 @@
-To update a Channel feed, send an HTTP GET or POST to <%= @ssl_api_domain %>update.json.xml . +To update a Channel feed, send an HTTP GET or POST to
+<%= @ssl_api_domain %>update.json.xml .

Valid parameters: