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

Commit fb77ad4

Browse files
committed
Added getCosmeticsByName()
1 parent 954cf72 commit fb77ad4

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

com/thoo/api/FortniteAPI.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.thoo.api
22

33
import com.thoo.api.interceptors.DefaultInterceptor
4-
import com.thoo.api.match.MatchBuilder
4+
import com.thoo.api.search.SearchBuilder
55
import com.thoo.api.model.*
66
import com.thoo.api.service.FortniteAPIService
77
import okhttp3.OkHttpClient
88
import retrofit2.Retrofit
99
import retrofit2.converter.gson.GsonConverterFactory
1010
import java.lang.reflect.Field
1111
import java.util.*
12+
import kotlin.collections.ArrayList
1213

1314
class FortniteAPI constructor(val key: String) {
1415
constructor(): this("null")
@@ -68,7 +69,7 @@ class FortniteAPI constructor(val key: String) {
6869

6970
fun getMatchingCreators(slug: String): BaseResponse<Array<CreatorCode>>? = service?.getMatchingCreators(slug)?.execute()?.body()
7071

71-
fun getMatchedCosmetics(matchBuilder: MatchBuilder): BaseResponse<Array<BRCosmeticData>>? {
72+
fun getMatchedCosmetics(matchBuilder: SearchBuilder): BaseResponse<Array<BRCosmeticData>>? {
7273
val fields: Array<Field> = matchBuilder.javaClass.declaredFields
7374
val queryMapString: HashMap<String, String> = HashMap()
7475
val queryMapBool: HashMap<String, Boolean> = HashMap()
@@ -86,4 +87,32 @@ class FortniteAPI constructor(val key: String) {
8687
return service?.matchCosmetics(queryMapString, queryMapBool)?.execute()?.body()
8788
}
8889

90+
fun getCosmeticsByName(vararg names: String): ArrayList<BRCosmeticData> {
91+
val cosmetics = ArrayList<BRCosmeticData>()
92+
getAllCosmetics()?.data?.forEach {
93+
if(names.contains(it.name)){
94+
cosmetics.add(it)
95+
}
96+
}
97+
return cosmetics
98+
}
99+
100+
fun getCosmeticsByName(vararg names: String, language: Language): ArrayList<BRCosmeticData> {
101+
val cosmetics = ArrayList<BRCosmeticData>()
102+
getAllCosmetics(language)?.data?.forEach {
103+
if(names.contains(it.name)){
104+
cosmetics.add(it)
105+
}
106+
}
107+
return cosmetics
108+
}
109+
110+
fun getCosmeticByName(name: String): BRCosmeticData? = getAllCosmetics()?.data?.filter {
111+
it.name.toLowerCase() == name.toLowerCase()
112+
}?.getOrNull(0)
113+
114+
fun getCosmeticByName(name: String, language: Language): BRCosmeticData? = getAllCosmetics(language)?.data?.filter {
115+
it.name.toLowerCase() == name.toLowerCase()
116+
}?.getOrNull(0)
117+
89118
}

com/thoo/api/match/MatchBuilder.kt renamed to com/thoo/api/search/SearchBuilder.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.thoo.api.match
1+
package com.thoo.api.search
22

3-
class MatchBuilder {
3+
class SearchBuilder {
44

55
private var type: String? = null
66
private var backendType: String? = null
@@ -24,107 +24,107 @@ class MatchBuilder {
2424
private var displayRarity: String? = null
2525
private var setText: String? = null
2626

27-
fun setDisplayRarity(displayRarity: String):MatchBuilder {
27+
fun setDisplayRarity(displayRarity: String):SearchBuilder {
2828
this.displayRarity = displayRarity
2929
return this
3030
}
3131

32-
fun setText(setText: String):MatchBuilder {
32+
fun setText(setText: String):SearchBuilder {
3333
this.setText = setText
3434
return this
3535
}
3636

37-
fun setType(type: String):MatchBuilder {
37+
fun setType(type: String):SearchBuilder {
3838
this.type = type
3939
return this
4040
}
4141

42-
fun setBackendType(backendType: String):MatchBuilder {
42+
fun setBackendType(backendType: String):SearchBuilder {
4343
this.backendType = backendType
4444
return this
4545
}
4646

47-
fun setRarity(rarity: String):MatchBuilder {
47+
fun setRarity(rarity: String):SearchBuilder {
4848
this.rarity = rarity
4949
return this
5050
}
5151

52-
fun setBackendRarity(backendRarity: String):MatchBuilder {
52+
fun setBackendRarity(backendRarity: String):SearchBuilder {
5353
this.backendRarity = backendRarity
5454
return this
5555
}
5656

57-
fun setName(name: String):MatchBuilder {
57+
fun setName(name: String):SearchBuilder {
5858
this.name = name
5959
return this
6060
}
6161

62-
fun setShortDescription(shortDescription: String):MatchBuilder {
62+
fun setShortDescription(shortDescription: String):SearchBuilder {
6363
this.shortDescription = shortDescription
6464
return this
6565
}
6666

67-
fun setDescription(description: String):MatchBuilder {
67+
fun setDescription(description: String):SearchBuilder {
6868
this.description = description
6969
return this
7070
}
7171

72-
fun setSet(set: String):MatchBuilder {
72+
fun setSet(set: String):SearchBuilder {
7373
this.set = set
7474
return this
7575
}
7676

77-
fun setSeries(series: String):MatchBuilder {
77+
fun setSeries(series: String):SearchBuilder {
7878
this.series = series
7979
return this
8080
}
8181

82-
fun setBackendSeries(backendSeries: String):MatchBuilder {
82+
fun setBackendSeries(backendSeries: String):SearchBuilder {
8383
this.backendSeries = backendSeries
8484
return this
8585
}
8686

87-
fun setSmallIcon(hasSmallIcon: Boolean):MatchBuilder {
87+
fun setSmallIcon(hasSmallIcon: Boolean):SearchBuilder {
8888
this.hasSmallIcon = hasSmallIcon
8989
return this
9090
}
9191

92-
fun setIcon(hasIcon: Boolean):MatchBuilder {
92+
fun setIcon(hasIcon: Boolean):SearchBuilder {
9393
this.hasIcon = hasIcon
9494
return this
9595
}
9696

97-
fun setFeaturedImage(hasFeaturedImage: Boolean):MatchBuilder {
97+
fun setFeaturedImage(hasFeaturedImage: Boolean):SearchBuilder {
9898
this.hasFeaturedImage = hasFeaturedImage
9999
return this
100100
}
101101

102-
fun setBackgroundImage(hasBackgroundImage: Boolean):MatchBuilder {
102+
fun setBackgroundImage(hasBackgroundImage: Boolean):SearchBuilder {
103103
this.hasBackgroundImage = hasBackgroundImage
104104
return this
105105
}
106106

107-
fun setCovertArt(hasCovertArt: Boolean):MatchBuilder {
107+
fun setCovertArt(hasCovertArt: Boolean):SearchBuilder {
108108
this.hasCovertArt = hasCovertArt
109109
return this
110110
}
111111

112-
fun setDecal(hasDecal: Boolean):MatchBuilder {
112+
fun setDecal(hasDecal: Boolean):SearchBuilder {
113113
this.hasDecal = hasDecal
114114
return this
115115
}
116116

117-
fun setVariants(hasVariants: Boolean):MatchBuilder {
117+
fun setVariants(hasVariants: Boolean):SearchBuilder {
118118
this.hasVariants = hasVariants
119119
return this
120120
}
121121

122-
fun setGameplayTags(hasGameplayTags: Boolean):MatchBuilder {
122+
fun setGameplayTags(hasGameplayTags: Boolean):SearchBuilder {
123123
this.hasGameplayTags = hasGameplayTags
124124
return this
125125
}
126126

127-
fun setGameplayTag(gameplayTag: String):MatchBuilder {
127+
fun setGameplayTag(gameplayTag: String):SearchBuilder {
128128
this.gameplayTag = gameplayTag
129129
return this
130130
}

example/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package example
22

33
import com.thoo.api.FortniteAPI
4-
import com.thoo.api.match.MatchBuilder
4+
import com.thoo.api.search.SearchBuilder
55

66
fun main(args : Array<String>){
77
val api: FortniteAPI = FortniteAPI("")
88

99
// Returns an Array<BRCosmeticData> of cosmetics which is an outfit and has a rare rarity
10-
val matchBuilder = MatchBuilder().setRarity("rare").setType("outfit")
10+
val matchBuilder = SearchBuilder().setRarity("rare").setType("outfit")
1111
api.getMatchedCosmetics(matchBuilder)?.data?.forEach {
1212
println(it.id)
1313
}

0 commit comments

Comments
 (0)