3030package com .jcabi .github ;
3131
3232import java .io .IOException ;
33+ import java .time .ZonedDateTime ;
3334import java .util .Arrays ;
3435import java .util .Map ;
3536import java .util .stream .Collectors ;
@@ -162,6 +163,14 @@ private enum KEY {
162163 this .key = json ;
163164 }
164165
166+ /**
167+ * Getter for the key.
168+ * @return The key of the JSON object returned by the GitHub API.
169+ */
170+ public String getKey () {
171+ return this .key ;
172+ }
173+
165174 /**
166175 * Extracts the JSON object returned by the GitHub to a map entry.
167176 * @param object The JSON object returned by the GitHub API.
@@ -188,5 +197,114 @@ Object value(final JsonObject object) {
188197 return result ;
189198 }
190199 }
200+
201+ /**
202+ * Smart RepositoryStatistics.
203+ *
204+ * @version $Id $
205+ * @author Volodya Lombrozo ([email protected] ) 206+ * @since 1.8.0
207+ */
208+ public static class Smart {
209+
210+ /**
211+ * Repository statistics.
212+ */
213+ private final RepositoryStatistics stats ;
214+
215+ /**
216+ * Public ctor.
217+ * @param repo
218+ */
219+ public Smart (final Repo repo ) {
220+ this (new RepositoryStatistics (repo ));
221+ }
222+
223+ /**
224+ * Public ctor.
225+ * @param statistics
226+ */
227+ public Smart (final RepositoryStatistics statistics ) {
228+ this .stats = statistics ;
229+ }
230+
231+ /**
232+ * Number of forks of this repository.
233+ * @return Number of forks
234+ * @throws IOException If there is any I/O problem
235+ */
236+ public int forks () throws IOException {
237+ return this .integer (KEY .FORKS_COUNT );
238+ }
239+
240+ /**
241+ * Number of users who have starred this repository.
242+ * @return Number of stargazers
243+ * @throws IOException If there is any I/O problem
244+ */
245+ public int stargazers () throws IOException {
246+ return this .integer (KEY .STARGAZERS_COUNT );
247+ }
248+
249+ /**
250+ * Number of users watching the repository.
251+ * @return Number of watchers
252+ * @throws IOException If there is any I/O problem
253+ */
254+ public int watchers () throws IOException {
255+ return this .integer (KEY .WATCHERS_COUNT );
256+ }
257+
258+ /**
259+ * The size of the repository.
260+ * @return Size of the repository
261+ * @throws IOException If there is any I/O problem
262+ */
263+ public int size () throws IOException {
264+ return this .integer (KEY .SIZE );
265+ }
266+
267+ /**
268+ * The number of open issues in this repository.
269+ * @return Number of open issues
270+ * @throws IOException If there is any I/O problem
271+ */
272+ public int openIssues () throws IOException {
273+ return this .integer (KEY .OPEN_ISSUES_COUNT );
274+ }
275+
276+ /**
277+ * The time the repository was created.
278+ * @return Time the repository was created
279+ * @throws IOException If there is any I/O problem
280+ */
281+ public ZonedDateTime created () throws IOException {
282+ return this .datetime (KEY .CREATED_AT );
283+ }
284+
285+ /**
286+ * Parses integer from JSON.
287+ * @param key Json key.
288+ * @return Integer value.
289+ * @throws IOException If there is any I/O problem
290+ */
291+ private int integer (final KEY key ) throws IOException {
292+ return Integer .parseInt (
293+ String .valueOf (this .stats .toMap ().get (key .getKey ()))
294+ );
295+ }
296+
297+ /**
298+ * Parses datetime from JSON.
299+ * @param key Json key.
300+ * @return Datetime value.
301+ * @throws IOException If there is any I/O problem
302+ */
303+ private ZonedDateTime datetime (final KEY key ) throws IOException {
304+ return ZonedDateTime .parse (
305+ String .valueOf (this .stats .toMap ().get (key .getKey ()))
306+ );
307+ }
308+ }
191309}
192310
0 commit comments