From 533acb07ad71a6f43429e6ee92adf77d2b115ce4 Mon Sep 17 00:00:00 2001 From: Iryna Svitlychenko Date: Sat, 11 Nov 2017 16:34:33 +0000 Subject: extending apply method for URIs containing scheme, host and path --- core/src/main/scala/com/softwaremill/sttp/Uri.scala | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core') diff --git a/core/src/main/scala/com/softwaremill/sttp/Uri.scala b/core/src/main/scala/com/softwaremill/sttp/Uri.scala index 9945179..a8403d7 100644 --- a/core/src/main/scala/com/softwaremill/sttp/Uri.scala +++ b/core/src/main/scala/com/softwaremill/sttp/Uri.scala @@ -193,6 +193,8 @@ object Uri { Uri(scheme, None, host, Some(port), Vector.empty, Vector.empty, None) def apply(scheme: String, host: String, port: Int, path: Seq[String]): Uri = Uri(scheme, None, host, Some(port), path, Vector.empty, None) + def apply(scheme: String, host: String, path: Seq[String]): Uri = + Uri(scheme, None, host, None, path, Vector.empty, None) sealed trait QueryFragment object QueryFragment { -- cgit v1.2.3 From 4ef6accfd07d13608c5773ed7b79aefa8db55905 Mon Sep 17 00:00:00 2001 From: Iryna Svitlychenko Date: Sat, 11 Nov 2017 17:01:51 +0000 Subject: added compatibility with Java URI --- core/src/main/scala/com/softwaremill/sttp/Uri.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/src/main/scala/com/softwaremill/sttp/Uri.scala b/core/src/main/scala/com/softwaremill/sttp/Uri.scala index a8403d7..e4d8a8e 100644 --- a/core/src/main/scala/com/softwaremill/sttp/Uri.scala +++ b/core/src/main/scala/com/softwaremill/sttp/Uri.scala @@ -1,7 +1,7 @@ package com.softwaremill.sttp import java.net.URLEncoder - +import java.net.URI import Uri.{QueryFragment, QueryFragmentEncoding, UserInfo} import Uri.QueryFragment.{KeyValue, Plain, Value} @@ -28,6 +28,7 @@ case class Uri(scheme: String, queryFragments: Seq[QueryFragment], fragment: Option[String]) { + def scheme(s: String): Uri = this.copy(scheme = s) def userInfo(username: String): Uri = @@ -195,6 +196,14 @@ object Uri { Uri(scheme, None, host, Some(port), path, Vector.empty, None) def apply(scheme: String, host: String, path: Seq[String]): Uri = Uri(scheme, None, host, None, path, Vector.empty, None) + def apply(javaUri: URI): Uri = { + val scheme: String = javaUri.getScheme + val host: String = javaUri.getHost + val port: Option[Int] = Option(javaUri.getPort) + val path: Seq[String] = javaUri.getPath.split("/").toList.tail + val fragment: Option[String] = Option(javaUri.getFragment) + Uri(scheme, None, host, port, path, Vector.empty, fragment) + } sealed trait QueryFragment object QueryFragment { -- cgit v1.2.3