Coverage Report - com.jcabi.github.ReleaseAsset
 
Classes in this File Line Coverage Branch Coverage Complexity
ReleaseAsset
N/A
N/A
1.273
ReleaseAsset$Smart
56%
18/32
0%
0/16
1.273
ReleaseAsset$Smart$AjcClosure1
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure11
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure13
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure15
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure17
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure19
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure21
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure23
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure25
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure27
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure29
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure3
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure31
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure33
0%
0/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure5
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure7
100%
1/1
N/A
1.273
ReleaseAsset$Smart$AjcClosure9
100%
1/1
N/A
1.273
 
 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.io.InputStream;
 36  
 import java.net.URL;
 37  
 import java.text.ParseException;
 38  
 import java.util.Date;
 39  
 import javax.json.Json;
 40  
 import javax.json.JsonObject;
 41  
 import javax.validation.constraints.NotNull;
 42  
 import lombok.EqualsAndHashCode;
 43  
 import lombok.ToString;
 44  
 
 45  
 /**
 46  
  * Github release asset.
 47  
  * @author Carlos Miranda (miranda.cma@gmail.com)
 48  
  * @version $Id$
 49  
  * @since 0.8
 50  
  */
 51  
 @Immutable
 52  
 @SuppressWarnings("PMD.TooManyMethods")
 53  
 public interface ReleaseAsset extends JsonReadable, JsonPatchable {
 54  
 
 55  
     /**
 56  
      * The release we're in.
 57  
      * @return Release
 58  
      */
 59  
     @NotNull(message = "release is never NULL")
 60  
     Release release();
 61  
 
 62  
     /**
 63  
      * Number.
 64  
      * @return Release asset number
 65  
      */
 66  
     int number();
 67  
 
 68  
     /**
 69  
      * Delete the release asset.
 70  
      * @throws IOException If there is any I/O problem
 71  
      * @see <a href="http://developer.github.com/v3/repos/releases/#delete-a-release-asset">Delete a Release Asset</a>
 72  
      */
 73  
     void remove() throws IOException;
 74  
 
 75  
     /**
 76  
      * Gets release asset raw content.
 77  
      * @return Release asset number
 78  
      * @throws IOException If there is any I/O problem
 79  
      * @see <a href="http://developer.github.com/v3/repos/releases/#get-a-single-release-asset">Get a single release asset</a>
 80  
      */
 81  
     @NotNull(message = "InputStream is never NULL")
 82  
     InputStream raw() throws IOException;
 83  
 
 84  
     /**
 85  
      * Smart ReleaseAsset with extra features.
 86  
      * @checkstyle MultipleStringLiterals (500 lines)
 87  
      */
 88  
     @Immutable
 89  0
     @ToString
 90  
     @Loggable(Loggable.DEBUG)
 91  0
     @EqualsAndHashCode(of = {"asset", "jsn" })
 92  
     final class Smart implements ReleaseAsset {
 93  
         /**
 94  
          * Encapsulated Release Asset.
 95  
          */
 96  
         private final transient ReleaseAsset asset;
 97  
         /**
 98  
          * SmartJson object for convenient JSON parsing.
 99  
          */
 100  
         private final transient SmartJson jsn;
 101  
 
 102  
         /**
 103  
          * Public ctor.
 104  
          * @param ast Release asset
 105  
          */
 106  
         public Smart(
 107  
             @NotNull(message = "ast can't be NULL") final ReleaseAsset ast
 108  11
         ) {
 109  11
             this.asset = ast;
 110  11
             this.jsn = new SmartJson(ast);
 111  11
         }
 112  
 
 113  
         /**
 114  
          * Get its URL.
 115  
          * @return URL of release asset
 116  
          * @throws IOException If there is any I/O problem
 117  
          */
 118  
         @NotNull(message = "URL is never NULL")
 119  
         public URL url() throws IOException {
 120  2
             return new URL(this.jsn.text("url"));
 121  
         }
 122  
 
 123  
         /**
 124  
          * Get its name.
 125  
          * @return Name of release asset
 126  
          * @throws IOException If there is any I/O problem
 127  
          */
 128  
         @NotNull(message = "name is never NULL")
 129  
         public String name() throws IOException {
 130  2
             return this.jsn.text("name");
 131  
         }
 132  
 
 133  
         /**
 134  
          * Get its label.
 135  
          * @return Label of release asset
 136  
          * @throws IOException If there is any I/O problem
 137  
          */
 138  
         @NotNull(message = "label is never NULL")
 139  
         public String label() throws IOException {
 140  2
             return this.jsn.text("label");
 141  
         }
 142  
 
 143  
         /**
 144  
          * Get its state.
 145  
          * @return State of release asset
 146  
          * @throws IOException If there is any I/O problem
 147  
          */
 148  
         @NotNull(message = "state is never NULL")
 149  
         public String state() throws IOException {
 150  2
             return this.jsn.text("state");
 151  
         }
 152  
 
 153  
         /**
 154  
          * Get its content type.
 155  
          * @return Content type of release asset
 156  
          * @throws IOException If there is any I/O problem
 157  
          */
 158  
         @NotNull(message = "type is never NULL")
 159  
         public String contentType() throws IOException {
 160  2
             return this.jsn.text("content_type");
 161  
         }
 162  
 
 163  
         /**
 164  
          * Get its size.
 165  
          * @return Size of release asset
 166  
          * @throws IOException If there is any I/O problem
 167  
          */
 168  
         public int size() throws IOException {
 169  2
             return this.jsn.number("size");
 170  
         }
 171  
 
 172  
         /**
 173  
          * Get its downloadCount.
 174  
          * @return Download count of release asset
 175  
          * @throws IOException If there is any I/O problem
 176  
          */
 177  
         public int downloadCount() throws IOException {
 178  2
             return this.jsn.number("download_count");
 179  
         }
 180  
 
 181  
         /**
 182  
          * When it was created.
 183  
          * @return Date of creation
 184  
          * @throws IOException If there is any I/O problem
 185  
          */
 186  
         @NotNull(message = "date is never NULL")
 187  
         public Date createdAt() throws IOException {
 188  
             try {
 189  2
                 return new Github.Time(
 190  
                     this.jsn.text("created_at")
 191  
                 ).date();
 192  0
             } catch (final ParseException ex) {
 193  0
                 throw new IllegalStateException(ex);
 194  
             }
 195  
         }
 196  
 
 197  
         /**
 198  
          * When it was updated.
 199  
          * @return Date of update
 200  
          * @throws IOException If there is any I/O problem
 201  
          */
 202  
         @NotNull(message = "date is never NULL")
 203  
         public Date updatedAt() throws IOException {
 204  
             try {
 205  2
                 return new Github.Time(
 206  
                     this.jsn.text("updated_at")
 207  
                 ).date();
 208  0
             } catch (final ParseException ex) {
 209  0
                 throw new IllegalStateException(ex);
 210  
             }
 211  
         }
 212  
 
 213  
         /**
 214  
          * Change its name.
 215  
          * @param text Name of release asset
 216  
          * @throws IOException If there is any I/O problem
 217  
          */
 218  
         public void name(
 219  
             @NotNull(message = "text can't be NULL") final String text
 220  
         ) throws IOException {
 221  2
             this.asset.patch(
 222  
                 Json.createObjectBuilder().add("name", text).build()
 223  
             );
 224  1
         }
 225  
 
 226  
         /**
 227  
          * Change its label.
 228  
          * @param text Label of release asset
 229  
          * @throws IOException If there is any I/O problem
 230  
          */
 231  
         public void label(
 232  
             @NotNull(message = "text can't be NULL") final String text
 233  
         ) throws IOException {
 234  2
             this.asset.patch(
 235  
                 Json.createObjectBuilder().add("label", text).build()
 236  
             );
 237  1
         }
 238  
 
 239  
         @Override
 240  
         @NotNull(message = "release is never NULL")
 241  
         public Release release() {
 242  0
             return this.asset.release();
 243  
         }
 244  
 
 245  
         @Override
 246  
         public int number() {
 247  0
             return this.asset.number();
 248  
         }
 249  
 
 250  
         @Override
 251  
         public void remove() throws IOException {
 252  0
             this.asset.remove();
 253  0
         }
 254  
 
 255  
         @Override
 256  
         @NotNull(message = "input stream is never NULL")
 257  
         public InputStream raw() throws IOException {
 258  0
             return this.asset.raw();
 259  
         }
 260  
 
 261  
         @Override
 262  
         public void patch(
 263  
             @NotNull(message = "JSON is never NULL") final JsonObject json
 264  
         ) throws IOException {
 265  0
             this.asset.patch(json);
 266  0
         }
 267  
 
 268  
         @Override
 269  
         @NotNull(message = "JSON is never NULL")
 270  
         public JsonObject json() throws IOException {
 271  0
             return this.asset.json();
 272  
         }
 273  
     }
 274  
 }