|
1 | 1 | package br.com.developers.github.http.service.request.impl; |
2 | 2 |
|
3 | | -import org.apache.log4j.Logger; |
4 | 3 | import org.springframework.http.HttpEntity; |
5 | 4 | import org.springframework.http.HttpHeaders; |
6 | 5 | import org.springframework.http.HttpMethod; |
7 | 6 | import org.springframework.http.ResponseEntity; |
8 | 7 | import org.springframework.stereotype.Component; |
9 | 8 | import org.springframework.web.client.RestTemplate; |
10 | 9 | import org.springframework.web.util.UriComponents; |
11 | | -import br.com.developers.github.http.resource.developer.Developer; |
12 | 10 | import br.com.developers.github.http.service.request.Send; |
13 | 11 | import lombok.AccessLevel; |
14 | 12 | import lombok.AllArgsConstructor; |
| 13 | +import lombok.extern.slf4j.Slf4j; |
15 | 14 |
|
| 15 | +@Slf4j |
16 | 16 | @AllArgsConstructor(access = AccessLevel.PACKAGE) |
17 | 17 | @Component |
18 | | -public class SendImpl implements Send<Developer> { |
19 | | - |
20 | | - private static final Logger LOG = Logger.getLogger(SendImpl.class); |
21 | | - |
| 18 | +public class SendImpl implements Send { |
22 | 19 | private RestTemplate restTemplate; |
23 | 20 |
|
24 | | - public ResponseEntity<Developer> sendRequest(UriComponents uri) { |
25 | | - LOG.info("Sending request to URI [ " + uri + " ]"); |
| 21 | + public ResponseEntity<Object> sendRequest(UriComponents url, HttpMethod httpMethod) { |
| 22 | + log.info("Sending request to URI [ " + url + " ]"); |
26 | 23 | HttpHeaders headers = createHttpHeaders(); |
27 | | - HttpEntity<Developer> entity = createHttpEntity(headers); |
28 | | - return this.restTemplate.exchange(uri.toUri(), HttpMethod.POST, entity, Developer.class); |
| 24 | + HttpEntity<Object> entity = createHttpEntity(headers); |
| 25 | + String uri = url.toUriString(); |
| 26 | + return this.restTemplate.exchange(uri, httpMethod, entity, Object.class); |
29 | 27 | } |
30 | 28 |
|
31 | 29 | private HttpHeaders createHttpHeaders() { |
32 | 30 | HttpHeaders headers = new HttpHeaders(); |
33 | | - headers.set("Accept", "application/vnd.github.v3+json"); |
| 31 | + headers.set("accept", "application/vnd.github.v3+json"); |
34 | 32 | return headers; |
35 | 33 | } |
36 | 34 |
|
37 | | - private HttpEntity<Developer> createHttpEntity(HttpHeaders headers) { |
38 | | - return new HttpEntity<Developer>(headers); |
| 35 | + private HttpEntity<Object> createHttpEntity(HttpHeaders headers) { |
| 36 | + return new HttpEntity<Object>(headers); |
39 | 37 | } |
40 | 38 |
|
41 | 39 | } |
0 commit comments