Skip to content

Commit

Permalink
Adding base ktor client and some octane GG models. (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamMc331 authored Dec 1, 2024
1 parent 36268e0 commit 3f13a45
Show file tree
Hide file tree
Showing 40 changed files with 1,234 additions and 21 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ cash-paparazzi = { id = "app.cash.paparazzi", version.ref = "paparazzi" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.compose", version.ref = "kmpCompose" }
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" }
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinter" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
13 changes: 13 additions & 0 deletions shared/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
alias(libs.plugins.compose.compiler)
alias(libs.plugins.kotlin.compose)
Expand Down Expand Up @@ -29,12 +30,24 @@ kotlin {
implementation(libs.cketti.codepoints)
implementation(libs.koin.core)
implementation(libs.kotlinx.datetime)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.logging)
implementation(libs.ktor.serialization.kotlinx.json)
}

commonTest.dependencies {
implementation(kotlin("test"))
implementation(libs.varabyte.truthish)
}

androidMain.dependencies {
implementation(libs.ktor.client.android)
}

iosMain.dependencies {
implementation(libs.ktor.client.ios)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ package com.adammcneilly.pocketleague.shared.app.core.models
* @property[prize] The amount of money awarded to the winners of the event.
*/
data class Event(
val id: String,
val name: String,
val startDateUTC: String?,
val endDateUTC: String?,
val imageURL: String?,
val stages: List<EventStage>,
val tier: EventTier,
val mode: String,
val region: Region,
val lan: Boolean,
val prize: Prize?,
val id: String = "",
val name: String = "",
val startDateUTC: String? = null,
val endDateUTC: String? = null,
val imageURL: String? = null,
val stages: List<EventStage> = emptyList(),
val tier: EventTier = EventTier.Unknown,
val mode: String = "",
val region: Region = Region.Unknown,
val lan: Boolean = false,
val prize: Prize? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ package com.adammcneilly.pocketleague.shared.app.core.models
* @property[location] The location of this stage if it is a [lan].
*/
data class EventStage(
val id: String,
val name: String,
val region: String,
val startDateUTC: String?,
val endDateUTC: String?,
val liquipedia: String,
val qualifier: Boolean,
val lan: Boolean,
val location: Location?,
val id: String = "",
val name: String = "",
val region: String = "",
val startDateUTC: String? = null,
val endDateUTC: String? = null,
val liquipedia: String = "",
val qualifier: Boolean = false,
val lan: Boolean = false,
val location: Location? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg

import com.adammcneilly.pocketleague.shared.app.core.models.EventTier

object OctaneGGEventTierMapper {
/**
* Converts a tier string from the Octane.gg api to an [EventTier] enum entry.
*/
fun fromString(
tier: String,
): EventTier {
return when (tier) {
"S" -> EventTier.S
"A" -> EventTier.A
"B" -> EventTier.B
"C" -> EventTier.C
"D" -> EventTier.D
else -> EventTier.Unknown
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg

import com.adammcneilly.pocketleague.shared.app.data.remote.BaseKtorClient

/**
* An instance of a [BaseKtorClient] that makes all requests to the octane.gg API.
*/
object OctaneGGKtorClient : BaseKtorClient(
baseURL = "https://zsr.octane.gg/",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg

import com.adammcneilly.pocketleague.shared.app.core.models.Region

object OctaneGGRegionMapper {
/**
* Converts a region string from the Octane.gg api to a [Region] enum entry.
*/
fun fromString(
region: String,
): Region {
return when (region) {
"NA" -> Region.NA
"EU" -> Region.EU
"OCE" -> Region.OCE
"SAM" -> Region.SAM
"ASIA" -> Region.APAC
"ME" -> Region.MENA
"INT" -> Region.INT
"AF" -> Region.SSA
else -> Region.Unknown
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents a player account within the octane.gg API.
*/
@Serializable
data class OctaneGGAccount(
@SerialName("id")
val id: String? = null,
@SerialName("platform")
val platform: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Advanced statistics for a player or a team.
*/
@Serializable
data class OctaneGGAdvancedStats(
@SerialName("goalParticipation")
val goalParticipation: Double? = null,
@SerialName("mvp")
val mvp: Boolean? = null,
@SerialName("rating")
val rating: Double? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Ball and possession related stats for a player or team.
*/
@Serializable
data class OctaneGGBallStats(
@SerialName("possessionTime")
val possessionTime: Double? = null,
@SerialName("timeInSide")
val timeInSide: Double? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Statistics about boost management for a player or team.
*/
@Serializable
data class OctaneGGBoostStats(
@SerialName("amountCollected")
val amountCollected: Int? = null,
@SerialName("amountCollectedBig")
val amountCollectedBig: Int? = null,
@SerialName("amountCollectedSmall")
val amountCollectedSmall: Int? = null,
@SerialName("amountOverfill")
val amountOverfill: Int? = null,
@SerialName("amountOverfillStolen")
val amountOverfillStolen: Int? = null,
@SerialName("amountStolen")
val amountStolen: Int? = null,
@SerialName("amountStolenBig")
val amountStolenBig: Int? = null,
@SerialName("amountStolenSmall")
val amountStolenSmall: Int? = null,
@SerialName("amountUsedWhileSupersonic")
val amountUsedWhileSupersonic: Int? = null,
@SerialName("avgAmount")
val avgAmount: Double? = null,
@SerialName("bcpm")
val bcpm: Double? = null,
@SerialName("bpm")
val bpm: Int? = null,
@SerialName("countCollectedBig")
val countCollectedBig: Int? = null,
@SerialName("countCollectedSmall")
val countCollectedSmall: Int? = null,
@SerialName("countStolenBig")
val countStolenBig: Int? = null,
@SerialName("countStolenSmall")
val countStolenSmall: Int? = null,
@SerialName("percentBoost0To25")
val percentBoost0To25: Double? = null,
@SerialName("percentBoost25To50")
val percentBoost25To50: Double? = null,
@SerialName("percentBoost50To75")
val percentBoost50To75: Double? = null,
@SerialName("percentBoost75To100")
val percentBoost75To100: Double? = null,
@SerialName("percentFullBoost")
val percentFullBoost: Double? = null,
@SerialName("percentZeroBoost")
val percentZeroBoost: Double? = null,
@SerialName("timeBoost0To25")
val timeBoost0To25: Double? = null,
@SerialName("timeBoost25To50")
val timeBoost25To50: Double? = null,
@SerialName("timeBoost50To75")
val timeBoost50To75: Double? = null,
@SerialName("timeBoost75To100")
val timeBoost75To100: Double? = null,
@SerialName("timeFullBoost")
val timeFullBoost: Double? = null,
@SerialName("timeZeroBoost")
val timeZeroBoost: Double? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import com.adammcneilly.pocketleague.shared.app.core.models.CoreStats
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* The core stats to track for a player or a team in any given match or stretch of time.
*/
@Serializable
data class OctaneGGCoreStats(
@SerialName("shots")
val shots: Int? = null,
@SerialName("goals")
val goals: Int? = null,
@SerialName("saves")
val saves: Int? = null,
@SerialName("assists")
val assists: Int? = null,
@SerialName("score")
val score: Int? = null,
@SerialName("shootingPercentage")
val shootingPercentage: Float? = null,
) {
/**
* Converts an [OctaneGGCoreStats] entity to a [CoreStats] entity.
*/
fun toCoreStats(): CoreStats {
return CoreStats(
shots = this.shots ?: 0,
goals = this.goals ?: 0,
saves = this.saves ?: 0,
assists = this.assists ?: 0,
score = this.score ?: 0,
shootingPercentage = this.shootingPercentage ?: 0F,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adammcneilly.pocketleague.shared.app.data.octanegg.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Statistics for demolitions for a player or team.
*/
@Serializable
data class OctaneGGDemoStats(
@SerialName("inflicted")
val inflicted: Int? = null,
@SerialName("taken")
val taken: Int? = null,
)
Loading

0 comments on commit 3f13a45

Please sign in to comment.