def getResultComparison(self, result): ''' Get a comparison report that describe the matches with this result. ''' headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.get(result.getComparisonReport(), headers=headers) if (response.status_code == Consts.HTTP_SUCCESS): return response.json() else: raise CommandFailedError(response)
def getResultText(self, result): ''' Download cached version of the result detected by Copyleaks. ''' headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.get(result.getCachedVersion(), headers=headers) if (response.status_code == Consts.HTTP_SUCCESS): return response.text else: raise CommandFailedError(response)
def delete(self): ''' Deletes the process once it has finished running ''' serviceUrl = '%s%s/%s/%s/delete' % (Consts.SERVICE_ENTRY_POINT, Consts.SERVICE_VERSION, self.getProduct(), self.getPID()) headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.delete(serviceUrl, headers=headers) if (response.status_code != Consts.HTTP_SUCCESS): raise CommandFailedError(response)
def getResutls(self): ''' Get the scan resutls from server. ''' serviceUrl = '%s%s/%s/%s/result' % (Consts.SERVICE_ENTRY_POINT, Consts.SERVICE_VERSION, self.getProduct(), self.getPID()) headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.get(serviceUrl, headers=headers) if (response.status_code == Consts.HTTP_SUCCESS): return ResultRecord.parseResults(response.json()) else: raise CommandFailedError(response)
def getSourceText(self): ''' Download the full-text of the content you uploaded. ''' serviceUrl = '%s%s/%s/source-text?pid=%s' % ( Consts.SERVICE_ENTRY_POINT, Consts.SERVICE_VERSION, Consts.DOWNLOADS_ENTRY_POINT, self.getPID()) headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.get(serviceUrl, headers=headers) if (response.status_code == Consts.HTTP_SUCCESS): return response.text else: raise CommandFailedError(response)
def isCompleted(self): ''' Checks if the operation has been completed ''' serviceUrl = '%s%s/%s/%s/status' % (Consts.SERVICE_ENTRY_POINT, Consts.SERVICE_VERSION, self.getProduct(), self.getPID()) headers = { Consts.AUTHORIZATION_HEADER: self.token.generateAuthrizationHeader() } response = requests.get(serviceUrl, headers=headers) if (response.status_code == Consts.HTTP_SUCCESS): iscompleted = response.json()['Status'] == 'Finished' return [iscompleted, response.json()['ProgressPercents']] else: raise CommandFailedError(response)
def login(self): ''' Login to Copyleaks authentication server. ''' url = "%s%s/account/login-api" % (Consts.SERVICE_ENTRY_POINT, Consts.SERVICE_VERSION) payload = {'email': self.Email, 'apikey': self.ApiKey} headers = {Consts.CONTENT_TYPE_HEADER: Consts.CONTENT_TYPE_JSON} response = requests.post(url, headers=headers, data=json.dumps(payload)) if (response.status_code == Consts.HTTP_SUCCESS): self.__setAccessToken(response.json()['access_token']) self.__setIssuedTime( parser.parse(response.json()['.issued']).replace(tzinfo=None)) self.__setExpiresTime( parser.parse(response.json()['.expires']).replace(tzinfo=None)) else: raise CommandFailedError(response)