Example #1
0
    def read(self, url, data=None, method='GET', format_='json'):
        """
        Returns parsed Python object or raises an error
        """
        assert format_ == 'json', "Only JSON format is supported at the moment"

        if '/gds/' not in url:
            url = '{0}.{1}'.format(url, format_)

        logger = logging.getLogger('python-odesk')

        logger.debug('Prepairing to make oDesk call')
        logger.debug('URL: {0}'.format(url))
        logger.debug('Data: {0}'.format(json.dumps(data)))
        logger.debug('Method: {0}'.format(method))
        response = self.urlopen(url, data, method)

        if response.status != 200:
            logger.debug('Error: {0}'.format(response))
            raise_http_error(url, response)

        result = response.data
        logger.debug('Response: {0}'.format(result))

        if format_ == 'json':
            try:
                result = json.loads(result)
            except ValueError:
                # Not a valid json string
                logger.debug('Response is not a valid json string')
                pass
        return result
Example #2
0
 def read(self, url, data=None, method='GET'):
     """
     Returns parsed Python object or raises an error
     """
     try:
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         raise_http_error(e)
Example #3
0
    def read(self, url, data=None, method='GET', fmt='json'):
        """
        Returns parsed Python object or raises an error.

        *Parameters:*
          :url:       Target url

          :data:      Dictionary with parameters

          :method:    (optional, default ``GET``)
                      HTTP method, possible values:
                        * ``GET``
                        * ``POST``
                        * ``PUT``
                        * ``DELETE``

          :fmt:         (optional, default ``json``)
                        API response format.
                        Currently only ``'json'`` is supported

        """
        assert fmt == 'json', "Only JSON format is supported at the moment"

        if '/gds/' not in url:
            url = '{0}.{1}'.format(url, fmt)

        logger = logging.getLogger('python-odesk')

        logger.debug('Prepairing to make oDesk call')
        logger.debug('URL: {0}'.format(url))
        try:
            logger.debug('Data: {0}'.format(
                json.dumps(data, default=decimal_default)))
        except TypeError:
            logger.debug('Data: {0}'.format(str(data)))
        logger.debug('Method: {0}'.format(method))
        response = self.urlopen(url, data, method)

        if response.status != 200:
            logger.debug('Error: {0}'.format(response))
            raise_http_error(url, response)

        result = response.data
        logger.debug('Response: {0}'.format(result))

        if fmt == 'json':
            try:
                result = json.loads(result)
            except ValueError:
                # Not a valid json string
                logger.debug('Response is not a valid json string')
                raise IncorrectJsonResponseError(
                    json.dumps({
                        'status': response.status,
                        'body': result
                    },
                               default=decimal_default))
        return result
Example #4
0
    def read(self, url, data=None, method='GET', fmt='json'):
        """
        Returns parsed Python object or raises an error.

        *Parameters:*
          :url:       Target url

          :data:      Dictionary with parameters

          :method:    (optional, default ``GET``)
                      HTTP method, possible values:
                        * ``GET``
                        * ``POST``
                        * ``PUT``
                        * ``DELETE``

          :fmt:         (optional, default ``json``)
                        API response format.
                        Currently only ``'json'`` is supported

        """
        assert fmt == 'json', "Only JSON format is supported at the moment"

        if '/gds/' not in url:
            url = '{0}.{1}'.format(url, fmt)

        logger = logging.getLogger('python-odesk')

        logger.debug('Prepairing to make oDesk call')
        logger.debug('URL: {0}'.format(url))
        try:
            logger.debug('Data: {0}'.format(
                json.dumps(data, default=decimal_default)))
        except TypeError:
            logger.debug('Data: {0}'.format(str(data)))
        logger.debug('Method: {0}'.format(method))
        response = self.urlopen(url, data, method)

        if response.status != 200:
            logger.debug('Error: {0}'.format(response))
            raise_http_error(url, response)

        result = response.data
        logger.debug('Response: {0}'.format(result))

        if fmt == 'json':
            try:
                result = json.loads(result)
            except ValueError:
                # Not a valid json string
                logger.debug('Response is not a valid json string')
                raise IncorrectJsonResponseError(
                    json.dumps({'status': response.status, 'body': result},
                               default=decimal_default)
                )
        return result
Example #5
0
 def read(self, url, data=None, method='GET'):
     """
     Returns parsed Python object or raises an error
     """
     try:
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         logger = logging.getLogger('python-odesk')
         logger.debug(e)
         raise_http_error(e)
 def read(self, url, data=None, method='GET'):
     """
     Returns parsed Python object or raises an error
     """
     try:
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         logger = logging.getLogger('python-odesk')
         logger.debug(e)
         raise_http_error(e)
Example #7
0
 def read(self, url, data=None, method='GET', format='json'):
     """
     Returns parsed Python object or raises an error
     """
     assert format == 'json', "Only JSON format is supported at the moment"
     url += '.' + format
     try:
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         raise_http_error(e)
Example #8
0
    def read(self, url, data={}, method='GET'):
        """
        Returns parsed Python object or raises an error
        """
        try:
            response = self.urlopen(url, data, method)
        except urllib2.HTTPError as e:
            raise_http_error(e)

        result = json.loads(response.read().decode("utf-8"))
        return result
Example #9
0
    def read(self, url, data={}, method='GET', format='json'):
        """
        Returns parsed Python object or raises an error
        """
        assert format == 'json', "Only JSON format is supported at the moment"
        url += '.' + format
        try:
            response = self.urlopen(url, data, method)
        except urllib2.HTTPError as e:
            raise_http_error(e)

        if format == 'json':
            result = json.loads(response.read().decode("utf-8"))
        return result
Example #10
0
    def read(self, url, data={}, method='GET', format='json'):
        """
        Returns parsed Python object or raises an error
        """
        assert format == 'json', "Only JSON format is supported at the moment"
        url += '.' + format
        try:
            response = self.urlopen(url, data, method)
        except urllib2.HTTPError as e:
            raise_http_error(e)

        if format == 'json':
            result = json.loads(response.read().decode("utf-8"))
        return result
Example #11
0
 def read(self, url, data=None, method='GET', format='json'):
     """
     Returns parsed Python object or raises an error
     """
     assert format == 'json', "Only JSON format is supported at the moment"
     url += '.' + format
     logger = logging.getLogger('python-odesk')
     try:
         logger.debug('Prepairing to make oDesk call')
         logger.debug('URL: ' + url)
         logger.debug('Data: ' + json.dumps(data))
         logger.debug('Method: ' + method)
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         logger.debug(e)
         raise_http_error(e)
Example #12
0
 def read(self, url, data=None, method="GET", format="json"):
     """
     Returns parsed Python object or raises an error
     """
     assert format == "json", "Only JSON format is supported at the moment"
     url += "." + format
     logger = logging.getLogger("python-odesk")
     try:
         logger.debug("Prepairing to make oDesk call")
         logger.debug("URL: " + url)
         logger.debug("Data: " + json.dumps(data))
         logger.debug("Method: " + method)
         response = self.urlopen(url, data, method)
     except urllib2.HTTPError, e:
         logger.debug(e)
         raise_http_error(e)