<commit_before>package com.podio.contact;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.podio.BaseAPI;
import com.podio.ResourceFactory;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;

/**
 * Each user have a profile attached, that holds all the personal details of the
 * user. This includes very basic information like the name and mail addresses,
 * but can also include more advanced fields like billing address and IM
 * addresses. Fields can have either one or multiple values. There can f.ex.
 * only be one name, but multiple mail addresses. The value of a field can
 * either be a string, a number or a date.
 */
public class ContactAPI extends BaseAPI {

	public ContactAPI(ResourceFactory resourceFactory) {
		super(resourceFactory);
	}

	/**
	 * Returns all the contact details about the user with the given id.
	 * 
	 * @param userId
	 *            The id of the user
	 * @return The contact profile
	 */
	public Profile getContact(int userId) {
		return getResourceFactory().getApiResource("/contact/" + userId).get(
				Profile.class);
	}

	/**
	 * Returns the value of a contact with the specific field
	 * 
	 * @param userId
	 *            The id of the user
	 * @param field
	 *            The field for which data should be returned
	 * @return The list of values for the given field
	 */
	public <T, R> List<T> getContactField(int userId, ProfileField<T, R> field) {
		List<R> values = getResourceFactory().getApiResource(
				"/contact/" + userId + "/" + field.getName())

		.get(new GenericType<List<R>>() {
		});

		List<T> formatted = new ArrayList<T>();
		for (R value : values) {
			formatted.add(field.parse(value));<commit_msg>added functionality to create and add a new space contact<commit_after>package com.podio.contact;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.core.MediaType;

import com.podio.BaseAPI;
import com.podio.ResourceFactory;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;

/**
 * Each user have a profile attached, that holds all the personal details of the
 * user. This includes very basic information like the name and mail addresses,
 * but can also include more advanced fields like billing address and IM
 * addresses. Fields can have either one or multiple values. There can f.ex.
 * only be one name, but multiple mail addresses. The value of a field can
 * either be a string, a number or a date.
 */
public class ContactAPI extends BaseAPI {

	public ContactAPI(ResourceFactory resourceFactory) {
		super(resourceFactory);
	}

         /**
	 * Adds a new contact to the given space.
	 * 
	 * @param spaceId
	 *            The id of the space the contact should be added to
	 * @param create
	 *            The data for the new contact
	 * @param silent
	 *            True if the create should be silent, false otherwise
	 * @return The id of the newly created contact
	 */
	public int addSpaceContact(int spaceId, ContactCreate create, boolean silent) {
		return getResourceFactory().getApiResource("/contact/space/" + spaceId + "/")
				.queryParam("silent", silent ? "1" : "0")
				.entity(create, MediaType.APPLICATION_JSON_TYPE)
				.post(ContactCreateResponse.class).getId();
	}
        
	/**
	 * Returns all the contact details about the user with the given id.
	 * 
	 * @param userId
	 *            The id of the user
	 * @return The contact profile
	 */
	public Profile getContact(int userId) {
		return getResourceFactory().getApiResource("/contact/" + userId).get(
				Profile.class);
	}

	/**
	 * Returns the value of a contact with the specific field
	 * 
	 * @param userId
	 *            The id of the user
	 * @param field
	 *            The field for which data should be returned
	 * @return The list of values for the given field
	 */
	public <T, R> List<T> getContactField(int userId, ProfileField<T, R> field) {
		List<R> values = getResourceFactory().getApiResource(
				"/contact/" + userId + "/" + field.getName())

		.get(new GenericType<List<R>>() {
		});

		List<T> formatted = new ArrayList<T>();
		for (R value : values) {
			formatted.add(field.parse(value));
{'fraction_non_alphanumeric': 0.09900761597045926, 'fraction_numerical': 0.00046157396722824835, 'mean_word_length': 3.355778894472362, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5004430', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1202, 'n_words': 462}