Exemplo n.º 1
0
 public function basicGet($url, $data = NULL)
 {
     $token = $this->getToken();
     if (!$token) {
         return false;
     }
     //
     $reqUrl = 'https://' . $this->host . $url;
     $request = new myRequest();
     $request->setMethod(myRequest::METHOD_GET);
     //
     if ($data) {
         $request->setParameters($data);
     }
     //
     $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $token]);
     $response = $request->sendRequest($reqUrl);
     if ($response->getStatus() == myResponse::STATUS_FORBIDDEN) {
         // try to regenerate token
         $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $this->generateToken()]);
         // retry request
         $response = $request->sendRequest($reqUrl);
     }
     return $response->getBody(true);
 }