mixcoatl/resource.py
def __doreq(self, method, **kwargs):
        """Performs the actual API call

        * calls `auth.get_sig` for signed headers
        * issues the requested :attr:`method` against the API endpoint
        * Handles requests appropriately based on sync/async nature of the call
            based on DCM API documentation
        """
        failures = [400, 403, 404, 409, 500, 501, 503]
        sig = auth.get_sig(method, self.path, endpoint=self.__endpoint)
        url = self.__endpoint.url + '/' + self.path
        ssl_verify = self.__endpoint.ssl_verify

        if self.payload_format == 'xml':
            payload_format = 'application/xml'
        elif self.payload_format == 'json':
            payload_format = 'application/json'
        else:
            raise AttributeError(
                'Wrong payload format: %s' % self.payload_format)

        headers = {'x-esauth-access': sig['access_key'],
                   'x-esauth-timestamp': str(sig['timestamp']),
                   'x-esauth-signature': str(sig['signature']),
                   'x-es-details': self.request_details,
                   'Accept': payload_format,
                   'User-Agent': sig['ua']}

        results = r.request(
            method, url, headers=headers, verify=ssl_verify, **kwargs)

        if 'DCM_DEBUG' in os.environ:
            print "URL: %s" % (url)
            print "method: %s" % (method)
            for key, value in kwargs.iteritems():
                print "%s = %s" % (key, value)
            for key, value in results.headers.iteritems():
                print "headers: %s = %s" % (key, value)

        self.last_error = None
        self.last_request = results
        self.__status_code = results.status_code

        if self.payload_format == 'xml':
            return results

        if results.status_code in failures:
            try:
                err = results.json()
                self.last_error = err['error']['message']
            except ValueError:
                self.last_error = results.content
            return self.last_error

        if method == 'GET':
            try:
                results.raise_for_status()
                self.last_error = None
                return results.json()
            except r.exceptions.HTTPError:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'DELETE':
            if results.status_code == 202:
                self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            elif results.status_code != 204:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
            else:
                return True
        if method == 'PUT':
            if results.status_code == 202:
                self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            elif results.status_code == 204:
                return True
            else:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'POST':
            if results.status_code in [201, 202]:
                if results.status_code == 202:
                    self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            else:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'HEAD':
            if results.status_code in [200]:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
Performs the actual API call

        * calls `auth.get_sig` for signed headers
        * issues the requested :attr:`method` against the API endpoint
        * Handles requests appropriately based on sync/async nature of the call
            based on DCM API documentation
        
Performs the actual API call
calls `auth.get_sig` for signed headers
issues the requested :attr:`method` against the API endpoint
Handles requests appropriately based on sync/async nature of the call
based on DCM API documentation
Performs the actual API call calls ` auth . get_sig ` for signed headers issues the requested : attr : ` method ` against the API endpoint Handles requests appropriately based on sync / async nature of the call based on DCM API documentation
def __doreq(self, method, **kwargs):
        failures = [400, 403, 404, 409, 500, 501, 503]
        sig = auth.get_sig(method, self.path, endpoint=self.__endpoint)
        url = self.__endpoint.url + '/' + self.path
        ssl_verify = self.__endpoint.ssl_verify
        if self.payload_format == 'xml':
            payload_format = 'application/xml'
        elif self.payload_format == 'json':
            payload_format = 'application/json'
        else:
            raise AttributeError(
                'Wrong payload format: %s' % self.payload_format)
        headers = {'x-esauth-access': sig['access_key'],
                   'x-esauth-timestamp': str(sig['timestamp']),
                   'x-esauth-signature': str(sig['signature']),
                   'x-es-details': self.request_details,
                   'Accept': payload_format,
                   'User-Agent': sig['ua']}
        results = r.request(
            method, url, headers=headers, verify=ssl_verify, **kwargs)
        if 'DCM_DEBUG' in os.environ:
            print "URL: %s" % (url)
            print "method: %s" % (method)
            for key, value in kwargs.iteritems():
                print "%s = %s" % (key, value)
            for key, value in results.headers.iteritems():
                print "headers: %s = %s" % (key, value)
        self.last_error = None
        self.last_request = results
        self.__status_code = results.status_code
        if self.payload_format == 'xml':
            return results
        if results.status_code in failures:
            try:
                err = results.json()
                self.last_error = err['error']['message']
            except ValueError:
                self.last_error = results.content
            return self.last_error
        if method == 'GET':
            try:
                results.raise_for_status()
                self.last_error = None
                return results.json()
            except r.exceptions.HTTPError:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'DELETE':
            if results.status_code == 202:
                self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            elif results.status_code != 204:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
            else:
                return True
        if method == 'PUT':
            if results.status_code == 202:
                self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            elif results.status_code == 204:
                return True
            else:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'POST':
            if results.status_code in [201, 202]:
                if results.status_code == 202:
                    self.current_job = results.json()['jobs'][0]['jobId']
                return results.json()
            else:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
        if method == 'HEAD':
            if results.status_code in [200]:
                try:
                    err = results.json()
                    self.last_error = err['error']['message']
                except ValueError:
                    self.last_error = results.content
                return False
