-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/scala/me/arcanis/ffxivbis/service/bis/parser/impl/XIVGear.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2019-2022 Evgeniy Alekseev. | ||
* | ||
* This file is part of ffxivbis | ||
* (see https://github.com/arcan1s/ffxivbis). | ||
* | ||
* License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package me.arcanis.ffxivbis.service.bis.parser.impl | ||
|
||
import akka.http.scaladsl.model.Uri | ||
import me.arcanis.ffxivbis.models.Job | ||
import me.arcanis.ffxivbis.service.bis.BisProvider | ||
import me.arcanis.ffxivbis.service.bis.parser.Parser | ||
import spray.json.{deserializationError, JsNumber, JsObject} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
object XIVGear extends Parser { | ||
|
||
override def parse(job: Job, js: JsObject)(implicit executionContext: ExecutionContext): Future[Map[String, Long]] = | ||
Future { | ||
val set = js.fields.get("items") match { | ||
case Some(JsObject(items)) => items | ||
case other => throw deserializationError(s"Invalid job name $other") | ||
} | ||
set.foldLeft(Map.empty[String, Long]) { | ||
case (acc, (key, JsObject(properties))) => | ||
val pieceId = properties.get("id").collect { case JsNumber(id) => | ||
id.toLong | ||
} | ||
(for ( | ||
piece <- BisProvider.remapKey(key); | ||
id <- pieceId | ||
) yield (piece, id)).map(acc + _).getOrElse(acc) | ||
case (acc, _) => acc | ||
} | ||
} | ||
|
||
override def uri(root: Uri, id: String): Uri = { | ||
val gearSet = Uri(id).query().get("page").map(_.replace("sl|", "")).getOrElse(id) | ||
root.withHost(s"api.${root.authority.host.address()}").withPath(Uri.Path / "shortlink" / gearSet) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters