Coverage Report - com.jcabi.github.DeployKey
 
Classes in this File Line Coverage Branch Coverage Complexity
DeployKey
N/A
N/A
1
DeployKey$Smart
45%
9/20
0%
0/16
1
DeployKey$Smart$AjcClosure1
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure11
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure13
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure15
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure17
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure3
100%
1/1
N/A
1
DeployKey$Smart$AjcClosure5
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure7
0%
0/1
N/A
1
DeployKey$Smart$AjcClosure9
100%
1/1
N/A
1
 
 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 javax.json.Json;
 37  
 import javax.json.JsonObject;
 38  
 import javax.validation.constraints.NotNull;
 39  
 import lombok.EqualsAndHashCode;
 40  
 import lombok.ToString;
 41  
 
 42  
 /**
 43  
  * Github deploy key.
 44  
  *
 45  
  * @author Andres Candal (andres.candal@rollasolution.com)
 46  
  * @version $Id$
 47  
  * @since 0.8
 48  
  * @see <a href="http://developer.github.com/v3/repos/keys/">Deploy Keys API</a>
 49  
  */
 50  
 @Immutable
 51  
 @SuppressWarnings("PMD.TooManyMethods")
 52  
 public interface DeployKey extends JsonReadable, JsonPatchable {
 53  
 
 54  
     /**
 55  
      * Get id of a deploy key.
 56  
      * @return Id
 57  
      */
 58  
     int number();
 59  
 
 60  
     /**
 61  
      * Delete a deploy key.
 62  
      * @throws java.io.IOException If there is any I/O problem
 63  
      * @see <a href="http://developer.github.com/v3/repos/keys/#delete">Remove a deploy key</a>
 64  
      */
 65  
     void remove() throws IOException;
 66  
 
 67  
     /**
 68  
      * Smart DeployKey with extra features.
 69  
      * @checkstyle MultipleStringLiterals (500 lines)
 70  
      */
 71  
     @Immutable
 72  0
     @ToString
 73  
     @Loggable(Loggable.DEBUG)
 74  0
     @EqualsAndHashCode(of = { "key", "jsn" })
 75  
     final class Smart implements DeployKey {
 76  
 
 77  
         /**
 78  
          * Encapsulated deploy key.
 79  
          */
 80  
         private final transient DeployKey key;
 81  
 
 82  
         /**
 83  
          * SmartJson object for convenient JSON parsing.
 84  
          */
 85  
         private final transient SmartJson jsn;
 86  
 
 87  
         /**
 88  
          * Public ctor.
 89  
          * @param dkey Deploy key
 90  
          */
 91  
         public Smart(
 92  
             @NotNull(message = "deploy key is never NULL") final DeployKey dkey
 93  2
         ) {
 94  2
             this.key = dkey;
 95  2
             this.jsn = new SmartJson(dkey);
 96  2
         }
 97  
 
 98  
         /**
 99  
          * Get its key value.
 100  
          * @return Value of deploy key
 101  
          * @throws IOException If there is any I/O problem
 102  
          */
 103  
         @NotNull(message = "key is never NULL")
 104  
         public String key() throws IOException {
 105  0
             return this.jsn.text("key");
 106  
         }
 107  
 
 108  
         /**
 109  
          * Change its value.
 110  
          * @param value Title of deploy key
 111  
          * @throws IOException If there is any I/O problem
 112  
          */
 113  
         public void key(
 114  
             @NotNull(message = "value can't be NULL") final String value
 115  
         ) throws IOException {
 116  2
             this.key.patch(
 117  
                 Json.createObjectBuilder().add("key", value).build()
 118  
             );
 119  1
         }
 120  
 
 121  
         /**
 122  
          * Get its URL.
 123  
          * @return URL of deploy key
 124  
          * @throws IOException If there is any I/O problem
 125  
          */
 126  
         @NotNull(message = "URL can't be NULL")
 127  
         public URL url() throws IOException {
 128  0
             return new URL(this.jsn.text("url"));
 129  
         }
 130  
 
 131  
         /**
 132  
          * Get its title.
 133  
          * @return Title of deploy key
 134  
          * @throws IOException If there is any I/O problem
 135  
          */
 136  
         @NotNull(message = "title is never NULL")
 137  
         public String title() throws IOException {
 138  0
             return this.jsn.text("title");
 139  
         }
 140  
 
 141  
         /**
 142  
          * Change its title.
 143  
          * @param text Title of deploy key
 144  
          * @throws IOException If there is any I/O problem
 145  
          */
 146  
         public void title(
 147  
             @NotNull(message = "text can't be NULL") final String text
 148  
         ) throws IOException {
 149  2
             this.key.patch(
 150  
                 Json.createObjectBuilder().add("title", text).build()
 151  
             );
 152  1
         }
 153  
 
 154  
         @Override
 155  
         @NotNull(message = "JSON is never NULL")
 156  
         public JsonObject json() throws IOException {
 157  0
             return this.key.json();
 158  
         }
 159  
 
 160  
         @Override
 161  
         public void patch(
 162  
             @NotNull(message = "JSON is never NULL") final JsonObject json
 163  
         ) throws IOException {
 164  0
             this.key.patch(json);
 165  0
         }
 166  
 
 167  
         @Override
 168  
         public int number() {
 169  0
             return this.key.number();
 170  
         }
 171  
 
 172  
         @Override
 173  
         public void remove() throws IOException {
 174  0
             this.key.remove();
 175  0
         }
 176  
     }
 177  
 
 178  
 }