in app/model/AWSCost.scala [78:108]
def pricesFromJson(url: String) = wsClient.url(url).withRequestTimeout(2.seconds).get map { response =>
logger.info("Fetched cost data")
implicit object BigDecimalReads extends Reads[BigDecimal]{
def reads(json: JsValue) = JsSuccess(Try { BigDecimal(json.as[String]) } getOrElse (BigDecimal(0)) )
}
implicit object RegionPricesReads extends Reads[RegionPrices] {
def reads(json: JsValue) = {
val JsArray(typeGroups) = json
val typeToCost = for {
group <- typeGroups
JsArray(size) = (group \ "sizes").get
s <- size
} yield {
val JsArray(c) = (s \ "valueColumns").get
(s \ "size").as[String] -> (c.head \ "prices" \ "USD").as[BigDecimal]
}
JsSuccess(RegionPrices(typeToCost.toMap))
}
}
implicit object OnDemandPricesReads extends Reads[OnDemandPrices] {
def reads(json: JsValue) = {
val JsArray(regionsJs) = (json \ "config" \ "regions").get
val regions = regionsJs.map { r =>
(r \ "region").as[String] -> (r \ "instanceTypes").as[RegionPrices]
}
JsSuccess(OnDemandPrices(regions.toMap))
}
}
Json.parse(response.body.dropWhile(_ != '{').takeWhile(_ != ')')).as[OnDemandPrices]
}