Search in sources :

Example 1 with GitHubDTO

use of com.nixmash.blog.jpa.dto.GitHubDTO in project nixmash-blog by mintster.

the class GithubJobUI method getDummyStats.

public GitHubDTO getDummyStats() {
    GitHubDTO gitHubDTO = new GitHubDTO();
    gitHubDTO.setStars(251);
    gitHubDTO.setForks(87);
    gitHubDTO.setSubscribers(45);
    gitHubDTO.setFollowers(87);
    return gitHubDTO;
}
Also used : GitHubDTO(com.nixmash.blog.jpa.dto.GitHubDTO)

Example 2 with GitHubDTO

use of com.nixmash.blog.jpa.dto.GitHubDTO in project nixmash-blog by mintster.

the class GitHubTests method getGitHubProjectStatsInClassObject.

@Test
public void getGitHubProjectStatsInClassObject() throws Exception {
    GitHubDTO gitHubDTO = restTemplate.getForObject(gitHubRepoUrl, GitHubDTO.class);
    assertThat(gitHubDTO.getSubscribers(), greaterThan(-1));
    HttpEntity<String> stringUserEntity = restTemplate.getForEntity(gitHubUserUrl, String.class);
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.readValue(stringUserEntity.getBody(), ObjectNode.class);
    gitHubDTO.setFollowers(node.get("followers").intValue());
    assertThat(gitHubDTO.getFollowers(), greaterThan(-1));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GitHubDTO(com.nixmash.blog.jpa.dto.GitHubDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with GitHubDTO

use of com.nixmash.blog.jpa.dto.GitHubDTO in project nixmash-blog by mintster.

the class WebUI method getGitHubStats.

public GitHubDTO getGitHubStats() {
    String gitHubRepoUrl = environment.getProperty("github.repo.url");
    String gitHubUserUrl = environment.getProperty("github.user.url");
    // Load Repository JSON elements into GitHubDTO Object
    GitHubDTO gitHubDTO = new GitHubDTO();
    RestTemplate restTemplate = new RestTemplate();
    try {
        gitHubDTO = restTemplate.getForObject(gitHubRepoUrl, GitHubDTO.class);
    } catch (RestClientException e) {
        gitHubDTO.setIsEmpty(true);
        return gitHubDTO;
    }
    // Load User Followers count from GitHub User JSON Endpoint and add to GitHubDTO
    HttpEntity<String> stringUserEntity = restTemplate.getForEntity(gitHubUserUrl, String.class);
    ObjectMapper mapper = new ObjectMapper();
    try {
        ObjectNode node = mapper.readValue(stringUserEntity.getBody(), ObjectNode.class);
        gitHubDTO.setFollowers(node.get("followers").intValue());
    } catch (IOException e) {
        logger.error("Error adding follower count from GitHub API to GitHubDTO object");
    }
    return gitHubDTO;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GitHubDTO(com.nixmash.blog.jpa.dto.GitHubDTO) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with GitHubDTO

use of com.nixmash.blog.jpa.dto.GitHubDTO in project nixmash-blog by mintster.

the class GithubJobUI method getGitHubStats.

public GitHubDTO getGitHubStats() {
    String gitHubRepoUrl = environment.getProperty("github.job.repo.url");
    String gitHubUserUrl = environment.getProperty("github.job.user.url");
    // Load Repository JSON elements into GitHubDTO Object
    GitHubDTO gitHubDTO = new GitHubDTO();
    RestTemplate restTemplate = new RestTemplate();
    try {
        gitHubDTO = restTemplate.getForObject(gitHubRepoUrl, GitHubDTO.class);
    } catch (RestClientException e) {
        gitHubDTO.setIsEmpty(true);
        return gitHubDTO;
    }
    // Load User Followers count from GitHub User JSON Endpoint and add to GitHubDTO
    HttpEntity<String> stringUserEntity = restTemplate.getForEntity(gitHubUserUrl, String.class);
    ObjectMapper mapper = new ObjectMapper();
    try {
        ObjectNode node = mapper.readValue(stringUserEntity.getBody(), ObjectNode.class);
        gitHubDTO.setFollowers(node.get("followers").intValue());
    } catch (IOException e) {
        logger.error("Error adding follower count from GitHub API to GitHubDTO object");
    }
    return gitHubDTO;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GitHubDTO(com.nixmash.blog.jpa.dto.GitHubDTO) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

GitHubDTO (com.nixmash.blog.jpa.dto.GitHubDTO)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 IOException (java.io.IOException)2 RestClientException (org.springframework.web.client.RestClientException)2 RestTemplate (org.springframework.web.client.RestTemplate)2 Test (org.junit.Test)1