Coverage Report - com.jcabi.github.RtRelease
 
Classes in this File Line Coverage Branch Coverage Complexity
RtRelease
76%
13/17
0%
0/10
1
RtRelease$AjcClosure1
0%
0/1
N/A
1
RtRelease$AjcClosure11
100%
1/1
N/A
1
RtRelease$AjcClosure3
100%
1/1
N/A
1
RtRelease$AjcClosure5
0%
0/1
N/A
1
RtRelease$AjcClosure7
100%
1/1
N/A
1
RtRelease$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 com.jcabi.http.Request;
 35  
 import com.jcabi.http.response.RestResponse;
 36  
 import java.io.IOException;
 37  
 import java.net.HttpURLConnection;
 38  
 import javax.json.JsonObject;
 39  
 import javax.validation.constraints.NotNull;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Github release.
 44  
  * @author Alexander Sinyagin (sinyagin.alexander@gmail.com)
 45  
  * @version $Id$
 46  
  */
 47  
 @Immutable
 48  
 @Loggable(Loggable.DEBUG)
 49  0
 @EqualsAndHashCode(of = "request")
 50  
 final class RtRelease implements Release {
 51  
 
 52  
     /**
 53  
      * API entry point.
 54  
      */
 55  
     private final transient Request entry;
 56  
 
 57  
     /**
 58  
      * RESTful request.
 59  
      */
 60  
     private final transient Request request;
 61  
 
 62  
     /**
 63  
      * Repository.
 64  
      */
 65  
     private final transient Repo owner;
 66  
 
 67  
     /**
 68  
      * Release id.
 69  
      */
 70  
     private final transient int release;
 71  
 
 72  
     /**
 73  
      * Public ctor.
 74  
      * @param req RESTful API entry point
 75  
      * @param repo Repository
 76  
      * @param nmbr Release id
 77  
      */
 78  6
     RtRelease(final Request req, final Repo repo, final int nmbr) {
 79  6
         this.entry = req;
 80  6
         this.release = nmbr;
 81  6
         this.owner = repo;
 82  6
         this.request = req.uri()
 83  
             .path("/repos")
 84  
             .path(repo.coordinates().user())
 85  
             .path(repo.coordinates().repo())
 86  
             .path("/releases")
 87  
             .path(String.valueOf(this.release))
 88  
             .back();
 89  6
     }
 90  
 
 91  
     @Override
 92  
     @NotNull(message = "repository is never NULL")
 93  
     public Repo repo() {
 94  0
         return this.owner;
 95  
     }
 96  
 
 97  
     @Override
 98  
     public int number() {
 99  2
         return this.release;
 100  
     }
 101  
 
 102  
     @Override
 103  
     @NotNull(message = "ReleaseAssets is never NULL")
 104  
     public ReleaseAssets assets() {
 105  0
         return new RtReleaseAssets(this.entry, this);
 106  
     }
 107  
 
 108  
     @Override
 109  
     @NotNull(message = "toString is never NULL")
 110  
     public String toString() {
 111  0
         return this.request.uri().get().toString();
 112  
     }
 113  
 
 114  
     @Override
 115  
     @NotNull(message = "JSON is never NULL")
 116  
     public JsonObject json() throws IOException {
 117  2
         return new RtJson(this.request).fetch();
 118  
     }
 119  
 
 120  
     @Override
 121  
     public void patch(
 122  
         @NotNull(message = "json can't be NULL") final JsonObject json
 123  
     ) throws IOException {
 124  4
         new RtJson(this.request).patch(json);
 125  2
     }
 126  
 
 127  
     @Override
 128  
     public void delete() throws IOException {
 129  2
         this.request.method(Request.DELETE).fetch()
 130  
             .as(RestResponse.class)
 131  
             .assertStatus(HttpURLConnection.HTTP_NO_CONTENT);
 132  1
     }
 133  
 
 134  
 }