function send_curl_request($verb, $url, $payload = '')
{
    $logger = \APS\LoggerRegistry::get();
    $application = \APS\Request::getController()->getResources("implementing(http://myweatherdemo.com/suwizardbasic/application/1.0)");
    $token = $application[0]->provider_token;
    $headers = array('Content-type: application/json', 'x-provider-token: ' . $token);
    $ch = curl_init();
    curl_setopt_array($ch, array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CUSTOMREQUEST => $verb, CURLOPT_HTTPHEADER => $headers, CURLOPT_POSTFIELDS => json_encode($payload)));
    $response = json_decode(curl_exec($ch));
    $logger->debug("Response was: " . print_r($response, true));
    curl_close($ch);
    return $response;
}
 /**
  * @verb(GET)
  * @path("/singleSignOn")
  */
 public function singleSignOn()
 {
     $apsc = \APS\Request::getController();
     $apsc2 = $apsc->impersonate($this);
     $domains = $apsc2->getResources('implementing(http://aps-standard.org/types/dns/zone/1.0)');
     $serviceDomains = array();
     foreach ($domains as $domain) {
         if (get_class($domain) == 'com\\parallels\\aps\\types\\pa\\dns\\zone\\paHostedDomain') {
             $serviceDomains[] = $domain->name;
         }
     }
     if (empty($serviceDomains)) {
         throw new Exception('No domains available');
     }
     $obj = array();
     $obj['url'] = singleSignOnURL($this->application->enduser_url, $this->application->enduser_apikey, $this->account->companyName, array('domain' => $serviceDomains));
     $obj['domains'] = $serviceDomains;
     return $obj;
 }
Exemple #3
0
 /**
  * @verb(GET)
  * @path("/updateResourceUsage")
  */
 public function updateResourceUsage()
 {
     $url = self::BASE_URL . $this->vps_id;
     $response = $this->send_curl_request('GET', $url);
     $this->cpuActualUsage = $response->cpuActualUsage;
     $this->ramActualUsage = $response->ramActualUsage;
     $this->diskActualUsage = $response->diskActualUsage;
     $usage = array();
     $usage['cpuActualUsage'] = $this->cpuActualUsage;
     $usage['ramActualUsage'] = $this->ramActualUsage;
     $usage['diskActualUsage'] = $this->diskActualUsage;
     // we need to update the resource in APSC DB explicitely since this is a custom operation
     $apsc = \APS\Request::getController();
     $apsc->updateResource($this);
     return $usage;
 }