예제 #1
0
 /**
  * Execute api call.
  *
  * @param string|null $url
  * @param string $method
  * @param array|null $data
  * @throws \Pecee\Http\Rest\RestException
  * @return \Pecee\Http\HttpResponse|mixed
  */
 public function api($url = null, $method = self::METHOD_GET, array $data = array())
 {
     if (!in_array($method, self::$METHODS)) {
         throw new RestException('Invalid request method');
     }
     if ($this->httpRequest->getRawPostData() !== null) {
         $data = $this->httpRequest->getRawPostData();
         if ($method !== self::METHOD_GET) {
             $this->httpRequest->setRawPostData($data);
         }
     } else {
         $data = array_merge($this->httpRequest->getPostData(), $data);
         if ($method !== self::METHOD_GET) {
             $this->httpRequest->setPostData($data);
         }
     }
     if ($method === self::METHOD_GET && is_array($data)) {
         $separator = strpos($url, '?') !== false ? '&' : '?';
         $url .= $separator . http_build_query($data);
     }
     $apiUrl = trim($this->getServiceUrl(), '/') . ($url !== null ? '/' . trim($url, '/') : '');
     $this->httpRequest->setUrl($apiUrl);
     $this->httpRequest->setMethod($method);
     $response = $this->httpRequest->execute(true);
     return $response;
 }
예제 #2
0
 /**
  * @param $domain
  *
  * @return \Bonnier\Shell\ShellResponse
  */
 public function get($domain)
 {
     $url = $this->generateUrl($domain);
     $request = new HttpRequest($url);
     $request->setBasicAuth($this->username, $this->password);
     return new ShellResponse($request->execute(true));
 }