Exemple #1
0
    def post(self, account_id):
        """
        POST /v1/ats-candidates/:account_id

        Create a new ATS candidate.

        :param account_id: int, id of the ATS account.
        :rtype string, JSON indicating success.
        """

        ats_service.app.logger.info("{} {} {} {}".format(
            request.method, request.path, request.user.email, request.user.id))
        data = get_valid_json_data(request)

        # Validate data fields
        validate_ats_candidate_data(data)

        # Validate ATS Account
        account = ATSAccount.get_by_id(account_id)
        if not account:
            raise NotFoundError(
                'Account id not found',
                additional_error_info=dict(account_id=account_id))

        # Create the candidate. No attempt to determine if duplicate.
        candidate = new_ats_candidate(account_id, data)

        response = json.dumps(
            dict(id=candidate.id,
                 message="ATS candidate successfully created."))
        headers = dict(Location=ATSServiceApiUrl.CANDIDATES % candidate.id)
        return ApiResponse(response, headers=headers, status=codes.CREATED)
Exemple #2
0
    def get(self, account_id):
        """
        GET /v1/ats-accounts/:account_id

        Retrieve an ATS accoun.

        :param account_id: int, id of the ATS account.
        :rtype string, JSON describing the account.
        """

        ats_service.app.logger.info("{} {} {} {}".format(
            request.method, request.path, request.user.email, request.user.id))
        account = ATSAccount.get_by_id(account_id)
        if not account:
            raise NotFoundError(
                'Account id not found',
                additional_error_info=dict(account_id=account_id))

        account_dict = account.to_dict()
        credentials = ATSCredential.get_by_id(account.ats_credential_id)
        ats = ATS.get_by_id(account.ats_id)
        account_dict.update({
            'credentials': credentials.credentials_json,
            'ats_name': ats.name,
            'ats_homepage': ats.homepage_url,
            'ats_login': ats.login_url
        })

        response = json.dumps(account_dict)
        headers = dict(Location=ATSServiceApiUrl.ACCOUNT % account_id)
        return ApiResponse(response, headers=headers, status=codes.OK)
Exemple #3
0
    def get(self, account_id):
        """
        GET /v1/ats-candidates/:account_id

        Retrieve all ATS candidates stored locally associated with an ATS account

        :param account_id: int, id of the ATS account.
        :rtype string, JSON with all candidates.
        """

        ats_service.app.logger.info("{} {} {} {}".format(
            request.method, request.path, request.user.email, request.user.id))
        account = ATSAccount.get_by_id(account_id)
        if not account:
            raise NotFoundError(
                'Account id not found',
                additional_error_info=dict(account_id=account_id))

        candidates = ATSCandidate.get_all(account_id)
        if candidates:
            # TODO: Consider adding the ATS-particular entry.
            response = json.dumps(dict(candidate_list=candidates))
            headers = dict(Location=ATSServiceApiUrl.CANDIDATES % account_id)
            return ApiResponse(response, headers=headers, status=codes.OK)

        ats_service.app.logger.info(
            "No candidates in ATS account {}".format(account_id))
        response = json.dumps(
            dict(account_id=account_id,
                 message="No candidates in ATS account {}".format(account_id)))
        headers = dict(Location=ATSServiceApiUrl.CANDIDATES % account_id)
        return ApiResponse(response, headers=headers, status=codes.NOT_FOUND)