Beispiel #1
0
 /**
  * Perform a GET request on the server
  * @param string $url
  * @param bool $requiresAuth Whether admin credentials should be sent
  * @return string Response body
  * @throws Exception If a 4xx or 5xx error is received
  */
 protected function get($url, $requiresAuth = false)
 {
     // Build the URL, with leading '/'
     $url = $this->server->getHost() . '/' . ltrim($url, '/');
     // Request headers to send
     $headers = array('Accept: application/xml,text/xml', sprintf('User-Agent: %s', Thawcast::getUserAgent()));
     // Request options
     $options = array();
     // Add credentials if the request needs to be authenticated
     if ($requiresAuth) {
         $options['auth'] = new Requests_Auth_Basic(array_values($this->server->getCredentials()));
     }
     $response = Requests::get($url, $headers, $options);
     if (!$response->success) {
         switch (substr($response->status_code, 0, 1)) {
             case 4:
                 throw new Exception(sprintf('A bad request was made (%d): "%s"', $response->status_code, $response->body));
             case 5:
                 throw new Exception(sprintf('A server error occured (%d): "%s"', $response->status_code, $response->body));
         }
     }
     return $response;
 }
Beispiel #2
0
 public function testAdminCredentials()
 {
     $thawcast = new Thawcast('http://localhost');
     $thawcast->setCredentials('admin', 'password');
     $this->assertEquals(array('username' => 'admin', 'password' => 'password'), $thawcast->getCredentials());
 }