From d9c902b3fe5f0a0c23de221f4da0553909c91c1d Mon Sep 17 00:00:00 2001 From: Viktor Podzigun Date: Mon, 25 May 2020 13:45:42 +0200 Subject: [PATCH] Renamed scommons-api-dom module to scommons-api-xhr, fixed #2 --- README.md | 2 +- build.sbt | 4 ++-- .../{ApiDom.scala => ApiXhr.scala} | 10 ++++---- .../api/http/xhr/XhrApiHttpClient.scala | 16 ++++++------- .../api/http/xhr}/raw/XMLHttpRequest.scala | 2 +- .../api/http/xhr/XhrApiHttpClientSpec.scala | 24 +++++++++---------- 6 files changed, 29 insertions(+), 29 deletions(-) rename project/src/main/scala/definitions/{ApiDom.scala => ApiXhr.scala} (76%) rename dom/src/main/scala/scommons/api/http/dom/DomApiHttpClient.scala => xhr/src/main/scala/scommons/api/http/xhr/XhrApiHttpClient.scala (87%) rename {dom/src/main/scala/scommons/api/http/dom => xhr/src/main/scala/scommons/api/http/xhr}/raw/XMLHttpRequest.scala (98%) rename dom/src/test/scala/scommons/api/http/dom/DomApiHttpClientSpec.scala => xhr/src/test/scala/scommons/api/http/xhr/XhrApiHttpClientSpec.scala (94%) diff --git a/README.md b/README.md index 683f8cc..9d67409 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ libraryDependencies ++= Seq( "org.scommons.api" %%% "scommons-api-joda-time" % scommonsApiVer, // client/js only - "org.scommons.api" %%% "scommons-api-dom" % scommonsApiVer, + "org.scommons.api" %%% "scommons-api-xhr" % scommonsApiVer, // server/jvm only "org.scommons.api" %% "scommons-api-play-ws" % scommonsApiVer diff --git a/build.sbt b/build.sbt index dd474a5..736bd61 100644 --- a/build.sbt +++ b/build.sbt @@ -22,7 +22,7 @@ lazy val `scommons-api` = (project in file(".")) `scommons-api-joda-time-jvm`, `scommons-api-joda-time-js`, `scommons-api-play-ws`, - `scommons-api-dom` + `scommons-api-xhr` ) lazy val `scommons-api-core-jvm` = ApiCore.jvm @@ -32,4 +32,4 @@ lazy val `scommons-api-admin-js` = ApiAdmin.js lazy val `scommons-api-joda-time-jvm` = ApiJodaTime.jvm lazy val `scommons-api-joda-time-js` = ApiJodaTime.js lazy val `scommons-api-play-ws` = ApiPlayWs.definition -lazy val `scommons-api-dom` = ApiDom.definition +lazy val `scommons-api-xhr` = ApiXhr.definition diff --git a/project/src/main/scala/definitions/ApiDom.scala b/project/src/main/scala/definitions/ApiXhr.scala similarity index 76% rename from project/src/main/scala/definitions/ApiDom.scala rename to project/src/main/scala/definitions/ApiXhr.scala index f233ca0..f94d124 100644 --- a/project/src/main/scala/definitions/ApiDom.scala +++ b/project/src/main/scala/definitions/ApiXhr.scala @@ -6,22 +6,22 @@ import sbt.Keys._ import sbt._ import scoverage.ScoverageKeys._ -object ApiDom extends ApiModule { +object ApiXhr extends ApiModule { - override val id: String = "scommons-api-dom" + override val id: String = "scommons-api-xhr" - override val base: File = file("dom") + override val base: File = file("xhr") override def definition: Project = { super.definition .enablePlugins(ScalaJSPlugin) .settings( - description := "Common Scala ApiHttpClient implementation using JavaScript XMLHttpRequest", + description := "Scala Commons ApiHttpClient implementation using JavaScript XMLHttpRequest", // disable scoverage, until the following issue is fixed: // https://github.com/scoverage/scalac-scoverage-plugin/issues/196 coverageEnabled := false, - coverageExcludedPackages := "scommons.api.http.dom.raw", + coverageExcludedPackages := "scommons.api.http.xhr.raw", //Opt-in @ScalaJSDefined by default scalacOptions += "-P:scalajs:sjsDefinedByDefault" diff --git a/dom/src/main/scala/scommons/api/http/dom/DomApiHttpClient.scala b/xhr/src/main/scala/scommons/api/http/xhr/XhrApiHttpClient.scala similarity index 87% rename from dom/src/main/scala/scommons/api/http/dom/DomApiHttpClient.scala rename to xhr/src/main/scala/scommons/api/http/xhr/XhrApiHttpClient.scala index ee0dec5..0c0b758 100644 --- a/dom/src/main/scala/scommons/api/http/dom/DomApiHttpClient.scala +++ b/xhr/src/main/scala/scommons/api/http/xhr/XhrApiHttpClient.scala @@ -1,7 +1,7 @@ -package scommons.api.http.dom +package scommons.api.http.xhr import scommons.api.http.ApiHttpData._ -import scommons.api.http.dom.DomApiHttpClient._ +import scommons.api.http.xhr.XhrApiHttpClient._ import scommons.api.http.{ApiHttpClient, ApiHttpData, ApiHttpResponse} import scala.concurrent.duration._ @@ -10,10 +10,10 @@ import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue import scala.scalajs.js import scala.scalajs.js.typedarray._ -class DomApiHttpClient(baseUrl: String, defaultTimeout: FiniteDuration = 30.seconds) +class XhrApiHttpClient(baseUrl: String, defaultTimeout: FiniteDuration = 30.seconds) extends ApiHttpClient(baseUrl, defaultTimeout) { - protected[dom] def execute(method: String, + protected[xhr] def execute(method: String, targetUrl: String, params: List[(String, String)], headers: List[(String, String)], @@ -49,7 +49,7 @@ class DomApiHttpClient(baseUrl: String, defaultTimeout: FiniteDuration = 30.seco } } - private[dom] def createRequest(): raw.XMLHttpRequest = new raw.XMLHttpRequest() + private[xhr] def createRequest(): raw.XMLHttpRequest = new raw.XMLHttpRequest() private def execute(req: raw.XMLHttpRequest, body: Option[String]): Future[raw.XMLHttpRequest] = { val promise = Promise[raw.XMLHttpRequest]() @@ -69,7 +69,7 @@ class DomApiHttpClient(baseUrl: String, defaultTimeout: FiniteDuration = 30.seco } } -object DomApiHttpClient { +object XhrApiHttpClient { private val headersLineRegex = """[\r\n]+""".r private val headersValueRegex = """: """.r @@ -81,7 +81,7 @@ object DomApiHttpClient { }.toMap } - private[dom] def getBodyAsBytes(response: js.Any): Seq[Byte] = { + private[xhr] def getBodyAsBytes(response: js.Any): Seq[Byte] = { if (response == null || js.isUndefined(response)) Nil else { //TODO: handle Blob response as well @@ -89,7 +89,7 @@ object DomApiHttpClient { } } - private[dom] def getFullUrl(url: String, params: List[(String, String)]): String = { + private[xhr] def getFullUrl(url: String, params: List[(String, String)]): String = { def enc(p: String) = js.URIUtils.encodeURIComponent(p) diff --git a/dom/src/main/scala/scommons/api/http/dom/raw/XMLHttpRequest.scala b/xhr/src/main/scala/scommons/api/http/xhr/raw/XMLHttpRequest.scala similarity index 98% rename from dom/src/main/scala/scommons/api/http/dom/raw/XMLHttpRequest.scala rename to xhr/src/main/scala/scommons/api/http/xhr/raw/XMLHttpRequest.scala index f3786c6..c79be75 100644 --- a/dom/src/main/scala/scommons/api/http/dom/raw/XMLHttpRequest.scala +++ b/xhr/src/main/scala/scommons/api/http/xhr/raw/XMLHttpRequest.scala @@ -1,4 +1,4 @@ -package scommons.api.http.dom.raw +package scommons.api.http.xhr.raw import scala.scalajs.js import scala.scalajs.js.annotation.JSGlobal diff --git a/dom/src/test/scala/scommons/api/http/dom/DomApiHttpClientSpec.scala b/xhr/src/test/scala/scommons/api/http/xhr/XhrApiHttpClientSpec.scala similarity index 94% rename from dom/src/test/scala/scommons/api/http/dom/DomApiHttpClientSpec.scala rename to xhr/src/test/scala/scommons/api/http/xhr/XhrApiHttpClientSpec.scala index 0de244e..951857b 100644 --- a/dom/src/test/scala/scommons/api/http/dom/DomApiHttpClientSpec.scala +++ b/xhr/src/test/scala/scommons/api/http/xhr/XhrApiHttpClientSpec.scala @@ -1,10 +1,10 @@ -package scommons.api.http.dom +package scommons.api.http.xhr import org.scalamock.scalatest.AsyncMockFactory import org.scalatest.{Assertion, AsyncFlatSpec, Inside, Matchers} import scommons.api.http.ApiHttpData.{StringData, UrlEncodedFormData} -import scommons.api.http.dom.DomApiHttpClient._ -import scommons.api.http.dom.DomApiHttpClientSpec.MockXMLHttpRequest +import scommons.api.http.xhr.XhrApiHttpClient._ +import scommons.api.http.xhr.XhrApiHttpClientSpec.MockXMLHttpRequest import scommons.api.http.{ApiHttpData, ApiHttpResponse} import scala.concurrent.ExecutionContext @@ -14,7 +14,7 @@ import scala.scalajs.js import scala.scalajs.js.annotation.JSExportAll import scala.scalajs.js.typedarray._ -class DomApiHttpClientSpec extends AsyncFlatSpec +class XhrApiHttpClientSpec extends AsyncFlatSpec with Matchers with Inside with AsyncMockFactory { @@ -23,9 +23,9 @@ class DomApiHttpClientSpec extends AsyncFlatSpec private val baseUrl = "http://test.api.client" - private class TestDomClient(req: MockXMLHttpRequest) extends DomApiHttpClient(baseUrl) { + private class TestXhrClient(req: MockXMLHttpRequest) extends XhrApiHttpClient(baseUrl) { - override private[dom] def createRequest(): raw.XMLHttpRequest = req.asInstanceOf[raw.XMLHttpRequest] + override private[xhr] def createRequest(): raw.XMLHttpRequest = req.asInstanceOf[raw.XMLHttpRequest] } private val params = List("p1" -> "1", "p2" -> "2") @@ -39,7 +39,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec val respHeaders = Map("test_header" -> Seq("test header value")) val expectedResult = ApiHttpResponse(targetUrl, 200, respHeaders, "some resp body") val req = stub[MockXMLHttpRequest] - val client = new TestDomClient(req) + val client = new TestXhrClient(req) (req.open _).when(*, *).returns(()) (req.timeout_= _).when(*).returns(()) @@ -77,7 +77,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec val respHeaders = Map("test_header" -> Seq("test header value")) val expectedResult = ApiHttpResponse(targetUrl, 200, respHeaders, "some resp body") val req = stub[MockXMLHttpRequest] - val client = new TestDomClient(req) + val client = new TestXhrClient(req) (req.open _).when(*, *).returns(()) (req.timeout_= _).when(*).returns(()) @@ -115,7 +115,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec val respHeaders = Map("test_header" -> Seq("test header value")) val expectedResult = ApiHttpResponse(targetUrl, 200, respHeaders, "some resp body") val req = stub[MockXMLHttpRequest] - val client = new TestDomClient(req) + val client = new TestXhrClient(req) (req.open _).when(*, *).returns(()) (req.timeout_= _).when(*).returns(()) @@ -155,7 +155,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec val respHeaders = Map("test_header" -> Seq("test header value")) val expectedResult = ApiHttpResponse(targetUrl, 200, respHeaders, "some resp body") val req = stub[MockXMLHttpRequest] - val client = new TestDomClient(req) + val client = new TestXhrClient(req) (req.open _).when(*, *).returns(()) (req.timeout_= _).when(*).returns(()) @@ -189,7 +189,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec //given val targetUrl = s"$baseUrl/api/get/url" val req = stub[MockXMLHttpRequest] - val client = new TestDomClient(req) + val client = new TestXhrClient(req) (req.open _).when(*, *).returns(()) (req.timeout_= _).when(*).returns(()) @@ -253,7 +253,7 @@ class DomApiHttpClientSpec extends AsyncFlatSpec } } -object DomApiHttpClientSpec { +object XhrApiHttpClientSpec { @JSExportAll trait MockXMLHttpRequest {