<?php

include_once 'Controller.php';

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (isset($_REQUEST['create_short_url']) && isset($_REQUEST['url'])) {
    $long_url = $_REQUEST['url'];
    $webhook = $_REQUEST['webhook'];
    $short_url = Controller::shorten_url($long_url, $webhook);
    if (!$short_url || is_null($short_url) || empty($short_url)) {
        echo json_encode(array("is_error" => "1", "message" => "failed to create short url"));
    } else {
        echo json_encode(array("is_error" => "0", "message" => "success", "short_url" => "$short_url"));
    }
} else {
    echo json_encode(array("is_error" => "1", "message" => "invalid command."));
}