Skip to content

Commit 6a59f2e

Browse files
sungsylux6
authored andcommitted
Basic API functions
1 parent cdf3b9f commit 6a59f2e

File tree

25 files changed

+614
-452
lines changed

25 files changed

+614
-452
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
uses: actions/setup-java@v1
1414
with:
1515
java-version: 1.8
16-
- name: Build with Gradle
16+
- name: Build and test with Gradle
1717
run: |
1818
gradle clean test

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# AzurApi-Kotlin
22
A Kotlin wrapper for Azur Lane JSON
3+
4+
## Support server
5+
![Discord Banner 2](https://discordapp.com/api/guilds/648206344729526272/widget.png?style=banner2)

build.gradle.kts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
val kotlinVersion = "1.3.61"
2+
val fuelVersion = "2.2.1"
3+
val kotlintestVersion = "3.4.2"
4+
15
plugins {
2-
`build-scan`
36
kotlin("jvm") version "1.3.61"
47
}
58

6-
group = "com.github.sylux6.azurapikotlin"
9+
group = "com.github.azurapi.azurapikotlin"
710
version = "v1.0.0"
811

912
repositories {
@@ -13,17 +16,15 @@ repositories {
1316

1417
dependencies {
1518
implementation(kotlin("stdlib-jdk8"))
16-
testImplementation("org.junit.jupiter:junit-jupiter:5.5.2")
17-
implementation("com.github.kittinunf.fuel:fuel:2.2.1")
18-
implementation("com.github.kittinunf.fuel:fuel-json:2.2.1")
19+
implementation("com.github.kittinunf.fuel:fuel:$fuelVersion")
20+
implementation("com.github.kittinunf.fuel:fuel-json:$fuelVersion")
1921
implementation("org.json", "json", "20190722")
22+
23+
testImplementation("io.kotlintest:kotlintest-runner-junit5:$kotlintestVersion")
2024
}
2125

22-
tasks.test {
26+
tasks.withType<Test> {
2327
useJUnitPlatform()
24-
testLogging {
25-
events("passed", "skipped", "failed")
26-
}
2728
}
2829

2930
tasks {
@@ -33,11 +34,4 @@ tasks {
3334
compileTestKotlin {
3435
kotlinOptions.jvmTarget = "1.8"
3536
}
36-
}
37-
38-
buildScan {
39-
termsOfServiceUrl = "https://gradle.com/terms-of-service"
40-
termsOfServiceAgree = "yes"
41-
42-
publishAlways()
4337
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.github.azurapi.azurapikotlin.api
2+
3+
import com.github.azurapi.azurapikotlin.internal.entities.Ship
4+
import com.github.azurapi.azurapikotlin.internal.exceptions.DatabaseException
5+
import com.github.azurapi.azurapikotlin.internal.exceptions.ShipNotFoundException
6+
import com.github.azurapi.azurapikotlin.internal.exceptions.ApiException
7+
import com.github.azurapi.azurapikotlin.json.Takao
8+
import java.util.stream.Collectors
9+
10+
/**
11+
* API class
12+
* @throws ShipNotFoundException
13+
* @throws DatabaseException
14+
* @throws ApiException
15+
*/
16+
class Atago {
17+
18+
private val database = try {
19+
Takao()
20+
} catch (e: DatabaseException) {
21+
throw DatabaseException(e.message ?: "")
22+
}
23+
24+
/**
25+
* @since 1.0.0
26+
*
27+
* Get information about a ship by name
28+
* @param name name of the ship
29+
*/
30+
fun getShipByName(name: String): Ship {
31+
val formattedName = name.toLowerCase()
32+
if (database.shipsByName.containsKey(formattedName)) {
33+
return database.shipsByName[formattedName]!!
34+
} else {
35+
throw ShipNotFoundException("Could not find ship with name: $name")
36+
}
37+
}
38+
39+
/**
40+
* @since 1.0.0
41+
*
42+
* Get information about a ship by id
43+
* @param id id of the ship
44+
*/
45+
fun getShipById(id: String): Ship {
46+
val formattedId = id.toLowerCase()
47+
if (database.shipsById.containsKey(formattedId)) {
48+
return database.shipsById[formattedId]!!
49+
} else {
50+
throw ShipNotFoundException("Could not find ship with id: $id")
51+
}
52+
}
53+
54+
/**
55+
* @since 1.0.0
56+
*
57+
* Get list of all ships
58+
*/
59+
fun getAllShips(): List<Ship> {
60+
return database.shipsById.values.stream().collect(Collectors.toList())
61+
}
62+
}

src/main/kotlin/com/github/sylux6/azurapikotlin/api/AtagoInfo.kt renamed to src/main/kotlin/com/github/azurapi/azurapikotlin/api/AtagoInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.sylux6.azurapikotlin.api
1+
package com.github.azurapi.azurapikotlin.api
22

33
/**
44
* API info

src/main/kotlin/com/github/sylux6/azurapikotlin/internal/entities/Ship.kt renamed to src/main/kotlin/com/github/azurapi/azurapikotlin/internal/entities/Ship.kt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.sylux6.azurapikotlin.internal.entities
1+
package com.github.azurapi.azurapikotlin.internal.entities
22

33
/**
44
* Stars of a ship
@@ -38,9 +38,9 @@ data class SkinInfo (
3838
*/
3939
data class Skin (
4040
val image: String,
41-
val background: String?,
41+
val background: String,
4242
val name: String,
43-
val chibi: String?,
43+
val chibi: String,
4444
val info: SkinInfo?
4545
)
4646

@@ -52,10 +52,10 @@ data class Skin (
5252
* @param cn chinese name
5353
*/
5454
data class Name (
55-
val jp: String?,
56-
val kr: String?,
55+
val jp: String,
56+
val kr: String,
5757
val en: String,
58-
val cn: String?
58+
val cn: String
5959
)
6060

6161
/**
@@ -97,9 +97,9 @@ data class StatsDetails (
9797
* @param base
9898
*/
9999
data class Stats (
100-
val level120: StatsDetails,
101-
val level100: StatsDetails,
102-
val base: StatsDetails
100+
val level120: StatsDetails,
101+
val level100: StatsDetails,
102+
val base: StatsDetails
103103
)
104104

105105
/**
@@ -121,11 +121,11 @@ data class Url (
121121
* @param pixiv
122122
*/
123123
data class Miscellaneous (
124-
val voice: String?,
125-
val twitter: Url?,
126-
val artist: String?,
127-
val web: Url?,
128-
val pixiv: Url?
124+
val voice: String,
125+
val twitter: Url?,
126+
val artist: String?,
127+
val web: Url?,
128+
val pixiv: Url?
129129
)
130130

131131
/**
@@ -145,18 +145,18 @@ data class Miscellaneous (
145145
* @param misc
146146
*/
147147
data class Ship (
148-
val wikiUrl: String,
149-
val id: String,
150-
val names: Name,
151-
val shipClass: String,
152-
val nationality: String,
153-
val hullType: String,
154-
val thumbnail: String,
155-
val skins: List<Skin>,
156-
val buildTime: String,
157-
val rarity: String,
158-
val stars: Stars?,
159-
val stats: Stats?,
160-
val misc: Miscellaneous?
148+
val wikiUrl: String,
149+
val id: String,
150+
val names: Name,
151+
val shipClass: String,
152+
val nationality: String,
153+
val hullType: String,
154+
val thumbnail: String,
155+
val skins: List<Skin>,
156+
val buildTime: String,
157+
val rarity: String,
158+
val stars: Stars?,
159+
val stats: Stats?,
160+
val misc: Miscellaneous?
161161
)
162162

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.azurapi.azurapikotlin.internal.exceptions
2+
3+
class ApiException(message: String = "") : Exception(message) {
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.github.azurapi.azurapikotlin.internal.exceptions
2+
3+
import java.lang.Exception
4+
5+
class DatabaseException(message: String = "") : Exception(message) {
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.azurapi.azurapikotlin.internal.exceptions
2+
3+
class ShipNotFoundException(message: String = "") : Exception(message) {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.github.azurapi.azurapikotlin.internal.responses
2+
3+
class ErrorResponse {
4+
}

0 commit comments

Comments
 (0)