identify url in runtime

This commit is contained in:
Evgenii Alekseev 2020-11-26 23:43:14 +03:00
parent 534ed98459
commit 25b05aa289
10 changed files with 19 additions and 22 deletions

View File

@ -1,7 +1,5 @@
me.arcanis.ffxivbis {
bis-provider {
# either use ariyala or etro
use-etro = no
# xivapi base url, string, required
xivapi-url = "https://xivapi.com"
# xivapi developer key, string, optional

View File

@ -34,9 +34,7 @@ class Application extends Actor with StrictLogging {
Migration(config).onComplete {
case Success(_) =>
val useEtro = config.getBoolean("me.arcanis.ffxivbis.bis-provider.use-etro")
val bisProvider = context.system.actorOf(BisProvider.props(useEtro), "bis-provider")
val bisProvider = context.system.actorOf(BisProvider.props, "bis-provider")
val storage = context.system.actorOf(DatabaseImpl.props, "storage")
val party = context.system.actorOf(PartyService.props(storage), "party")
val http = new RootEndpoint(context.system, party, bisProvider)

View File

@ -14,7 +14,7 @@ import spray.json.{JsNumber, JsObject, JsString, deserializationError}
import scala.concurrent.{ExecutionContext, Future}
trait Ariyala {
object Ariyala {
def idParser(job: Job.Job, js: JsObject)
(implicit executionContext: ExecutionContext): Future[Map[String, Long]] =

View File

@ -19,11 +19,7 @@ import spray.json._
import scala.concurrent.{ExecutionContext, Future}
abstract class BisProvider extends Actor with XivApi with StrictLogging {
def idParser(job: Job.Job, js: JsObject)
(implicit executionContext: ExecutionContext): Future[Map[String, Long]]
def uri(root: Uri, id: String): Uri
class BisProvider extends Actor with XivApi with StrictLogging {
override def receive: Receive = {
case BisProvider.GetBiS(link, job) =>
@ -40,15 +36,20 @@ abstract class BisProvider extends Actor with XivApi with StrictLogging {
val url = Uri(link)
val id = Paths.get(link).normalize.getFileName.toString
sendRequest(uri(url, id), BisProvider.parseBisJsonToPieces(job, idParser, getPieceType))
val (idParser, uri) =
if (url.authority.host.address().contains("etro")) {
(Etro.idParser(_, _), Etro.uri(url, id))
} else {
(Ariyala.idParser(_, _), Ariyala.uri(url, id))
}
sendRequest(uri, BisProvider.parseBisJsonToPieces(job, idParser, getPieceType))
}
}
object BisProvider {
def props(useEtro: Boolean): Props =
if (useEtro) Props(new BisProvider with Etro)
else Props(new BisProvider with Ariyala)
def props: Props = Props(new BisProvider)
case class GetBiS(link: String, job: Job.Job)

View File

@ -14,7 +14,7 @@ import spray.json.{JsNumber, JsObject}
import scala.concurrent.{ExecutionContext, Future}
trait Etro {
object Etro {
def idParser(job: Job.Job, js: JsObject)
(implicit executionContext: ExecutionContext): Future[Map[String, Long]] =

View File

@ -31,7 +31,7 @@ class BiSEndpointTest extends WordSpec
implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout)
private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props)
private val provider: ActorRef = system.actorOf(BisProvider.props(false))
private val provider: ActorRef = system.actorOf(BisProvider.props)
private val party: ActorRef = system.actorOf(PartyService.props(storage))
private val route: Route = new BiSEndpoint(party, provider)(timeout).route

View File

@ -30,7 +30,7 @@ class PartyEndpointTest extends WordSpec
implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout)
private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props)
private val provider: ActorRef = system.actorOf(BisProvider.props(false))
private val provider: ActorRef = system.actorOf(BisProvider.props)
private val route: Route = new PartyEndpoint(storage, provider)(timeout).route
override def testConfig: Config = Settings.withRandomDatabase

View File

@ -30,7 +30,7 @@ class PlayerEndpointTest extends WordSpec
implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout)
private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props)
private val provider: ActorRef = system.actorOf(BisProvider.props(false))
private val provider: ActorRef = system.actorOf(BisProvider.props)
private val party: ActorRef = system.actorOf(PartyService.props(storage))
private val route: Route = new PlayerEndpoint(party, provider)(timeout).route

View File

@ -23,7 +23,7 @@ class LootSelectorTest extends TestKit(ActorSystem("lootselector"))
private val timeout: FiniteDuration = 60 seconds
override def beforeAll(): Unit = {
val provider = system.actorOf(BisProvider.props(false))
val provider = system.actorOf(BisProvider.props)
val dncSet = Await.result((provider ? BisProvider.GetBiS(Fixtures.link, Job.DNC) )(timeout).mapTo[BiS], timeout)
dnc = dnc.withBiS(Some(dncSet))

View File

@ -19,13 +19,13 @@ class BisProviderTest extends TestKit(ActorSystem("bis-provider"))
"ariyala actor" must {
"get best in slot set (ariyala)" in {
val provider = system.actorOf(BisProvider.props(false))
val provider = system.actorOf(BisProvider.props)
provider ! BisProvider.GetBiS(Fixtures.link, Job.DNC)
expectMsg(timeout, Fixtures.bis)
}
"get best in slot set (etro)" in {
val provider = system.actorOf(BisProvider.props(true))
val provider = system.actorOf(BisProvider.props)
provider ! BisProvider.GetBiS(Fixtures.link3, Job.DNC)
expectMsg(timeout, Fixtures.bis)
}