<commit_before>package io.github.zwieback.relef.web.rest.services;

import io.github.zwieback.relef.services.SleepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Service
public class RestService {

    private final RestTemplate restTemplate;
    private final SleepService sleepService;

    @Value("${client.userAgent}")
    private String userAgent;

    @Autowired
    public RestService(RestTemplate restTemplate, SleepService sleepService) {
        this.restTemplate = restTemplate;
        this.sleepService = sleepService;
    }

    public HttpHeaders buildHeaders() {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add(HttpHeaders.USER_AGENT, userAgent);
        httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        return httpHeaders;
    }

    public <T> HttpEntity<T> buildEntity(T body, HttpHeaders httpHeaders) {
        return new HttpEntity<>(body, httpHeaders);
    }

    public <T> T post(String url, HttpEntity<?> entity, Class<T> responseType) {
        return post(url, entity, responseType, new HashMap<>());
    }

    public <T> T post(String url, HttpEntity<?> entity, Class<T> responseType, Map<String, ?> urlParams) {
        return exchange(url, HttpMethod.POST, entity, responseType, urlParams);
    }

    private <T> T exchange(String url, HttpMethod method, HttpEntity<?> entity, Class<T> responseType,
                           Map<String, ?> urlParams) {
        StopWatch watch = new StopWatch();
        watch.start();
        ResponseEntity<T> response = restTemplate.exchange(url, method, entity, responseType, urlParams);
        watch.stop();
        sleepService.sleepIfNeeded(watch.getTotalTimeMillis());
        return response.getBody();
    }
}
<commit_msg>RP-21: added get() and buildEmptyHeaders() methods to RestService to download photos of products<commit_after>package io.github.zwieback.relef.web.rest.services;

import io.github.zwieback.relef.services.SleepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Service
public class RestService {

    private final RestTemplate restTemplate;
    private final SleepService sleepService;

    @Value("${client.userAgent}")
    private String userAgent;

    @Autowired
    public RestService(RestTemplate restTemplate, SleepService sleepService) {
        this.restTemplate = restTemplate;
        this.sleepService = sleepService;
    }

    public HttpHeaders buildHeaders() {
        HttpHeaders httpHeaders = buildEmptyHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
        return httpHeaders;
    }

    public HttpHeaders buildEmptyHeaders() {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add(HttpHeaders.USER_AGENT, userAgent);
        return httpHeaders;
    }

    public <T> HttpEntity<T> buildEntity(T body, HttpHeaders httpHeaders) {
        return new HttpEntity<>(body, httpHeaders);
    }

    public <T> T get(String url, HttpEntity<?> entity, Class<T> responseType) {
        return exchange(url, HttpMethod.GET, entity, responseType, new HashMap<>());
    }

    public <T> T post(String url, HttpEntity<?> entity, Class<T> responseType) {
        return post(url, entity, responseType, new HashMap<>());
    }

    public <T> T post(String url, HttpEntity<?> entity, Class<T> responseType, Map<String, ?> urlParams) {
        return exchange(url, HttpMethod.POST, entity, responseType, urlParams);
    }

    private <T> T exchange(String url, HttpMethod method, HttpEntity<?> entity, Class<T> responseType,
                           Map<String, ?> urlParams) {
        StopWatch watch = new StopWatch();
        watch.start();
        ResponseEntity<T> response = restTemplate.exchange(url, method, entity, responseType, urlParams);
        watch.stop();
        sleepService.sleepIfNeeded(watch.getTotalTimeMillis());
        return response.getBody();
    }
}

{'fraction_non_alphanumeric': 0.10391249474127051, 'fraction_numerical': 0.00042069835927639884, 'mean_word_length': 3.8719262295081966, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '535300', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1282, 'n_words': 302}