Project

General

Profile

Feature #7338

REST webservice for personal messages reading

Added by Yannick Warnier about 5 years ago. Updated almost 5 years ago.

Status:
Feature implemented
Priority:
Normal
Assignee:
Category:
Web services
Target version:
Start date:
20/10/2014
Due date:
% Done:

100%

Estimated time:
Spent time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

In order to develop the mobile app to get your personal Chamilo messages on your smartphone, we need a series of webservices as described below. The objective of this task is to develop these web services.

File

In order to develop REST webservices (which don't really exist in any coordinated fashion in Chamilo), we will create a main/webservices/rest.php file which contains the main controller and the available webservices, and will call Chamilo functions/methods as needed

Authentication

We want to ensure an authentication that is as secure as possible, but this will require HTTPS (we cannot ensure security in the communication with a non-HTTPS Chamilo portal).

The first connection with any Chamilo portal, in the mobile app, will require the URL of the portal and the introduction of the login/password information.
This will generate a new API key (a new user field of type "text" called api_key_message, or the existing one if one already exists). The API key is a random SHA1 key.

The SHA1 key is returned by the webservice, so the mobile application can store it.

So, something like this (all the function names are invented):

if (isValidPassword($username, $password)) {
    $userInfo = api_get_user_info($username);
    if (UserField::fieldExists('api_key_message')) {
        $apiKey = UserField::get_field_value('api_key_message', $username);
        return json_encode('result' => $apiKey);
    } else {
        UserField::createUserField('api_key_message');
        $apiKey = generateApiKey();
        $result = UserField::create('api_key_message', $username, $apiKey);
        if ($result) {
            return json_encode('result' => $apiKey);
        } else {
            return json_encode('result' => false);
        }
    }
} else {
    return json_encode('result' => false);
}

Later on, all other webservices will only work with the API key.

Web services

Get new messages count

public function getNewMessagesCount($username, $apiKey, $last = 0) {
    $userInfo = api_get_user_info_from_username($username);
    // get count of new messages for this user, since the last message already received
    return json_encode('result' => $count);
}

Get new messages

public function getNewMessages($username, $apiKey, $last = 0) {
    $userInfo = api_get_user_info_from_username($username);
    // get new messages for this user, since the last message already received
    $messages = ...
    // $messages should be an array something like this:
    // 0 => array('id' => $row['id'], 'title' => $row['title'], 'sender' => $row['sender'], 'content' => $row['content']),
    // 1 => array('id' => ...),
    // 2 => array('id' => ...), ...
    return json_encode(
        'result' => $count,
        'messages' => $messages
    );
}

Associated revisions

Revision c8f940be (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Add REST web service for get personal messages - refs #7338

Revision 4a5c020e (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Count the messages from the last received message - refs #7338

Revision 8879b58e (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Minor - Update PHPDoc - refs #7338

Revision 34bc804a (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Get messages data from the last received message - refs #7338

Revision eb007dd0 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Minor - Update PHPDoc - refs #7338

Revision 2f0d9334 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Generate api keys - refs #7338

Revision 1825fc0b (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Update the getNewMessages method - refs #7338

Revision 63c4c4a3 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Minor - Fix PHPDoc - refs #7338

Revision 44decfb8 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Filter before calling a database method - refs #7338

Revision 858e6042 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Update the API key generator method - refs #7338

Revision 67fdab3c (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Remove unnecessary filters - refs #7338

Revision f21a0ac5 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Add links to the portal and messaging tool - refs #7338

Revision cce71ec4 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Add webservices classes for autload - refs #7338

Revision 8ee9d1d8 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Fix undefined index E_NOTICE - refs #7338

Revision 9301494d (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Add status for right response - refs #7338

Revision 47922c72 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Fix define a method like abstract static E_STRICT - refs #7338

Revision 4c39ea00 (diff)
Added by Angel Fernando Quiroz Campos about 5 years ago

Add information about whether there is attachments - refs #7338

Revision d4d5d77a
Added by Yannick Warnier about 5 years ago

Merge pull request #391 from AngelFQC/7338

Add REST web service for get personal messages - refs #7338

Revision 5eb945a5 (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Sort messages by recent date - refs #7338

Revision 3e500c8e (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Add sent date to message - refs #7338

Revision b852f740 (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Add content type header to JSON response - refs #7338

Revision 7bdf7db2 (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Add CORS header to JSON response - refs #7338

Revision 5ec47155
Added by Yannick Warnier almost 5 years ago

Merge pull request #445 from AngelFQC/7338

Update REST web service - refs #7338

Revision 5b634884 (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Fix get message sender - refs #7338

Revision 6dc7648c
Added by Yannick Warnier almost 5 years ago

Merge pull request #450 from AngelFQC/7338

Fix get message sender - refs #7338

Revision f887d25a (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Minor - Fix rest webservice PHPDoc - refs #7338

Revision f74e1bb2 (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Move REST webservice to main directory - refs #7338

Revision 81460571
Added by Julio almost 5 years ago

Merge pull request #453 from AngelFQC/7338

Fix PHPDoc and move REST webservice to main directory - refs #7338

Revision 19a0b74a (diff)
Added by Angel Fernando Quiroz Campos almost 5 years ago

Fix require libs and classes - refs #7338

Revision 04d49f5f
Added by Yannick Warnier almost 5 years ago

Merge pull request #454 from AngelFQC/7338

Fix require libs and classes - refs #7338

Revision fe8646d7 (diff)
Added by Angel Fernando Quiroz Campos over 4 years ago

Fix valid user for web service - refs #7338

Revision 8220115c (diff)
Added by Angel Fernando Quiroz Campos over 4 years ago

Fix valid user password when username doesn't exists - refs #7338

History

#1

Updated by Yannick Warnier about 5 years ago

  • Description updated (diff)
#2

Updated by Angel Quiroz about 5 years ago

  • % Done changed from 10 to 20

At the moment

I started with create the rest.php and classe for the web service
Add methods for get the user api key, check if the api is valid for a user, check whether the username and password are valid

https://github.com/angelfqc/chamilo-lms/tree/7338

#3

Updated by Angel Quiroz about 5 years ago

POST Request to /webservices/rest.php

To get api key
Params

action = loginNewMessages
username
password

Success return

{"status": "true", "apiKey":"The api key"}

Failed return

{"status":false}

To count new messages
Params

action = countNewMessages
username
api_key

Success return

{"status": "true", "count":"12"}

Failed return

{"status":false}

To get new messages data
Params

action = getNewMessages
username
api_key

Success return

{"status": "true", "messages": [{id: 0, title: '', sender: {id: 0, lastname: '', firstname: '', completeName: ''}, content: ''}, {...}]}

Failed return

{"status":false}

PR: https://github.com/chamilo/chamilo-lms/pull/391

#4

Updated by Angel Quiroz about 5 years ago

  • % Done changed from 20 to 50

What I need to do is check for attachments

Updated PR

#5

Updated by Angel Quiroz about 5 years ago

  • Assignee changed from Angel Quiroz to Yannick Warnier

Add information about whether there is attachments

PR: https://github.com/chamilo/chamilo-lms/pull/391

#6

Updated by Angel Quiroz about 5 years ago

  • Status changed from Assigned to Needs testing
  • Assignee deleted (Yannick Warnier)
#7

Updated by Yannick Warnier about 5 years ago

  • Status changed from Needs testing to Feature implemented
  • Assignee set to Angel Quiroz
  • % Done changed from 50 to 100

This is a new feature that does not appear directly to the normal final users, so it can be closed without specific testing.

Good job!

#9

Updated by Angel Quiroz almost 5 years ago

Receiver information is sent but not the sender

https://github.com/chamilo/chamilo-lms/pull/450

#10

Updated by Angel Quiroz almost 5 years ago

Move the REST webservice to main directory and fix the PHPDoc package name

https://github.com/chamilo/chamilo-lms/pull/453 and https://github.com/chamilo/chamilo-lms/pull/454

Also available in: Atom PDF