Skip to main content

Sample Code Snippets and Examples

LOGIN

CODE
<?php

function getTokenFromMedianovaCloud($apiKey, $apiSecret) {
    $apiEndpoint = 'https://cloud.medianova.com/api/v1/auth/login/token';

    // POST parameters
    $postData = [
        'api_key' => $apiKey,
        'api_secret' => $apiSecret,
    ];

    // send a POST request using cURL 
    $ch = curl_init($apiEndpoint);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    // perform the request
    $response = curl_exec($ch);

    // cURL error handling
    if (curl_errno($ch)) {
        return 'cURL Hatası: ' . curl_error($ch);
    }

    // cURL close
    curl_close($ch);

    // Convert the API response from JSON to an array.
    $responseData = json_decode($response, true);

    // 
    if (isset($responseData['token'])) {
        // Successful login
        return 'Token okey. Token: ' . $responseData['token'];
    } else {
        // Unsuccesful login
        return 'Token not okey. Hata: ' . $responseData['message'];
    }
}

// Example Usage
$apiKey = 'your_api_key';
$apiSecret = 'your_api_secret';

$result = getTokenFromMedianovaCloud($apiKey, $apiSecret);

echo $result;

?>

RESOURCE CREATE

CODE
<?php

function createCDNResource($organizationUuid, $resourceType, $resourceName, $resourceLabel, $dataSource, $protocol, $originUrl) {
    $apiEndpoint = "https://cloud.medianova.com/api/v1/cdn/{$organizationUuid}/resource";

    // Prepare POST data
    $postData = [
        'resource_type' => $resourceType,
        'resource_name' => $resourceName,
        'resource_label' => $resourceLabel,
        'data_source' => $dataSource,
        'protocol' => $protocol,
        'origin_url' => $originUrl,
    ];

    // Initialize cURL session
    $ch = curl_init($apiEndpoint);

    // Set cURL options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    // Execute the request
    $response = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        return 'cURL Error: ' . curl_error($ch);
    }

    // Close cURL session
    curl_close($ch);

    // Convert the API response from JSON to an array
    $responseData = json_decode($response, true);

    // Process the API response
    if (isset($responseData['success']) && $responseData['success'] == true) {
        // Successful resource creation
        return 'Resource Created Successfully. Resource ID: ' . $responseData['resource_id'];
    } else {
        // Failed resource creation
        return 'Resource Creation Failed. Error: ' . $responseData['error_message'];
    }
}

// Example Usage
$organizationUuid = 'your_organization_uuid';
$resourceType = 'image';
$resourceName = 'example.jpg';
$resourceLabel = 'Example Image';
$dataSource = 'origin';
$protocol = 'https';
$originUrl = 'https://example.com/images/';

$result = createCDNResource($organizationUuid, $resourceType, $resourceName, $resourceLabel, $dataSource, $protocol, $originUrl);

echo $result;

?>

PURGE

CODE
<?php

function purgeCDNResource($organizationUuid, $resourceUuid, $filePath) {
    $apiEndpoint = "https://cloud.medianova.com/api/v1/cdn/{$organizationUuid}/job/{$resourceUuid}/purge";

    // Prepare POST data
    $postData = [
        'file_path' => $filePath,
    ];

    // Initialize cURL session
    $ch = curl_init($apiEndpoint);

    // Set cURL options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    // Execute the request
    $response = curl_exec($ch);

    // Check for cURL errors
    if (curl_errno($ch)) {
        return 'cURL Error: ' . curl_error($ch);
    }

    // Close cURL session
    curl_close($ch);

    // Convert the API response from JSON to an array
    $responseData = json_decode($response, true);

    // Process the API response
    if (isset($responseData['success']) && $responseData['success'] == true) {
        // Successful purge request
        return 'Purge Request Successful. Job ID: ' . $responseData['job_id'];
    } else {
        // Failed purge request
        return 'Purge Request Failed. Error: ' . $responseData['error_message'];
    }
}

// Example Usage
$organizationUuid = 'your_organization_uuid';
$resourceUuid = 'your_resource_uuid';
$filePath = '/path/to/your/file';

$result = purgeCDNResource($organizationUuid, $resourceUuid, $filePath);

echo $result;

?>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.