1
1
package de .innfactory .smithy4play .client
2
2
3
- import cats .data .{ EitherT , Kleisli }
3
+ import cats .data .EitherT
4
4
import play .api .libs .ws .{ writeableOf_ByteArray , WSClient , WSResponse }
5
5
import smithy4s .client .UnaryLowLevelClient
6
6
import smithy4s .http .{ CaseInsensitive , HttpRequest , HttpResponse }
@@ -16,22 +16,22 @@ class Smithy4PlayWsClient[Alg[_[_, _, _, _, _]]](
16
16
requestIsSuccessful : (Hints , HttpResponse [Blob ]) => Boolean = matchStatusCodeForResponse,
17
17
explicitDefaultsEncoding : Boolean = true
18
18
)(implicit ec : ExecutionContext , wsClient : WSClient )
19
- extends UnaryLowLevelClient [RunnableClientRequest , HttpRequest [Blob ], HttpResponse [Blob ]] {
19
+ extends UnaryLowLevelClient [FinishedClientResponse , HttpRequest [Blob ], HttpResponse [Blob ]] {
20
20
21
21
val underlyingClient = new SmithyPlayClient [Alg , Smithy4PlayWsClient [Alg ]](
22
22
baseUri = baseUri,
23
23
service = service,
24
24
client = this ,
25
25
middleware = middleware,
26
- requestIsSuccessful = (_, _) => true ,
26
+ requestIsSuccessful = requestIsSuccessful ,
27
27
toSmithy4sClient = x => x
28
28
)
29
29
30
- def transformer (): Alg [Kind1 [ClientFinishedResponse ]# toKind5] =
30
+ def transformer (): Alg [Kind1 [RunnableClientResponse ]# toKind5] =
31
31
underlyingClient.service.algebra(underlyingClient.compiler)
32
32
33
33
private def buildPath (req : HttpRequest [Blob ]): String =
34
- baseUri + req.uri.path.mkString(" /" )
34
+ baseUri + req.uri.path.mkString(" /" , " / " , " " )
35
35
36
36
private def toHeaders (request : HttpRequest [Blob ]): List [(String , String )] =
37
37
request.headers.flatMap { case (insensitive, strings) =>
@@ -52,7 +52,7 @@ class Smithy4PlayWsClient[Alg[_[_, _, _, _, _]]](
52
52
53
53
override def run [Output ](
54
54
request : HttpRequest [Blob ]
55
- )(responseCB : HttpResponse [Blob ] => RunnableClientRequest [Output ]): RunnableClientRequest [Output ] = Kleisli { _ =>
55
+ )(responseCB : HttpResponse [Blob ] => FinishedClientResponse [Output ]): FinishedClientResponse [Output ] = {
56
56
val clientResponse = wsClient
57
57
.url(buildPath(request))
58
58
.withQueryStringParameters(toQueryParameters(request): _* )
@@ -63,13 +63,7 @@ class Smithy4PlayWsClient[Alg[_[_, _, _, _, _]]](
63
63
64
64
val httpResponse = clientResponse.map(wsRequestToResponse)
65
65
66
- println(" run ws client" )
67
-
68
- EitherT (httpResponse.flatMap { httpResponse =>
69
- println(" httpresponse present and running internally" )
70
- val v = responseCB(httpResponse).run(() => httpResponse).value
71
- v
72
- })
66
+ EitherT (httpResponse.flatMap(responseCB(_).value))
73
67
74
68
}
75
69
}
@@ -81,6 +75,6 @@ object Smithy4PlayWsClient {
81
75
middleware : Endpoint .Middleware [Smithy4PlayWsClient [Alg ]],
82
76
requestIsSuccessful : (Hints , HttpResponse [Blob ]) => Boolean = matchStatusCodeForResponse,
83
77
explicitDefaultsEncoding : Boolean = true
84
- )(implicit ec : ExecutionContext , wsClient : WSClient ): Alg [Kind1 [ClientFinishedResponse ]# toKind5] =
78
+ )(implicit ec : ExecutionContext , wsClient : WSClient ): Alg [Kind1 [RunnableClientResponse ]# toKind5] =
85
79
new Smithy4PlayWsClient (baseUri, service, middleware, requestIsSuccessful, explicitDefaultsEncoding).transformer()
86
80
}
0 commit comments