py_nextbus/client.py
def _perform_request(self, params):
        """Make a request to the NextBus API with given parameters.

        Arguments:
            params: (Dictionary) Query parameters to provide with the request.

        Returns:
            If the output_format is "json": Dictionary containing the JSON returned by the request.
            If the output_format is "xml": String containing the XML returned by the request.

        Raises:
            urllib.error.HTTPError: If an HTTP error occurs when making the request to the NextBus
                API.
            json.decoder.JSONDecodeError: If the output_format is "json" and the response was not
                valid JSON.
        """

        if self.output_format == 'json':
            base_url = NEXTBUS_JSON_FEED_URL
        elif self.output_format == 'xml':
            base_url = NEXTBUS_XML_FEED_URL
        else:
            raise ValueError('Invalid output_format: %s' % self.output_format)

        url = '%s?%s' % (base_url, urllib.parse.urlencode(params, safe='&='))

        headers = {}

        if self.use_compression:
            headers['Accept-Encoding'] = 'gzip, deflate'

        request = urllib.request.Request(url=url,
                                         headers=headers,
                                         method='GET')

        try:
            LOG.info('Making request to URL %s', url)
            with urllib.request.urlopen(request) as response:
                response_text = response.read()

                if self.output_format == 'json':
                    response = json.loads(response_text)
                elif self.output_format == 'xml':
                    response = response_text

        except urllib.error.HTTPError as exc:
            LOG.error('Request returned status %s due to reason: %s', exc.code, exc.reason)
            raise exc
        except json.decoder.JSONDecodeError as exc:
            LOG.error('Request did not return valid JSON. %s', exc)
            raise exc
        else:
            return response
Make a request to the NextBus API with given parameters.

        Arguments:
            params: (Dictionary) Query parameters to provide with the request.

        Returns:
            If the output_format is "json": Dictionary containing the JSON returned by the request.
            If the output_format is "xml": String containing the XML returned by the request.

        Raises:
            urllib.error.HTTPError: If an HTTP error occurs when making the request to the NextBus
                API.
            json.decoder.JSONDecodeError: If the output_format is "json" and the response was not
                valid JSON.
        
Make a request to the NextBus API with given parameters.
Make a request to the NextBus API with given parameters .
def _perform_request(self, params):
        if self.output_format == 'json':
            base_url = NEXTBUS_JSON_FEED_URL
        elif self.output_format == 'xml':
            base_url = NEXTBUS_XML_FEED_URL
        else:
            raise ValueError('Invalid output_format: %s' % self.output_format)
        url = '%s?%s' % (base_url, urllib.parse.urlencode(params, safe='&='))
        headers = {}
        if self.use_compression:
            headers['Accept-Encoding'] = 'gzip, deflate'
        request = urllib.request.Request(url=url,
                                         headers=headers,
                                         method='GET')
        try:
            LOG.info('Making request to URL %s', url)
            with urllib.request.urlopen(request) as response:
                response_text = response.read()
                if self.output_format == 'json':
                    response = json.loads(response_text)
                elif self.output_format == 'xml':
                    response = response_text
        except urllib.error.HTTPError as exc:
            LOG.error('Request returned status %s due to reason: %s', exc.code, exc.reason)
            raise exc
        except json.decoder.JSONDecodeError as exc:
            LOG.error('Request did not return valid JSON. %s', exc)
            raise exc
        else:
            return response
def _perform_request ( self , params ) : if self . output_format == 'json' : base_url = NEXTBUS_JSON_FEED_URL elif self . output_format == 'xml' : base_url = NEXTBUS_XML_FEED_URL else : raise ValueError ( 'Invalid output_format: %s' % self . output_format ) url = '%s?%s' % ( base_url , urllib . parse . urlencode ( params , safe = '&=' ) ) headers = { } if self . use_compression : headers [ 'Accept-Encoding' ] = 'gzip, deflate' request = urllib . request . Request ( url = url , headers = headers , method = 'GET' ) try : LOG . info ( 'Making request to URL %s' , url ) with urllib . request . urlopen ( request ) as response : response_text = response . read ( ) if self . output_format == 'json' : response = json . loads ( response_text ) elif self . output_format == 'xml' : response = response_text except urllib . error . HTTPError as exc : LOG . error ( 'Request returned status %s due to reason: %s' , exc . code , exc . reason ) raise exc except json . decoder . JSONDecodeError as exc : LOG . error ( 'Request did not return valid JSON. %s' , exc ) raise exc else : return response
Make a request to the NextBus API with given parameters.
Make a request to the NextBus API with given parameters .
"""Make a request to the NextBus API with given parameters.

        Arguments:
            params: (Dictionary) Query parameters to provide with the request.

        Returns:
            If the output_format is "json": Dictionary containing the JSON returned by the request.
            If the output_format is "xml": String containing the XML returned by the request.

        Raises:
            urllib.error.HTTPError: If an HTTP error occurs when making the request to the NextBus
                API.
            json.decoder.JSONDecodeError: If the output_format is "json" and the response was not
                valid JSON.
        """
If the output_format is "json": Dictionary containing the JSON returned by the request.
If the output_format is "xml": String containing the XML returned by the request.
If the output_format is " json " : Dictionary containing the JSON returned by the request . If the output_format is " xml " : String containing the XML returned by the request .
If an HTTP error occurs when making the request to the NextBus
API.
If an HTTP error occurs when making the request to the NextBus API .
urllib.error.HTTPError
If the output_format is "json" and the response was not
valid JSON.
If the output_format is " json " and the response was not valid JSON .
json.decoder.JSONDecodeError
self
params
(Dictionary) Query parameters to provide with the request.
( Dictionary ) Query parameters to provide with the request .