1 | 0 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
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 java.util.ArrayList; |
37 | |
import java.util.List; |
38 | |
import java.util.Map; |
39 | |
import javax.json.JsonObject; |
40 | |
import javax.json.JsonValue; |
41 | |
import lombok.EqualsAndHashCode; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | @Immutable |
52 | |
@Loggable(Loggable.DEBUG) |
53 | 0 | @EqualsAndHashCode(of = { "ghub", "entry", "coords" }) |
54 | |
@SuppressWarnings |
55 | |
( |
56 | |
{ |
57 | |
"PMD.TooManyMethods", |
58 | |
"PMD.CouplingBetweenObjects" |
59 | |
} |
60 | |
) |
61 | |
final class RtRepo implements Repo { |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private final transient Github ghub; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private final transient Request entry; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private final transient Request request; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
private final transient Coordinates coords; |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 36 | RtRepo(final Github github, final Request req, final Coordinates crd) { |
90 | 36 | this.ghub = github; |
91 | 36 | this.entry = req; |
92 | 36 | this.coords = crd; |
93 | 36 | this.request = this.entry.uri() |
94 | 36 | .path("/repos") |
95 | 36 | .path(this.coords.user()) |
96 | 36 | .path(this.coords.repo()) |
97 | 36 | .back(); |
98 | 36 | } |
99 | |
|
100 | |
@Override |
101 | |
public String toString() { |
102 | 0 | return this.coords.toString(); |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public Github github() { |
107 | 0 | return this.ghub; |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public Coordinates coordinates() { |
112 | 102 | return this.coords; |
113 | |
} |
114 | |
|
115 | |
@Override |
116 | |
public Issues issues() { |
117 | 4 | return new RtIssues(this.entry, this); |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public Milestones milestones() { |
122 | 0 | return new RtMilestones(this.entry, this); |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public Pulls pulls() { |
127 | 2 | return new RtPulls(this.entry, this); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public Hooks hooks() { |
132 | 2 | return new RtHooks(this.entry, this); |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public IssueEvents issueEvents() { |
137 | 2 | return new RtIssueEvents(this.entry, this); |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public Labels labels() { |
142 | 2 | return new RtLabels(this.entry, this); |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public Assignees assignees() { |
147 | 0 | return new RtAssignees(this.entry, this); |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public Releases releases() { |
152 | 2 | return new RtReleases(this.entry, this); |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public DeployKeys keys() { |
157 | 2 | return new RtDeployKeys(this.entry, this); |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public Forks forks() { |
162 | 0 | return new RtForks(this.entry, this); |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public Contents contents() { |
167 | 6 | return new RtContents(this.entry, this); |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public Collaborators collaborators() { |
172 | 0 | return new RtCollaborators(this.entry, this); |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
public Git git() { |
177 | 2 | return new RtGit(this.entry, this); |
178 | |
} |
179 | |
|
180 | |
@Override |
181 | |
public Stars stars() { |
182 | 2 | return new RtStars(this.entry, this); |
183 | |
} |
184 | |
|
185 | |
@Override |
186 | |
public Notifications notifications() { |
187 | 3 | return new RtNotifications( |
188 | 1 | this.request.uri().path("notifications").back() |
189 | |
); |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") |
194 | |
public Iterable<Language> languages() throws IOException { |
195 | 4 | final RtJson json = new RtJson( |
196 | 2 | this.request.uri() |
197 | 2 | .path("/languages") |
198 | 2 | .back() |
199 | |
); |
200 | 2 | final JsonObject object = json.fetch(); |
201 | 2 | final List<Language> languages = |
202 | 2 | new ArrayList<Language>(object.size()); |
203 | 2 | for (final Map.Entry<String, JsonValue> value : object.entrySet()) { |
204 | 3 | final String name = value.getKey(); |
205 | 6 | languages.add( |
206 | |
new RtLanguage( |
207 | |
name, |
208 | 3 | object.getJsonNumber(name).longValue() |
209 | |
) |
210 | |
); |
211 | 3 | } |
212 | 2 | return languages; |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public void patch( |
217 | |
final JsonObject json) |
218 | |
throws IOException { |
219 | 2 | new RtJson(this.request).patch(json); |
220 | 1 | } |
221 | |
|
222 | |
@Override |
223 | |
public RepoCommits commits() { |
224 | 4 | return new RtRepoCommits(this.entry, this); |
225 | |
} |
226 | |
|
227 | |
@Override |
228 | |
public Branches branches() { |
229 | 2 | return new RtBranches(this.entry, this); |
230 | |
} |
231 | |
|
232 | |
@Override |
233 | |
public JsonObject json() throws IOException { |
234 | 2 | return new RtJson(this.request).fetch(); |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public int compareTo(final Repo repo) { |
239 | 0 | return this.coords.compareTo(repo.coordinates()); |
240 | |
} |
241 | |
} |