Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RtUserOrganizations |
|
| 1.0;1 | ||||
RtUserOrganizations$AjcClosure1 |
|
| 1.0;1 | ||||
RtUserOrganizations$AjcClosure3 |
|
| 1.0;1 | ||||
RtUserOrganizations$AjcClosure5 |
|
| 1.0;1 | ||||
RtUserOrganizations$OrganizationMapping |
|
| 1.0;1 |
1 | 2 | /** |
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 java.io.IOException; | |
36 | import javax.json.JsonObject; | |
37 | import lombok.EqualsAndHashCode; | |
38 | ||
39 | /** | |
40 | * Github user organizations. | |
41 | * @author Paul Polishchuk (ppol@ua.fm) | |
42 | * @author Chris Rebert (github@chrisrebert.com) | |
43 | * @version $Id: 441293a7e78c7473853bb98de05de03c1c1c1501 $ | |
44 | * @see <a href="http://developer.github.com/v3/orgs/">Organizations API</a> | |
45 | * @since 0.24 | |
46 | * @checkstyle MultipleStringLiterals (500 lines) | |
47 | */ | |
48 | @Immutable | |
49 | @Loggable(Loggable.DEBUG) | |
50 | 0 | @EqualsAndHashCode(of = { "entry", "ghub", "owner" }) |
51 | final class RtUserOrganizations implements UserOrganizations { | |
52 | ||
53 | /** | |
54 | * API entry point. | |
55 | */ | |
56 | private final transient Request entry; | |
57 | ||
58 | /** | |
59 | * Github. | |
60 | */ | |
61 | private final transient Github ghub; | |
62 | ||
63 | /** | |
64 | * User we're in. | |
65 | */ | |
66 | private final transient User owner; | |
67 | ||
68 | /** | |
69 | * Public ctor. | |
70 | * @param github Github | |
71 | * @param req Request | |
72 | * @param user User | |
73 | */ | |
74 | RtUserOrganizations( | |
75 | final Github github, | |
76 | final Request req, | |
77 | final User user | |
78 | 2 | ) { |
79 | 2 | this.entry = req; |
80 | 2 | this.ghub = github; |
81 | 2 | this.owner = user; |
82 | 2 | } |
83 | ||
84 | @Override | |
85 | public Github github() { | |
86 | 0 | return this.ghub; |
87 | } | |
88 | ||
89 | @Override | |
90 | public User user() { | |
91 | 0 | return this.owner; |
92 | } | |
93 | ||
94 | @Override | |
95 | public Iterable<Organization> iterate() throws IOException { | |
96 | 2 | final String login = this.owner.login(); |
97 | 2 | return new RtPagination<Organization>( |
98 | 1 | this.entry.uri().path("/users").path(login).path("/orgs").back(), |
99 | 1 | new OrganizationMapping(this.ghub.organizations()) |
100 | ); | |
101 | } | |
102 | ||
103 | /** | |
104 | * Maps organization JSON objects to Organization instances. | |
105 | */ | |
106 | 3 | private static final class OrganizationMapping |
107 | implements RtValuePagination.Mapping<Organization, JsonObject> { | |
108 | /** | |
109 | * Organizations. | |
110 | */ | |
111 | private final transient Organizations organizations; | |
112 | ||
113 | /** | |
114 | * Ctor. | |
115 | * @param orgs Organizations | |
116 | */ | |
117 | 1 | OrganizationMapping(final Organizations orgs) { |
118 | 1 | this.organizations = orgs; |
119 | 1 | } |
120 | ||
121 | @Override | |
122 | public Organization map(final JsonObject object) { | |
123 | 3 | return this.organizations.get(object.getString("login")); |
124 | } | |
125 | } | |
126 | } |