| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RtPublicMembers |
|
| 1.0;1 | ||||
| RtPublicMembers$1 |
|
| 1.0;1 | ||||
| RtPublicMembers$AjcClosure1 |
|
| 1.0;1 | ||||
| RtPublicMembers$AjcClosure3 |
|
| 1.0;1 | ||||
| RtPublicMembers$AjcClosure5 |
|
| 1.0;1 | ||||
| RtPublicMembers$AjcClosure7 |
|
| 1.0;1 | ||||
| RtPublicMembers$AjcClosure9 |
|
| 1.0;1 |
| 1 | 8 | /** |
| 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 | import org.hamcrest.Matchers; | |
| 41 | ||
| 42 | /** | |
| 43 | * Public members of a GitHub organization. | |
| 44 | * | |
| 45 | * @author Chris Rebert (github@chrisrebert.com) | |
| 46 | * @version $Id: 7d246ede5f0adeed244dd3b741e9fb0dbddb38fc $ | |
| 47 | * @see <a href="https://developer.github.com/v3/orgs/members/">Organization Members API</a> | |
| 48 | * @since 0.24 | |
| 49 | */ | |
| 50 | @Immutable | |
| 51 | @Loggable(Loggable.DEBUG) | |
| 52 | 0 | @EqualsAndHashCode(of = { "entry", "organization" }) |
| 53 | 2 | public final class RtPublicMembers implements PublicMembers { |
| 54 | /** | |
| 55 | * API entry point. | |
| 56 | */ | |
| 57 | private final transient Request entry; | |
| 58 | ||
| 59 | /** | |
| 60 | * RESTful request. | |
| 61 | */ | |
| 62 | private final transient Request request; | |
| 63 | ||
| 64 | /** | |
| 65 | * Organization. | |
| 66 | */ | |
| 67 | private final transient Organization organization; | |
| 68 | ||
| 69 | /** | |
| 70 | * Public ctor. | |
| 71 | * @param req Request | |
| 72 | * @param organ Organization | |
| 73 | */ | |
| 74 | public RtPublicMembers( | |
| 75 | final Request req, | |
| 76 | final Organization organ | |
| 77 | 5 | ) { |
| 78 | 5 | this.entry = req; |
| 79 | 5 | this.request = req.uri() |
| 80 | 5 | .path("/orgs") |
| 81 | 5 | .path(organ.login()) |
| 82 | 5 | .path("public_members") |
| 83 | 5 | .back(); |
| 84 | 5 | this.organization = organ; |
| 85 | 5 | } |
| 86 | ||
| 87 | @Override | |
| 88 | public Organization org() { | |
| 89 | 2 | return this.organization; |
| 90 | } | |
| 91 | ||
| 92 | @Override | |
| 93 | public void conceal( | |
| 94 | final User user | |
| 95 | ) throws IOException { | |
| 96 | 4 | this.request |
| 97 | 2 | .uri().path(user.login()).back() |
| 98 | 2 | .method(Request.DELETE) |
| 99 | 2 | .fetch().as(RestResponse.class) |
| 100 | 2 | .assertStatus(HttpURLConnection.HTTP_NO_CONTENT); |
| 101 | 1 | } |
| 102 | ||
| 103 | @Override | |
| 104 | public void publicize( | |
| 105 | final User user | |
| 106 | ) throws IOException { | |
| 107 | 4 | this.request |
| 108 | 2 | .uri().path(user.login()).back() |
| 109 | 2 | .method(Request.PUT) |
| 110 | 2 | .fetch().as(RestResponse.class) |
| 111 | 2 | .assertStatus(HttpURLConnection.HTTP_NO_CONTENT); |
| 112 | 1 | } |
| 113 | ||
| 114 | @Override | |
| 115 | public Iterable<User> iterate() { | |
| 116 | 4 | return new RtPagination<User>( |
| 117 | this.request, | |
| 118 | 3 | new RtValuePagination.Mapping<User, JsonObject>() { |
| 119 | @Override | |
| 120 | public User map(final JsonObject object) { | |
| 121 | 2 | return new RtUser( |
| 122 | 1 | RtPublicMembers.this.organization.github(), |
| 123 | 1 | RtPublicMembers.this.entry, |
| 124 | 1 | object.getString("login") |
| 125 | ); | |
| 126 | } | |
| 127 | } | |
| 128 | ); | |
| 129 | } | |
| 130 | ||
| 131 | @Override | |
| 132 | public boolean contains( | |
| 133 | final User user | |
| 134 | ) throws IOException { | |
| 135 | 11 | return this.request |
| 136 | 4 | .uri().path(user.login()).back() |
| 137 | 4 | .method(Request.GET) |
| 138 | 4 | .fetch().as(RestResponse.class) |
| 139 | 4 | .assertStatus( |
| 140 | 4 | Matchers.isOneOf( |
| 141 | 4 | HttpURLConnection.HTTP_NO_CONTENT, |
| 142 | 4 | HttpURLConnection.HTTP_NOT_FOUND |
| 143 | ) | |
| 144 | ) | |
| 145 | 3 | .status() == HttpURLConnection.HTTP_NO_CONTENT; |
| 146 | } | |
| 147 | } |