Implementation of Skynet API into wordpress for CrowdDesk use

Hello CakePHP community and thank you much for taking me in!

My problem is as follows:

I need to implement the Skynet API for management of CrowdDesk project into wordpress, which is written in CakePHP.

I tried to translate CakePHP into the wordpress framework and think it is done correctly, however wordpress does not receive any API callbacks from the Skynet servers, leading me to believe it is not implemented correctly.

Here the original CakePHP code as found in the Skynet documentation:

var $apiKey = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'; 
var $apiUrl = 'https://api.crowddesk.io'; 
var $apiAccept = 'application/json'; 
var $apiContentType = 'application/json'; 
var $apiUserAgent = 'CrowdDesk CMS'; 
function curl($methodUrl, $call = 'GET', $data = NULL) { 
if (!$apiKey || !$apiUrl) return false; 
$url = $this->apiUrl.$methodUrl; 
$ch = curl_init($url); 
if ($call == 'POST') { 
curl_setopt($ch, CURLOPT_POST, 1); 
 $data = json_encode($data); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
 } 
 curl_setopt($ch, CURLOPT_TIMEOUT, 3); 
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
 url_setopt($ch, CURLOPT_HTTPHEADER, array( 
 'Authorization: Token token='.$this->apiKey, 
 'Accept: '.$this->apiAccept, 
 'Content-Type: '.$this->apiContentType, 
 'User-Agent: '.$this->apiUserAgent)); 
 curl_setopt ($ch, CURLOPT_HEADER, false); 
 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
 $return['curl_exec'] = curl_exec($ch); 
 $return['curl_error'] = curl_error($ch); 
 $return['curl_httpcode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
 curl_close($ch); 
 return $return; 
 }

Here my translation into the wordpress framework

/*API Call CrowdDesk*/

$apiKey = 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6';
$apiUrl = 'https://api.crowddesk.io';
$apiAccept = 'application/json';
$apiContentType = 'application/json';
$apiUserAgent = 'CrowdDesk CMS';

function myCurl($methodUrl, $call = 'GET', $data = NULL) {
  if (!SKYNET_API_TOKEN || !SKYNET_API_URL) return false;
  $url = $apiUrl.$methodUrl;
  $ch = curl_init($url);

  if ($call == 'POST') {
    curl_setopt($ch, CURLOPT_POST, 1);
    $data = json_encode($data);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  }
  curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  curl_setopt($ch, CURLOPT_HTTPHEADER, array(	'Authorization: Token token='.$apiKey,
                                              'Accept: '.$apiAccept,
                                              'Content-Type: '.$apiContentType,
                                              'User-Agent: '.$apiUserAgent));

  // Aktivieren für Header, deaktivieren für array
  curl_setopt ($ch, CURLOPT_HEADER, false);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

  $return['curl_exec'] = curl_exec($ch);

  // ## AKTIVIEREN UM HTTPCODE 200 ODER FEHLER ZU SEHEN	// BZW ECHO
  $return['curl_error'] = curl_error($ch);
  $return['curl_httpcode'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  #$return['curl_info'] = curl_getinfo($ch);

  curl_close($ch);
  return $return;

}

Furthermore to receive project information from the Skynet API, the function get projects by id needs to be translated too, so here goes:


function get_project_by_id($projectID) { 
 $return = $this->curl('/v1/projects/'.$projectID, 'GET'); 
 if ($return['curl_httpcode'] != '200') return false; 
 return json_decode($return['curl_exec'], true); 
 }

My Translation:


function get_project_by_id($projectID) {
  $return = myCurl('/v1/projects/'.$projectID, 'GET', NULL);
  if ($return['curl_httpcode'] != '200') return false;
  return json_decode($return['curl_exec'], true);
}

With these two code snippets in the wordpress functions.php, project information should be received via the http call [GET] /v1/projects/projectID

The API Key is the one from the documentation and is replaced with a newly generated key from the Skynet Backend. The projectID is replaced with the actual project ID also from the Skynet Backend. CURL is activated on the server.

I tried calling the project information also via PHP with:


<?php
$api_callback = get_project_by_id(387);
if ($api_callback) {
      $investments_sum = $api_callback['investments_sum'];
      $investments_count = $api_callback['investments_count'];
}
?>

but no luck there either.

My questions to you folks: Did I correctly translate CakePHP into the Wordpress framework or can you spot any mistakes? Anything else I must consider? Thank you much for your help, hugely appreciated!

Which part of this has to do with CakePHP? I don’t see anything in here anywhere that looks like it.