Ejemplo n.º 1
0
def create_aftale():
    config = config_data.ConfigData()

    aftale_response = {'contact_id': '', 'aftale_id': '', 'error': None}

    error, aftale_request = schema_validation.validate_json_schema(
        aftale_post_schema.get_schema(), request)
    if error is not None:
        aftale_response['error'] = error
        return jsonify(aftale_response)

    aftale_response['contact_id'], error = _get_contact_id_from_crm(
        aftale_request, config)
    if error is not None:
        aftale_response['error'] = error
        return jsonify(aftale_response)

    if aftale_response['contact_id'] is None:
        aftale_response['contact_id'], aftale_response[
            'error'] = _create_new_contact(aftale_request, config)

    if aftale_response['error'] is None:
        aftale_response['aftale_id'], aftale_response[
            'error'] = _create_aftale(aftale_request, config)

    if aftale_response['error'] is None:
        oauth_connect.connector.associate(
            'nrq_bidragsaftales', aftale_response['aftale_id'],
            'nrq_contact_nrq_bidragsaftale_Bidragyder', 'contacts',
            aftale_response['contact_id'], config)

    return jsonify(aftale_response)
Ejemplo n.º 2
0
def is_alive():
    query = "/contacts?$select=contactid&$top=1"
    config = config_data.ConfigData()

    headers, header_error = oauth_connect.connector.get_request_headers(config)

    is_alive_response = {
        'is_alive': False,
        'error': header_error,
        'proof': None
    }

    if headers is None:
        return jsonify(is_alive_response)

    crm_response = requests.get(config.api_url + query, headers=headers)

    try:
        crm_results = crm_response.json()
        is_alive_response[
            'proof'] = 'there is a contact with id = ' + crm_results['value'][
                0]['contactid']
        is_alive_response['is_alive'] = True
    except JSONDecodeError as message:
        is_alive_response['is_alive'] = False
        is_alive_response['error'] = repr(crm_response)
    except KeyError as message:
        is_alive_response['is_alive'] = False
        is_alive_response['error'] = repr(crm_response)

    return jsonify(is_alive_response)
Ejemplo n.º 3
0
def receive_hook_aftale(action, of_id):
    config = config_data.ConfigData()

    hook_response = {}

    error = activate_action(config, hook_response, action, of_id)

    if error is not None:
        hook_response['error'] = repr(error)

    return jsonify(hook_response)
Ejemplo n.º 4
0
def create_indbetaling():
    config = config_data.ConfigData()

    indbetaling_response = {'indbetaling_id': None, 'error': None}

    error, indbetaling_request = schema_validation.validate_json_schema(
        indbetaling_post_schema.get_schema(), request)
    if error is not None:
        indbetaling_response['error'] = error
        return jsonify(indbetaling_response)

    indbetaling_response['indbetaling_id'], error = _create_indbetaling(
        indbetaling_request, config)

    return jsonify(indbetaling_response)
Ejemplo n.º 5
0
def update_aftale():
    config = config_data.ConfigData()

    aftale_response = {'error': None}

    error, aftale_request = schema_validation.validate_json_schema(
        aftale_patch_schema.get_schema(), request)
    if error is not None:
        aftale_response['error'] = error
        return jsonify(aftale_response)

    returned_id, aftale_response['error'] = _update_aftale(
        aftale_request, config)

    if returned_id != aftale_request['aftale_id']:
        aftale_response['error'] = 'id (' + aftale_request[
            'aftale_id'] + ') is not (' + repr(returned_id) + ')'

    return jsonify(aftale_response)
Ejemplo n.º 6
0
def update_indbetaling():
    config = config_data.ConfigData()

    indbetaling_response = {'error': None}

    error, indbetaling_request = schema_validation.validate_json_schema(
        indbetaling_patch_schema.get_schema(), request)
    if error is not None:
        indbetaling_response['error'] = error
        return jsonify(indbetaling_response)

    returned_id, indbetaling_response['error'] = _update_indbetaling(
        indbetaling_request, config)

    if returned_id != indbetaling_request['indbetaling_id']:
        indbetaling_response['error'] = 'id (' + indbetaling_request[
            'indbetaling_id'] + ') is not (' + repr(returned_id) + ')'

    return jsonify(indbetaling_response)