Coverage Report - com.jcabi.github.User
 
Classes in this File Line Coverage Branch Coverage Complexity
User
N/A
N/A
1.17
User$Smart
54%
30/55
0%
0/18
1.17
User$Smart$AjcClosure1
0%
0/1
N/A
1.17
User$Smart$AjcClosure11
0%
0/1
N/A
1.17
User$Smart$AjcClosure13
0%
0/1
N/A
1.17
User$Smart$AjcClosure15
0%
0/1
N/A
1.17
User$Smart$AjcClosure17
0%
0/1
N/A
1.17
User$Smart$AjcClosure19
100%
1/1
N/A
1.17
User$Smart$AjcClosure21
0%
0/1
N/A
1.17
User$Smart$AjcClosure23
0%
0/1
N/A
1.17
User$Smart$AjcClosure25
0%
0/1
N/A
1.17
User$Smart$AjcClosure27
0%
0/1
N/A
1.17
User$Smart$AjcClosure29
0%
0/1
N/A
1.17
User$Smart$AjcClosure3
0%
0/1
N/A
1.17
User$Smart$AjcClosure31
100%
1/1
N/A
1.17
User$Smart$AjcClosure33
0%
0/1
N/A
1.17
User$Smart$AjcClosure35
100%
1/1
N/A
1.17
User$Smart$AjcClosure37
100%
1/1
N/A
1.17
User$Smart$AjcClosure39
100%
1/1
N/A
1.17
User$Smart$AjcClosure41
100%
1/1
N/A
1.17
User$Smart$AjcClosure43
100%
1/1
N/A
1.17
User$Smart$AjcClosure45
100%
1/1
N/A
1.17
User$Smart$AjcClosure47
100%
1/1
N/A
1.17
User$Smart$AjcClosure49
100%
1/1
N/A
1.17
User$Smart$AjcClosure5
0%
0/1
N/A
1.17
User$Smart$AjcClosure51
100%
1/1
N/A
1.17
User$Smart$AjcClosure53
100%
1/1
N/A
1.17
User$Smart$AjcClosure55
100%
1/1
N/A
1.17
User$Smart$AjcClosure57
100%
1/1
N/A
1.17
User$Smart$AjcClosure59
100%
1/1
N/A
1.17
User$Smart$AjcClosure61
100%
1/1
N/A
1.17
User$Smart$AjcClosure63
100%
1/1
N/A
1.17
User$Smart$AjcClosure65
100%
1/1
N/A
1.17
User$Smart$AjcClosure67
100%
1/1
N/A
1.17
User$Smart$AjcClosure69
100%
1/1
N/A
1.17
User$Smart$AjcClosure7
0%
0/1
N/A
1.17
User$Smart$AjcClosure71
100%
1/1
N/A
1.17
User$Smart$AjcClosure73
100%
1/1
N/A
1.17
User$Smart$AjcClosure75
100%
1/1
N/A
1.17
User$Smart$AjcClosure77
100%
1/1
N/A
1.17
User$Smart$AjcClosure9
100%
1/1
N/A
1.17
 
 1  2
 /**
 2  
  * Copyright (c) 2013-2015, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import java.io.IOException;
 35  
 import java.net.URL;
 36  
 import java.text.ParseException;
 37  
 import java.util.Date;
 38  
 import java.util.List;
 39  
 import javax.json.JsonObject;
 40  
 import javax.validation.constraints.NotNull;
 41  
 import lombok.EqualsAndHashCode;
 42  
 import lombok.ToString;
 43  
 
 44  
 /**
 45  
  * Github user.
 46  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 47  
  * @version $Id$
 48  
  * @checkstyle MultipleStringLiterals (500 lines)
 49  
  * @see <a href="http://developer.github.com/v3/users/">User API</a>
 50  
  * @since 0.1
 51  
  */
 52  
 @Immutable
 53  
 @SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessivePublicCount",
 54  
     "PMD.GodClass" })
 55  
 public interface User extends JsonReadable, JsonPatchable {
 56  
 
 57  
     /**
 58  
      * Github we're in.
 59  
      * @return Github
 60  
      * @since 0.4
 61  
      */
 62  
     @NotNull(message = "Github is never NULL")
 63  
     Github github();
 64  
 
 65  
     /**
 66  
      * Get his login.
 67  
      * @return Login name
 68  
      * @throws IOException If it fails
 69  
      */
 70  
     @NotNull(message = "login is never NULL")
 71  
     String login() throws IOException;
 72  
 
 73  
     /**
 74  
      * Get his organizations.
 75  
      * @return Organizations organizations
 76  
      */
 77  
     @NotNull(message = "organizations is never NULL")
 78  
     Organizations organizations();
 79  
 
 80  
     /**
 81  
      * Get his keys.
 82  
      * @return PublicKeys keys
 83  
      */
 84  
     @NotNull(message = "keys is never NULL")
 85  
     PublicKeys keys();
 86  
 
 87  
     /**
 88  
      * Get user's emails.
 89  
      * @return User's emails
 90  
      * @since 0.8
 91  
      */
 92  
     @NotNull(message = "user emails is never NULL")
 93  
     UserEmails emails();
 94  
 
 95  
     /**
 96  
      * Returns all notifications of a user.
 97  
      * Wraps the call "List your notifications". See "List your notifications"
 98  
      * at https://developer.github.com/v3/activity/notifications/
 99  
      * @see <a href="https://developer.github.com/v3/activity/notifications/#list-your-notifications">List your notifications</a>
 100  
      * @return Returns all notifications for this user.
 101  
      * @throws IOException Thrown, if an error during sending request and/or
 102  
      *  receiving response occurs.
 103  
      */
 104  
     List<Notification> notifications() throws IOException;
 105  
 
 106  
     /**
 107  
      * Marks notifications as read.
 108  
      * @param lastread Describes the last point that notifications were
 109  
      *  checked.
 110  
      * @see <a href="https://developer.github.com/v3/activity/notifications/#mark-as-read">Mark as read</a>
 111  
      */
 112  
     void markAsRead(final Date lastread);
 113  
 
 114  
     /**
 115  
      * Smart user with extra features.
 116  
      * @see <a href="http://developer.github.com/v3/users/#get-a-single-user">Get a Single User</a>
 117  
      */
 118  
     @Immutable
 119  0
     @ToString
 120  
     @Loggable(Loggable.DEBUG)
 121  0
     @EqualsAndHashCode(of = { "user", "jsn" })
 122  
     final class Smart implements User {
 123  
         /**
 124  
          * Encapsulated user.
 125  
          */
 126  
         private final transient User user;
 127  
         /**
 128  
          * SmartJson object for convenient JSON parsing.
 129  
          */
 130  
         private final transient SmartJson jsn;
 131  
 
 132  
         /**
 133  
          * Public ctor.
 134  
          * @param usr User
 135  
          */
 136  
         public Smart(
 137  
             @NotNull(message = "user can't be NULL") final User usr
 138  29
         ) {
 139  29
             this.user = usr;
 140  29
             this.jsn = new SmartJson(usr);
 141  29
         }
 142  
 
 143  
         /**
 144  
          * Get his ID.
 145  
          * @return Unique user ID
 146  
          * @throws IOException If it fails
 147  
          * @checkstyle MethodName (3 lines)
 148  
          */
 149  
         @SuppressWarnings("PMD.ShortMethodName")
 150  
         public int id() throws IOException {
 151  0
             return this.user.json().getJsonNumber("id").intValue();
 152  
         }
 153  
 
 154  
         /**
 155  
          * Get his avatar URL.
 156  
          * @return URL of the avatar
 157  
          * @throws IOException If it fails
 158  
          */
 159  
         @NotNull(message = "URL is never NULL")
 160  
         public URL avatarUrl() throws IOException {
 161  0
             return new URL(this.jsn.text("avatar_url"));
 162  
         }
 163  
 
 164  
         /**
 165  
          * Get his URL.
 166  
          * @return URL of the user
 167  
          * @throws IOException If it fails
 168  
          */
 169  
         @NotNull(message = "URL is never NULL")
 170  
         public URL url() throws IOException {
 171  0
             return new URL(this.jsn.text("url"));
 172  
         }
 173  
 
 174  
         /**
 175  
          * Get his name.
 176  
          * @return User name
 177  
          * @throws IOException If it fails
 178  
          */
 179  
         @NotNull(message = "Name is never NULL")
 180  
         public String name() throws IOException {
 181  0
             final JsonObject json = this.json();
 182  0
             if (!json.containsKey("name")) {
 183  0
                 throw new IllegalStateException(
 184  
                     String.format(
 185  
                         // @checkstyle LineLength (1 line)
 186  
                         "User %s doesn't have a name specified in his/her Github account; use #hasName() first.",
 187  
                         this.login()
 188  
                     )
 189  
                 );
 190  
             }
 191  0
             return json.getString("name");
 192  
         }
 193  
 
 194  
         /**
 195  
          * Check if user has name.
 196  
          * @return True if user has name
 197  
          * @throws IOException If it fails
 198  
          */
 199  
         public boolean hasName() throws IOException {
 200  4
             return this.json().containsKey("name");
 201  
         }
 202  
 
 203  
         /**
 204  
          * Get his company.
 205  
          * @return Company name
 206  
          * @throws IOException If it fails
 207  
          */
 208  
         @NotNull(message = "Company is never NULL")
 209  
         public String company() throws IOException {
 210  0
             return this.jsn.text("company");
 211  
         }
 212  
 
 213  
         /**
 214  
          * Get his location.
 215  
          * @return Location name
 216  
          * @throws IOException If it fails
 217  
          */
 218  
         @NotNull(message = "Location is never NULL")
 219  
         public String location() throws IOException {
 220  0
             return this.jsn.text("location");
 221  
         }
 222  
 
 223  
         /**
 224  
          * Get his email.
 225  
          * @return Email
 226  
          * @throws IOException If it fails
 227  
          */
 228  
         @NotNull(message = "Email is never NULL")
 229  
         public String email() throws IOException {
 230  0
             return this.jsn.text("email");
 231  
         }
 232  
 
 233  
         @Override
 234  
         @NotNull(message = "Github is never NULL")
 235  
         public Github github() {
 236  0
             return this.user.github();
 237  
         }
 238  
 
 239  
         @Override
 240  
         @NotNull(message = "Login is never NULL")
 241  
         public String login() throws IOException {
 242  10
             return this.user.login();
 243  
         }
 244  
 
 245  
         @Override
 246  
         @NotNull(message = "Organizations is never NULL")
 247  
         public Organizations organizations() {
 248  0
             return this.user.organizations();
 249  
         }
 250  
 
 251  
         @Override
 252  
         @NotNull(message = "Keys is never NULL")
 253  
         public PublicKeys keys() {
 254  0
             return this.user.keys();
 255  
         }
 256  
 
 257  
         @Override
 258  
         @NotNull(message = "Emails is never NULL")
 259  
         public UserEmails emails() {
 260  0
             return this.user.emails();
 261  
         }
 262  
 
 263  
         @Override
 264  
         public List<Notification> notifications() throws IOException {
 265  0
             return this.user.notifications();
 266  
         }
 267  
 
 268  
         @Override
 269  
         public void markAsRead(final Date lastread) {
 270  0
             this.user.markAsRead(lastread);
 271  0
         }
 272  
 
 273  
         @Override
 274  
         @NotNull(message = "Json is never NULL")
 275  
         public JsonObject json() throws IOException {
 276  4
             return this.user.json();
 277  
         }
 278  
 
 279  
         @Override
 280  
         public void patch(
 281  
             @NotNull(message = "Json can't be NULL") final JsonObject json
 282  
         ) throws IOException {
 283  0
             this.user.patch(json);
 284  0
         }
 285  
 
 286  
         /**
 287  
          * Returns the value of gravatar_id property of User's JSON.
 288  
          * @return The 'gravatar_id' property value.
 289  
          * @throws IOException If any I/O error occurs.
 290  
          */
 291  
         @NotNull(message = "Gravatar is never NULL")
 292  
         public String gravatar() throws IOException {
 293  2
             return this.jsn.text("gravatar_id");
 294  
         }
 295  
 
 296  
         /**
 297  
          * Returns the value of html_url property of User's JSON.
 298  
          * @return The 'html_url' property value.
 299  
          * @throws IOException If any I/O error occurs.
 300  
          */
 301  
         @NotNull(message = "Html URL is never NULL")
 302  
         public String htmlUrl() throws IOException {
 303  2
             return this.jsn.text("html_url");
 304  
         }
 305  
 
 306  
         /**
 307  
          * Returns the value of followers_url property of User's JSON.
 308  
          * @return The 'followers_url' property value.
 309  
          * @throws IOException If any I/O error occurs.
 310  
          */
 311  
         @NotNull(message = "Followers URL is never NULL")
 312  
         public String follwersUrl() throws IOException {
 313  2
             return this.jsn.text("followers_url");
 314  
         }
 315  
 
 316  
         /**
 317  
          * Returns the value of following_url property of User's JSON.
 318  
          * @return The 'following_url' property value.
 319  
          * @throws IOException If any I/O error occurs.
 320  
          */
 321  
         @NotNull(message = "Following URL is never NULL")
 322  
         public String followingUrl() throws IOException {
 323  2
             return this.jsn.text("following_url");
 324  
         }
 325  
 
 326  
         /**
 327  
          * Returns the value of gists_url property of User's JSON.
 328  
          * @return The 'gists_url' property value.
 329  
          * @throws IOException If any I/O error occurs.
 330  
          */
 331  
         @NotNull(message = "Gists URL is never NULL")
 332  
         public String gistsUrl() throws IOException {
 333  2
             return this.jsn.text("gists_url");
 334  
         }
 335  
 
 336  
         /**
 337  
          * Returns the value of starred_url property of User's JSON.
 338  
          * @return The 'starred_url' property value.
 339  
          * @throws IOException If any I/O error occurs.
 340  
          */
 341  
         @NotNull(message = "Starred URL is never NULL")
 342  
         public String starredUrl() throws IOException {
 343  2
             return this.jsn.text("starred_url");
 344  
         }
 345  
 
 346  
         /**
 347  
          * Returns the value of subscriptions_url property of User's JSON.
 348  
          * @return The 'subscriptions_url' property value.
 349  
          * @throws IOException If any I/O error occurs.
 350  
          */
 351  
         @NotNull(message = "Subscriptions URL is never NULL")
 352  
         public String subscriptionsUrl() throws IOException {
 353  2
             return this.jsn.text("subscriptions_url");
 354  
         }
 355  
 
 356  
         /**
 357  
          * Returns the value of organizations_url property of User's JSON.
 358  
          * @return The 'organizations_url' property value.
 359  
          * @throws IOException If any I/O error occurs.
 360  
          */
 361  
         @NotNull(message = "Organizations URL is never NULL")
 362  
         public String organizationsUrl() throws IOException {
 363  2
             return this.jsn.text("organizations_url");
 364  
         }
 365  
 
 366  
         /**
 367  
          * Returns the value of repos_url property of User's JSON.
 368  
          * @return The 'repos_url' property value.
 369  
          * @throws IOException If any I/O error occurs.
 370  
          */
 371  
         @NotNull(message = "Repos URL is never NULL")
 372  
         public String reposUrl() throws IOException {
 373  2
             return this.jsn.text("repos_url");
 374  
         }
 375  
 
 376  
         /**
 377  
          * Returns the value of events_url property of User's JSON.
 378  
          * @return The 'events_url' property value.
 379  
          * @throws IOException If any I/O error occurs.
 380  
          */
 381  
         @NotNull(message = "Events URL is never NULL")
 382  
         public String eventsUrl() throws IOException {
 383  2
             return this.jsn.text("events_url");
 384  
         }
 385  
 
 386  
         /**
 387  
          * Returns the value of received_events_url property of User's JSON.
 388  
          * @return The 'received_events_url' property value.
 389  
          * @throws IOException If any I/O error occurs.
 390  
          */
 391  
         @NotNull(message = "Received enets URL is never NULL")
 392  
         public String receivedEventsUrl() throws IOException {
 393  2
             return this.jsn.text("received_events_url");
 394  
         }
 395  
 
 396  
         /**
 397  
          * Returns the value of type property of User's JSON.
 398  
          * @return The 'type' property value.
 399  
          * @throws IOException If any I/O error occurs.
 400  
          */
 401  
         @NotNull(message = "Type is never NULL")
 402  
         public String type() throws IOException {
 403  2
             return this.jsn.text("type");
 404  
         }
 405  
 
 406  
         /**
 407  
          * Returns the value of site_admin property of User's JSON.
 408  
          * @return The 'site_admin' property value.
 409  
          * @throws IOException If any I/O error occurs.
 410  
          */
 411  
         public boolean siteAdmin() throws IOException {
 412  2
             return "true".equals(this.jsn.text("site_admin"));
 413  
         }
 414  
 
 415  
         /**
 416  
          * Returns the value of blog property of User's JSON.
 417  
          * @return The 'blog' property value.
 418  
          * @throws IOException If any I/O error occurs.
 419  
          */
 420  
         @NotNull(message = "Blog is never NULL")
 421  
         public String blog() throws IOException {
 422  2
             return this.jsn.text("blog");
 423  
         }
 424  
 
 425  
         /**
 426  
          * Returns the value of hireable property of User's JSON.
 427  
          * @return The 'hireable' property value.
 428  
          * @throws IOException If any I/O error occurs.
 429  
          */
 430  
         @NotNull(message = "Hireable is never NULL")
 431  
         public boolean hireable() throws IOException {
 432  2
             return "true".equals(this.jsn.text("hireable"));
 433  
         }
 434  
 
 435  
         /**
 436  
          * Returns the value of bio property of User's JSON.
 437  
          * @return The 'bio' property value.
 438  
          * @throws IOException If any I/O error occurs.
 439  
          */
 440  
         @NotNull(message = "Bio is never NULL")
 441  
         public String bio() throws IOException {
 442  2
             return this.jsn.text("bio");
 443  
         }
 444  
 
 445  
         /**
 446  
          * Returns the value of public_repos property of User's JSON.
 447  
          * @return The 'public_repos' property value.
 448  
          * @throws IOException If any I/O error occurs.
 449  
          */
 450  
         public int publicRepos() throws IOException {
 451  2
             return Integer.parseInt(this.jsn.text("public_repos"));
 452  
         }
 453  
 
 454  
         /**
 455  
          * Returns the value of public_gists property of User's JSON.
 456  
          * @return The 'public_gists' property value.
 457  
          * @throws IOException If any I/O error occurs.
 458  
          */
 459  
         public int publicGists() throws IOException {
 460  2
             return Integer.parseInt(this.jsn.text("public_gists"));
 461  
         }
 462  
 
 463  
         /**
 464  
          * Returns the value of followers property of User's JSON.
 465  
          * @return The 'followers' property value.
 466  
          * @throws IOException If any I/O error occurs.
 467  
          */
 468  
         public int followersCount() throws IOException {
 469  2
             return Integer.parseInt(this.jsn.text("followers"));
 470  
         }
 471  
 
 472  
         /**
 473  
          * Returns the value of following property of User's JSON.
 474  
          * @return The 'following' property value.
 475  
          * @throws IOException If any I/O error occurs.
 476  
          */
 477  
         public int followingCount() throws IOException {
 478  2
             return Integer.parseInt(this.jsn.text("following"));
 479  
         }
 480  
 
 481  
         /**
 482  
          * Returns the value of created_at property of User's JSON.
 483  
          * @return The 'created_at' property value.
 484  
          * @throws IOException If any I/O error occurs.
 485  
          */
 486  
         @NotNull(message = "Created time is never NULL")
 487  
         public Github.Time created() throws IOException {
 488  
             try {
 489  2
                 return new Github.Time(this.jsn.text("created_at"));
 490  0
             } catch (final ParseException ex) {
 491  0
                 throw new IllegalArgumentException(
 492  
                     "Cannot parse value of 'created_at' property",
 493  
                     ex
 494  
                 );
 495  
             }
 496  
         }
 497  
 
 498  
         /**
 499  
          * Returns the value of updated_at property of User's JSON.
 500  
          * @return The 'updated_at' property value.
 501  
          * @throws IOException If any I/O error occurs.
 502  
          */
 503  
         @NotNull(message = "Updated time is never NULL")
 504  
         public Github.Time updated() throws IOException {
 505  
             try {
 506  2
                 return new Github.Time(this.jsn.text("updated_at"));
 507  0
             } catch (final ParseException ex) {
 508  0
                 throw new IllegalArgumentException(
 509  
                     "Cannot parse value of 'updated_at' property",
 510  
                     ex
 511  
                 );
 512  
             }
 513  
         }
 514  
     }
 515  
 }