lib/TheTwelve/Foursquare/EndpointGateway.php
public function makeApiRequest($resource, array $params = array(), $method = 'GET')
    {

        $uri = $this->requestUri . '/' . ltrim($resource, '/');

        if ($this->hasValidToken()) {
            $params['oauth_token'] = $this->token;
        } else {
            $params['client_id'] = $this->clientId;
            $params['client_secret'] = $this->clientSecret;
        }

        // apply a dated "version"
        $params['v'] = $this->dateVerified->format('Ymd');

        switch ($method) {
            case 'GET':
                $response = json_decode($this->httpClient->get($uri, $params));
                break;
            case 'POST':
                $response = json_decode($this->httpClient->post($uri, $params));
                break;
            default:
                throw new \RuntimeException('Currently only HTTP methods "GET" and "POST" are supported.');
        }

        //TODO check headers for api request limit

        if (isset($response->meta)) {

            if (isset($response->meta->code)
                && $response->meta->code != 200
            ) {
                //TODO handle case
            }

            if (isset($response->meta->notifications)
                && is_array($response->meta->notifications)
                && count($response->meta->notifications)
            ) {

                //TODO handle notifications

            }

        }

        return $response->response;

    }
public function makeApiRequest($resource, array $params = array(), $method = 'GET')
    {

        $uri = $this->requestUri . '/' . ltrim($resource, '/');

        if ($this->hasValidToken()) {
            $params['oauth_token'] = $this->token;
        } else {
            $params['client_id'] = $this->clientId;
            $params['client_secret'] = $this->clientSecret;
        }

        // apply a dated "version"
        $params['v'] = $this->dateVerified->format('Ymd');

        switch ($method) {
            case 'GET':
                $response = json_decode($this->httpClient->get($uri, $params));
                break;
            case 'POST':
                $response = json_decode($this->httpClient->post($uri, $params));
                break;
            default:
                throw new \RuntimeException('Currently only HTTP methods "GET" and "POST" are supported.');
        }

        //TODO check headers for api request limit

        if (isset($response->meta)) {

            if (isset($response->meta->code)
                && $response->meta->code != 200
            ) {
                //TODO handle case
            }

            if (isset($response->meta->notifications)
                && is_array($response->meta->notifications)
                && count($response->meta->notifications)
            ) {

                //TODO handle notifications

            }

        }

        return $response->response;

    }
public function makeApiRequest ( $ resource , array $ params = array ( ) , $ method = 'GET' ) { $ uri = $ this -> requestUri . '/' . ltrim ( $ resource , '/' ) ; if ( $ this -> hasValidToken ( ) ) { $ params [ 'oauth_token' ] = $ this -> token ; } else { $ params [ 'client_id' ] = $ this -> clientId ; $ params [ 'client_secret' ] = $ this -> clientSecret ; } // apply a dated "version" $ params [ 'v' ] = $ this -> dateVerified -> format ( 'Ymd' ) ; switch ( $ method ) { case 'GET' : $ response = json_decode ( $ this -> httpClient -> get ( $ uri , $ params ) ) ; break ; case 'POST' : $ response = json_decode ( $ this -> httpClient -> post ( $ uri , $ params ) ) ; break ; default : throw new \ RuntimeException ( 'Currently only HTTP methods "GET" and "POST" are supported.' ) ; } //TODO check headers for api request limit if ( isset ( $ response -> meta ) ) { if ( isset ( $ response -> meta -> code ) && $ response -> meta -> code != 200 ) { //TODO handle case } if ( isset ( $ response -> meta -> notifications ) && is_array ( $ response -> meta -> notifications ) && count ( $ response -> meta -> notifications ) ) { //TODO handle notifications } } return $ response -> response ; }
make a generic request to the api
@param string $resource
@param array $params
@param string $method
@return \stdClass
make a generic request to the api