Coverage Report - com.jcabi.github.Gist
 
Classes in this File Line Coverage Branch Coverage Complexity
Gist
N/A
N/A
1.045
Gist$Smart
40%
11/27
16%
2/12
1.045
Gist$Smart$AjcClosure1
100%
1/1
N/A
1.045
Gist$Smart$AjcClosure11
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure13
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure15
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure17
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure19
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure21
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure23
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure3
100%
1/1
N/A
1.045
Gist$Smart$AjcClosure5
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure7
0%
0/1
N/A
1.045
Gist$Smart$AjcClosure9
0%
0/1
N/A
1.045
 
 1  0
 /**
 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.util.ArrayList;
 36  
 import java.util.Collection;
 37  
 import javax.json.JsonObject;
 38  
 import javax.json.JsonValue;
 39  
 import javax.validation.constraints.NotNull;
 40  
 import lombok.EqualsAndHashCode;
 41  
 import lombok.ToString;
 42  
 
 43  
 /**
 44  
  * Github gist.
 45  
  *
 46  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 47  
  * @version $Id$
 48  
  * @since 0.1
 49  
  * @see <a href="http://developer.github.com/v3/gists/">Gists API</a>
 50  
  */
 51  
 @Immutable
 52  
 @SuppressWarnings("PMD.TooManyMethods")
 53  
 public interface Gist extends JsonReadable, JsonPatchable {
 54  
 
 55  
     /**
 56  
      * Github we're in.
 57  
      * @return Github
 58  
      */
 59  
     @NotNull(message = "Github is never NULL")
 60  
     Github github();
 61  
 
 62  
     /**
 63  
      * Get gist identifier.
 64  
      * @return Gist identifier
 65  
      */
 66  
     @NotNull(message = "Identifier is never NULL")
 67  
     String identifier();
 68  
 
 69  
     /**
 70  
      * Read file content.
 71  
      * @param name Name of it
 72  
      * @return File content
 73  
      * @throws IOException If there is any I/O problem
 74  
      * @see <a href="http://developer.github.com/v3/gists/#get-a-single-gist">Get a Single Gist</a>
 75  
      */
 76  
     @NotNull(message = "file content is never NULL")
 77  
     String read(@NotNull(message = "file name can't be NULL") String name)
 78  
         throws IOException;
 79  
 
 80  
     /**
 81  
      * Write file content.
 82  
      * @param name Name of it
 83  
      * @param content Content to write
 84  
      * @throws IOException If there is any I/O problem
 85  
      * @see <a href="http://developer.github.com/v3/gists/#edit-a-gist">Edit a Gist</a>
 86  
      */
 87  
     void write(
 88  
         @NotNull(message = "file name can't be NULL") String name,
 89  
         @NotNull(message = "file content can't be NULL") String content)
 90  
         throws IOException;
 91  
 
 92  
     /**
 93  
      * Star a gist.
 94  
      * @throws IOException If there is any I/O problem
 95  
      */
 96  
     void star() throws IOException;
 97  
 
 98  
     /**
 99  
      * Unstar a gist.
 100  
      * @throws IOException If there is any I/O problem
 101  
      */
 102  
     void unstar() throws IOException;
 103  
 
 104  
     /**
 105  
      * Checks if Gist is starred.
 106  
      * @throws IOException If there is any I/O problem
 107  
      * @return True if gist is starred
 108  
      */
 109  
     boolean starred() throws IOException;
 110  
 
 111  
     /**
 112  
      * Fork the gist.
 113  
      * @return Forked gist
 114  
      * @throws IOException If there is any I/O problem
 115  
      */
 116  
     @NotNull(message = "gist is never NULL")
 117  
     Gist fork() throws IOException;
 118  
 
 119  
     /**
 120  
      * Get all comments of the gist.
 121  
      * @return GistComments
 122  
      * @throws IOException If there is any I/O problem
 123  
      * @see <a href="http://developer.github.com/v3/gists/comments/">Gist Comments API</a>
 124  
      */
 125  
     @NotNull(message = "comments are never NULL")
 126  
     GistComments comments() throws IOException;
 127  
 
 128  
     /**
 129  
      * Smart Gist with extra features.
 130  
      */
 131  
     @Immutable
 132  0
     @ToString
 133  
     @Loggable(Loggable.DEBUG)
 134  0
     @EqualsAndHashCode(of = "gist")
 135  
     final class Smart implements Gist {
 136  
         /**
 137  
          * Encapsulated gist.
 138  
          */
 139  
         private final transient Gist gist;
 140  
         /**
 141  
          * Public ctor.
 142  
          * @param gst Gist
 143  
          */
 144  7
         public Smart(@NotNull(message = "gst can't be NULL") final Gist gst) {
 145  7
             this.gist = gst;
 146  7
         }
 147  
 
 148  
         /**
 149  
          * Get gist id.
 150  
          * @return Gist id
 151  
          */
 152  
         @Override
 153  
         @NotNull(message = "identifier is never NULL")
 154  
         public String identifier() {
 155  12
             return this.gist.identifier();
 156  
         }
 157  
 
 158  
         /**
 159  
          * Get a list of all file names in the gist.
 160  
          * @return File names
 161  
          * @throws IOException If there is any I/O problem
 162  
          */
 163  
         @NotNull(message = "Iterable of files is never NULL")
 164  
         public Iterable<String> files() throws IOException {
 165  2
             final JsonObject array = this.gist.json().getJsonObject("files");
 166  1
             final Collection<String> files =
 167  
                 new ArrayList<String>(array.size());
 168  1
             for (final JsonValue value : array.values()) {
 169  1
                 files.add(JsonObject.class.cast(value).getString("filename"));
 170  1
             }
 171  1
             return files;
 172  
         }
 173  
         @Override
 174  
         @NotNull(message = "Github is never NULL")
 175  
         public Github github() {
 176  0
             return this.gist.github();
 177  
         }
 178  
         @Override
 179  
         @NotNull(message = "read is never NULL")
 180  
         public String read(
 181  
             @NotNull(message = "name can't be NULL") final String name
 182  
         ) throws IOException {
 183  0
             return this.gist.read(name);
 184  
         }
 185  
         @Override
 186  
         public void write(
 187  
             @NotNull(message = "name can't be NULL") final String name,
 188  
             @NotNull(message = "content can't be NULL") final String content
 189  
         ) throws IOException {
 190  0
             this.gist.write(name, content);
 191  0
         }
 192  
 
 193  
         @Override
 194  
         public void star() throws IOException {
 195  0
             this.gist.star();
 196  0
         }
 197  
 
 198  
         @Override
 199  
         public void unstar() throws IOException {
 200  0
             this.gist.unstar();
 201  0
         }
 202  
 
 203  
         @Override
 204  
         public boolean starred() throws IOException {
 205  0
             return this.gist.starred();
 206  
         }
 207  
 
 208  
         @Override
 209  
         @NotNull(message = "fork is never NULL")
 210  
         public Gist fork() throws IOException {
 211  0
             return this.gist.fork();
 212  
         }
 213  
 
 214  
         @Override
 215  
         @NotNull(message = "gist comments is never NULL")
 216  
         public GistComments comments() throws IOException {
 217  0
             return this.gist.comments();
 218  
         }
 219  
 
 220  
         @Override
 221  
         @NotNull(message = "JSON is never NULL")
 222  
         public JsonObject json() throws IOException {
 223  0
             return this.gist.json();
 224  
         }
 225  
 
 226  
         @Override
 227  
         public void patch(
 228  
             @NotNull(message = "json can't be NULL") final JsonObject json
 229  
         ) throws IOException {
 230  0
             this.gist.patch(json);
 231  0
         }
 232  
     }
 233  
 
 234  
 }