Skip to content

Commit

Permalink
Removing the schema configuration (#57)
Browse files Browse the repository at this point in the history
* Removing the schema configuration

* updated sbt version
  • Loading branch information
whiteshadow-gr authored Jul 28, 2021
1 parent 7570825 commit 2cb4d1d
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 77 deletions.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Written by Andrius Aucinas <[email protected]>, 2 / 2017
#
#
sbt.version=1.5.3
sbt.version=1.5.5
6 changes: 3 additions & 3 deletions src/it/scala/org/hatdex/dex/apiV3/DexApplicationsItTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class DexApplicationsItTest extends AsyncFunSuite with Matchers with ScalaCheckD
implicit val ec = scala.concurrent.ExecutionContext.global
test("Get All Applications") {
play.api.test.WsTestClient.withClient { ws =>
val client = new DexClient(ws, "localhost:9000", "http://")
val client = new DexClient(ws, "http://localhost:9000")
client.applications() map { _ mustBe a [Seq[_]] }
}
}

test("Get All Applications with filters and pagination") {
play.api.test.WsTestClient.withClient { ws =>
val client = new DexClient(ws, "localhost:9000", "http://")
val client = new DexClient(ws, "http://localhost:9000")
client.applications(unpublished = Some(true), kind = Some(ApplicationKind.DataPlug("Blah")), startId = None, limit = Some(5)) map { _ mustBe a [Seq[_]] }
}
}

test("Get Application By Id") {
play.api.test.WsTestClient.withClient { ws =>
val client = new DexClient(ws, "localhost:9000", "http://")
val client = new DexClient(ws, "http://localhost:9000")
recoverToSucceededIf[DetailsNotFoundException] {
client.application("Some Id") map { _ mustBe a [Seq[_]] }
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/scala/org/hatdex/dex/api/DexClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ import javax.inject.Inject

class DexClient(
val ws: WSClient,
val dexAddress: String,
override val schema: String)
val dexAddress: String)
extends DexOffers
with DexNotices
with DexDataPlugs
with DexStats {

@Inject def this(
ws: WSClient,
dexAddress: String) = this(ws, dexAddress, "https://")

val logger: Logger = play.api.Logger(this.getClass)
}
3 changes: 1 addition & 2 deletions src/main/scala/org/hatdex/dex/api/DexDataPlugs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import scala.concurrent.{ ExecutionContext, Future }
trait DexDataPlugs {
val logger: Logger
val ws: WSClient
val schema: String
val dexAddress: String

def dataplugConnectHat(
Expand All @@ -21,7 +20,7 @@ trait DexDataPlugs {
logger.debug(s"Connect dataplug $dataplugId to $hatAddress via MarketSquare")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/dataplugs/$dataplugId/connect")
.url(s"$dexAddress/api/dataplugs/$dataplugId/connect")
.withVirtualHost(dexAddress)
.withQueryStringParameters(("hat", hatAddress))
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/org/hatdex/dex/api/DexNotices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import scala.concurrent.{ ExecutionContext, Future }
trait DexNotices {
val logger: Logger
val ws: WSClient
val schema: String
val dexAddress: String

import DexJsonFormats._
Expand All @@ -24,7 +23,7 @@ trait DexNotices {
logger.debug(s"Post notice $notice to MarketSquare")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/notices")
.url(s"$dexAddress/api/notices")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/org/hatdex/dex/api/DexOffers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import scala.concurrent.{ ExecutionContext, Future }
trait DexOffers {
val logger: Logger
val ws: WSClient
val schema: String
val dexAddress: String

import io.dataswift.models.dex.json.DexJsonFormats._
Expand All @@ -26,7 +25,7 @@ trait DexOffers {
logger.debug(s"Get Data Debit $offerId values from $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/offer/$offerId/claims")
.url(s"$dexAddress/api/offer/$offerId/claims")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/org/hatdex/dex/api/DexStats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ trait DexStats {

val logger: Logger
val ws: WSClient
val schema: String
val dexAddress: String

def postStats(
access_token: String,
stats: Seq[DataStats]
)(implicit ec: ExecutionContext): Future[Unit] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/stats/report")
.url(s"$dexAddress/stats/report")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down
21 changes: 10 additions & 11 deletions src/main/scala/org/hatdex/dex/apiV2/DexApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ trait DexApplications {

protected val logger: Logger
protected val ws: WSClient
protected val schema: String
protected val dexAddress: String
protected val apiVersion: String

Expand All @@ -27,7 +26,7 @@ trait DexApplications {

def applications(includeUnpublished: Boolean = false)(implicit ec: ExecutionContext): Future[Seq[Application]] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications")
.url(s"$dexAddress/api/$apiVersion/applications")
.withVirtualHost(dexAddress)
.withQueryStringParameters("unpublished" -> includeUnpublished.toString)
.withHttpHeaders("Accept" -> "application/json")
Expand Down Expand Up @@ -58,7 +57,7 @@ trait DexApplications {
)(implicit ec: ExecutionContext): Future[Application] = {
val requestedLanguage = lang.getOrElse("en")
val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/$applicationId")
.url(s"$dexAddress/api/$apiVersion/applications/$applicationId")
.withVirtualHost(dexAddress)
.withQueryStringParameters("lang" -> requestedLanguage)
.withHttpHeaders("Accept" -> "application/json")
Expand Down Expand Up @@ -91,7 +90,7 @@ trait DexApplications {
includeUnpublished: Boolean = false
)(implicit ec: ExecutionContext): Future[Seq[ApplicationHistory]] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications-history")
.url(s"$dexAddress/api/$apiVersion/applications-history")
.withVirtualHost(dexAddress)
.withQueryStringParameters("unpublished" -> includeUnpublished.toString)
.withHttpHeaders("Accept" -> "application/json")
Expand Down Expand Up @@ -123,7 +122,7 @@ trait DexApplications {
logger.debug(s"Register new app with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications")
.url(s"$dexAddress/api/$apiVersion/applications")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -161,7 +160,7 @@ trait DexApplications {
logger.debug(s"Editing app with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/${application.id}")
.url(s"$dexAddress/api/$apiVersion/applications/${application.id}")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -199,7 +198,7 @@ trait DexApplications {
logger.debug(s"Publishing app with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/${application.id}/publish")
.url(s"$dexAddress/api/$apiVersion/applications/${application.id}/publish")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -230,7 +229,7 @@ trait DexApplications {
logger.debug(s"Suspending app with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/${application.id}/suspend")
.url(s"$dexAddress/api/$apiVersion/applications/${application.id}/suspend")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -258,7 +257,7 @@ trait DexApplications {
logger.debug(s"Fetching application $applicationId with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/$applicationId")
.url(s"$dexAddress/api/$apiVersion/applications/$applicationId")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json")

Expand Down Expand Up @@ -296,7 +295,7 @@ trait DexApplications {
logger.debug(s"Updating developer with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/developer")
.url(s"$dexAddress/api/$apiVersion/applications/developer")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -334,7 +333,7 @@ trait DexApplications {
logger.debug(s"Creating new app version with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/$apiVersion/applications/${application.id}/versions")
.url(s"$dexAddress/api/$apiVersion/applications/${application.id}/versions")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down
9 changes: 2 additions & 7 deletions src/main/scala/org/hatdex/dex/apiV2/DexClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ import javax.inject.Inject

class DexClient(
val ws: WSClient,
val dexAddress: String,
override val schema: String,
override val apiVersion: String)
val dexAddress: String)
extends DexOffers
with DexNotices
with DexDataPlugs
with DexStats
with DexUsers
with DexApplications {

@Inject def this(
ws: WSClient,
dexAddress: String) = this(ws, dexAddress, "https://", "v1.1")

override val apiVersion: String = "v2"
val logger: Logger = play.api.Logger(this.getClass)
}
11 changes: 5 additions & 6 deletions src/main/scala/org/hatdex/dex/apiV2/DexOffers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import scala.concurrent.{ ExecutionContext, Future }
trait DexOffers {
protected val logger: Logger
protected val ws: WSClient
protected val schema: String
protected val dexAddress: String
protected val apiVersion: String

Expand All @@ -22,7 +21,7 @@ trait DexOffers {
logger.debug(s"Get DEX data offers from $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/v2/offers")
.url(s"$dexAddress/api/v2/offers")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json")

Expand Down Expand Up @@ -53,7 +52,7 @@ trait DexOffers {
logger.debug(s"Register new offer with $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/v2/offer")
.url(s"$dexAddress/api/v2/offer")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -91,7 +90,7 @@ trait DexOffers {
logger.debug(s"Get Data Debit $offerId values from $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/v2/offer/$offerId/claims")
.url(s"$dexAddress/api/v2/offer/$offerId/claims")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand Down Expand Up @@ -131,7 +130,7 @@ trait DexOffers {
logger.debug(s"Get Data Debit $offerId values from $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/v2/offer/$offerId/registerClaim")
.url(s"$dexAddress/api/v2/offer/$offerId/registerClaim")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)
.withQueryStringParameters(("hat", hat))
Expand Down Expand Up @@ -183,7 +182,7 @@ trait DexOffers {
logger.debug(s"Get Data Debit $offerId values from $dexAddress")

val request: WSRequest = ws
.url(s"$schema$dexAddress/api/v2/offer/$offerId")
.url(s"$dexAddress/api/v2/offer/$offerId")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)
.withQueryStringParameters(("status", status))
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/org/hatdex/dex/apiV2/DexStats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ trait DexStats {

protected val logger: Logger
protected val ws: WSClient
protected val schema: String
protected val dexAddress: String
protected val apiVersion: String

Expand All @@ -29,7 +28,7 @@ trait DexStats {
stats: Seq[DataStats]
)(implicit ec: ExecutionContext): Future[Unit] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/stats/report")
.url(s"$dexAddress/stats/report")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> access_token)

Expand All @@ -47,7 +46,7 @@ trait DexStats {

def availableData()(implicit ec: ExecutionContext): Future[Seq[NamespaceStructure]] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/stats/available-data")
.url(s"$dexAddress/stats/available-data")
.withVirtualHost(dexAddress)
.withHttpHeaders("Accept" -> "application/json")

Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/org/hatdex/dex/apiV2/DexUsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ trait DexUsers {

protected val logger: Logger
protected val ws: WSClient
protected val schema: String
protected val dexAddress: String
protected val apiVersion: String

Expand All @@ -22,7 +21,7 @@ trait DexUsers {
domain: String
)(implicit ec: ExecutionContext): Future[Done] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/api/users/registerHat")
.url(s"$dexAddress/api/users/registerHat")
.withHttpHeaders("Accept" -> "application/json")

val hat = Json.obj("hatAddress" -> Json.toJson(s"$hatName.$domain"))
Expand All @@ -42,7 +41,7 @@ trait DexUsers {
applicationId: String
)(implicit ec: ExecutionContext): Future[Done] = {
val request: WSRequest = ws
.url(s"$schema$dexAddress/api/users/register-consent/$applicationId")
.url(s"$dexAddress/api/users/register-consent/$applicationId")
.withVirtualHost(dexAddress)
.withRequestTimeout(2500.millis)
.withHttpHeaders("Accept" -> "application/json", "X-Auth-Token" -> accessToken)
Expand Down
Loading

0 comments on commit 2cb4d1d

Please sign in to comment.