@@ -2,24 +2,21 @@ package com.codacy.client.bitbucket.client
2
2
3
3
import java .net .URI
4
4
5
- import akka .stream .Materializer
6
5
import com .codacy .client .bitbucket .client .Authentication ._
7
6
import com .codacy .client .bitbucket .util .HTTPStatusCodes
8
7
import com .codacy .client .bitbucket .util .Implicits .URIQueryParam
8
+ import com .ning .http .client .AsyncHttpClientConfig
9
+ import play .api .http .Writeable
9
10
import play .api .libs .json ._
10
- import play .api .libs .ws .BodyWritable
11
- import play .api .libs .ws .DefaultBodyWritables ._
12
- import play .api .libs .ws .JsonBodyWritables ._
13
- import play .api .libs .ws .ahc .StandaloneAhcWSClient
14
- import play .shaded .ahc .org .asynchttpclient .DefaultAsyncHttpClient
11
+ import play .api .libs .ws .ning .{NingAsyncHttpClientConfigBuilder , NingWSClient }
15
12
16
13
import scala .compat .Platform .EOL
17
14
import scala .concurrent .Await
18
15
import scala .concurrent .duration .{Duration , SECONDS }
19
16
import scala .util .{Failure , Properties , Success , Try }
20
17
21
18
22
- class BitbucketClient (credentials : Credentials )( implicit materializer : Materializer ) {
19
+ class BitbucketClient (credentials : Credentials ) {
23
20
24
21
private lazy val requestTimeout = Duration (10 , SECONDS )
25
22
@@ -54,7 +51,7 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
54
51
(FIRST_PAGE + 1 to lastPage).par.map { page =>
55
52
val nextUrl = new URI (request.url).addQuery(s " page= $page" ).toString
56
53
get(nextUrl) match {
57
- case Right (json ) => extractValues(json )
54
+ case Right (nextJson ) => extractValues(nextJson )
58
55
case Left (error) => FailedResponse (error.detail)
59
56
}
60
57
}.to[Seq ]
@@ -75,7 +72,7 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
75
72
/*
76
73
* Does an API request
77
74
*/
78
- private def performRequest [D , T ](method : String , request : Request [T ], values : D )(implicit reader : Reads [T ], writer : BodyWritable [D ]): RequestResponse [T ] = withClientRequest { client =>
75
+ private def performRequest [D , T ](method : String , request : Request [T ], values : D )(implicit reader : Reads [T ], writer : Writeable [D ]): RequestResponse [T ] = withClientRequest { client =>
79
76
val jpromise = client.url(request.url)
80
77
.authenticate(authenticator)
81
78
.withFollowRedirects(follow = true )
@@ -111,7 +108,7 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
111
108
value
112
109
}
113
110
114
- def postForm [T ](request : Request [T ], values : Map [ String , Seq [ String ]] )(implicit reader : Reads [T ]): RequestResponse [T ] = {
111
+ def postForm [D , T ](request : Request [T ], values : D )(implicit reader : Reads [T ], writer : Writeable [ D ]): RequestResponse [T ] = {
115
112
performRequest(" POST" , request, values)
116
113
}
117
114
@@ -178,15 +175,15 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
178
175
}
179
176
}
180
177
181
- private def withClientEither [T ](block : StandaloneAhcWSClient => Either [ResponseError , T ]): Either [ResponseError , T ] = {
178
+ private def withClientEither [T ](block : NingWSClient => Either [ResponseError , T ]): Either [ResponseError , T ] = {
182
179
withClient(block) match {
183
180
case Success (res) => res
184
181
case Failure (error) =>
185
182
Left (ResponseError (" Request failed" , getFullStackTrace(error), error.getMessage))
186
183
}
187
184
}
188
185
189
- private def withClientRequest [T ](block : StandaloneAhcWSClient => RequestResponse [T ]): RequestResponse [T ] = {
186
+ private def withClientRequest [T ](block : NingWSClient => RequestResponse [T ]): RequestResponse [T ] = {
190
187
withClient(block) match {
191
188
case Success (res) => res
192
189
case Failure (error) =>
@@ -200,8 +197,10 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
200
197
}
201
198
}
202
199
203
- private def withClient [T ](block : StandaloneAhcWSClient => T ): Try [T ] = {
204
- val client = new StandaloneAhcWSClient (new DefaultAsyncHttpClient )
200
+ private def withClient [T ](block : NingWSClient => T ): Try [T ] = {
201
+ val config = new NingAsyncHttpClientConfigBuilder ().build()
202
+ val clientConfig = new AsyncHttpClientConfig .Builder (config).build()
203
+ val client = new NingWSClient (clientConfig)
205
204
val result = Try (block(client))
206
205
client.close()
207
206
result
0 commit comments