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