Example #1
0
 /**
  * @param $methodName
  * @param RequestInterface $request
  * @return mixed
  */
 public function call($endpoint, $request)
 {
     $client = new Client(['verify' => false]);
     $parameters = array_merge($this->config->getParameterArray(), $request->getParameterArray());
     try {
         $res = $client->request($request->method, $this->url . $endpoint, array_merge(['headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json', 'Client-Secret' => $this->config->clientSecret, 'Access-Token' => $this->config->accessToken]], $parameters));
         $this->response = $res;
         return $res;
     } catch (\Exception $e) {
         preg_match('/{"ErrorInformation":{"Error":(\\d+),"Message":"(.+)","Code":(\\d+)}/i', $e->getMessage(), $matches);
         if (isset($matches[0])) {
             throw new Exception(sprintf("ERROR: %s (%s)", Util::removeUnicodeSequences($matches[2]), $matches[3]), $matches[3]);
         }
         throw $e;
     }
     return false;
 }