Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RtUsers |
|
| 1.0;1 | ||||
RtUsers$1 |
|
| 1.0;1 | ||||
RtUsers$AjcClosure1 |
|
| 1.0;1 | ||||
RtUsers$AjcClosure3 |
|
| 1.0;1 | ||||
RtUsers$AjcClosure5 |
|
| 1.0;1 | ||||
RtUsers$AjcClosure7 |
|
| 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 javax.json.JsonObject; | |
36 | import lombok.EqualsAndHashCode; | |
37 | ||
38 | /** | |
39 | * Github users. | |
40 | * | |
41 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
42 | * @version $Id: 0ea00b1aa472da9d4dd283fe431a8e96ebc7254c $ | |
43 | * @since 0.4 | |
44 | */ | |
45 | @Immutable | |
46 | @Loggable(Loggable.DEBUG) | |
47 | 0 | @EqualsAndHashCode(of = { "ghub", "request" }) |
48 | final class RtUsers implements Users { | |
49 | ||
50 | /** | |
51 | * API entry point. | |
52 | */ | |
53 | private final transient Request entry; | |
54 | ||
55 | /** | |
56 | * Github. | |
57 | */ | |
58 | private final transient Github ghub; | |
59 | ||
60 | /** | |
61 | * RESTful request. | |
62 | */ | |
63 | private final transient Request request; | |
64 | ||
65 | /** | |
66 | * Public ctor. | |
67 | * @param github Github | |
68 | * @param req Request | |
69 | */ | |
70 | RtUsers( | |
71 | final Github github, | |
72 | final Request req | |
73 | 5 | ) { |
74 | 5 | this.entry = req; |
75 | 5 | this.ghub = github; |
76 | 5 | this.request = this.entry.uri().path("/users").back(); |
77 | 5 | } |
78 | ||
79 | @Override | |
80 | public String toString() { | |
81 | 0 | return this.request.uri().get().toString(); |
82 | } | |
83 | ||
84 | @Override | |
85 | public Github github() { | |
86 | 0 | return this.ghub; |
87 | } | |
88 | ||
89 | @Override | |
90 | public User self() { | |
91 | 2 | return new RtUser(this.ghub, this.entry, ""); |
92 | } | |
93 | ||
94 | @Override | |
95 | public User get(final String login) { | |
96 | 8 | return new RtUser(this.ghub, this.entry, login); |
97 | } | |
98 | ||
99 | @Override | |
100 | public Iterable<User> iterate( | |
101 | final String identifier | |
102 | ) { | |
103 | 3 | return new RtPagination<User>( |
104 | 1 | this.request.uri().queryParam("since", identifier).back(), |
105 | 3 | new RtValuePagination.Mapping<User, JsonObject>() { |
106 | @Override | |
107 | public User map(final JsonObject object) { | |
108 | 4 | return RtUsers.this.get( |
109 | 2 | String.valueOf(object.getInt("id")) |
110 | ); | |
111 | } | |
112 | } | |
113 | ); | |
114 | } | |
115 | ||
116 | } |