public function call($call, array $params = array())
    {
        $startTime = microtime(true);

        if (!array_key_exists('culture', $params)) {
            $params['culture'] = $this->culture;
        }

        $url = $this->generateUrl($call, $params);
        $this->logger->debug('call start', array(
            'url'      => $url,
        ));

        $key = $this->cache->generateCacheKey($url);
        $content = $this->cache->get($key);
        if ($content !== false) {
            $this->logger->debug('call end', array(
                'url'      => $url,
                'cache'    => true,
                'time'     => microtime(true) - $startTime,
                'response' => $content,
            ));

            return $content;
        }

        $request = $this->createRequest($url);

        if (!ini_get('open_basedir') && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
            $request->setOption(CURLOPT_FOLLOWLOCATION, true);
        }

        $response = $request->get();

        if ($request->getError()) {
            $this->throwError('The Api call returned an error: "' . $request->getError() . '"');
        }

        if ($request->getStatusCode() == 401) {
            $this->throwError('Bad Username / Password ' . $request->getStatusCode(), '\Justimmo\Exception\AuthenticationException');
        }

        if ($request->getStatusCode() == 404) {
            $this->throwError('Api call not found: ' . $request->getStatusCode(), '\Justimmo\Exception\NotFoundException');
        }

        if ($request->getStatusCode() >= 400 && $request->getStatusCode() < 500) {
            $exception = new InvalidRequestException('The Api call returned status code ' . $request->getStatusCode());
            $exception->setResponse($request->getContent());
            $this->logger->error($exception->getMessage());

            throw $exception;
        }

        if ($request->getStatusCode() != 200) {
            $this->throwError('The Api call returned status code ' . $request->getStatusCode(), '\Justimmo\Exception\StatusCodeException');
        }

        $this->cache->set($key, $response);

        $this->logger->debug('call end', array(
            'url'      => $url,
            'cache'    => false,
            'time'     => microtime(true) - $startTime,
            'response' => $response,
        ));

        return $response;
    }
public function call($call, array $params = array())
    {
        $startTime = microtime(true);

        if (!array_key_exists('culture', $params)) {
            $params['culture'] = $this->culture;
        }

        $url = $this->generateUrl($call, $params);
        $this->logger->debug('call start', array(
            'url'      => $url,
        ));

        $key = $this->cache->generateCacheKey($url);
        $content = $this->cache->get($key);
        if ($content !== false) {
            $this->logger->debug('call end', array(
                'url'      => $url,
                'cache'    => true,
                'time'     => microtime(true) - $startTime,
                'response' => $content,
            ));

            return $content;
        }

        $request = $this->createRequest($url);

        if (!ini_get('open_basedir') && filter_var(ini_get('safe_mode'), FILTER_VALIDATE_BOOLEAN) === false) {
            $request->setOption(CURLOPT_FOLLOWLOCATION, true);
        }

        $response = $request->get();

        if ($request->getError()) {
            $this->throwError('The Api call returned an error: "' . $request->getError() . '"');
        }

        if ($request->getStatusCode() == 401) {
            $this->throwError('Bad Username / Password ' . $request->getStatusCode(), '\Justimmo\Exception\AuthenticationException');
        }

        if ($request->getStatusCode() == 404) {
            $this->throwError('Api call not found: ' . $request->getStatusCode(), '\Justimmo\Exception\NotFoundException');
        }

        if ($request->getStatusCode() >= 400 && $request->getStatusCode() < 500) {
            $exception = new InvalidRequestException('The Api call returned status code ' . $request->getStatusCode());
            $exception->setResponse($request->getContent());
            $this->logger->error($exception->getMessage());

            throw $exception;
        }

        if ($request->getStatusCode() != 200) {
            $this->throwError('The Api call returned status code ' . $request->getStatusCode(), '\Justimmo\Exception\StatusCodeException');
        }

        $this->cache->set($key, $response);

        $this->logger->debug('call end', array(
            'url'      => $url,
            'cache'    => false,
            'time'     => microtime(true) - $startTime,
            'response' => $response,
        ));

        return $response;
    }
public function call ( $ call , array $ params = array ( ) ) { $ startTime = microtime ( true ) ; if ( ! array_key_exists ( 'culture' , $ params ) ) { $ params [ 'culture' ] = $ this -> culture ; } $ url = $ this -> generateUrl ( $ call , $ params ) ; $ this -> logger -> debug ( 'call start' , array ( 'url' => $ url , ) ) ; $ key = $ this -> cache -> generateCacheKey ( $ url ) ; $ content = $ this -> cache -> get ( $ key ) ; if ( $ content !== false ) { $ this -> logger -> debug ( 'call end' , array ( 'url' => $ url , 'cache' => true , 'time' => microtime ( true ) - $ startTime , 'response' => $ content , ) ) ; return $ content ; } $ request = $ this -> createRequest ( $ url ) ; if ( ! ini_get ( 'open_basedir' ) && filter_var ( ini_get ( 'safe_mode' ) , FILTER_VALIDATE_BOOLEAN ) === false ) { $ request -> setOption ( CURLOPT_FOLLOWLOCATION , true ) ; } $ response = $ request -> get ( ) ; if ( $ request -> getError ( ) ) { $ this -> throwError ( 'The Api call returned an error: "' . $ request -> getError ( ) . '"' ) ; } if ( $ request -> getStatusCode ( ) == 401 ) { $ this -> throwError ( 'Bad Username / Password ' . $ request -> getStatusCode ( ) , '\Justimmo\Exception\AuthenticationException' ) ; } if ( $ request -> getStatusCode ( ) == 404 ) { $ this -> throwError ( 'Api call not found: ' . $ request -> getStatusCode ( ) , '\Justimmo\Exception\NotFoundException' ) ; } if ( $ request -> getStatusCode ( ) >= 400 && $ request -> getStatusCode ( ) < 500 ) { $ exception = new InvalidRequestException ( 'The Api call returned status code ' . $ request -> getStatusCode ( ) ) ; $ exception -> setResponse ( $ request -> getContent ( ) ) ; $ this -> logger -> error ( $ exception -> getMessage ( ) ) ; throw $ exception ; } if ( $ request -> getStatusCode ( ) != 200 ) { $ this -> throwError ( 'The Api call returned status code ' . $ request -> getStatusCode ( ) , '\Justimmo\Exception\StatusCodeException' ) ; } $ this -> cache -> set ( $ key , $ response ) ; $ this -> logger -> debug ( 'call end' , array ( 'url' => $ url , 'cache' => false , 'time' => microtime ( true ) - $ startTime , 'response' => $ response , ) ) ; return $ response ; }
Makes a call to the justimmo api

@param $call
@param array $params

@return mixed
Makes a call to the justimmo api