| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GistComment |
|
| 1.375;1.375 | ||||
| GistComment$Smart |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure1 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure11 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure13 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure15 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure17 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure19 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure21 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure23 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure3 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure5 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure7 |
|
| 1.375;1.375 | ||||
| GistComment$Smart$AjcClosure9 |
|
| 1.375;1.375 |
| 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 java.io.IOException; | |
| 35 | import java.net.URL; | |
| 36 | import java.text.ParseException; | |
| 37 | import java.util.Date; | |
| 38 | import javax.json.Json; | |
| 39 | import javax.json.JsonObject; | |
| 40 | import lombok.EqualsAndHashCode; | |
| 41 | import lombok.ToString; | |
| 42 | ||
| 43 | /** | |
| 44 | * Gist comment. | |
| 45 | * | |
| 46 | * <p>Gist Comment implements {@link JsonReadable}, that's how you can get | |
| 47 | * its full details in JSON format. | |
| 48 | * For example, to get its author's Github login | |
| 49 | * you get the entire JSON and then gets its element: | |
| 50 | * | |
| 51 | * <pre>String login = comment.json() | |
| 52 | * .getJsonObject("user") | |
| 53 | * .getString("login");</pre> | |
| 54 | * | |
| 55 | * <p>However, it's better to use a supplementary "smart" decorator, which | |
| 56 | * automates most of these operations: | |
| 57 | * | |
| 58 | * <pre>String login = new GistComment.Smart(comment).author().login();</pre> | |
| 59 | * | |
| 60 | * @author Giang Le (giang@vn-smartsolutions.com) | |
| 61 | * @version $Id: 1e268c9588c46d25101231ec9c30bc0ec9d96a65 $ | |
| 62 | * @since 0.8 | |
| 63 | * @see <a href="http://developer.github.com/v3/gists/comments/">Gist Comments API</a> | |
| 64 | * @checkstyle MultipleStringLiterals (500 lines) | |
| 65 | */ | |
| 66 | @Immutable | |
| 67 | @SuppressWarnings("PMD.TooManyMethods") | |
| 68 | public interface GistComment | |
| 69 | extends Comparable<GistComment>, JsonReadable, JsonPatchable { | |
| 70 | /** | |
| 71 | * The gist it's in. | |
| 72 | * @return Owner of the comment | |
| 73 | */ | |
| 74 | Gist gist(); | |
| 75 | ||
| 76 | /** | |
| 77 | * Number. | |
| 78 | * @return Comment id | |
| 79 | */ | |
| 80 | int number(); | |
| 81 | ||
| 82 | /** | |
| 83 | * Delete the comment. | |
| 84 | * @throws java.io.IOException If there is any I/O problem | |
| 85 | * @see <a href="http://developer.github.com/v3/gists/comments/#delete-a-comment">Delete a Comment</a> | |
| 86 | */ | |
| 87 | void remove() throws IOException; | |
| 88 | ||
| 89 | /** | |
| 90 | * Smart comment with additional features. | |
| 91 | */ | |
| 92 | 0 | @Immutable |
| 93 | 0 | @ToString |
| 94 | @Loggable(Loggable.DEBUG) | |
| 95 | 0 | @EqualsAndHashCode(of = { "comment", "jsn" }) |
| 96 | final class Smart implements GistComment { | |
| 97 | /** | |
| 98 | * Encapsulated gist comment. | |
| 99 | */ | |
| 100 | private final transient GistComment comment; | |
| 101 | /** | |
| 102 | * SmartJson object for convenient JSON parsing. | |
| 103 | */ | |
| 104 | private final transient SmartJson jsn; | |
| 105 | ||
| 106 | /** | |
| 107 | * Public ctor. | |
| 108 | * @param cmt Comment | |
| 109 | */ | |
| 110 | 2 | public Smart(final GistComment cmt) { |
| 111 | 2 | this.comment = cmt; |
| 112 | 2 | this.jsn = new SmartJson(cmt); |
| 113 | 2 | } |
| 114 | ||
| 115 | /** | |
| 116 | * Get its author. | |
| 117 | * @return Author of comment | |
| 118 | * @throws IOException If there is any I/O problem | |
| 119 | */ | |
| 120 | public User author() throws IOException { | |
| 121 | 0 | return this.comment.gist().github().users().get( |
| 122 | 0 | this.comment.json().getJsonObject("user").getString("login") |
| 123 | ); | |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * Get its body. | |
| 128 | * @return Body of comment | |
| 129 | * @throws IOException If there is any I/O problem | |
| 130 | */ | |
| 131 | public String body() throws IOException { | |
| 132 | 4 | return this.jsn.text("body"); |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Change comment body. | |
| 137 | * @param text Body of comment | |
| 138 | * @throws IOException If there is any I/O problem | |
| 139 | */ | |
| 140 | public void body(final String text) throws IOException { | |
| 141 | 0 | this.comment.patch( |
| 142 | 0 | Json.createObjectBuilder().add("body", text).build() |
| 143 | ); | |
| 144 | 0 | } |
| 145 | ||
| 146 | /** | |
| 147 | * Get its URL. | |
| 148 | * @return URL of comment | |
| 149 | * @throws IOException If there is any I/O problem | |
| 150 | */ | |
| 151 | public URL url() throws IOException { | |
| 152 | 0 | return new URL(this.jsn.text("url")); |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * When this comment was created. | |
| 157 | * @return Date of creation | |
| 158 | * @throws IOException If there is any I/O problem | |
| 159 | */ | |
| 160 | public Date createdAt() throws IOException { | |
| 161 | try { | |
| 162 | 0 | return new Github.Time( |
| 163 | 0 | this.jsn.text("created_at") |
| 164 | 0 | ).date(); |
| 165 | 0 | } catch (final ParseException ex) { |
| 166 | 0 | throw new IOException(ex); |
| 167 | } | |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * When this comment was updated last time. | |
| 172 | * @return Date of update | |
| 173 | * @throws IOException If there is any I/O problem | |
| 174 | */ | |
| 175 | public Date updatedAt() throws IOException { | |
| 176 | try { | |
| 177 | 0 | return new Github.Time( |
| 178 | 0 | this.jsn.text("updated_at") |
| 179 | 0 | ).date(); |
| 180 | 0 | } catch (final ParseException ex) { |
| 181 | 0 | throw new IOException(ex); |
| 182 | } | |
| 183 | } | |
| 184 | ||
| 185 | @Override | |
| 186 | public Gist gist() { | |
| 187 | 0 | return this.comment.gist(); |
| 188 | } | |
| 189 | ||
| 190 | @Override | |
| 191 | public int number() { | |
| 192 | 0 | return this.comment.number(); |
| 193 | } | |
| 194 | ||
| 195 | @Override | |
| 196 | public void remove() throws IOException { | |
| 197 | 0 | this.comment.remove(); |
| 198 | 0 | } |
| 199 | ||
| 200 | @Override | |
| 201 | public int compareTo(final GistComment cmt) { | |
| 202 | 0 | return this.comment.compareTo(cmt); |
| 203 | } | |
| 204 | ||
| 205 | @Override | |
| 206 | public void patch(final JsonObject json) throws IOException { | |
| 207 | 0 | this.comment.patch(json); |
| 208 | 0 | } |
| 209 | ||
| 210 | @Override | |
| 211 | public JsonObject json() throws IOException { | |
| 212 | 0 | return this.comment.json(); |
| 213 | } | |
| 214 | } | |
| 215 | } |