Skip to content

Commit

Permalink
Merge pull request #8 from mille5a9/dev
Browse files Browse the repository at this point in the history
Use gson instead of kotlinx.serialization
  • Loading branch information
mille5a9 authored Dec 31, 2023
2 parents 85f078e + bb32423 commit 90eae5c
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 107 deletions.
4 changes: 2 additions & 2 deletions api-nba-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ val ossrhUsername: String by project
val ossrhPassword: String by project

group = "io.github.mille5a9"
version = "1.0.3-alpha"
version = "1.0.4-alpha"
description = "Unofficial wrapper for the API-SPORTS NBA API"

plugins {
Expand Down Expand Up @@ -41,8 +41,8 @@ dependencies {
implementation(libs.guava)

api("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-serialization-gson:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")

testImplementation("io.ktor:ktor-client-mock:$ktorVersion")
Expand Down
5 changes: 2 additions & 3 deletions api-nba-kotlin/src/main/kotlin/api/nba/kotlin/ApiNbaClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.parameter
import io.ktor.client.request.url
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json
import io.ktor.serialization.gson.gson


/**
Expand All @@ -43,7 +42,7 @@ class ApiNbaClient(
}

private val httpClient: HttpClient = HttpClient(httpClientEngine ?: CIO.create()) {
install(ContentNegotiation) { json(Json { isLenient = true }) }
install(ContentNegotiation) { gson { setLenient() } }
install(HttpCache)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ data class Parameters(
*
* @return the parameters map.
*/
fun getParams(): Map<String, String?> = mapOf(
"id" to id?.toString(),
"game" to game?.toString(),
"season" to season?.toString(),
"team" to team?.toString(),
fun getParams(): Map<String, Any?> = mapOf(
"id" to id,
"game" to game,
"season" to season,
"team" to team,
"league" to league,
"conference" to conference,
"division" to division,
Expand Down
3 changes: 0 additions & 3 deletions api-nba-kotlin/src/main/kotlin/api/nba/kotlin/models/Team.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package api.nba.kotlin.models

import kotlinx.serialization.Serializable

/**
* Represents an NBA team.
*
Expand All @@ -11,7 +9,6 @@ import kotlinx.serialization.Serializable
* @property code The code of the team.
* @property logo The URL of the team's logo.
*/
@Serializable
data class Team(
val id: Int,
val name: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package api.nba.kotlin.responses

import api.nba.kotlin.serializers.MapSerializer
import kotlinx.serialization.Serializable

/**
* Represents the response returned from an API endpoint.
*
Expand All @@ -14,10 +11,9 @@ import kotlinx.serialization.Serializable
* @property response The response data, represented as a list of type T.
* @constructor Creates a new instance of EndpointResponse.
*/
@Serializable
data class EndpointResponse<T : Any>(
val get: String,
@Serializable(with = MapSerializer::class) val parameters: Map<String, String>,
val parameters: Map<String, String>,
val errors: List<String>,
val results: Int,
val response: List<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.nba.kotlin.responses

import api.nba.kotlin.models.Team
import kotlinx.serialization.Serializable

/**
* Represents the response data for retrieving games from the NBA API.
Expand All @@ -21,7 +20,6 @@ import kotlinx.serialization.Serializable
* @param leadChanges The number of lead changes in the game.
* @param nugget Additional information about the game.
*/
@Serializable
data class GamesResponse(
val id: Int,
val league: String,
Expand All @@ -46,7 +44,6 @@ data class GamesResponse(
* @property end The end timestamp of the date.
* @property duration The duration of the date.
*/
@Serializable
data class Date(
val start: String,
val end: String?,
Expand All @@ -61,7 +58,6 @@ data class GamesResponse(
* @property short The short representation of the game status.
* @property long The long representation of the game status.
*/
@Serializable
data class Status(
val clock: String?,
val halftime: Boolean?,
Expand All @@ -76,7 +72,6 @@ data class GamesResponse(
* @property total The total number of periods in the game.
* @property endOfPeriod Indicates if the current period has ended.
*/
@Serializable
data class Periods(
val current: Int,
val total: Int,
Expand All @@ -91,7 +86,6 @@ data class GamesResponse(
* @property state The state where the arena is located.
* @property country The country where the arena is located.
*/
@Serializable
data class Arena(
val name: String?,
val city: String?,
Expand All @@ -105,7 +99,6 @@ data class GamesResponse(
* @property visitors The visiting team.
* @property home The home team.
*/
@Serializable
data class Teams(
val visitors: Team,
val home: Team,
Expand All @@ -117,7 +110,6 @@ data class GamesResponse(
* @property visitors The visiting team's score.
* @property home The home team's score.
*/
@Serializable
data class Scores(
val visitors: Score,
val home: Score,
Expand All @@ -132,7 +124,6 @@ data class GamesResponse(
* @property linescore The linescore of the game.
* @property points The total number of points.
*/
@Serializable
data class Score(
val win: Int?,
val loss: Int?,
Expand All @@ -147,7 +138,6 @@ data class GamesResponse(
* @property win The number of wins.
* @property loss The number of losses.
*/
@Serializable
data class Series(
val win: Int?,
val loss: Int?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package api.nba.kotlin.responses

import api.nba.kotlin.models.Team
import kotlinx.serialization.Serializable

@Serializable
data class GamesStatisticsResponse(
val team: Team,
val statistics: List<GameStatistics>,
Expand Down Expand Up @@ -37,7 +35,6 @@ data class GamesStatisticsResponse(
* @property blocks The number of blocks.
* @property plusMinus The plus/minus of the team.
*/
@Serializable
data class GameStatistics(
val fastBreakPoints: Int,
val pointsInPaint: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package api.nba.kotlin.responses

import kotlinx.serialization.Serializable

/**
* Represents a response object for retrieving player information.
*
Expand All @@ -16,7 +14,6 @@ import kotlinx.serialization.Serializable
* @property affiliation The affiliation of the player.
* @property leagues The leagues in which the player has played.
*/
@Serializable
data class PlayersResponse(
val id: Int,
val firstname: String,
Expand All @@ -35,7 +32,6 @@ data class PlayersResponse(
* @property date The birth date of the player in the format "YYYY-mm-DD".
* @property country The country of birth of the player.
*/
@Serializable
data class Birth(
val date: String?,
val country: String?,
Expand All @@ -47,7 +43,6 @@ data class PlayersResponse(
* @property start The starting season of the player in the NBA.
* @property pro The number of seasons the player has played in the NBA.
*/
@Serializable
data class Nba(
val start: Int,
val pro: Int,
Expand All @@ -60,7 +55,6 @@ data class PlayersResponse(
* @property inches The height of the player in inches.
* @property meters The height of the player in meters.
*/
@Serializable
data class Height(
val feets: String?,
val inches: String?,
Expand All @@ -73,7 +67,6 @@ data class PlayersResponse(
* @property pounds The weight of the player in pounds.
* @property kilograms The weight of the player in kilograms.
*/
@Serializable
data class Weight(
val pounds: String?,
val kilograms: String?,
Expand All @@ -89,7 +82,6 @@ data class PlayersResponse(
* @property utah The Utah league in which the player has played.
* @property orlando The Orlando league in which the player has played.
*/
@Serializable
data class Leagues(
val standard: League? = null,
val africa: League? = null,
Expand All @@ -106,7 +98,6 @@ data class PlayersResponse(
* @property active Indicates if the player is currently active in the league.
* @property pos The position of the player in the league.
*/
@Serializable
data class League(
val jersey: Int?,
val active: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.nba.kotlin.responses

import api.nba.kotlin.models.Team
import kotlinx.serialization.Serializable

/**
* Represents the response object for player statistics.
Expand Down Expand Up @@ -31,7 +30,6 @@ import kotlinx.serialization.Serializable
* @param blocks The total number of blocks by the player.
* @param plusMinus The plus/minus of the player.
*/
@Serializable
data class PlayersStatisticsResponse(
val player: Player,
val team: Team,
Expand Down Expand Up @@ -66,14 +64,12 @@ data class PlayersStatisticsResponse(
* @property firstname The firstname of the player.
* @property lastname The lastname of the player.
*/
@Serializable
data class Player(val id: Int, val firstname: String, val lastname: String)

/**
* Represents a game in the NBA.
*
* @property id The unique identifier of the game.
*/
@Serializable
data class Game(val id: Int)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.nba.kotlin.responses

import api.nba.kotlin.models.Team
import kotlinx.serialization.Serializable

/**
* Represents a response object for retrieving standings information.
Expand All @@ -18,7 +17,6 @@ import kotlinx.serialization.Serializable
* @param winStreak The win streak status.
* @param tieBreakerPoints The tie-breaker points (can be null).
*/
@Serializable
data class StandingsResponse(
val league: String,
val season: Int,
Expand All @@ -40,7 +38,6 @@ data class StandingsResponse(
* @property win The number of wins.
* @property loss The number of losses.
*/
@Serializable
data class Conference(
val name: String,
val rank: Int,
Expand All @@ -57,7 +54,6 @@ data class StandingsResponse(
* @property loss The number of losses.
* @property gamesBehind The games behind as a string.
*/
@Serializable
data class Division(
val name: String,
val rank: Int,
Expand All @@ -75,7 +71,6 @@ data class StandingsResponse(
* @property percentage The win percentage as a string.
* @property lastTen The number of wins in the last ten games.
*/
@Serializable
data class Record(
val home: Int,
val away: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api.nba.kotlin.responses

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import com.google.gson.annotations.SerializedName

/**
* Represents the status response received from the API.
Expand All @@ -13,7 +12,6 @@ import kotlinx.serialization.Serializable
* @property paging The map containing the paging information.
* @property response The response object.
*/
@Serializable
data class StatusResponse(
val get: String,
val parameters: List<String>,
Expand All @@ -29,7 +27,6 @@ data class StatusResponse(
* @property account The account information.
* @property subscription The subscription information.
* @property requests The*/
@Serializable
data class Response(
val account: Account,
val subscription: Subscription,
Expand All @@ -43,7 +40,6 @@ data class StatusResponse(
* @property lastname The last name of the account owner.
* @property email The email address of the account owner.
*/
@Serializable
data class Account(
val firstname: String,
val lastname: String,
Expand All @@ -57,7 +53,6 @@ data class StatusResponse(
* @property end The end date of the subscription.
* @property active Indicates whether the subscription is active or not.
*/
@Serializable
data class Subscription(
val plan: String,
val end: String,
Expand All @@ -70,9 +65,8 @@ data class StatusResponse(
* @property current The current number of requests made.
* @property limitDay The daily limit for requests.
*/
@Serializable
data class Requests(
val current: Int,
@SerialName("limit_day") val limitDay: Int,
@SerializedName("limit_day") val limitDay: Int,
)
}
Loading

0 comments on commit 90eae5c

Please sign in to comment.