File tree Expand file tree Collapse file tree
main/kotlin/com/baeldung/fuel Expand file tree Collapse file tree Original file line number Diff line number Diff line change 8787 <artifactId >h2</artifactId >
8888 <version >${h2database.version} </version >
8989 </dependency >
90+ <dependency >
91+ <groupId >com.github.kittinunf.fuel</groupId >
92+ <artifactId >fuel</artifactId >
93+ <version >${fuel.version} </version >
94+ </dependency >
95+ <dependency >
96+ <groupId >com.github.kittinunf.fuel</groupId >
97+ <artifactId >fuel-gson</artifactId >
98+ <version >${fuel.version} </version >
99+ </dependency >
100+ <dependency >
101+ <groupId >com.github.kittinunf.fuel</groupId >
102+ <artifactId >fuel-rxjava</artifactId >
103+ <version >${fuel.version} </version >
104+ </dependency >
105+ <dependency >
106+ <groupId >com.github.kittinunf.fuel</groupId >
107+ <artifactId >fuel-coroutines</artifactId >
108+ <version >${fuel.version} </version >
109+ </dependency >
90110 </dependencies >
91111
92112 <properties >
100120 <assertj .version>3.10.0</assertj .version>
101121 <h2database .version>1.4.197</h2database .version>
102122 <exposed .version>0.10.4</exposed .version>
123+ <fuel .version>1.15.0</fuel .version>
103124 </properties >
104125
105- </project >
126+ </project >
Original file line number Diff line number Diff line change 1+ package com.baeldung.fuel
2+
3+ import com.github.kittinunf.fuel.core.Request
4+
5+ fun tokenInterceptor () = {
6+ next: (Request ) -> Request ->
7+ { req: Request ->
8+ req.header(mapOf (" Authorization" to " Bearer AbCdEf123456" ))
9+ next(req)
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.fuel
2+
3+ import com.github.kittinunf.fuel.core.ResponseDeserializable
4+ import com.google.gson.Gson
5+
6+ data class Post (var userId : Int ,
7+ var id : Int ,
8+ var title : String ,
9+ var body : String ){
10+
11+
12+ class Deserializer : ResponseDeserializable <Array <Post >> {
13+ override fun deserialize (content : String ): Array <Post > = Gson ().fromJson(content, Array <Post >::class .java)
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ package com.baeldung.fuel
2+
3+ import com.github.kittinunf.fuel.core.Method
4+ import com.github.kittinunf.fuel.util.FuelRouting
5+
6+ sealed class PostRoutingAPI : FuelRouting {
7+
8+ override val basePath = " https://jsonplaceholder.typicode.com"
9+
10+ class posts (val id : String , override val body : String? ): PostRoutingAPI()
11+
12+ class comments (val postId : String , override val body : String? ): PostRoutingAPI()
13+
14+ override val method: Method
15+ get() {
16+ return when (this ) {
17+ is PostRoutingAPI .posts -> Method .GET
18+ is PostRoutingAPI .comments -> Method .GET
19+ }
20+ }
21+
22+ override val path: String
23+ get() {
24+ return when (this ) {
25+ is PostRoutingAPI .posts -> " /posts"
26+ is PostRoutingAPI .comments -> " /comments"
27+ }
28+ }
29+
30+ override val params: List <Pair <String , Any ?>>?
31+ get() {
32+ return when (this ) {
33+ is PostRoutingAPI .posts -> listOf (" id" to this .id)
34+ is PostRoutingAPI .comments -> listOf (" postId" to this .postId)
35+ }
36+ }
37+
38+ override val headers: Map <String , String >?
39+ get() {
40+ return null
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ internal class BuilderPatternUnitTest {
9393 Assertions .assertNull(foodOrder.fish)
9494 }
9595
96+
9697 @Test
9798 fun whenBuildingFoodOrderApplySettingValues_thenFieldsNotNull () {
9899
You can’t perform that action at this time.
0 commit comments