Skip to content

Commit 3b1be2b

Browse files
authored
refactor: remove dependency on scala-uri (#601)
#601
1 parent 5e1dbe0 commit 3b1be2b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ lazy val root = project
3939
)
4040

4141
// Project dependencies
42-
libraryDependencies += "io.lemonlabs" %% "scala-uri" % "1.4.10"
4342
libraryDependencies += "org.asynchttpclient" % "async-http-client" % "2.10.5"
4443
libraryDependencies += "io.netty" % "netty-resolver-dns" % "4.1.45.Final"
4544
libraryDependencies += "org.json4s" %% "json4s-ast" % "3.6.7"

src/main/scala/algolia/http/HttpPayload.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import java.net.InetAddress
2929

3030
import algolia.objects.RequestOptions
3131
import io.netty.resolver.NameResolver
32-
import io.lemonlabs.uri.dsl._
3332
import org.asynchttpclient.{Request, RequestBuilder}
3433

3534
private[algolia] sealed trait HttpVerb
@@ -67,7 +66,7 @@ private[algolia] case class HttpPayload(
6766
headers: Map[String, String],
6867
dnsNameResolver: NameResolver[InetAddress]
6968
): Request = {
70-
val uri = path.foldLeft(host)((url, p) => url / p)
69+
val uri = path.foldLeft(host)((url, p) => insertPath(url, p))
7170

7271
var builder: RequestBuilder =
7372
new RequestBuilder().setMethod(verb.toString).setUrl(uri)
@@ -109,4 +108,17 @@ private[algolia] case class HttpPayload(
109108
s"$verb $host${_path}${_query}${_body}"
110109
}
111110

111+
private def insertPath(url: String, path: String) =
112+
url.indexOf('?') match {
113+
case -1 => appendPath(url, path)
114+
case i => appendPath(url.substring(0, i), path) + url.substring(i)
115+
}
116+
117+
private def appendPath(url: String, path: String) =
118+
if (url.endsWith("/")) {
119+
url + path
120+
} else {
121+
url + "/" + path
122+
}
123+
112124
}

0 commit comments

Comments
 (0)