Normalize actions of api REST - refs #8366

remotes/angel/1.11.x
Angel Fernando Quiroz Campos 8 years ago
parent d256f87771
commit 747e7e4a94
  1. 48
      main/inc/lib/webservices/Rest.php
  2. 38
      main/webservices/api/v2.php

@ -17,25 +17,25 @@ class Rest extends WebService
const SERVIVE_NAME = 'MsgREST';
const EXTRA_FIELD_GCM_REGISTRATION = 'gcm_registration_id';
const ACTION_AUTH = 'authenticate';
const ACTION_USER_MESSAGES = 'user_messages';
const ACTION_GCM_ID = 'gcm_id';
const ACTION_USER_COURSES = 'user_courses';
const ACTION_PROFILE = 'user_profile';
const ACTION_COURSE_INFO = 'course_info';
const ACTION_COURSE_DESCRIPTIONS = 'course_descriptions';
const ACTION_COURSE_DOCUMENTS = 'course_documents';
const ACTION_COURSE_ANNOUNCEMENTS = 'course_announcements';
const ACTION_COURSE_ANNOUNCEMENT = 'course_announcement';
const ACTION_COURSE_AGENDA = 'course_agenda';
const ACTION_COURSE_NOTEBOOKS = 'course_notebooks';
const ACTION_COURSE_FORUM_CATEGORIES = 'course_forumcategories';
const ACTION_COURSE_FORUM = 'course_forum';
const ACTION_COURSE_FORUM_THREAD = 'course_forumthread';
const ACTION_COURSE_LEARNPATHS = 'course_learnpaths';
const ACTION_COURSE_LEARNPATH = 'course_learnpath';
const ACTION_SAVE_FORUM_POST = 'save_forum_post';
const ACTION_USER_SESSIONS = 'user_sessions';
const GET_AUTH = 'authenticate';
const GET_USER_MESSAGES = 'user_messages';
const SAVE_GCM_ID = 'gcm_id';
const GET_USER_COURSES = 'user_courses';
const GET_PROFILE = 'user_profile';
const GET_COURSE_INFO = 'course_info';
const GET_COURSE_DESCRIPTIONS = 'course_descriptions';
const GET_COURSE_DOCUMENTS = 'course_documents';
const GET_COURSE_ANNOUNCEMENTS = 'course_announcements';
const GET_COURSE_ANNOUNCEMENT = 'course_announcement';
const GET_COURSE_AGENDA = 'course_agenda';
const GET_COURSE_NOTEBOOKS = 'course_notebooks';
const GET_COURSE_FORUM_CATEGORIES = 'course_forumcategories';
const GET_COURSE_FORUM = 'course_forum';
const GET_COURSE_FORUM_THREAD = 'course_forumthread';
const GET_COURSE_LEARNPATHS = 'course_learnpaths';
const GET_COURSE_LEARNPATH = 'course_learnpath';
const SAVE_FORUM_POST = 'save_forum_post';
const GET_USER_SESSIONS = 'user_sessions';
const SAVE_USER_MESSAGE = 'save_user_message';
const GET_MESSAGE_USERS = 'message_users';
@ -60,6 +60,11 @@ class Rest extends WebService
parent::__construct($username, $apiKey);
}
/**
* Set the current course
* @param int $id
* @throws Exception
*/
public function setCourse($id)
{
if (!$id) {
@ -79,7 +84,10 @@ class Rest extends WebService
$this->course = $course;
}
/** Set the current session */
/** Set the current session
* @param int $id
* @throws Exception
*/
public function setSession($id)
{
if (!$id) {

@ -31,7 +31,7 @@ try {
}
switch ($action) {
case Rest::ACTION_AUTH:
case Rest::GET_AUTH:
Rest::init();
$password = isset($_POST['password']) ? $_POST['password'] : null;
@ -49,7 +49,7 @@ try {
]);
break;
case Rest::ACTION_GCM_ID:
case Rest::SAVE_GCM_ID:
$gcmId = isset($_POST['registration_id']) ? Security::remove_XSS($_POST['registration_id']) : null;
$restApi->setGcmId($gcmId);
@ -57,7 +57,7 @@ try {
$restResponse->setData(['status' => true]);
break;
case Rest::ACTION_USER_MESSAGES:
case Rest::GET_USER_MESSAGES:
$lastMessageId = isset($_POST['last']) ? intval($_POST['last']) : 0;
$messages = $restApi->getUserMessages($lastMessageId);
@ -65,25 +65,25 @@ try {
$restResponse->setData($messages);
break;
case Rest::ACTION_USER_COURSES:
case Rest::GET_USER_COURSES:
$courses = $restApi->getUserCourses();
$restResponse->setData($courses);
break;
case Rest::ACTION_COURSE_INFO:
case Rest::GET_COURSE_INFO:
$courseInfo = $restApi->getCourseInfo();
$restResponse->setData($courseInfo);
break;
case Rest::ACTION_COURSE_DESCRIPTIONS:
case Rest::GET_COURSE_DESCRIPTIONS:
$descriptions = $restApi->getCourseDescriptions();
$restResponse->setData($descriptions);
break;
case Rest::ACTION_COURSE_DOCUMENTS:
case Rest::GET_COURSE_DOCUMENTS:
$directoryId = isset($_POST['dir_id']) ? Security::remove_XSS($_POST['dir_id']) : null;
$documents = $restApi->getCourseDocuments($directoryId);
@ -91,13 +91,13 @@ try {
$restResponse->setData($documents);
break;
case Rest::ACTION_COURSE_ANNOUNCEMENTS:
case Rest::GET_COURSE_ANNOUNCEMENTS:
$announcements = $restApi->getCourseAnnouncements();
$restResponse->setData($announcements);
break;
case Rest::ACTION_COURSE_ANNOUNCEMENT:
case Rest::GET_COURSE_ANNOUNCEMENT:
$announcementId = isset($_POST['announcement']) ? Security::remove_XSS($_POST['announcement']) : 0;
$announcement = $restApi->getCourseAnnouncement($announcementId);
@ -105,25 +105,25 @@ try {
$restResponse->setData($announcement);
break;
case Rest::ACTION_COURSE_AGENDA:
case Rest::GET_COURSE_AGENDA:
$agenda = $restApi->getCourseAgenda();
$restResponse->setData($agenda);
break;
case Rest::ACTION_COURSE_NOTEBOOKS:
case Rest::GET_COURSE_NOTEBOOKS:
$notebooks = $restApi->getCourseNotebooks();
$restResponse->setData($notebooks);
break;
case Rest::ACTION_COURSE_FORUM_CATEGORIES:
case Rest::GET_COURSE_FORUM_CATEGORIES:
$forums = $restApi->getCourseForumCategories();
$restResponse->setData($forums);
break;
case Rest::ACTION_COURSE_FORUM:
case Rest::GET_COURSE_FORUM:
$forumId = isset($_POST['forum']) ? Security::remove_XSS($_POST['forum']) : 0;
$forum = $restApi->getCourseForum($forumId);
@ -131,7 +131,7 @@ try {
$restResponse->setData($forum);
break;
case Rest::ACTION_COURSE_FORUM_THREAD:
case Rest::GET_COURSE_FORUM_THREAD:
$threadId = isset($_POST['thread']) ? Security::remove_XSS($_POST['thread']) : 0;
$thread = $restApi->getCourseForumThread($threadId);
@ -139,25 +139,25 @@ try {
$restResponse->setData($thread);
break;
case Rest::ACTION_PROFILE:
case Rest::GET_PROFILE:
$userInfo = $restApi->getUserProfile();
$restResponse->setData($userInfo);
break;
case Rest::ACTION_COURSE_LEARNPATHS:
case Rest::GET_COURSE_LEARNPATHS:
$data = $restApi->getCourseLearnPaths();
$restResponse->setData($data);
break;
case Rest::ACTION_COURSE_LEARNPATH:
case Rest::GET_COURSE_LEARNPATH:
$lpId = isset($_REQUEST['lp_id']) ? intval($_REQUEST['lp_id']) : 0;
$restApi->showLearningPath($lpId);
break;
case Rest::ACTION_SAVE_FORUM_POST:
case Rest::SAVE_FORUM_POST:
if (
empty($_POST['title']) || empty($_POST['text']) || empty($_POST['thread']) || empty($_POST['forum'])
) {
@ -181,7 +181,7 @@ try {
$restResponse->setData($data);
break;
case Rest::ACTION_USER_SESSIONS:
case Rest::GET_USER_SESSIONS:
$courses = $restApi->getUserSessions();
$restResponse->setData($courses);

Loading…
Cancel
Save