Repository navigation
Expand file tree
/
Copy pathRoutes.java
More file actions
160 lines (130 loc) · 5.91 KB
/
Copy pathRoutes.java
File metadata and controls
160 lines (130 loc) · 5.91 KB
1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package io.getstream.core.utils;
import com.google.common.base.Joiner;
import io.getstream.core.models.FeedID;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
public final class Routes {
private static final String basePath = "/api/v1.0/";
private static final String analyticsPath = "/analytics/v1.0/";
private static final String personalizationPath = "/personalization/v1.0/";
private static final String analyticsSubdomain = "analytics";
private static final String personalizationSubdomain = "personalization";
private static final String activitiesPath = "activities/";
private static final String activityUpdatePath = "activity/";
private static final String addToManyPath = "feed/add_to_many/";
private static final String followManyPath = "follow_many/";
private static final String unfollowManyPath = "unfollow_many/";
private static final String collectionsPath = "collections/";
private static final String filesPath = "files/";
private static final String imagesPath = "images/";
private static final String openGraphPath = "og/";
private static final String reactionsPath = "reaction/";
private static final String toTargetUpdatePath = "/activity_to_targets/";
private static final String usersPath = "user/";
private static final String followStatsPath = "stats/follow/";
private Routes() {
/* nothing to see here */
}
public static URL buildFeedURL(URL baseURL, FeedID feed, String path)
throws MalformedURLException {
return new URL(baseURL, basePath + feedPath(feed) + path);
}
public static URL buildEnrichedFeedURL(URL baseURL, FeedID feed, String path)
throws MalformedURLException {
return new URL(baseURL, basePath + enrichedFeedPath(feed) + path);
}
public static URL buildToTargetUpdateURL(URL baseURL, FeedID feed) throws MalformedURLException {
return new URL(baseURL, basePath + feedTargetsPath(feed) + toTargetUpdatePath);
}
public static URL buildActivitiesURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + activitiesPath);
}
public static URL buildEnrichedActivitiesURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + enriched(activitiesPath));
}
public static URL buildCollectionsURL(URL baseURL, String path) throws MalformedURLException {
return new URL(baseURL, basePath + collectionsPath + path);
}
public static URL buildReactionsURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + reactionsPath);
}
public static URL buildReactionsURL(URL baseURL, String path) throws MalformedURLException {
return new URL(baseURL, basePath + reactionsPath + path);
}
public static URL buildUsersURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + usersPath);
}
public static URL buildUsersURL(URL baseURL, String path) throws MalformedURLException {
return new URL(baseURL, basePath + usersPath + path);
}
public static URL buildBatchCollectionsURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + collectionsPath);
}
public static URL buildOpenGraphURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + openGraphPath);
}
public static URL buildFilesURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + filesPath);
}
public static URL buildImagesURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + imagesPath);
}
public static URL buildPersonalizationURL(URL baseURL, String path) throws MalformedURLException {
return buildSubdomainPath(baseURL, personalizationSubdomain, personalizationPath, path);
}
public static URL buildAnalyticsURL(URL baseURL, String path) throws MalformedURLException {
return buildSubdomainPath(baseURL, analyticsSubdomain, analyticsPath, path);
}
public static URL buildActivityUpdateURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + activityUpdatePath);
}
public static URL buildAddToManyURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + addToManyPath);
}
public static URL buildFollowManyURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + followManyPath);
}
public static URL buildUnfollowManyURL(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + unfollowManyPath);
}
public static URL followStatsPath(URL baseURL) throws MalformedURLException {
return new URL(baseURL, basePath + followStatsPath);
}
private static URL buildSubdomainPath(URL baseURL, String subdomain, String apiPath, String path)
throws MalformedURLException {
try {
URI baseURI = baseURL.toURI();
String[] parts = baseURI.getHost().split("\\.");
// assume at minimum host will have name and TLD parts
if (parts.length > 2) {
// replace first subdomain
parts[0] = subdomain;
}
return new URI(
baseURI.getScheme(),
baseURI.getUserInfo(),
Joiner.on(".").join(parts),
baseURI.getPort(),
baseURI.getPath() + apiPath + path,
baseURI.getQuery(),
null)
.toURL();
} catch (URISyntaxException e) {
throw new MalformedURLException(e.getReason());
}
}
private static String feedPath(FeedID feed) {
return String.format("feed/%s/%s", feed.getSlug(), feed.getUserID());
}
private static String feedTargetsPath(FeedID feed) {
return String.format("feed_targets/%s/%s", feed.getSlug(), feed.getUserID());
}
private static String enrichedFeedPath(FeedID feed) {
return String.format("enrich/feed/%s/%s", feed.getSlug(), feed.getUserID());
}
private static String enriched(String url) {
return String.format("enrich/%s", url);
}
}