Changeset 6061 for sandbox/webservice/api/rest
- Timestamp:
- 04/27/12 15:18:00 (12 years ago)
- Location:
- sandbox/webservice/api/rest
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/webservice/api/rest/catalog/ContactsResource.php
r6019 r6061 24 24 return $this->getGlobalContacts($search, $this->getParam('contactID')); 25 25 else{ 26 $ this->setError(Errors::CATALOG_MIN_ARGUMENT_SEARCH, $this-> getMinArgumentSearch());27 return $this->getResponse();26 $error = Errors::get(Errors::CATALOG_MIN_ARGUMENT_SEARCH, $this-> getMinArgumentSearch()); 27 throw new ResponseException($error['message'], $error['code']); 28 28 } 29 29 } -
sandbox/webservice/api/rest/core/Errors.php
r6019 r6061 58 58 ); 59 59 60 static public function get($code, $arg){ 61 $errors = self::$reservedErrors + self::$applicationErrors; 60 static public function set($code, $message){ 61 return array ("code" => $code, "message" => $message); 62 } 63 64 static public function get($code, $argument = false){ 65 $errors = self::$reservedErrors + self::$applicationErrors; 62 66 $message = $errors[$code]; 63 if($arg){ 64 $message = str_replace("%1", $arg, $message); 65 } 66 if(!$message){ 67 if(!$message) 67 68 $message = $errors[self::E_UNKNOWN_ERROR]; 68 } 69 if($argument) 70 $message = str_replace("%1", $argument, $message); 69 71 70 return array ("code" => $code, "message" => $message); 71 } 72 return array ("code" => $code, "message" => $message); 73 } 74 75 static public function getResponse($request, $responseException){ 76 $response = new Response($request); 77 $response->code = Response::OK; 78 $response->addHeader('content-type', 'application/json'); 79 if($request->id) 80 $body['id'] = $request->id; 81 82 $code = $responseException->getCode(); 83 $error = Errors::get($code); 84 $message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']); 85 $body['error'] = array("code" => $code, "message" => $message); 86 $response->body = json_encode($body); 87 return $response; 88 } 72 89 73 90 } -
sandbox/webservice/api/rest/core/Expresso.php
r6022 r6061 59 59 } 60 60 61 public function setError($errorID, $arg1 = false) { 62 if($errorID) 63 $this-> error = Errors::get($errorID, $arg1); 64 else 65 $this-> error = null; 61 public function setError($error) { 62 $this-> error = $error; 66 63 } 67 64 … … 96 93 $response->addHeader('content-type', 'application/json'); 97 94 95 if($this->getId()) 96 $body['id'] = $this->getId(); 97 if($this->getResult()) 98 $body['result'] = $this->getResult(); 99 else 100 throw new ResponseException("",Errors::E_UNKNOWN_ERROR); 98 101 99 if($this->getResult()) {100 $body['result'] = $this->getResult();101 }102 elseif($this->getError()){103 $body['error'] = $this->getError();104 }105 else{106 $this->setError(Errors::E_INTERNAL_ERROR);107 $body['error'] = $this->getError();108 }109 110 if($this->getId()) {111 $body['id'] = $this->getId();112 }113 114 102 $response->body = json_encode($body); 115 103 … … 143 131 list($sessionid, $kp3) = explode(":", $this->getParam('auth')); 144 132 if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){ 145 return true;133 return $sessionid; 146 134 } 147 135 else{ 148 $this-> setError(Errors::LOGIN_AUTH_INVALID); 149 return false; 136 throw new ResponseException("",Errors::LOGIN_AUTH_INVALID); 150 137 } 151 138 } 152 139 else{ 153 $this-> setError(Errors::LOGIN_NOT_LOGGED_IN); 154 return false; 140 throw new ResponseException("",Errors::LOGIN_NOT_LOGGED_IN); 155 141 } 156 142 } -
sandbox/webservice/api/rest/core/LoginResource.php
r6019 r6061 4 4 public function post($request){ 5 5 // to Receive POST Params (use $this->params) 6 parent::post($request); 7 8 if(!$this-> isLoggedIn()) 9 { 10 if($sessionid = $GLOBALS['phpgw']->session->create($this->getParam('user'), $this->getParam('password'))) 11 { 12 $result = array( 13 'auth' => $sessionid.":".$GLOBALS['phpgw']->session->kp3, 14 'profile' => array($this->getUserProfile()) 15 ); 16 $this->setError(false); 17 $this->setResult($result); 18 } 19 else 20 { 21 $this->setError($GLOBALS['phpgw']->session->cd_reason); 22 } 6 parent::post($request); 7 if($sessionid = $GLOBALS['phpgw']->session->create($this->getParam('user'), $this->getParam('password'))) 8 { 9 $result = array( 10 'auth' => $sessionid.":".$GLOBALS['phpgw']->session->kp3, 11 'profile' => array($this->getUserProfile()) 12 ); 13 $this->setResult($result); 23 14 } 24 15 else 25 16 { 26 $result = array('auth' => $this->getParam('auth')); 27 $this->setResult($result); 17 throw new ResponseException("",$GLOBALS['phpgw']->session->cd_reason); 28 18 } 29 30 //to Send Response (JSON RPC format) 31 return $this->getResponse(); 19 return $this->getResponse(); 32 20 } 33 21 -
sandbox/webservice/api/rest/dispatch.php
r6025 r6061 51 51 break; 52 52 default: 53 $expresso = new Expresso($request->id); 54 $expresso->post($request); 55 $expresso->setError("".$e->getCode(), $request->uri); 56 $response = $expresso->getResponse(); 53 $response = Errors::getResponse($request, $e); 57 54 } 58 55 }
Note: See TracChangeset
for help on using the changeset viewer.