source: sandbox/webservice/api/rest/dispatch.php @ 7855

Revision 7855, 3.1 KB checked in by alexandrecorreia, 9 years ago (diff)

Ticket #2507 - Correções dentro da API do webservice do expresso

  • Property svn:executable set to *
Line 
1<?php
2
3define('API_DIRECTORY','/var/www/expresso/api/rest', True);
4
5// load libraries
6require_once(API_DIRECTORY.'/../library/tonic/lib/tonic.php');
7require_once(API_DIRECTORY.'/../library/utils/Errors.php');
8
9// load adapters
10require_once(API_DIRECTORY."/../adapters/ExpressoAdapter.php");
11require_once(API_DIRECTORY."/../adapters/MailAdapter.php");
12require_once(API_DIRECTORY."/../adapters/CatalogAdapter.php");
13require_once(API_DIRECTORY."/../adapters/CalendarAdapter.php");
14require_once(API_DIRECTORY."/../adapters/AdminAdapter.php" );
15
16// Load all resources
17require_once(API_DIRECTORY."/admin/CreateUserResource.php");
18require_once(API_DIRECTORY."/admin/DeleteUserResource.php");
19require_once(API_DIRECTORY."/admin/EditUserResource.php");
20require_once(API_DIRECTORY."/admin/RenameUserResource.php");
21require_once(API_DIRECTORY."/admin/SearchUserResource.php");
22require_once(API_DIRECTORY."/admin/UpdateUserResource.php");
23
24require_once(API_DIRECTORY."/availableServers/AvailableServersResource.php");
25
26require_once(API_DIRECTORY."/core/ExpressoVersionResource.php");
27require_once(API_DIRECTORY."/core/LoginResource.php");
28require_once(API_DIRECTORY."/core/LogoutResource.php");
29
30require_once(API_DIRECTORY."/mail/FoldersResource.php");
31require_once(API_DIRECTORY."/mail/MessagesResource.php");
32require_once(API_DIRECTORY."/mail/AddFolderResource.php");
33require_once(API_DIRECTORY."/mail/DelFolderResource.php");
34require_once(API_DIRECTORY."/mail/DelMessageResource.php");
35require_once(API_DIRECTORY."/mail/RenameFolderResource.php");
36require_once(API_DIRECTORY."/mail/CleanTrashResource.php");
37require_once(API_DIRECTORY."/mail/AttachmentResource.php");
38require_once(API_DIRECTORY."/mail/SendResource.php");
39require_once(API_DIRECTORY."/mail/SendSupportFeedbackResource.php");
40
41require_once(API_DIRECTORY."/catalog/ContactsResource.php");
42require_once(API_DIRECTORY."/catalog/ContactPictureResource.php");
43require_once(API_DIRECTORY."/calendar/EventsResource.php");
44
45//Retrieveing the mapping of the URIs and his respectives classNames and classPath
46$config = parse_ini_file( API_DIRECTORY . '/../config/Tonic.srv', true );
47$autoload = array();
48$classpath = array();
49
50foreach( $config as $uri => $classFile )
51{
52        foreach( $classFile as $className => $filePath )
53        {
54                $autoload[ $uri ] = $className;
55                $classpath[ $className ] = $filePath;
56        }
57
58        $request = new Request(array(
59                        'baseUri' => dirname($_SERVER['SCRIPT_NAME']),
60                        'autoload' => $autoload
61        ));
62}
63       
64try {
65
66        $resource = $request->loadResource();
67        $response = $resource->exec($request);
68       
69} catch (ResponseException $e) {
70       
71        switch ($e->getCode()) {
72               
73                case Response::UNAUTHORIZED:
74                        $response = $e->response($request);
75                        $response->addHeader('WWW-Authenticate', 'Basic realm="Tonic"');
76                        break;
77                default:
78                       
79                        $response = new Response($request);
80                        $response->code = Response::OK;
81                        $response->addHeader('content-type', 'application/json');
82                        if($request->id)
83                                $body['id']     = $request->id;
84                       
85                        $body['error'] = array("code" => "".$e->getCode(), "message" => $e->getMessage());
86                        $response->body = json_encode($body);
87        }
88}
89
90$response->output();
91
92?>
Note: See TracBrowser for help on using the repository browser.