def __doreq ( self , method , ** kwargs ) : failures = [ 400 , 403 , 404 , 409 , 500 , 501 , 503 ] sig = auth . get_sig ( method , self . path , endpoint = self . __endpoint ) url = self . __endpoint . url + '/' + self . path ssl_verify = self . __endpoint . ssl_verify if self . payload_format == 'xml' : payload_format = 'application/xml' elif self . payload_format == 'json' : payload_format = 'application/json' else : raise AttributeError ( 'Wrong payload format: %s' % self . payload_format ) headers = { 'x-esauth-access' : sig [ 'access_key' ] , 'x-esauth-timestamp' : str ( sig [ 'timestamp' ] ) , 'x-esauth-signature' : str ( sig [ 'signature' ] ) , 'x-es-details' : self . request_details , 'Accept' : payload_format , 'User-Agent' : sig [ 'ua' ] } results = r . request ( method , url , headers = headers , verify = ssl_verify , ** kwargs ) if 'DCM_DEBUG' in os . environ : print "URL: %s" % ( url ) print "method: %s" % ( method ) for key , value in kwargs . iteritems ( ) : print "%s = %s" % ( key , value ) for key , value in results . headers . iteritems ( ) : print "headers: %s = %s" % ( key , value ) self . last_error = None self . last_request = results self . __status_code = results . status_code if self . payload_format == 'xml' : return results if results . status_code in failures : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return self . last_error if method == 'GET' : try : results . raise_for_status ( ) self . last_error = None return results . json ( ) except r . exceptions . HTTPError : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return False if method == 'DELETE' : if results . status_code == 202 : self . current_job = results . json ( ) [ 'jobs' ] [ 0 ] [ 'jobId' ] return results . json ( ) elif results . status_code != 204 : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return False else : return True if method == 'PUT' : if results . status_code == 202 : self . current_job = results . json ( ) [ 'jobs' ] [ 0 ] [ 'jobId' ] return results . json ( ) elif results . status_code == 204 : return True else : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return False if method == 'POST' : if results . status_code in [ 201 , 202 ] : if results . status_code == 202 : self . current_job = results . json ( ) [ 'jobs' ] [ 0 ] [ 'jobId' ] return results . json ( ) else : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return False if method == 'HEAD' : if results . status_code in [ 200 ] : try : err = results . json ( ) self . last_error = err [ 'error' ] [ 'message' ] except ValueError : self . last_error = results . content return False
Performs the actual API call
 calls `auth.get_sig` for signed headers
 issues the requested :attr:`method` against the API endpoint
 Handles requests appropriately based on sync/async nature of the call
based on DCM API documentation
Performs the actual API call calls ` auth . get_sig ` for signed headers issues the requested : attr : ` method ` against the API endpoint Handles requests appropriately based on sync / async nature of the call based on DCM API documentation
"""Performs the actual API call

        * calls `auth.get_sig` for signed headers
        * issues the requested :attr:`method` against the API endpoint
        * Handles requests appropriately based on sync/async nature of the call
            based on DCM API documentation
        """
self
method