Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit b7b5ef1

Browse files
committed
Recode
1 parent 3aabf11 commit b7b5ef1

37 files changed

+761
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea/
2+
/build/
3+
/.gradle/

LISENCE.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ MIT License
22

33
Copyright (c) 2020 Fortnite-API.com
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
611

7-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
814

9-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Soon, recoding

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ repositories {
1111

1212
dependencies {
1313
implementation(kotlin("stdlib"))
14+
implementation("com.squareup.retrofit2:retrofit:2.9.0")
15+
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
16+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
1417
}
Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,51 @@
11
package com.thoo.api
22

3-
class FortniteAPI {
3+
import com.thoo.api.endpoints.*
4+
import com.thoo.api.enums.Language
5+
import com.thoo.api.services.*
6+
import okhttp3.OkHttpClient
7+
import org.jetbrains.annotations.NotNull
8+
import retrofit2.Retrofit
9+
import retrofit2.converter.gson.GsonConverterFactory
10+
11+
@Suppress("unused")
12+
class FortniteAPI private constructor(
13+
private val apiKey: String?,
14+
language: Language,
15+
httpClient: OkHttpClient
16+
) {
17+
18+
// The `/v2/` is a bug fix but won't actually get applied
19+
private val retrofit = Retrofit.Builder()
20+
.baseUrl("https://fortnite-api.com/v2/")
21+
.client(httpClient)
22+
//.addCallAdapterFactory(ApiCallAdapterFactory())
23+
.addConverterFactory(GsonConverterFactory.create()).build()
24+
25+
@JvmField val aes = AESEndpoints(retrofit, AESService::class.java)
26+
@JvmField val map = MapEndpoints(retrofit, MapService::class.java, language)
27+
@JvmField val playlist = PlaylistEndpoints(retrofit, PlaylistService::class.java, language)
28+
@JvmField val banner = BannerEndpoints(retrofit, BannerService::class.java, language)
29+
@JvmField val creator = CreatorEndpoints(retrofit, CreatorService::class.java)
30+
@JvmField val cosmetic = CosmeticEndpoints(retrofit, CosmeticService::class.java, language)
31+
32+
companion object {
33+
34+
@JvmOverloads
35+
@JvmStatic
36+
fun create(
37+
apiKey: String? = null,
38+
@NotNull language: Language = Language.EN,
39+
httpClient: OkHttpClient? = null
40+
): FortniteAPI = FortniteAPI(apiKey, language,
41+
httpClient ?: OkHttpClient.Builder().addInterceptor interceptor@ {
42+
if(apiKey == null) return@interceptor it.proceed(it.request())
43+
val request = it.request()
44+
val requestBuilder = request.newBuilder()
45+
requestBuilder.header("x-api-key", apiKey)
46+
return@interceptor it.proceed(requestBuilder.build())
47+
}.build())
48+
49+
}
50+
451
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.thoo.api.endpoints
2+
3+
import com.thoo.api.enums.KeyFormat
4+
import com.thoo.api.models.AesModel
5+
import com.thoo.api.models.BaseModel
6+
import com.thoo.api.services.AESService
7+
import com.thoo.api.utils.send
8+
import retrofit2.Retrofit
9+
10+
@SuppressWarnings("unused")
11+
class AESEndpoints(
12+
retrofit: Retrofit,
13+
clazz: Class<out AESService>
14+
): EndpointBase<AESService>(retrofit, clazz) {
15+
16+
@JvmOverloads fun getAes(keyFormat: KeyFormat = KeyFormat.HEX): BaseModel<AesModel> =
17+
service.getAes(keyFormat.code).send()
18+
19+
@JvmOverloads suspend fun getAesAsync(keyFormat: KeyFormat = KeyFormat.HEX): BaseModel<AesModel> =
20+
service.getAesAsync(keyFormat.code)
21+
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.thoo.api.endpoints
2+
3+
import com.thoo.api.enums.Language
4+
import com.thoo.api.services.BannerService
5+
import com.thoo.api.utils.send
6+
import retrofit2.Retrofit
7+
8+
@SuppressWarnings("unused")
9+
class BannerEndpoints(
10+
retrofit: Retrofit,
11+
clazz: Class<out BannerService>,
12+
private val language: Language
13+
): EndpointBase<BannerService>(retrofit, clazz) {
14+
15+
@JvmOverloads fun getBanners(language: Language = this.language) =
16+
service.getBanners(language.code).send()
17+
18+
fun getBannerColors() = service.getBannerColors().send()
19+
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.thoo.api.endpoints
2+
3+
import com.thoo.api.enums.Language
4+
import com.thoo.api.services.CosmeticService
5+
import com.thoo.api.utils.send
6+
import retrofit2.Retrofit
7+
8+
@SuppressWarnings("unused")
9+
class CosmeticEndpoints(
10+
retrofit: Retrofit,
11+
clazz: Class<out CosmeticService>,
12+
private val language: Language
13+
): EndpointBase<CosmeticService>(retrofit, clazz) {
14+
15+
@JvmOverloads fun getCosmetics(language: Language = this.language) =
16+
service.getCosmetics(language.code).send()
17+
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.thoo.api.endpoints
2+
3+
import com.thoo.api.services.CreatorService
4+
import com.thoo.api.utils.send
5+
import retrofit2.Retrofit
6+
7+
@SuppressWarnings("unused")
8+
class CreatorEndpoints(
9+
retrofit: Retrofit,
10+
clazz: Class<out CreatorService>
11+
): EndpointBase<CreatorService>(retrofit, clazz) {
12+
13+
fun getCreator(name: String) = service.getCreator(name).send()
14+
fun searchCreator(name: String) = service.searchCreator(name).send()
15+
fun searchCreators(name: String) = service.searchCreators(name).send()
16+
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.thoo.api.endpoints
2+
3+
import retrofit2.Retrofit
4+
5+
open class EndpointBase<T>(
6+
retrofit: Retrofit,
7+
clazz: Class<out T>,
8+
) {
9+
10+
val service: T = retrofit.create(clazz)
11+
12+
}

0 commit comments

Comments
 (0)