Coverage Report - com.jcabi.github.Organization
 
Classes in this File Line Coverage Branch Coverage Complexity
Organization
N/A
N/A
1.103
Organization$Smart
47%
20/42
0%
0/16
1.103
Organization$Smart$AjcClosure1
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure11
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure13
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure15
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure17
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure19
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure21
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure23
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure25
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure27
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure29
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure3
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure31
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure33
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure35
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure37
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure39
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure41
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure43
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure45
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure47
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure49
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure5
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure51
0%
0/1
N/A
1.103
Organization$Smart$AjcClosure7
100%
1/1
N/A
1.103
Organization$Smart$AjcClosure9
0%
0/1
N/A
1.103
 
 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 javax.json.Json;
 39  
 import javax.json.JsonObject;
 40  
 import javax.validation.constraints.NotNull;
 41  
 import lombok.EqualsAndHashCode;
 42  
 import lombok.ToString;
 43  
 
 44  
 /**
 45  
  * Github organization.
 46  
  *
 47  
  * <p>Use a supplementary "smart" decorator to get other properties
 48  
  * from an organization, for example:
 49  
  *
 50  
  * <pre> Organization.Smart org = new Organization.Smart(origin);
 51  
  * if (org.name() == null) {
 52  
  *   name = "new_name";
 53  
  * }</pre>
 54  
  * @author Paul Polishchuk (ppol@ua.fm)
 55  
  * @version $Id$
 56  
  * @checkstyle MultipleStringLiterals (500 lines)
 57  
  * @see <a href="http://developer.github.com/v3/issues/">Issues API</a>
 58  
  * @since 0.7
 59  
  */
 60  
 @Immutable
 61  
 @SuppressWarnings("PMD.TooManyMethods")
 62  
 public interface Organization extends Comparable<Organization>,
 63  
     JsonReadable, JsonPatchable {
 64  
 
 65  
     /**
 66  
      * Github we're in.
 67  
      * @return Github
 68  
      */
 69  
     @NotNull(message = "Github is never NULL")
 70  
     Github github();
 71  
 
 72  
     /**
 73  
      * Get this organization's login.
 74  
      * @return Login name
 75  
      */
 76  
     @NotNull(message = "login is never NULL")
 77  
     String login();
 78  
 
 79  
     /**
 80  
      * Smart Organization with extra features.
 81  
      */
 82  0
     @Immutable
 83  0
     @ToString
 84  
     @Loggable(Loggable.DEBUG)
 85  0
     @EqualsAndHashCode(of = { "org", "jsn" })
 86  
     final class Smart implements Organization {
 87  
 
 88  
         /**
 89  
          * Encapsulated org.
 90  
          */
 91  
         private final transient Organization org;
 92  
 
 93  
         /**
 94  
          * SmartJson object for convenient JSON parsing.
 95  
          */
 96  
         private final transient SmartJson jsn;
 97  
 
 98  
         /**
 99  
          * Public ctor.
 100  
          * @param orgn Organization
 101  
          */
 102  
         public Smart(
 103  
             @NotNull(message = "orgn can't be NULL") final Organization orgn
 104  15
         ) {
 105  15
             this.org = orgn;
 106  15
             this.jsn = new SmartJson(orgn);
 107  15
         }
 108  
 
 109  
         /**
 110  
          * Get this organization's ID.
 111  
          * @return Unique organization ID
 112  
          * @throws IOException If it fails
 113  
          */
 114  
         public int number() throws IOException {
 115  0
             return this.org.json().getJsonNumber("id").intValue();
 116  
         }
 117  
 
 118  
         /**
 119  
          * Get its company.
 120  
          * @return Company of organization
 121  
          * @throws IOException If there is any I/O problem
 122  
          */
 123  
         @NotNull(message = "company is never NULL")
 124  
         public String company() throws IOException {
 125  2
             return this.jsn.text("company");
 126  
         }
 127  
 
 128  
         /**
 129  
          * Change its company.
 130  
          * @param company Company of organization
 131  
          * @throws IOException If there is any I/O problem
 132  
          */
 133  
         public void company(
 134  
             @NotNull(message = "company can't be NULL") final String company
 135  
         ) throws IOException {
 136  0
             this.org.patch(
 137  
                 Json.createObjectBuilder().add("company", company).build()
 138  
             );
 139  0
         }
 140  
 
 141  
         /**
 142  
          * Get its location.
 143  
          * @return Location of organization
 144  
          * @throws IOException If there is any I/O problem
 145  
          */
 146  
         @NotNull(message = "location is never NULL")
 147  
         public String location() throws IOException {
 148  2
             return this.jsn.text("location");
 149  
         }
 150  
 
 151  
         /**
 152  
          * Change its location.
 153  
          * @param location Location of organization
 154  
          * @throws IOException If there is any I/O problem
 155  
          */
 156  
         public void location(
 157  
             @NotNull(message = "location can't be NULL") final String location
 158  
         ) throws IOException {
 159  0
             this.org.patch(
 160  
                 Json.createObjectBuilder().add("location", location).build()
 161  
             );
 162  0
         }
 163  
 
 164  
         /**
 165  
          * Get its name.
 166  
          * @return Name of organization
 167  
          * @throws IOException If there is any I/O problem
 168  
          */
 169  
         @NotNull(message = "name is never NULL")
 170  
         public String name() throws IOException {
 171  2
             return this.jsn.text("name");
 172  
         }
 173  
 
 174  
         /**
 175  
          * Change its name.
 176  
          * @param name Company of organization
 177  
          * @throws IOException If there is any I/O problem
 178  
          */
 179  
         public void name(
 180  
             @NotNull(message = "name can't be NULL") final String name
 181  
         ) throws IOException {
 182  0
             this.org.patch(
 183  
                 Json.createObjectBuilder().add("name", name).build()
 184  
             );
 185  0
         }
 186  
 
 187  
         /**
 188  
          * Get its email.
 189  
          * @return Email of organization
 190  
          * @throws IOException If there is any I/O problem
 191  
          */
 192  
         @NotNull(message = "email is never NULL")
 193  
         public String email() throws IOException {
 194  2
             return this.jsn.text("email");
 195  
         }
 196  
 
 197  
         /**
 198  
          * Change its email.
 199  
          * @param email Email of organization
 200  
          * @throws IOException If there is any I/O problem
 201  
          */
 202  
         public void email(
 203  
             @NotNull(message = "email can't be NULL") final String email
 204  
         ) throws IOException {
 205  0
             this.org.patch(
 206  
                 Json.createObjectBuilder().add("email", email).build()
 207  
             );
 208  0
         }
 209  
 
 210  
         /**
 211  
          * Get its billingEmail.
 212  
          * @return BillingEmail of organization
 213  
          * @throws IOException If there is any I/O problem
 214  
          */
 215  
         @NotNull(message = "billing email is never NULL")
 216  
         public String billingEmail() throws IOException {
 217  2
             return this.jsn.text("billing_email");
 218  
         }
 219  
 
 220  
         /**
 221  
          * Change its billingEmail.
 222  
          * @param billingemail BillingEmail of organization
 223  
          * @throws IOException If there is any I/O problem
 224  
          */
 225  
         public void billingEmail(
 226  
             @NotNull(message = "billingemail can't be NULL")
 227  
             final String billingemail
 228  
         )
 229  
             throws IOException {
 230  0
             this.org.patch(
 231  
                 Json.createObjectBuilder()
 232  
                     .add("billing_email", billingemail).build()
 233  
             );
 234  0
         }
 235  
 
 236  
         /**
 237  
          * Get its blog.
 238  
          * @return Blog of organization
 239  
          * @throws IOException If there is any I/O problem
 240  
          */
 241  
         @NotNull(message = "blog is never NULL")
 242  
         public String blog() throws IOException {
 243  2
             return this.jsn.text("blog");
 244  
         }
 245  
 
 246  
         /**
 247  
          * Get its URL.
 248  
          * @return URL of organization
 249  
          * @throws IOException If there is any I/O problem
 250  
          */
 251  
         @NotNull(message = "URL is never NULL")
 252  
         public URL url() throws IOException {
 253  2
             return new URL(this.jsn.text("url"));
 254  
         }
 255  
 
 256  
         /**
 257  
          * Get its HTML URL.
 258  
          * @return HTML URL of organization
 259  
          * @throws IOException If there is any I/O problem
 260  
          */
 261  
         @NotNull(message = "url is never NULL")
 262  
         public URL htmlUrl() throws IOException {
 263  2
             return new URL(this.jsn.text("html_url"));
 264  
         }
 265  
 
 266  
         /**
 267  
          * Get its avatar URL.
 268  
          * @return Avatar URL of organization
 269  
          * @throws IOException If there is any I/O problem
 270  
          */
 271  
         @NotNull(message = "avatar url is never NULL")
 272  
         public URL avatarUrl() throws IOException {
 273  2
             return new URL(this.jsn.text("avatar_url"));
 274  
         }
 275  
 
 276  
         /**
 277  
          * When this organisation was created.
 278  
          * @return Date of creation
 279  
          * @throws IOException If there is any I/O problem
 280  
          */
 281  
         @NotNull(message = "date is never NULL")
 282  
         public Date createdAt() throws IOException {
 283  
             try {
 284  2
                 return new Github.Time(
 285  
                     this.jsn.text("created_at")
 286  
                 ).date();
 287  0
             } catch (final ParseException ex) {
 288  0
                 throw new IllegalStateException(ex);
 289  
             }
 290  
         }
 291  
 
 292  
         /**
 293  
          * Get its public repos count.
 294  
          * @return Count of public repos of organization
 295  
          * @throws IOException If there is any I/O problem
 296  
          */
 297  
         public int publicRepos() throws IOException {
 298  2
             return this.jsn.number("public_repos");
 299  
         }
 300  
 
 301  
         /**
 302  
          * Get its public gists count.
 303  
          * @return Count of public gists of organization
 304  
          * @throws IOException If there is any I/O problem
 305  
          */
 306  
         public int publicGists() throws IOException {
 307  2
             return this.jsn.number("public_gists");
 308  
         }
 309  
 
 310  
         /**
 311  
          * Get its followers count.
 312  
          * @return Count of followers of organization
 313  
          * @throws IOException If there is any I/O problem
 314  
          */
 315  
         public int followers() throws IOException {
 316  2
             return this.jsn.number("followers");
 317  
         }
 318  
 
 319  
         /**
 320  
          * Get its following count.
 321  
          * @return Count of following of organization
 322  
          * @throws IOException If there is any I/O problem
 323  
          */
 324  
         public int following() throws IOException {
 325  2
             return this.jsn.number("following");
 326  
         }
 327  
 
 328  
         /**
 329  
          * Get its type.
 330  
          * @return Type of organization
 331  
          * @throws IOException If there is any I/O problem
 332  
          */
 333  
         @NotNull(message = "type is never NULL")
 334  
         public String type() throws IOException {
 335  2
             return this.jsn.text("type");
 336  
         }
 337  
 
 338  
         @Override
 339  
         @NotNull(message = "login is never NULL")
 340  
         public String login() {
 341  0
             return this.org.login();
 342  
         }
 343  
 
 344  
         @Override
 345  
         @NotNull(message = "github is never NULL")
 346  
         public Github github() {
 347  0
             return this.org.github();
 348  
         }
 349  
 
 350  
         @Override
 351  
         @NotNull(message = "Json is never NULL")
 352  
         public JsonObject json() throws IOException {
 353  0
             return this.org.json();
 354  
         }
 355  
 
 356  
         @Override
 357  
         public void patch(
 358  
             @NotNull(message = "json can't be NULL") final JsonObject json
 359  
         ) throws IOException {
 360  0
             this.org.patch(json);
 361  0
         }
 362  
 
 363  
         @Override
 364  
         public int compareTo(
 365  
             @NotNull(message = "obj can't be NULL") final Organization obj
 366  
         ) {
 367  0
             return this.org.compareTo(obj);
 368  
         }
 369  
     }
 370  
 
 371  
 }