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

Commit f0e9d04

Browse files
committed
Update
0 parents  commit f0e9d04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+573
-0
lines changed

WrapperFortniteAPI.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />

pom.xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.thoo</groupId>
8+
<artifactId>WrapperFortniteAPI</artifactId>
9+
<version>2.3</version>
10+
11+
<properties>
12+
<kotlin.version>1.3.72</kotlin.version>
13+
</properties>
14+
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<configuration>
21+
<source>8</source>
22+
<target>8</target>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-shade-plugin</artifactId>
28+
<version>3.2.3</version>
29+
<configuration>
30+
</configuration>
31+
<executions>
32+
<execution>
33+
<phase>package</phase>
34+
<goals>
35+
<goal>shade</goal>
36+
</goals>
37+
</execution>
38+
</executions>
39+
</plugin>
40+
<plugin>
41+
<groupId>org.jetbrains.kotlin</groupId>
42+
<artifactId>kotlin-maven-plugin</artifactId>
43+
<version>${kotlin.version}</version>
44+
<executions>
45+
<execution>
46+
<id>compile</id>
47+
<phase>compile</phase>
48+
<goals>
49+
<goal>compile</goal>
50+
</goals>
51+
</execution>
52+
<execution>
53+
<id>test-compile</id>
54+
<phase>test-compile</phase>
55+
<goals>
56+
<goal>test-compile</goal>
57+
</goals>
58+
</execution>
59+
</executions>
60+
<configuration>
61+
<jvmTarget>1.8</jvmTarget>
62+
</configuration>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
<dependencies>
68+
<dependency>
69+
<groupId>com.google.code.gson</groupId>
70+
<artifactId>gson</artifactId>
71+
<version>2.8.3</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.squareup.okhttp3</groupId>
75+
<artifactId>okhttp</artifactId>
76+
<version>4.2.2</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.squareup.retrofit2</groupId>
80+
<artifactId>retrofit</artifactId>
81+
<version>2.8.1</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>com.squareup.retrofit2</groupId>
85+
<artifactId>converter-gson</artifactId>
86+
<version>2.7.2</version>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.jetbrains.kotlin</groupId>
90+
<artifactId>kotlin-stdlib-jdk8</artifactId>
91+
<version>${kotlin.version}</version>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.jetbrains.kotlin</groupId>
95+
<artifactId>kotlin-test</artifactId>
96+
<version>${kotlin.version}</version>
97+
<scope>test</scope>
98+
</dependency>
99+
</dependencies>
100+
101+
102+
</project>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package com.thoo.api
2+
3+
import com.thoo.api.endpoints.AESEndpoint
4+
import com.thoo.api.endpoints.CosmeticEndpoint
5+
import com.thoo.api.endpoints.CreatorCodeEndpoint
6+
import com.thoo.api.endpoints.NewsEndpoint
7+
import com.thoo.api.enums.Language
8+
import okhttp3.Interceptor
9+
import okhttp3.OkHttpClient
10+
import okhttp3.Response
11+
import org.jetbrains.annotations.NotNull
12+
import retrofit2.Retrofit
13+
import retrofit2.converter.gson.GsonConverterFactory
14+
import java.security.SecureRandom
15+
import java.security.cert.X509Certificate
16+
import javax.net.ssl.*
17+
18+
class FortniteAPI private constructor(
19+
private val key: String,
20+
private val language: Language,
21+
private val client: OkHttpClient,
22+
private val debug: Boolean
23+
) {
24+
25+
init {
26+
val clientBuilder = client.newBuilder()
27+
if(key == "None") clientBuilder.addInterceptor(KeyInterceptor(key))
28+
clientBuilder.addInterceptor(LanguageInterceptor(language))
29+
if(debug){
30+
val trustManager = arrayOf<TrustManager>(
31+
object: X509TrustManager {
32+
override fun checkClientTrusted(chain: Array<X509Certificate?>?, authType: String?) {}
33+
override fun checkServerTrusted(chain: Array<X509Certificate?>?, authType: String?) {}
34+
override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
35+
}
36+
)
37+
val context = SSLContext.getInstance("SSL")
38+
context.init(null, trustManager, SecureRandom())
39+
val factory = context.socketFactory
40+
clientBuilder.sslSocketFactory(factory, trustManager[0] as X509TrustManager)
41+
clientBuilder.hostnameVerifier(HostnameVerifier { _, _ -> true })
42+
}
43+
}
44+
45+
private val retrofit = Retrofit.Builder()
46+
.addConverterFactory(GsonConverterFactory.create())
47+
.baseUrl("https://fortnite-api.com")
48+
.client(client).build()
49+
50+
private val aesEndpoint = AESEndpoint(retrofit)
51+
private val cosmeticEndpoint = CosmeticEndpoint(retrofit, language)
52+
private val newsEndpoint = NewsEndpoint(retrofit, language)
53+
private val createCodeEndpoint = CreatorCodeEndpoint(retrofit)
54+
55+
fun getAESEndpoint(): AESEndpoint = aesEndpoint
56+
fun getCosmeticEndpoint(): CosmeticEndpoint = cosmeticEndpoint
57+
fun getNewsEndpoint(): NewsEndpoint = newsEndpoint
58+
fun getCreatorEndpoint(): CreatorCodeEndpoint = createCodeEndpoint
59+
60+
private inner class LanguageInterceptor(
61+
private val language: Language
62+
) : Interceptor {
63+
64+
override fun intercept(chain: Interceptor.Chain): Response {
65+
val request = chain.request().newBuilder()
66+
if(chain.request().header("language") != null) request.header("language", language.code)
67+
return chain.proceed(request.build())
68+
}
69+
70+
}
71+
72+
private inner class KeyInterceptor(
73+
private val key: String
74+
) : Interceptor {
75+
76+
override fun intercept(chain: Interceptor.Chain): Response {
77+
val request = chain.request().newBuilder().header("x-api-key", key).build()
78+
return chain.proceed(request)
79+
}
80+
81+
}
82+
83+
class Builder {
84+
85+
private var key: String = "None"
86+
private var language: Language = Language.EN
87+
private var client: OkHttpClient = OkHttpClient()
88+
private var debug: Boolean = false
89+
90+
fun setKey(@NotNull key: String): Builder {
91+
this.key = key
92+
return this
93+
}
94+
95+
fun setLanguage(@NotNull language: Language): Builder {
96+
this.language = language
97+
return this
98+
}
99+
100+
fun setClient(@NotNull client: OkHttpClient): Builder {
101+
this.client = client
102+
return this
103+
}
104+
105+
fun setDebug(@NotNull debug: Boolean): Builder {
106+
this.debug = debug
107+
return this
108+
}
109+
110+
fun build(): FortniteAPI {
111+
return FortniteAPI(
112+
key = key,
113+
language = language,
114+
client = client,
115+
debug = debug
116+
)
117+
}
118+
119+
}
120+
121+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
class AESEndpoint(retrofit: Retrofit) : Endpoint<AESService>(retrofit, AESService::class.java) {
11+
12+
@JvmOverloads fun getAES(format: KeyFormat = KeyFormat.HEX): BaseModel<AESModel>? = service.aes().send()
13+
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
class CosmeticEndpoint(retrofit: Retrofit, private val defaultLang: Language) :
9+
Endpoint<CosmeticService>(retrofit, CosmeticService::class.java) {
10+
11+
@JvmOverloads fun getCosmetics(language: Language = defaultLang) = service.cosmetics(language.code).send()
12+
@JvmOverloads fun getCosmeticByID(id: String, language: Language = defaultLang) = service.cosmeticByID(id, language.code).send()
13+
@JvmOverloads fun getCosmeticsByID(vararg ids: String, language: Language = defaultLang) = service.cosmeticsByID(language.code, *ids).send()
14+
15+
}
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 com.thoo.api.services.CreatorCodeService
4+
import com.thoo.api.utils.send
5+
import retrofit2.Retrofit
6+
7+
class CreatorCodeEndpoint(retrofit: Retrofit) :
8+
Endpoint<CreatorCodeService>(retrofit, CreatorCodeService::class.java) {
9+
10+
fun getCreatorCode(slug: String) = service.getCreatorCode(slug).send()
11+
12+
}
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+
abstract class Endpoint<T>(
6+
retrofit: Retrofit,
7+
clazz: Class<T>
8+
) {
9+
10+
protected val service: T = retrofit.create(clazz)
11+
12+
}
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.enums.Language
4+
import com.thoo.api.enums.NewsType
5+
import com.thoo.api.services.NewsService
6+
import com.thoo.api.utils.send
7+
import retrofit2.Retrofit
8+
9+
class NewsEndpoint(retrofit: Retrofit, private val defaultLang: Language) :
10+
Endpoint<NewsService>(retrofit, NewsService::class.java) {
11+
12+
@JvmOverloads fun getNews(lang: Language = defaultLang) = service.getNews(lang.code).send()
13+
@JvmOverloads fun getBrNews(lang: Language = defaultLang) = service.getSpecNews(NewsType.BR.code, lang.code).send()
14+
@JvmOverloads fun getStwNews(lang: Language = defaultLang) = service.getSpecNews(NewsType.STW.code, lang.code).send()
15+
@JvmOverloads fun getCreativeNews(lang: Language = defaultLang) = service.getSpecNews(NewsType.CREA.code, lang.code).send()
16+
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.thoo.api.enums
2+
3+
enum class KeyFormat(val code: String) {
4+
5+
HEX("hex"),
6+
BASE64("base64")
7+
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.thoo.api.enums
2+
3+
enum class Language(val code: String) {
4+
5+
AR("ar"),
6+
DE("de"),
7+
EN("en"),
8+
ES419("es-419"),
9+
ES("es"),
10+
FR("fr"),
11+
IT("it"),
12+
JA("ja"),
13+
KO("ko"),
14+
PL("pl"),
15+
PTBR("pt-BR"),
16+
RU("ru"),
17+
TR("tr"),
18+
ZHCN("zh-CN"),
19+
ZHHANT("zh-Hant");
20+
21+
}

0 commit comments

Comments
 (0)