Coverage Report - com.jcabi.github.User
 
Classes in this File Line Coverage Branch Coverage Complexity
User
N/A
N/A
1.188
User$Smart
47%
30/63
0%
0/22
1.188
User$Smart$AjcClosure1
0%
0/1
N/A
1.188
User$Smart$AjcClosure11
100%
1/1
N/A
1.188
User$Smart$AjcClosure13
0%
0/1
N/A
1.188
User$Smart$AjcClosure15
0%
0/1
N/A
1.188
User$Smart$AjcClosure17
0%
0/1
N/A
1.188
User$Smart$AjcClosure19
0%
0/1
N/A
1.188
User$Smart$AjcClosure21
100%
1/1
N/A
1.188
User$Smart$AjcClosure23
0%
0/1
N/A
1.188
User$Smart$AjcClosure25
0%
0/1
N/A
1.188
User$Smart$AjcClosure27
0%
0/1
N/A
1.188
User$Smart$AjcClosure29
0%
0/1
N/A
1.188
User$Smart$AjcClosure3
0%
0/1
N/A
1.188
User$Smart$AjcClosure31
0%
0/1
N/A
1.188
User$Smart$AjcClosure33
100%
1/1
N/A
1.188
User$Smart$AjcClosure35
0%
0/1
N/A
1.188
User$Smart$AjcClosure37
100%
1/1
N/A
1.188
User$Smart$AjcClosure39
100%
1/1
N/A
1.188
User$Smart$AjcClosure41
100%
1/1
N/A
1.188
User$Smart$AjcClosure43
100%
1/1
N/A
1.188
User$Smart$AjcClosure45
100%
1/1
N/A
1.188
User$Smart$AjcClosure47
100%
1/1
N/A
1.188
User$Smart$AjcClosure49
100%
1/1
N/A
1.188
User$Smart$AjcClosure5
0%
0/1
N/A
1.188
User$Smart$AjcClosure51
100%
1/1
N/A
1.188
User$Smart$AjcClosure53
100%
1/1
N/A
1.188
User$Smart$AjcClosure55
100%
1/1
N/A
1.188
User$Smart$AjcClosure57
100%
1/1
N/A
1.188
User$Smart$AjcClosure59
100%
1/1
N/A
1.188
User$Smart$AjcClosure61
100%
1/1
N/A
1.188
User$Smart$AjcClosure63
100%
1/1
N/A
1.188
User$Smart$AjcClosure65
100%
1/1
N/A
1.188
User$Smart$AjcClosure67
100%
1/1
N/A
1.188
User$Smart$AjcClosure69
100%
1/1
N/A
1.188
User$Smart$AjcClosure7
0%
0/1
N/A
1.188
User$Smart$AjcClosure71
100%
1/1
N/A
1.188
User$Smart$AjcClosure73
100%
1/1
N/A
1.188
User$Smart$AjcClosure75
100%
1/1
N/A
1.188
User$Smart$AjcClosure77
100%
1/1
N/A
1.188
User$Smart$AjcClosure79
100%
1/1
N/A
1.188
User$Smart$AjcClosure9
0%
0/1
N/A
1.188
 
 1  0
 /**
 2  
  * Copyright (c) 2013-2017, 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 lombok.EqualsAndHashCode;
 41  
 import lombok.ToString;
 42  
 
 43  
 /**
 44  
  * Github user.
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id: 0ac552da601c94c011b549da288ca9dd36298aec $
 47  
  * @checkstyle MultipleStringLiterals (500 lines)
 48  
  * @see <a href="http://developer.github.com/v3/users/">User API</a>
 49  
  * @since 0.1
 50  
  */
 51  
 @Immutable
 52  
 @SuppressWarnings({"PMD.TooManyMethods", "PMD.ExcessivePublicCount",
 53  
     "PMD.GodClass" })
 54  
 public interface User extends JsonReadable, JsonPatchable {
 55  
 
 56  
     /**
 57  
      * Github we're in.
 58  
      * @return Github
 59  
      * @since 0.4
 60  
      */
 61  
     Github github();
 62  
 
 63  
     /**
 64  
      * Get his login.
 65  
      * @return Login name
 66  
      * @throws IOException If it fails
 67  
      */
 68  
     String login() throws IOException;
 69  
 
 70  
     /**
 71  
      * Get his organizations.
 72  
      * @return UserOrganizations organizations
 73  
      */
 74  
     UserOrganizations organizations();
 75  
 
 76  
     /**
 77  
      * Get his keys.
 78  
      * @return PublicKeys keys
 79  
      */
 80  
     PublicKeys keys();
 81  
 
 82  
     /**
 83  
      * Get user's emails.
 84  
      * @return User's emails
 85  
      * @since 0.8
 86  
      */
 87  
     UserEmails emails();
 88  
 
 89  
     /**
 90  
      * Returns all notifications of a user.
 91  
      * Wraps the call "List your notifications". See "List your notifications"
 92  
      * at https://developer.github.com/v3/activity/notifications/
 93  
      * @see <a href="https://developer.github.com/v3/activity/notifications/#list-your-notifications">List your notifications</a>
 94  
      * @return Returns all notifications for this user.
 95  
      * @throws IOException Thrown, if an error during sending request and/or
 96  
      *  receiving response occurs.
 97  
      */
 98  
     List<Notification> notifications() throws IOException;
 99  
 
 100  
     /**
 101  
      * Marks notifications as read.
 102  
      * @param lastread Describes the last point that notifications were
 103  
      *  checked.
 104  
      * @see <a href="https://developer.github.com/v3/activity/notifications/#mark-as-read">Mark as read</a>
 105  
      */
 106  
     void markAsRead(final Date lastread);
 107  
 
 108  
     /**
 109  
      * Smart user with extra features.
 110  
      * @see <a href="http://developer.github.com/v3/users/#get-a-single-user">Get a Single User</a>
 111  
      */
 112  
     @Immutable
 113  0
     @ToString
 114  
     @Loggable(Loggable.DEBUG)
 115  0
     @EqualsAndHashCode(of = { "user", "jsn" })
 116  
     final class Smart implements User {
 117  
         /**
 118  
          * Encapsulated user.
 119  
          */
 120  
         private final transient User user;
 121  
         /**
 122  
          * SmartJson object for convenient JSON parsing.
 123  
          */
 124  
         private final transient SmartJson jsn;
 125  
 
 126  
         /**
 127  
          * Public ctor.
 128  
          * @param usr User
 129  
          */
 130  29
         public Smart(final User usr) {
 131  29
             this.user = usr;
 132  29
             this.jsn = new SmartJson(usr);
 133  29
         }
 134  
 
 135  
         /**
 136  
          * Does it exist in GitHub?
 137  
          * @return TRUE if this user truly exists
 138  
          * @throws IOException If it fails
 139  
          * @since 0.34
 140  
          */
 141  
         public boolean exists() throws IOException {
 142  0
             boolean exists = true;
 143  
             try {
 144  0
                 this.id();
 145  0
             } catch (final AssertionError ex) {
 146  0
                 exists = false;
 147  0
             }
 148  0
             return exists;
 149  
         }
 150  
 
 151  
         /**
 152  
          * Get his ID.
 153  
          * @return Unique user ID
 154  
          * @throws IOException If it fails
 155  
          * @checkstyle MethodName (3 lines)
 156  
          */
 157  
         @SuppressWarnings("PMD.ShortMethodName")
 158  
         public int id() throws IOException {
 159  0
             return this.user.json().getJsonNumber("id").intValue();
 160  
         }
 161  
 
 162  
         /**
 163  
          * Get his avatar URL.
 164  
          * @return URL of the avatar
 165  
          * @throws IOException If it fails
 166  
          */
 167  
         public URL avatarUrl() throws IOException {
 168  0
             return new URL(this.jsn.text("avatar_url"));
 169  
         }
 170  
 
 171  
         /**
 172  
          * Get his URL.
 173  
          * @return URL of the user
 174  
          * @throws IOException If it fails
 175  
          */
 176  
         public URL url() throws IOException {
 177  0
             return new URL(this.jsn.text("url"));
 178  
         }
 179  
 
 180  
         /**
 181  
          * Get his name.
 182  
          * @return User name
 183  
          * @throws IOException If it fails
 184  
          */
 185  
         public String name() throws IOException {
 186  0
             final JsonObject json = this.json();
 187  0
             if (!json.containsKey("name")) {
 188  0
                 throw new IllegalStateException(
 189  0
                     String.format(
 190  
                         // @checkstyle LineLength (1 line)
 191  
                         "User %s doesn't have a name specified in his/her Github account; use #hasName() first.",
 192  0
                         this.login()
 193  
                     )
 194  
                 );
 195  
             }
 196  0
             return json.getString("name");
 197  
         }
 198  
 
 199  
         /**
 200  
          * Check if user has name.
 201  
          * @return True if user has name
 202  
          * @throws IOException If it fails
 203  
          */
 204  
         public boolean hasName() throws IOException {
 205  4
             return this.json().containsKey("name");
 206  
         }
 207  
 
 208  
         /**
 209  
          * Get his company.
 210  
          * @return Company name
 211  
          * @throws IOException If it fails
 212  
          */
 213  
         public String company() throws IOException {
 214  0
             return this.jsn.text("company");
 215  
         }
 216  
 
 217  
         /**
 218  
          * Get his location.
 219  
          * @return Location name
 220  
          * @throws IOException If it fails
 221  
          */
 222  
         public String location() throws IOException {
 223  0
             return this.jsn.text("location");
 224  
         }
 225  
 
 226  
         /**
 227  
          * Get his email.
 228  
          * @return Email
 229  
          * @throws IOException If it fails
 230  
          */
 231  
         public String email() throws IOException {
 232  0
             return this.jsn.text("email");
 233  
         }
 234  
 
 235  
         @Override
 236  
         public Github github() {
 237  0
             return this.user.github();
 238  
         }
 239  
 
 240  
         @Override
 241  
         public String login() throws IOException {
 242  10
             return this.user.login();
 243  
         }
 244  
 
 245  
         @Override
 246  
         public UserOrganizations organizations() {
 247  0
             return this.user.organizations();
 248  
         }
 249  
 
 250  
         @Override
 251  
         public PublicKeys keys() {
 252  0
             return this.user.keys();
 253  
         }
 254  
 
 255  
         @Override
 256  
         public UserEmails emails() {
 257  0
             return this.user.emails();
 258  
         }
 259  
 
 260  
         @Override
 261  
         public List<Notification> notifications() throws IOException {
 262  0
             return this.user.notifications();
 263  
         }
 264  
 
 265  
         @Override
 266  
         public void markAsRead(final Date lastread) {
 267  0
             this.user.markAsRead(lastread);
 268  0
         }
 269  
 
 270  
         @Override
 271  
         public JsonObject json() throws IOException {
 272  4
             return this.user.json();
 273  
         }
 274  
 
 275  
         @Override
 276  
         public void patch(
 277  
             final JsonObject json
 278  
         ) throws IOException {
 279  0
             this.user.patch(json);
 280  0
         }
 281  
 
 282  
         /**
 283  
          * Returns the value of gravatar_id property of User's JSON.
 284  
          * @return The 'gravatar_id' property value.
 285  
          * @throws IOException If any I/O error occurs.
 286  
          */
 287  
         public String gravatar() throws IOException {
 288  2
             return this.jsn.text("gravatar_id");
 289  
         }
 290  
 
 291  
         /**
 292  
          * Returns the value of html_url property of User's JSON.
 293  
          * @return The 'html_url' property value.
 294  
          * @throws IOException If any I/O error occurs.
 295  
          */
 296  
         public String htmlUrl() throws IOException {
 297  2
             return this.jsn.text("html_url");
 298  
         }
 299  
 
 300  
         /**
 301  
          * Returns the value of followers_url property of User's JSON.
 302  
          * @return The 'followers_url' property value.
 303  
          * @throws IOException If any I/O error occurs.
 304  
          */
 305  
         public String followersUrl() throws IOException {
 306  2
             return this.jsn.text("followers_url");
 307  
         }
 308  
 
 309  
         /**
 310  
          * Returns the value of following_url property of User's JSON.
 311  
          * @return The 'following_url' property value.
 312  
          * @throws IOException If any I/O error occurs.
 313  
          */
 314  
         public String followingUrl() throws IOException {
 315  2
             return this.jsn.text("following_url");
 316  
         }
 317  
 
 318  
         /**
 319  
          * Returns the value of gists_url property of User's JSON.
 320  
          * @return The 'gists_url' property value.
 321  
          * @throws IOException If any I/O error occurs.
 322  
          */
 323  
         public String gistsUrl() throws IOException {
 324  2
             return this.jsn.text("gists_url");
 325  
         }
 326  
 
 327  
         /**
 328  
          * Returns the value of starred_url property of User's JSON.
 329  
          * @return The 'starred_url' property value.
 330  
          * @throws IOException If any I/O error occurs.
 331  
          */
 332  
         public String starredUrl() throws IOException {
 333  2
             return this.jsn.text("starred_url");
 334  
         }
 335  
 
 336  
         /**
 337  
          * Returns the value of subscriptions_url property of User's JSON.
 338  
          * @return The 'subscriptions_url' property value.
 339  
          * @throws IOException If any I/O error occurs.
 340  
          */
 341  
         public String subscriptionsUrl() throws IOException {
 342  2
             return this.jsn.text("subscriptions_url");
 343  
         }
 344  
 
 345  
         /**
 346  
          * Returns the value of organizations_url property of User's JSON.
 347  
          * @return The 'organizations_url' property value.
 348  
          * @throws IOException If any I/O error occurs.
 349  
          */
 350  
         public String organizationsUrl() throws IOException {
 351  2
             return this.jsn.text("organizations_url");
 352  
         }
 353  
 
 354  
         /**
 355  
          * Returns the value of repos_url property of User's JSON.
 356  
          * @return The 'repos_url' property value.
 357  
          * @throws IOException If any I/O error occurs.
 358  
          */
 359  
         public String reposUrl() throws IOException {
 360  2
             return this.jsn.text("repos_url");
 361  
         }
 362  
 
 363  
         /**
 364  
          * Returns the value of events_url property of User's JSON.
 365  
          * @return The 'events_url' property value.
 366  
          * @throws IOException If any I/O error occurs.
 367  
          */
 368  
         public String eventsUrl() throws IOException {
 369  2
             return this.jsn.text("events_url");
 370  
         }
 371  
 
 372  
         /**
 373  
          * Returns the value of received_events_url property of User's JSON.
 374  
          * @return The 'received_events_url' property value.
 375  
          * @throws IOException If any I/O error occurs.
 376  
          */
 377  
         public String receivedEventsUrl() throws IOException {
 378  2
             return this.jsn.text("received_events_url");
 379  
         }
 380  
 
 381  
         /**
 382  
          * Returns the value of type property of User's JSON.
 383  
          * @return The 'type' property value.
 384  
          * @throws IOException If any I/O error occurs.
 385  
          */
 386  
         public String type() throws IOException {
 387  2
             return this.jsn.text("type");
 388  
         }
 389  
 
 390  
         /**
 391  
          * Returns the value of site_admin property of User's JSON.
 392  
          * @return The 'site_admin' property value.
 393  
          * @throws IOException If any I/O error occurs.
 394  
          */
 395  
         public boolean siteAdmin() throws IOException {
 396  2
             return "true".equals(this.jsn.text("site_admin"));
 397  
         }
 398  
 
 399  
         /**
 400  
          * Returns the value of blog property of User's JSON.
 401  
          * @return The 'blog' property value.
 402  
          * @throws IOException If any I/O error occurs.
 403  
          */
 404  
         public String blog() throws IOException {
 405  2
             return this.jsn.text("blog");
 406  
         }
 407  
 
 408  
         /**
 409  
          * Returns the value of hireable property of User's JSON.
 410  
          * @return The 'hireable' property value.
 411  
          * @throws IOException If any I/O error occurs.
 412  
          */
 413  
         public boolean hireable() throws IOException {
 414  2
             return "true".equals(this.jsn.text("hireable"));
 415  
         }
 416  
 
 417  
         /**
 418  
          * Returns the value of bio property of User's JSON.
 419  
          * @return The 'bio' property value.
 420  
          * @throws IOException If any I/O error occurs.
 421  
          */
 422  
         public String bio() throws IOException {
 423  2
             return this.jsn.text("bio");
 424  
         }
 425  
 
 426  
         /**
 427  
          * Returns the value of public_repos property of User's JSON.
 428  
          * @return The 'public_repos' property value.
 429  
          * @throws IOException If any I/O error occurs.
 430  
          */
 431  
         public int publicRepos() throws IOException {
 432  2
             return Integer.parseInt(this.jsn.text("public_repos"));
 433  
         }
 434  
 
 435  
         /**
 436  
          * Returns the value of public_gists property of User's JSON.
 437  
          * @return The 'public_gists' property value.
 438  
          * @throws IOException If any I/O error occurs.
 439  
          */
 440  
         public int publicGists() throws IOException {
 441  2
             return Integer.parseInt(this.jsn.text("public_gists"));
 442  
         }
 443  
 
 444  
         /**
 445  
          * Returns the value of followers property of User's JSON.
 446  
          * @return The 'followers' property value.
 447  
          * @throws IOException If any I/O error occurs.
 448  
          */
 449  
         public int followersCount() throws IOException {
 450  2
             return Integer.parseInt(this.jsn.text("followers"));
 451  
         }
 452  
 
 453  
         /**
 454  
          * Returns the value of following property of User's JSON.
 455  
          * @return The 'following' property value.
 456  
          * @throws IOException If any I/O error occurs.
 457  
          */
 458  
         public int followingCount() throws IOException {
 459  2
             return Integer.parseInt(this.jsn.text("following"));
 460  
         }
 461  
 
 462  
         /**
 463  
          * Returns the value of created_at property of User's JSON.
 464  
          * @return The 'created_at' property value.
 465  
          * @throws IOException If any I/O error occurs.
 466  
          */
 467  
         public Github.Time created() throws IOException {
 468  
             try {
 469  2
                 return new Github.Time(this.jsn.text("created_at"));
 470  0
             } catch (final ParseException ex) {
 471  0
                 throw new IllegalArgumentException(
 472  
                     "Cannot parse value of 'created_at' property",
 473  
                     ex
 474  
                 );
 475  
             }
 476  
         }
 477  
 
 478  
         /**
 479  
          * Returns the value of updated_at property of User's JSON.
 480  
          * @return The 'updated_at' property value.
 481  
          * @throws IOException If any I/O error occurs.
 482  
          */
 483  
         public Github.Time updated() throws IOException {
 484  
             try {
 485  2
                 return new Github.Time(this.jsn.text("updated_at"));
 486  0
             } catch (final ParseException ex) {
 487  0
                 throw new IllegalArgumentException(
 488  
                     "Cannot parse value of 'updated_at' property",
 489  
                     ex
 490  
                 );
 491  
             }
 492  
         }
 493  
     }
 494  
 }