Skip to content

Commit dd0c858

Browse files
committed
Add some common new util methods and url methods
1 parent 4129d07 commit dd0c858

18 files changed

Lines changed: 289 additions & 69 deletions

library/src/main/java/me/proxer/library/api/AdaptionInfoAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AdaptionInfoAdapter {
1313

1414
@FromJson
1515
AdaptionInfo fromJson(final IntermediateAdaptionInfo json) {
16-
return new AdaptionInfo(json.id, json.name, ProxerUtils.toApiEnum(Medium.class, json.medium));
16+
return new AdaptionInfo(json.id, json.name, ProxerUtils.toSafeApiEnum(Medium.class, json.medium));
1717
}
1818

1919
static class IntermediateAdaptionInfo {

library/src/main/java/me/proxer/library/api/DelimitedEnumSetAdapterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void toJson(final JsonWriter writer, @Nullable final Set<T> value) throws
8181
StringBuilder result = new StringBuilder();
8282

8383
for (final T item : value) {
84-
result.append(ProxerUtils.getApiEnumName(item));
84+
result.append(ProxerUtils.getSafeApiEnumName(item));
8585
result.append(delimiter);
8686
}
8787

library/src/main/java/me/proxer/library/api/EnumRetrofitConverterFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class EnumRetrofitConverterFactory extends Converter.Factory {
1616
public Converter<?, String> stringConverter(final Type type, final Annotation[] annotations,
1717
final Retrofit retrofit) {
1818
if (((Class<?>) type).isEnum()) {
19-
return (Converter<Enum<?>, String>) ProxerUtils::getApiEnumName;
19+
return (Converter<Enum<?>, String>) ProxerUtils::getSafeApiEnumName;
2020
}
2121

2222
return null;

library/src/main/java/me/proxer/library/api/LoggingInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.logging.Logger;
1717

1818
/**
19-
* @author Ruben Gees.
19+
* @author Ruben Gees
2020
*/
2121
@AllArgsConstructor
2222
class LoggingInterceptor implements Interceptor {

library/src/main/java/me/proxer/library/api/messenger/MessengerApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,6 @@ private String constructMessageFromAction(final MessageAction action, final Stri
121121
throw new IllegalArgumentException("Invalid action: " + action);
122122
}
123123

124-
return "/" + ProxerUtils.getApiEnumName(action) + " " + subject;
124+
return "/" + ProxerUtils.getSafeApiEnumName(action) + " " + subject;
125125
}
126126
}

library/src/main/java/me/proxer/library/entity/info/AnimeEpisode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Entity holding the data of a single anime episode.
1313
*
14-
* @author Ruben Gees.
14+
* @author Ruben Gees
1515
*/
1616
@ToString(callSuper = true)
1717
@EqualsAndHashCode(callSuper = true)

library/src/main/java/me/proxer/library/entity/info/EpisodeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Entity containing information about the available episodes or chapters of an media entry.
1515
*
16-
* @author Ruben Gees.
16+
* @author Ruben Gees
1717
*/
1818
@Value
1919
@EqualsAndHashCode(onParam = @__({@Nullable}))

library/src/main/java/me/proxer/library/entity/info/MangaEpisode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* Entity holding the data of a single anime chapter.
1313
*
14-
* @author Ruben Gees.
14+
* @author Ruben Gees
1515
*/
1616
@Getter
1717
@ToString(callSuper = true)

library/src/main/java/me/proxer/library/entity/info/Relation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* Entity representing a single relation of an {@link Entry}.
2222
*
23-
* @author Ruben Gees.
23+
* @author Ruben Gees
2424
*/
2525
@Value
2626
@EqualsAndHashCode(onParam = @__({@Nullable}))

library/src/main/java/me/proxer/library/util/ProxerUrls.java

Lines changed: 135 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import lombok.experimental.Accessors;
55
import lombok.experimental.UtilityClass;
66
import me.proxer.library.entity.notifications.NewsArticle;
7+
import me.proxer.library.enums.AnimeLanguage;
78
import me.proxer.library.enums.Device;
9+
import me.proxer.library.enums.Language;
810
import okhttp3.HttpUrl;
911

1012
import java.util.regex.Pattern;
@@ -62,6 +64,16 @@ public final class ProxerUrls {
6264
.addPathSegment("")
6365
.build();
6466

67+
/**
68+
* Returns the base url for all proxy links.
69+
*/
70+
private final HttpUrl proxyBase = new HttpUrl.Builder()
71+
.scheme("https")
72+
.host("prxr.me")
73+
.addPathSegment("img")
74+
.addPathSegment("")
75+
.build();
76+
6577
/**
6678
* Returns the image link of a {@link NewsArticle}, based on its
6779
* {@code id} and {@code image}.
@@ -95,6 +107,24 @@ public HttpUrl entryImage(final String id) {
95107
.build();
96108
}
97109

110+
/**
111+
* Returns the link to the image behind the proxy.
112+
*/
113+
public HttpUrl proxyImage(final HttpUrl url) {
114+
return proxyBase.newBuilder()
115+
.addQueryParameter("url", url.toString())
116+
.build();
117+
}
118+
119+
/**
120+
* Returns the link to the image behind the proxy.
121+
*/
122+
public HttpUrl proxyImage(final String url) {
123+
return proxyBase.newBuilder()
124+
.addQueryParameter("url", url)
125+
.build();
126+
}
127+
98128
/**
99129
* Returns the image link of the translator group.
100130
*/
@@ -118,7 +148,7 @@ public HttpUrl industryImage(final String id) {
118148
/**
119149
* Returns the image link of the hoster.
120150
*/
121-
public static HttpUrl hosterImage(final String id) {
151+
public HttpUrl hosterImage(final String id) {
122152
return webBase.newBuilder()
123153
.addPathSegment("images")
124154
.addPathSegment("hoster")
@@ -130,8 +160,7 @@ public static HttpUrl hosterImage(final String id) {
130160
* Returns the image link of the page, based on the {@code server} number, the {@code entryId}, the {@code id} of
131161
* the chapter and the file{@code name} of the page.
132162
*/
133-
public static HttpUrl mangaPageImage(final String server, final String entryId, final String id,
134-
final String name) {
163+
public HttpUrl mangaPageImage(final String server, final String entryId, final String id, final String name) {
135164
return new HttpUrl.Builder()
136165
.scheme("https")
137166
.host(String.format("manga%s.proxer.me", server))
@@ -145,105 +174,182 @@ public static HttpUrl mangaPageImage(final String server, final String entryId,
145174
/**
146175
* Returns the link for the donation web page.
147176
*/
148-
public HttpUrl donateWeb() {
177+
public HttpUrl donateWeb(final Device device) {
149178
return webBase.newBuilder()
150179
.addPathSegment("donate")
180+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
151181
.build();
152182
}
153183

154184
/**
155185
* Returns the link for the donation web page.
156186
*/
157-
public HttpUrl donateWeb(final Device device) {
158-
return donateWeb().newBuilder()
159-
.addQueryParameter("device", ProxerUtils.getApiEnumName(device))
160-
.build();
187+
public HttpUrl donateWeb() {
188+
return donateWeb(Device.DEFAULT);
161189
}
162190

163191
/**
164192
* Returns the link for the wiki web page, based on the {@code topic}.
165193
*/
166-
public static HttpUrl wikiWeb(final String topic) {
194+
public HttpUrl wikiWeb(final String topic) {
167195
return webBase.newBuilder()
168196
.addPathSegment("wiki")
169197
.addPathSegment(topic)
198+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(Device.DEFAULT))
170199
.build();
171200
}
172201

173202
/**
174203
* Returns the link for the user's web page.
175204
*/
176-
public HttpUrl userWeb(final String id) {
205+
public HttpUrl userWeb(final String id, final Device device) {
177206
return webBase.newBuilder()
178207
.addPathSegment("user")
179208
.addPathSegment(id)
209+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
180210
.build();
181211
}
182212

183213
/**
184214
* Returns the link for the user's web page.
185215
*/
186-
public HttpUrl userWeb(final String id, final Device device) {
187-
return userWeb(id).newBuilder()
188-
.addQueryParameter("device", ProxerUtils.getApiEnumName(device))
189-
.build();
216+
public HttpUrl userWeb(final String id) {
217+
return userWeb(id, Device.DEFAULT);
190218
}
191219

192220
/**
193221
* Returns the link for the web page of the requested forum thread, residing in the category, specified by the
194222
* {@code categoryId}.
195223
*/
196-
public HttpUrl forumWeb(final String categoryId, final String threadId) {
224+
public HttpUrl forumWeb(final String categoryId, final String threadId, final Device device) {
197225
return webBase.newBuilder()
198226
.addPathSegment("forum")
199227
.addPathSegment(categoryId)
200228
.addPathSegment(threadId)
229+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
201230
.build();
202231
}
203232

204233
/**
205234
* Returns the link for the web page of the requested forum thread, residing in the category, specified by the
206235
* {@code categoryId}.
207236
*/
208-
public HttpUrl forumWeb(final String categoryId, final String threadId, final Device device) {
209-
return forumWeb(categoryId, threadId).newBuilder()
210-
.addQueryParameter("device", ProxerUtils.getApiEnumName(device))
211-
.build();
237+
public HttpUrl forumWeb(final String categoryId, final String threadId) {
238+
return forumWeb(categoryId, threadId, Device.DEFAULT);
212239
}
213240

214241
/**
215242
* Returns the link for the web page of the requested news article, residing in the category, specified by the
216243
* {@code categoryId}.
217244
*/
218-
public HttpUrl newsWeb(final String categoryId, final String threadId) {
219-
return forumWeb(categoryId, threadId);
245+
public HttpUrl newsWeb(final String categoryId, final String threadId, final Device device) {
246+
return forumWeb(categoryId, threadId, device);
220247
}
221248

222249
/**
223250
* Returns the link for the web page of the requested news article, residing in the category, specified by the
224251
* {@code categoryId}.
225252
*/
226-
public HttpUrl newsWeb(final String categoryId, final String threadId, final Device device) {
227-
return forumWeb(categoryId, threadId, device);
253+
public HttpUrl newsWeb(final String categoryId, final String threadId) {
254+
return forumWeb(categoryId, threadId);
255+
}
256+
257+
/**
258+
* Returns the link for the web page of the requested info page.
259+
*/
260+
public HttpUrl infoWeb(final String id, final Device device) {
261+
return webBase.newBuilder()
262+
.addPathSegment("info")
263+
.addPathSegment(id)
264+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
265+
.build();
266+
}
267+
268+
/**
269+
* Returns the link for the web page of the requested industry.
270+
*/
271+
public HttpUrl infoWeb(final String id) {
272+
return infoWeb(id, Device.DEFAULT);
273+
}
274+
275+
/**
276+
* Returns the link for the web page of the requested industry.
277+
*/
278+
public HttpUrl industryWeb(final String id) {
279+
return webBase.newBuilder()
280+
.addPathSegment("industry")
281+
.addPathSegment(id)
282+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(Device.DEFAULT))
283+
.build();
284+
}
285+
286+
/**
287+
* Returns the link for the web page of the requested translator group.
288+
*/
289+
public HttpUrl translatorGroupWeb(final String id) {
290+
return webBase.newBuilder()
291+
.addPathSegment("translatorgroups")
292+
.addPathSegment(id)
293+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(Device.DEFAULT))
294+
.build();
295+
}
296+
297+
/**
298+
* Returns the link for the watch page of an anime.
299+
*/
300+
public HttpUrl animeWeb(final String id, final int episode, final AnimeLanguage language, final Device device) {
301+
return webBase.newBuilder()
302+
.addPathSegment("watch")
303+
.addPathSegment(id)
304+
.addPathSegment(String.valueOf(episode))
305+
.addPathSegment(ProxerUtils.getSafeApiEnumName(language))
306+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
307+
.build();
308+
}
309+
310+
/**
311+
* Returns the link for the watch page of an anime.
312+
*/
313+
public HttpUrl animeWeb(final String id, final int episode, final AnimeLanguage language) {
314+
return animeWeb(id, episode, language, Device.DEFAULT);
315+
}
316+
317+
/**
318+
* Returns the link for the read page of a manga.
319+
*/
320+
public HttpUrl mangaWeb(final String id, final int episode, final Language language, final Device device) {
321+
return webBase.newBuilder()
322+
.addPathSegment("chapter")
323+
.addPathSegment(id)
324+
.addPathSegment(String.valueOf(episode))
325+
.addPathSegment(ProxerUtils.getSafeApiEnumName(language))
326+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
327+
.build();
328+
}
329+
330+
/**
331+
* Returns the link for the read page of a manga.
332+
*/
333+
public HttpUrl mangaWeb(final String id, final int episode, final Language language) {
334+
return mangaWeb(id, episode, language, Device.DEFAULT);
228335
}
229336

230337
/**
231338
* Returns the link for the web page to solve the captcha.
232339
*/
233-
public HttpUrl captchaWeb() {
340+
public HttpUrl captchaWeb(final Device device) {
234341
return webBase.newBuilder()
235342
.addPathSegment("misc")
236343
.addPathSegment("captcha")
344+
.addQueryParameter("device", ProxerUtils.getSafeApiEnumName(device))
237345
.build();
238346
}
239347

240348
/**
241349
* Returns the link for the web page to solve the captcha.
242350
*/
243-
public HttpUrl captchaWeb(final Device device) {
244-
return captchaWeb().newBuilder()
245-
.addQueryParameter("device", device == Device.DEFAULT ? "default" : "mobile")
246-
.build();
351+
public HttpUrl captchaWeb() {
352+
return captchaWeb(Device.DEFAULT);
247353
}
248354

249355
/**
@@ -258,7 +364,7 @@ public boolean hasProxerHost(final HttpUrl url) {
258364
*/
259365
public boolean hasProxerWebOrCdnOrStreamHost(final HttpUrl url) {
260366
return url.host().equals(webBase.host()) || url.host().equals(cdnBase.host())
261-
|| url.host().equals(streamBase.host());
367+
|| url.host().equals(proxyBase.host()) || url.host().equals(streamBase.host());
262368
}
263369

264370
/**

0 commit comments

Comments
 (0)