<?php

class GupshopUtils extends WebServiceFeedback
{
    private $feedbackUrl;
    private $apikey;
    private $authtoken;

    public function __construct($registry)
    {
        parent::__construct($registry);

        if ($this->config->get('gupshop_api') && $this->config->get('gupshop_api')) {
            $this->apikey = trim($this->config->get('gupshop_api'));
            $this->authtoken = $this->config->get('gupshop_user_service').':'.$this->config->get('gupshop_password_service');
        }

        $this->feedbackUrl = $this->getApiDomain().'/futura';

    }

    public function callAPI($url, $method = 'GET', $dataSend = false, $header = array(), $options = array())
    {
        $result = parent::callAPI($url, $method, $dataSend, $header, $options);

        if($this->getHttpcode() == 400){
            //$this->setLogError($result);
        }

        if(property_exists($result, 'type') && ($result->type == 'error')){

            if(property_exists($result, 'fields')){

                $error         = new stdObject();
                $error->type   = 'error';
                $error->fields = $result->fields;

                return $error;
            }

            return $result;
        }

        return $result;

    }

    public function getApikey()
    {
        return $this->apikey;
    }

    public function getFeedbackUrl()
    {
        return $this->feedbackUrl;
    }

    public function getAuthtoken()
    {
        return $this->authtoken;
    }

}