protected function validate(&$data, $method)
    {
        if ( is_array($data) === false ) {
            throw new InvalidApiResponseException('Google Url Shortener returned a response that could not be handled');
        }

        if (!empty($data['error']['errors'])) {
            $error = json_encode($data['error']['errors']);
            throw new InvalidApiResponseException('Google Url Shortener returned the following error: '.$error);
        }

        if (empty($data['status']) && $method == 'expand') {
            throw new InvalidApiResponseException('Google Url Shortener has no status');
        }

        if ( !empty($data['status']) && $data['status']!='OK' && $method == 'expand') {
            throw new InvalidApiResponseException('Google Url Shortener returned an invalid status');
        }

        if (empty($data['id'])) {
            throw new InvalidApiResponseException('Google Url Shortener cannot provide the shortened Url');
        }

        if (empty($data['longUrl'])) {
            throw new InvalidApiResponseException('Google Url Shortener cannot provide the original Url');
        }

        return $data;
    }