| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RtGistComment |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure1 |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure11 |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure3 |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure5 |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure7 |
|
| 1.0;1 | ||||
| RtGistComment$AjcClosure9 |
|
| 1.0;1 |
| 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 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 lombok.EqualsAndHashCode; | |
| 40 | ||
| 41 | /** | |
| 42 | * Gist comment. | |
| 43 | * | |
| 44 | * @author Giang Le (giang@vn-smartsolutions.com) | |
| 45 | * @version $Id: 3edb43e6e15ed4f7c59070d934e71c78841b340c $ | |
| 46 | * @since 0.8 | |
| 47 | */ | |
| 48 | 0 | @Immutable |
| 49 | @Loggable(Loggable.DEBUG) | |
| 50 | 0 | @EqualsAndHashCode(of = { "request", "owner", "num" }) |
| 51 | final class RtGistComment implements GistComment { | |
| 52 | /** | |
| 53 | * RESTful request. | |
| 54 | */ | |
| 55 | private final transient Request request; | |
| 56 | ||
| 57 | /** | |
| 58 | * Gist we're in. | |
| 59 | */ | |
| 60 | private final transient Gist owner; | |
| 61 | ||
| 62 | /** | |
| 63 | * Comment number. | |
| 64 | */ | |
| 65 | private final transient int num; | |
| 66 | ||
| 67 | /** | |
| 68 | * Public ctor. | |
| 69 | * @param req RESTful request | |
| 70 | * @param gist Gist of this comment | |
| 71 | * @param number Number of the get | |
| 72 | */ | |
| 73 | 5 | RtGistComment(final Request req, final Gist gist, final int number) { |
| 74 | 6 | this.request = req.uri() |
| 75 | 6 | .path("/gists") |
| 76 | 6 | .path(new Gist.Smart(gist).identifier()) |
| 77 | 5 | .path("/comments") |
| 78 | 5 | .path(Integer.toString(number)) |
| 79 | 5 | .back(); |
| 80 | 5 | this.owner = gist; |
| 81 | 5 | this.num = number; |
| 82 | 5 | } |
| 83 | ||
| 84 | @Override | |
| 85 | public String toString() { | |
| 86 | 0 | return this.request.uri().get().toString(); |
| 87 | } | |
| 88 | ||
| 89 | @Override | |
| 90 | public Gist gist() { | |
| 91 | 0 | return this.owner; |
| 92 | } | |
| 93 | ||
| 94 | @Override | |
| 95 | public int number() { | |
| 96 | 0 | return this.num; |
| 97 | } | |
| 98 | ||
| 99 | @Override | |
| 100 | public void remove() throws IOException { | |
| 101 | 2 | this.request.method(Request.DELETE).fetch() |
| 102 | 1 | .as(RestResponse.class) |
| 103 | 1 | .assertStatus(HttpURLConnection.HTTP_NO_CONTENT); |
| 104 | 1 | } |
| 105 | ||
| 106 | @Override | |
| 107 | public int compareTo( | |
| 108 | final GistComment comment | |
| 109 | ) { | |
| 110 | 0 | return this.number() - comment.number(); |
| 111 | } | |
| 112 | ||
| 113 | @Override | |
| 114 | public void patch( | |
| 115 | final JsonObject json | |
| 116 | ) throws IOException { | |
| 117 | 2 | new RtJson(this.request).patch(json); |
| 118 | 1 | } |
| 119 | ||
| 120 | @Override | |
| 121 | public JsonObject json() throws IOException { | |
| 122 | 6 | return new RtJson(this.request).fetch(); |
| 123 | } | |
| 124 | } |