<commit_before>package be.ugent.oomo.groep12.studgent.utilities;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import be.ugent.oomo.groep12.studgent.R;
import be.ugent.oomo.groep12.studgent.exception.CurlException;
import android.content.res.Resources;

public class CurlUtil {
	public static String get(String resource) throws CurlException {
		String api = App.getContext().getResources().getString(R.string.studgent_api);
		String target = api + '/' + resource;
		try {
			
		    HttpClient httpclient = new DefaultHttpClient();
		    HttpResponse response = httpclient.execute(new HttpGet(target));
		    StatusLine statusLine = response.getStatusLine();
		    if(statusLine.getStatusCode() == HttpStatus.SC_OK){
		        ByteArrayOutputStream out = new ByteArrayOutputStream();
		        response.getEntity().writeTo(out);
		        out.close();
		        return out.toString();
		    } else{
		        //Closes the connection.
		        response.getEntity().getContent().close();
		        throw new CurlException(statusLine.getReasonPhrase());
		    }

		} catch (Exception e) {
			throw new CurlException(e);
		}
	}
}<commit_msg>Issue #14: more get requests (by id, by name, per page)<commit_after>package be.ugent.oomo.groep12.studgent.utilities;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import be.ugent.oomo.groep12.studgent.R;
import be.ugent.oomo.groep12.studgent.exception.CurlException;
import android.content.res.Resources;

public class CurlUtil {
	
	/**
	 * Executes a GET request to the resource specified in the parameter.
	 * @param resource from the backend api
	 * @return String with list of json items
	 * @throws CurlException
	 */
	public static String get(String resource) throws CurlException {
		String api = App.getContext().getResources().getString(R.string.studgent_api);
		String target = api + '/' + resource;
		try {
			
		    HttpClient httpclient = new DefaultHttpClient();
		    HttpResponse response = httpclient.execute(new HttpGet(target));
		    StatusLine statusLine = response.getStatusLine();
		    if(statusLine.getStatusCode() == HttpStatus.SC_OK){
		        ByteArrayOutputStream out = new ByteArrayOutputStream();
		        response.getEntity().writeTo(out);
		        out.close();
		        return out.toString();
		    } else{
		        //Closes the connection.
		        response.getEntity().getContent().close();
		        throw new CurlException(statusLine.getReasonPhrase());
		    }

		} catch (Exception e) {
			throw new CurlException(e);
		}
	}

	
	/**
	 * GET request to the backend api to retrieve one object, specified by id.
	 * @param resource of the backend api
	 * @param id of the requested object
	 * @return String with one json item
	 * @throws CurlException
	 */
	public static String get_by_id(String resource, int id) throws CurlException{
		return get(resource + "/id/" + id);
	}

	/**
	 * GET request to the backend api to retrieve objects, filtered by name specified in the parameter
	 * @param resource of the backend api
	 * @param name to filter items on
	 * @return String with filtered list with json items
	 * @throws CurlException
	 */
	public static String get_by_name(String resource, String name) throws CurlException{
		return get(resource + "/name/" + name);
	}
	
	/**	
	 * GET request to the backend api to retrieve objects per page
	 * @param resource of the backend api
	 * @param perpage amount of objects per page
	 * @param page offset, pagenumber
	 * @return String with page from list with json items
	 * @throws CurlException
	 */
	public static String get_paged(String resource, int perpage, int page) throws CurlException{
		return get(resource + "/page/" + perpage + '/' + page);
	}
}
{'fraction_non_alphanumeric': 0.10331339162448228, 'fraction_numerical': 0.0032213529682466636, 'mean_word_length': 3.7404580152671754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5042094', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1216, 'n_words': 346}