public List<JsonObject> nextPage() throws IOException, DeserializationException { if (RELATIVE_LINK_NOT_FOUND.equals(nextPageUrl)) { throw new IllegalStateException("GitHub API no more issues to fetch"); } URL url = new URL(nextPageUrl); LOG.info("GitHub API querying page {}", queryParamValue(url, "page")); LOG.lifecycle("GET " + nextPageUrl); URLConnection urlConnection = url.openConnection(); LOG.info("Established connection to GitHub API"); String resetInLocalTime = resetLimitInLocalTimeOrEmpty(urlConnection); LOG.info("GitHub API rate info => Remaining : {}, Limit : {}, Reset at: {}", urlConnection.getHeaderField("X-RateLimit-Remaining"), urlConnection.getHeaderField("X-RateLimit-Limit"), resetInLocalTime); nextPageUrl = extractRelativeLink(urlConnection.getHeaderField("Link"), "next"); return parseJsonFrom(urlConnection); }
private static JsonObject extractResponse(Response response) throws StashClientException { PeekableInputStream bodyStream = new PeekableInputStream(response.getResponseBodyAsStream()); try { if (!bodyStream.peek().isPresent()) { return null; } String contentType = response.getHeader("Content-Type"); if (!JSON.match(contentType.trim())) { throw new StashClientException("Received response with type " + contentType + " instead of JSON"); } Reader body = new InputStreamReader(bodyStream); Object obj = Jsoner.deserialize(body); return (JsonObject)obj; } catch (DeserializationException | ClassCastException | IOException e) { throw new StashClientException("Could not parse JSON response: " + e, e); } }
public Collection<ReleaseNotesData> deserialize(String jsonData) { try { final JsonArray jsonArray = (JsonArray) Jsoner.deserialize(jsonData); return deserialize(jsonArray); } catch (DeserializationException e) { throw new RuntimeException("Can't deserialize JSON: " + jsonData, e); } }
public GitCommit deserialize(String jsonData) { try { final JsonObject jsonObject = (JsonObject) Jsoner.deserialize(jsonData); return deserialize(jsonObject); } catch (DeserializationException e) { throw new RuntimeException("Can't deserialize JSON: " + jsonData, e); } }
public DefaultContributionSet deserialize(String jsonData) { try { final JsonObject jsonObject = (JsonObject) Jsoner.deserialize(jsonData); return deserialize(jsonObject); } catch (DeserializationException e) { throw new RuntimeException("Can't deserialize JSON: " + jsonData, e); } }
public DefaultImprovement deserialize(String jsonData) { try { final JsonObject jsonObject = (JsonObject) Jsoner.deserialize(jsonData); return deserialize(jsonObject); } catch (DeserializationException e) { throw new RuntimeException("Can't deserialize JSON: " + jsonData, e); } }
private Set<ProjectContributor> extractContributors(List<JsonObject> page, final String readOnlyAuthToken) throws IOException, DeserializationException { //Since returned contributor does not have 'name' element, we need to fetch the user data to get his name //TODO (maybe) add static caching of this. Names don't change that often, let's just cache this forever in build cache. GitHubObjectFetcher objectFetcher = new GitHubObjectFetcher(readOnlyAuthToken); Function<JsonObject, ProjectContributor> projectContributorFetcherFunction = new ProjectContributorFetcherFunction(objectFetcher); return new ConcurrentDispatcher().dispatch(projectContributorFetcherFunction, page); }
public JsonObject getPage(String pageUrl) throws IOException, DeserializationException { URL url = new URL(String.format("%s%s%s", pageUrl, "?access_token=", authToken)); LOG.info("GitHub API querying page {}", url); LOG.lifecycle("GET {}", url); URLConnection urlConnection = url.openConnection(); String resetInLocalTime = resetLimitInLocalTimeOrEmpty(urlConnection); LOG.info("GitHub API rate info => Remaining : {}, Limit : {}, Reset at: {}", urlConnection.getHeaderField("X-RateLimit-Remaining"), urlConnection.getHeaderField("X-RateLimit-Limit"), resetInLocalTime); return parseJsonFrom(urlConnection); }
private JsonObject parseJsonFrom(URLConnection urlConnection) throws IOException, DeserializationException { InputStream response = urlConnection.getInputStream(); String content = IOUtil.readFully(response); LOG.info("GitHub API responded successfully."); return (JsonObject) Jsoner.deserialize(content); }
private List<JsonObject> parseJsonFrom(URLConnection urlConnection) throws IOException, DeserializationException { InputStream response = urlConnection.getInputStream(); LOG.info("Reading remote stream from GitHub API"); String content = IOUtil.readFully(response); LOG.info("GitHub API responded successfully."); @SuppressWarnings("unchecked") List<JsonObject> issues = (List<JsonObject>) Jsoner.deserialize(content); LOG.info("GitHub API returned {} Json objects.", issues.size()); return issues; }
private JsonObject readJsonResource(String name) throws DeserializationException, IOException { return (JsonObject) Jsoner.deserialize(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(name))); }
@TaskAction public void findOpenPullRequest() throws IOException, DeserializationException { pullRequest = new FindOpenPullRequest().findOpenPullRequest(this); }
public List<JsonObject> nextPage() throws IOException, DeserializationException { lastFetchedPage = fetcher.nextPage(); return lastFetchedPage; }
List<JsonObject> nextPage() throws IOException, DeserializationException { lastFetchedPage = fetcher.nextPage(); return lastFetchedPage; }
List<JsonObject> nextPage() throws IOException, DeserializationException { return fetcher.nextPage(); }