@@ -4,25 +4,24 @@ import io.circe.parser.parse
44import io .circe .{Json , ParsingFailure }
55import scalaj .http .{Http , HttpRequest , HttpResponse , HttpOptions }
66
7- class HttpHelper (apiUrl : String , extraHeaders : Map [String , String ], allowUnsafeSSL : Boolean = false ) {
7+ class HttpHelper (apiUrl : String , extraHeaders : Map [String , String ], allowUnsafeSSL : Boolean ) {
88
99 private lazy val connectionTimeoutMs = 2000
1010 private lazy val readTimeoutMs = 5000
1111
1212 private val remoteUrl = apiUrl + " /2.0"
1313
14+ private def httpOptions = if (allowUnsafeSSL) Seq (HttpOptions .allowUnsafeSSL) else Seq .empty
15+
1416 def get (endpoint : String ): Either [ParsingFailure , Json ] = {
1517 val headers : Map [String , String ] = Map (" Content-Type" -> " application/json" ) ++ extraHeaders
1618
1719 val response : HttpResponse [String ] =
18- if (allowUnsafeSSL)
19- Http (s " $remoteUrl$endpoint" )
20- .headers(headers)
21- .timeout(connectionTimeoutMs, readTimeoutMs)
22- .options(HttpOptions .allowUnsafeSSL)
23- .asString
24- else
25- Http (s " $remoteUrl$endpoint" ).headers(headers).timeout(connectionTimeoutMs, readTimeoutMs).asString
20+ Http (s " $remoteUrl$endpoint" )
21+ .headers(headers)
22+ .timeout(connectionTimeoutMs, readTimeoutMs)
23+ .options(httpOptions)
24+ .asString
2625
2726 parse(response.body)
2827
@@ -34,11 +33,7 @@ class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeS
3433 } ++ extraHeaders
3534
3635 val request : HttpRequest = dataOpt.map { data =>
37- if (allowUnsafeSSL) {
38- Http (s " $remoteUrl$endpoint" ).options(HttpOptions .allowUnsafeSSL).postData(data.toString)
39- } else {
40- Http (s " $remoteUrl$endpoint" ).postData(data.toString)
41- }
36+ Http (s " $remoteUrl$endpoint" ).options(httpOptions).postData(data.toString)
4237
4338 }.getOrElse(Http (s " $remoteUrl$endpoint" ))
4439 .method(" POST" )
0 commit comments