Skip to content

Commit e85cb05

Browse files
committed
get page number differently when using swapi mirror
1 parent feefd8a commit e85cb05

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

swapi-sdk/src/main/java/net/gotev/swapi/extensions/StringExtensions.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.gotev.swapi.extensions
22

3+
import net.gotev.swapi.SwapiOrigin
34
import net.gotev.swapi.models.Manufacturer
5+
import net.gotev.swapi.swapiClient
46
import java.util.Locale
57

68
fun String.asCSVList() = split(",").map { it.trim() }
@@ -9,7 +11,11 @@ fun String.asLintedLowercaseCSVList() = asCSVList()
911
.map { it.split("/") }
1012
.flatten() // theed palace space vessel engineering corps/nubia star drives
1113

12-
fun String.pageNumber() = split("=").getOrNull(1)?.toInt()
14+
fun String.pageNumber() = if (swapiClient is SwapiOrigin) {
15+
split("=").getOrNull(1)?.toInt()
16+
} else {
17+
split("page").getOrNull(1)?.replace(".json", "")?.toInt()
18+
}
1319

1420
internal fun String.lintManufacturer() = when (val linted = replace(".", "")) {
1521
"incom" -> Manufacturer.IncomCorporation.rawValue

0 commit comments

Comments
 (0)