File tree Expand file tree Collapse file tree 7 files changed +126
-0
lines changed
main/kotlin/me/proxer/library
kotlin/me/proxer/library/api/wiki Expand file tree Collapse file tree 7 files changed +126
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import me.proxer.library.api.messenger.MessengerApi
1616import me.proxer.library.api.notifications.NotificationsApi
1717import me.proxer.library.api.ucp.UcpApi
1818import me.proxer.library.api.user.UserApi
19+ import me.proxer.library.api.wiki.WikiApi
1920import me.proxer.library.internal.DefaultLoginTokenManager
2021import me.proxer.library.internal.adapter.BooleanAdapterFactory
2122import me.proxer.library.internal.adapter.ConferenceAdapter
@@ -146,6 +147,12 @@ class ProxerApi private constructor(retrofit: Retrofit) {
146147 val comment = CommentApi (retrofit)
147148 @JvmName(" comment" ) get
148149
150+ /* *
151+ * The respective API.
152+ */
153+ val wiki = WikiApi (retrofit)
154+ @JvmName(" wiki" ) get
155+
149156 /* *
150157 *
151158 * You can set customized instances of the internally used libraries: Moshi, OkHttp and Retrofit.
Original file line number Diff line number Diff line change 1+ package me.proxer.library.api.wiki
2+
3+ import me.proxer.library.ProxerCall
4+ import me.proxer.library.entity.wiki.WikiPage
5+ import retrofit2.http.GET
6+ import retrofit2.http.Query
7+
8+ /* *
9+ * @author Ruben Gees
10+ */
11+ internal interface InternalApi {
12+
13+ @GET(" wiki/content" )
14+ fun content (@Query(" title" ) title : String ): ProxerCall <WikiPage >
15+ }
Original file line number Diff line number Diff line change 1+ package me.proxer.library.api.wiki
2+
3+ import retrofit2.Retrofit
4+
5+ /* *
6+ * API for the User class.
7+ *
8+ * @author Ruben Gees
9+ */
10+ class WikiApi internal constructor(retrofit : Retrofit ) {
11+
12+ private val internalApi = retrofit.create(InternalApi ::class .java)
13+
14+ /* *
15+ * Returns the respective endpoint.
16+ */
17+ fun content (title : String ): WikiContentEndpoint {
18+ return WikiContentEndpoint (internalApi, title)
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package me.proxer.library.api.wiki
2+
3+ import me.proxer.library.ProxerCall
4+ import me.proxer.library.api.Endpoint
5+ import me.proxer.library.entity.wiki.WikiPage
6+
7+ /* *
8+ * Endpoint for requesting the content of a proxer wiki page.
9+ *
10+ * @author Ruben Gees
11+ */
12+ class WikiContentEndpoint internal constructor(
13+ private val internalApi : InternalApi ,
14+ private val title : String
15+ ) : Endpoint<WikiPage> {
16+
17+ override fun build (): ProxerCall <WikiPage > {
18+ return internalApi.content(title)
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package me.proxer.library.entity.wiki
2+
3+ import com.squareup.moshi.Json
4+ import com.squareup.moshi.JsonClass
5+
6+ /* *
7+ * Entity representing a page of the proxer wiki.
8+ *
9+ * @property type The type of the source content. Might be something like "html" or "markdown".
10+ * @property content The content of the page as html.
11+ */
12+ @JsonClass(generateAdapter = true )
13+ data class WikiPage (
14+ @Json(name = " type" ) val type : String ,
15+ @Json(name = " content" ) val content : String
16+ )
Original file line number Diff line number Diff line change 1+ package me.proxer.library.api.wiki
2+
3+ import me.proxer.library.ProxerTest
4+ import me.proxer.library.entity.wiki.WikiPage
5+ import me.proxer.library.runRequest
6+ import org.amshove.kluent.shouldEqual
7+ import org.junit.jupiter.api.Test
8+
9+ /* *
10+ * @author Ruben Gees
11+ */
12+ class WikiContentEndpointTest : ProxerTest () {
13+
14+ private val expectedContent = WikiPage (
15+ " html" ,
16+ " <b>Some content</b>"
17+ )
18+
19+ @Test
20+ fun testDefault () {
21+ val (result, _) = server.runRequest(" wiki_content.json" ) {
22+ api.wiki.content(" abc" )
23+ .build()
24+ .execute()
25+ }
26+
27+ result shouldEqual expectedContent
28+ }
29+
30+ @Test
31+ fun testPath () {
32+ val (_, request) = server.runRequest(" wiki_content.json" ) {
33+ api.wiki.content(" abc" )
34+ .build()
35+ .execute()
36+ }
37+
38+ request.path shouldEqual " /api/v1/wiki/content?title=abc"
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ {
2+ "error" : 0 ,
3+ "message" : " Abfrage erfolgreich" ,
4+ "data" : {
5+ "type" : " html" ,
6+ "content" : " <b>Some content</b>"
7+ }
8+ }
You can’t perform that action at this time.
0 commit comments