Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
- Bug fixing
Browse files Browse the repository at this point in the history
- Deprecation of Connector.kt finished, all functions moved out to Companion / JVMStatic Companion
  • Loading branch information
Doomsdayrs committed Jan 7, 2021
1 parent 0ffa5b7 commit ad77048
Show file tree
Hide file tree
Showing 38 changed files with 570 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal fun getDefaultOkHttpClient() = OkHttpClient().let {

internal fun getDefaultJSONParser() = Json {
encodeDefaults = true
prettyPrint = true
coerceInputValues = true
}

Expand Down
132 changes: 52 additions & 80 deletions src/main/java/com/github/doomsdayrs/jikan4java/core/Connector.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.doomsdayrs.jikan4java.core

import com.github.doomsdayrs.jikan4java.common.JIKAN_URL
import com.github.doomsdayrs.jikan4java.data.enums.Days
import com.github.doomsdayrs.jikan4java.data.enums.Season
import com.github.doomsdayrs.jikan4java.data.enums.meta.MetaPeriod
import com.github.doomsdayrs.jikan4java.data.enums.meta.MetaRequest
Expand All @@ -15,10 +14,9 @@ import com.github.doomsdayrs.jikan4java.data.model.main.manga.Manga
import com.github.doomsdayrs.jikan4java.data.model.main.meta.Meta
import com.github.doomsdayrs.jikan4java.data.model.main.person.Person
import com.github.doomsdayrs.jikan4java.data.model.main.producer.ProducerPage
import com.github.doomsdayrs.jikan4java.data.model.main.schedule.Day
import com.github.doomsdayrs.jikan4java.data.model.main.schedule.SchedulePage
import com.github.doomsdayrs.jikan4java.data.model.main.season.SeasonSearch
import com.github.doomsdayrs.jikan4java.data.model.main.season.seasonarchive.SeasonArchive
import com.github.doomsdayrs.jikan4java.data.model.main.season.SeasonPage
import com.github.doomsdayrs.jikan4java.data.model.main.season.seasonarchive.SeasonArchivePage
import com.github.doomsdayrs.jikan4java.data.model.main.user.User
import java.util.concurrent.CompletableFuture

Expand Down Expand Up @@ -46,41 +44,36 @@ import java.util.concurrent.CompletableFuture
class Connector(
val retriever: Retriever
) {
/**
* Returns current schedule for all anime
*
* @return Schedule
*/
@Deprecated(
"Moved to companion",
replaceWith = ReplaceWith("SchedulePage.getSchedule(retriever)")
)
val currentSchedulePage: CompletableFuture<JikanResult<SchedulePage>>
get() = retriever("$JIKAN_URL/schedule")
get() = SchedulePage.getSchedule(retriever)

@Deprecated(
"Moved to companion",
replaceWith = ReplaceWith("Club.getByID(retriever,ID)")
)
fun retrieveClub(ID: Int) = Club.getByID(retriever, ID)

/**
* 35 per page
*
* @param id of club
* @param page page
* @return Members
*/

@Deprecated(
"Moved to companion",
ReplaceWith("ClubMemberPage.get(retriever,id,1)")
)
@Suppress("MemberVisibilityCanBePrivate")
fun getMembers(
id: Int,
page: Int
): CompletableFuture<JikanResult<ClubMemberPage>> =
retriever("$JIKAN_URL/club/$id/members/$page")
ClubMemberPage.get(retriever, id, page)

/**
* Returns first page, 35 count
*
* @param id of club
* @return Members
*/
@Deprecated("Removal warning", ReplaceWith("getMembers(id,1)"))

@Deprecated(
"Moved to companion",
ReplaceWith("ClubMemberPage.get(retriever,id,1)")
)
fun getMembers(id: Int) = getMembers(id, 1)

@Deprecated(
Expand Down Expand Up @@ -120,40 +113,34 @@ class Connector(
)
fun getCharacterPictures(id: Int) = Character.getPictures(retriever, id)

/**
* Returns a user object
*
* @param name the name of the user to retrieve
* @return User
*/
@Deprecated(
"Moved to companion",
replaceWith = ReplaceWith("User.getByName(retriever,name)")
)
fun userRetrieve(name: String): CompletableFuture<JikanResult<User>> =
User.getByName(retriever, name)

/**
* Retrieves Magazines
*
* @param ID ID of magazine
* @param page page to core for
* @return MagazinePage object
*/

@Deprecated(
"Moved to companion",
replaceWith = ReplaceWith("MagazinePage.get(retriever,ID,page)")
)
fun magazineSearch(
ID: Int,
page: Int
): CompletableFuture<JikanResult<MagazinePage>> =
retriever("$JIKAN_URL/magazine/$ID/$page")
MagazinePage.get(retriever, ID, page)

/**
* Gets meta data from API. WARNING USING MAY CAUSE ERRORS BEYOND IMAGINATION FOR ANYTHING BUT STATUS
* Gets meta data from API.
* WARNING USING MAY CAUSE ERRORS BEYOND IMAGINATION FOR ANYTHING BUT STATUS
*
* @param metaRequest REQUEST / STATUS
* @param metaType ANIME / CHARACTER / MANGA / PERSON / SEARCH / SCHEDULE / SEASON / TOP
* @param metaPeriod MONTHLY / WEEKLY / TODAY
* @return Completable future of metaRequest's class
*/
@Deprecated("Just don't use ever, Look at the JikanStatus object and use its get")
inline fun <reified T : Class<V>, V : Meta> getMeta(
metaRequest: MetaRequest,
metaType: MetaType,
Expand All @@ -169,54 +156,39 @@ class Connector(
return retriever("$JIKAN_URL/meta/$option")
}

/**
* Retrieves Producer
*
* @param ID ID of magazine
* @param page page to core for
* @return Producer object
*/
@Deprecated(
"Moved to companion",
ReplaceWith(
"ProducerPage.search(retriever,ID,page)",
"com.github.doomsdayrs.jikan4java.data.model.main.producer.ProducerPage"
)
)
fun producerSearch(
ID: Int,
page: Int
): CompletableFuture<JikanResult<ProducerPage>> =
retriever("$JIKAN_URL/producer/$ID/$page")
) = ProducerPage.search(retriever, ID, page)

/**
* Returns all anime schedule on a certain day
*
* @param day Day to retrieve, Can also be other or unknown
* @return DaySchedule object
*/
fun scheduleSearch(day: Days): CompletableFuture<JikanResult<Day>> =
retriever("$JIKAN_URL/schedule/$day")

/**
* Searches for anime by season
*
* @param year Year
* @param season Season
* @return SeasonSearchObject
*/
@Deprecated(
"Moved to companion",
ReplaceWith("SeasonPage.get(retriever,year,season)")
)
fun seasonSearch(
year: Int,
season: Season
): CompletableFuture<JikanResult<SeasonSearch>> =
retriever("$JIKAN_URL/season/$year/$season")
): CompletableFuture<JikanResult<SeasonPage>> =
SeasonPage.get(retriever, year, season)

/**
* Returns next season of anime
*
* @return SeasonSearchObject
*/
fun seasonLater(): CompletableFuture<JikanResult<SeasonSearch>> =
retriever("$JIKAN_URL/season/later")

/**
* Returns archive of all possible seasons and years
*
* @return SeasonArchive
*/
fun seasonArchive(): CompletableFuture<JikanResult<SeasonArchive>> =
retriever("$JIKAN_URL/season/archive")
@Deprecated(
"Moved to companion",
ReplaceWith("SeasonPage.getNextSeason(retriever)")
)
fun seasonLater() = SeasonPage.getNextSeason(retriever)

@Deprecated(
"Moved to companion",
ReplaceWith("SeasonArchivePage.get(retriever)")
)
fun seasonArchive() = SeasonArchivePage.get(retriever)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.doomsdayrs.jikan4java.data.exceptions.RequestError
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.future.future
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.*
import okhttp3.OkHttpClient
import okhttp3.Request
Expand Down Expand Up @@ -76,7 +77,7 @@ class Retriever(

if (debugMode)
println(
"JSONOBJECT: $jsonElement"
"JSONOBJECT:\n${format.encodeToString(jsonElement)}"
)

val jsonObject: JsonObject = jsonElement.jsonObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import java.util.concurrent.CompletableFuture
*
* @author github.com/doomsdayrs
*/
interface MyAnimeListSelfType<SELF> : MyAnimeListEntityPoint {
interface MyAnimeListSelfType<SELF> {

/**
* Gets [SELF] by it's ID
Expand Down
41 changes: 0 additions & 41 deletions src/main/java/com/github/doomsdayrs/jikan4java/data/enums/Days.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.doomsdayrs.jikan4java.data.enums.meta

import com.github.doomsdayrs.jikan4java.data.model.main.meta.Status
import com.github.doomsdayrs.jikan4java.data.model.main.meta.JikanStatus

/*
* This file is part of Jikan4java.
Expand All @@ -25,7 +25,7 @@ import com.github.doomsdayrs.jikan4java.data.model.main.meta.Status
*/
enum class MetaRequest(private val type: String, val aClass: Class<*>?) {
REQUEST("requests", null),
STATUS("status", Status::class.java);
STATUS("status", JikanStatus::class.java);

override fun toString(): String = type
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,11 @@ data class Anime(

companion object : MyAnimeListSelfType<Anime>,
MyAnimeListDirectPicturesEndPoint {
@JvmStatic
override fun getByID(retriever: Retriever, id: Int) =
retriever<Anime>("$JIKAN_URL/$urlPoint/$id")

override val urlPoint: String by lazy { "anime" }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ data class Character(
MyAnimeListDirectPicturesEndPoint {
override val urlPoint: String by lazy { "character" }

@JvmStatic
override fun getByID(
retriever: Retriever,
id: Int
Expand Down
Loading

0 comments on commit ad77048

Please sign in to comment.