From 07aade688292da9a4b5369500cde821769b7eadc Mon Sep 17 00:00:00 2001 From: lukemelia Date: Thu, 4 May 2006 05:38:47 +0000 Subject: [PATCH] Add two new API methods: ListContexts and ListProjects. See http://0.0.0.0:3000/backend/invoke to experiment. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@234 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/apis/todo_api.rb | 9 +++++++++ tracks/app/controllers/backend_controller.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/tracks/app/apis/todo_api.rb b/tracks/app/apis/todo_api.rb index 385a207f..584640ca 100644 --- a/tracks/app/apis/todo_api.rb +++ b/tracks/app/apis/todo_api.rb @@ -2,4 +2,13 @@ class TodoApi < ActionWebService::API::Base api_method :new_todo, :expects => [{:username => :string}, {:token => :string}, {:context_id => :int}, {:description => :string}], :returns => [:int] + + api_method :list_contexts, + :expects => [{:username => :string}, {:token => :string}], + :returns => [[Context]] + + api_method :list_projects, + :expects => [{:username => :string}, {:token => :string}], + :returns => [[Project]] + end diff --git a/tracks/app/controllers/backend_controller.rb b/tracks/app/controllers/backend_controller.rb index ee8fa802..6746bcca 100644 --- a/tracks/app/controllers/backend_controller.rb +++ b/tracks/app/controllers/backend_controller.rb @@ -16,6 +16,22 @@ class BackendController < ApplicationController item.id end + def list_contexts(username, token) + if !check_token_against_user_word(username, token) + raise "invalid token" + end + + @user.contexts + end + + def list_projects(username, token) + if !check_token_against_user_word(username, token) + raise "invalid token" + end + + @user.projects + end + protected # Check whether the token in the URL matches the word in the User's table