Skip to content
This repository has been archived by the owner on Nov 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #10 from GSculerlor/user-endpoints
Browse files Browse the repository at this point in the history
Implement user endpoints
  • Loading branch information
GSculerlor authored Apr 27, 2020
2 parents c9378f8 + 16ebc3b commit 8106d84
Show file tree
Hide file tree
Showing 28 changed files with 964 additions and 50 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ repositories {
}

group = "com.github.GSculerlor"
version = "1.1.0"
version = "1.1.2"

dependencies {
implementation(kotlin("stdlib-jdk8"))

//Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.5")

//Ktor
implementation("io.ktor:ktor-client-core:1.2.1")
Expand Down
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
kotlin.code.style=official
group=moe.ganen
version=1.1.0
kotlin.code.style=official
2 changes: 1 addition & 1 deletion src/main/kotlin/moe/ganen/jikankt/JikanClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ open class JikanClient {

companion object {
private const val JIKANKT_NAME = "JikanKt"
private const val JIKANKT_VERSION = "1.1.0"
private const val JIKANKT_VERSION = "1.1.2"
}
}
126 changes: 124 additions & 2 deletions src/main/kotlin/moe/ganen/jikankt/JikanKt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import moe.ganen.jikankt.models.season.Season
import moe.ganen.jikankt.models.season.SeasonArchives
import moe.ganen.jikankt.models.season.SeasonType
import moe.ganen.jikankt.models.top.*
import moe.ganen.jikankt.models.user.*
import moe.ganen.jikankt.models.user.enums.AnimeStatusType
import moe.ganen.jikankt.models.user.enums.HistoryType
import moe.ganen.jikankt.models.user.enums.MangaStatusType
import moe.ganen.jikankt.utils.InterfaceAdapter
import moe.ganen.jikankt.utils.deserialize

Expand Down Expand Up @@ -361,7 +365,7 @@ object JikanKt {
additionalQuery: AnimeSearchQuery? = null,
page: Int? = 1
): AnimeSearchResult {
val formattedQuery = query.replace(" ", "_")
val formattedQuery = query.replace(" ", "%20")
val formattedAdditionalQuery = additionalQuery?.toString() ?: ""

return gson.deserialize(
Expand Down Expand Up @@ -405,7 +409,7 @@ object JikanKt {
additionalQuery: MangaSearchQuery? = null,
page: Int? = 1
): MangaSearchResult {
val formattedQuery = query.replace(" ", "_")
val formattedQuery = query.replace(" ", "%20")
val formattedAdditionalQuery = additionalQuery?.toString() ?: ""

return gson.deserialize(
Expand Down Expand Up @@ -435,4 +439,122 @@ object JikanKt {
//endregion

//endregion

//region User

/**
* Fetches MyAnimeList user related data.
* Note: About is returned in HTML as MyAnimeList allows custom "about" sections for users that can consist of images,
* formatting, etc.
* @param username: User's username on MyAnimeList.
* @return User's profile data.
*/
suspend fun getUser(username: String): User = gson.deserialize(
restClient.request("user/$username/"),
User::class.java
)

/**
* Fetches MyAnimeList user's history.
* @param username: User's username on MyAnimeList.
* @param type: History type (Anime, manga).
* @return User's profile data.
*/
suspend fun getUserHistory(username: String, type: HistoryType = HistoryType.All): UserHistory = gson.deserialize(
restClient.request("user/$username/history/${if (type != HistoryType.All) type.name.toLowerCase() else ""}"),
UserHistory::class.java
)

/**
* Fetches MyAnimeList user's friend.
* @param username: User's username on MyAnimeList.
* @param page: Optional, default is 1. Index of page.
* @return User's profile data.
*/
suspend fun getUserFriends(username: String, page: Int = 1): UserFriends = gson.deserialize(
restClient.request("user/$username/friends/$page"),
UserFriends::class.java
)

/**
* Fetches MyAnimeList user's anime list.
* @param username: User's username on MyAnimeList.
* @param filter: Optional, filter list.
* @param page: Optional, default is 1. Index of page.
* @return User's anime list.
*/
suspend fun getUserAnimeList(
username: String,
filter: AnimeStatusType = AnimeStatusType.All,
page: Int = 1
): UserAnimeList = gson.deserialize(
restClient.request("user/$username/animelist/${filter.name.toLowerCase()}/$page"),
UserAnimeList::class.java
)

/**
* Fetches MyAnimeList user's manga list.
* @param username: User's username on MyAnimeList.
* @param filter: Optional, filter list.
* @param page: Optional, default is 1. Index of page.
* @return User's manga list.
*/
suspend fun getUserMangaList(
username: String,
filter: MangaStatusType = MangaStatusType.All,
page: Int = 1
): UserMangaList = gson.deserialize(
restClient.request("user/$username/mangalist/${filter.name.toLowerCase()}/$page"),
UserMangaList::class.java
)

/**
* Fetches MyAnimeList user's anime list.
* @param username: User's username on MyAnimeList.
* @param query: Query to filter by.
* @param additionalQuery: Optional, additional query.
* @param page: Optional, default is 1. Index of page.
* @return User's anime list.
*/
suspend fun getUserAnimeList(
username: String,
query: String,
page: Int? = 1,
additionalQuery: AnimeListSearchQuery? = null
): UserAnimeList {
val formattedQuery = query.replace(" ", "%20")
val formattedAdditionalQuery = additionalQuery?.toString() ?: ""
val formattedPage = "&page=${page}"

return gson.deserialize(
restClient.request("user/$username/animelist?q=${formattedQuery}${formattedAdditionalQuery}${formattedPage}"),
UserAnimeList::class.java
)
}

/**
* Fetches MyAnimeList user's manga list.
* @param username: User's username on MyAnimeList.
* @param query: Query to filter by.
* @param additionalQuery: Optional, additional query.
* @param page: Optional, default is 1. Index of page.
* @return User's manga list.
*/
suspend fun getUserMangaList(
username: String,
query: String,
page: Int? = 1,
additionalQuery: MangaListSearchQuery? = null
): UserMangaList {
val formattedQuery = query.replace(" ", "%20")
val formattedAdditionalQuery = additionalQuery?.toString() ?: ""
val formattedPage = "&page=${page}"

return gson.deserialize(
restClient.request("user/$username/mangalist?q=${formattedQuery}${formattedAdditionalQuery}${formattedPage}"),
UserMangaList::class.java
)
}

//endregion
}
2 changes: 1 addition & 1 deletion src/main/kotlin/moe/ganen/jikankt/models/anime/Anime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package moe.ganen.jikankt.models.anime
import com.google.gson.annotations.SerializedName
import moe.ganen.jikankt.models.base.Entity
import moe.ganen.jikankt.models.base.MalEntity
import moe.ganen.jikankt.models.base.enum.AnimeType
import moe.ganen.jikankt.models.base.types.MalSubEntity
import moe.ganen.jikankt.models.base.types.RelatedAnime
import moe.ganen.jikankt.models.base.types.TimeInterval
import moe.ganen.jikankt.models.search.enums.AnimeType

/**
* Anime data class.
Expand Down
36 changes: 0 additions & 36 deletions src/main/kotlin/moe/ganen/jikankt/models/base/enum/AnimeType.kt

This file was deleted.

138 changes: 138 additions & 0 deletions src/main/kotlin/moe/ganen/jikankt/models/base/types/AnimeListEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package moe.ganen.jikankt.models.base.types

import com.google.gson.annotations.SerializedName
import moe.ganen.jikankt.models.base.MalEntity
import java.util.*

data class AnimeListEntity(
/**
* ID associated with MyAnimeList.
*/
@SerializedName("mal_id")
override val malId: Int,

/**
* Title of the anime.
*/
@SerializedName("title")
val title: String? = null,

/**
* Anime's MyAnimeList link.
*/
@SerializedName("url")
val url: String? = null,

/**
* Anime's MyAnimeList cover/image link.
*/
@SerializedName("image_url")
val imageUrl: String? = null,

/**
* Anime video's MyAnimeList URL
*/
@SerializedName("video_url")
val videoUrl: String? = null,

/**
* Type of the anime.
*/
@SerializedName("type")
val type: String? = null,

/**
* User's amount of watched episodes.
*/
@SerializedName("watched_episodes")
val episodesWatched: Int? = null,

/**
* Anime's episodes total count.
*/
@SerializedName("total_episodes")
val episodesTotal: Int? = null,

/**
* User's score on this anime.
*/
@SerializedName("score")
val score: Double? = null,
/**
* Whether anime have episode video.
*/
@SerializedName("has_episode_video")
val hasEpisodeVideo: Boolean? = null,

/**
* Whether anime have promo video.
*/
@SerializedName("has_promo_video")
val hasPromoVideo: Boolean? = null,

/**
* Whether anime have video.
*/
@SerializedName("has_video")
val hasVideo: Boolean? = null,

/**
* Whether user is currently rewatching this anime.
*/
@SerializedName("is_rewatching")
val isRewatching: Boolean? = null,

/**
* Age rating of the anime.
*/
@SerializedName("rating")
val rating: String? = null,

/**
* Anime start date.
*/
@SerializedName("start_date")
val startDate: Date? = null,

/**
* Anime end date.
*/
@SerializedName("end_date")
val endDate: Date? = null,

/**
* User's start date watching the anime.
*/
@SerializedName("watch_start_date")
val startWatchDate: Date? = null,

/**
* User's finished date watching the anime.
*/
@SerializedName("watch_end_date")
val endWatchDate: Date? = null,

/**
* Total amount of days user has been watching anime.
*/
@SerializedName("days")
val days: Int? = null,

/**
* Priority of anime on user's list.
*/
@SerializedName("priority")
val priority: String? = null,

/**
* Current airing status of anime.
*/
@SerializedName("airing_status")
val airingStatus: String? = null,

/**
* Current user's watching status of anime.
*/
@SerializedName("watching_status")
val watchingStatus: String? = null
) : MalEntity
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package moe.ganen.jikankt.models.base.types

import com.google.gson.annotations.SerializedName
import moe.ganen.jikankt.models.base.MalEntity
import moe.ganen.jikankt.models.base.enum.AnimeType
import moe.ganen.jikankt.models.search.enums.AnimeType
import java.util.*

data class AnimeSearchSubEntity(
Expand Down
Loading

0 comments on commit 8106d84

Please sign in to comment.