Ejemplo n.º 1
0
 private function validateRequest($serverKey, $token, $method, $language, $version)
 {
     // If the request comes from the local computer, then don't require authorization,
     // otherwise check the headers
     if (HttpUtils::isLocal()) {
         return true;
     } else {
         if (empty($serverKey)) {
             throw new MashapeException(EXCEPTION_EMPTY_SERVERKEY, EXCEPTION_XML_CODE);
         }
         $url = MASHAPE_TOKEN_VALIDATION_URL . "?" . QUERY_PARAM_TOKEN . "=" . $token . "&" . QUERY_PARAM_SERVERKEY . "=" . $serverKey . "&" . QUERY_PARAM_METHOD . "=" . $method . "&" . QUERY_PARAM_LANGUAGE . "=" . $language . "&" . QUERY_PARAM_VERSION . "=" . $version;
         $response = HttpUtils::makeHttpRequest($url);
         if (empty($response)) {
             throw new MashapeException(EXCEPTION_EMPTY_REQUEST, EXCEPTION_SYSTEM_ERROR_CODE);
         }
         $validationResponse = json_decode($response);
         if (empty($validationResponse)) {
             throw new MashapeException(EXCEPTION_JSONDECODE_REQUEST, EXCEPTION_SYSTEM_ERROR_CODE);
         }
         if (!empty($validationResponse->errors)) {
             $error = $validationResponse->errors[0];
             throw new MashapeException($error->message, $error->code);
         }
         $authorization = $validationResponse->authorized;
         $GLOBALS[UID] = $validationResponse->uid;
         if ($authorization == true) {
             return true;
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @TODO: This is an integration test with www.mashape.com
  *        This test could fail if the site is unreachable (maintenance, dns, proxy, firewall etc.)
  *        The external resource should be mocked
  *        ~ dluc
  */
 function testMakeHttpRequest()
 {
     $response = HttpUtils::makeHttpRequest("http://www.mashape.com");
     $this->assertFalse(empty($response));
 }