/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1-dev * User agent: apibuilder app.apibuilder.io/speedwing/pagerduty-api/0.0.1-dev/http4s_0_18 */ package com.speedwing.pagerduty.api.v0.models { final case class CreateEvent( serviceKey: String, eventType: com.speedwing.pagerduty.api.v0.models.EventType, incidentKey: _root_.scala.Option[String] = None, description: _root_.scala.Option[String] = None, details: _root_.scala.Option[Map[String, _root_.io.circe.Json]] = None, client: _root_.scala.Option[String] = None, clientUrl: _root_.scala.Option[String] = None, contexts: _root_.scala.Option[Map[String, _root_.io.circe.Json]] = None ) sealed trait EventType extends _root_.scala.Product with _root_.scala.Serializable object EventType { case object Trigger extends EventType { override def toString = "trigger" } case object Acknowledge extends EventType { override def toString = "acknowledge" } case object Resolve extends EventType { override def toString = "resolve" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends EventType /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[EventType] = scala.List(Trigger, Acknowledge, Resolve) private val byName: Map[String, EventType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): EventType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[EventType] = byName.get(value.toLowerCase) } } package com.speedwing.pagerduty.api.v0.models { package object json { import io.circe.Decoder._ import io.circe.Encoder._ import scala.language.implicitConversions // See below - Make Scala 2.11 Either monadic import scala.util.Try import io.circe.{Json, JsonObject, Encoder, Decoder, DecodingFailure} import io.circe.syntax._ import com.speedwing.pagerduty.api.v0.models.json._ // Make Scala 2.11 Either monadic private[v0] implicit def eitherOps[A,B](e: Either[A,B]) = cats.implicits.catsSyntaxEither(e) private[v0] implicit val decodeUUID: Decoder[_root_.java.util.UUID] = Decoder.decodeString.emapTry(str => Try(_root_.java.util.UUID.fromString(str))) private[v0] implicit val encodeUUID: Encoder[_root_.java.util.UUID] = Encoder.encodeString.contramap[_root_.java.util.UUID](uuid => uuid.toString) private[v0] implicit val decodeInstant: Decoder[_root_.java.time.Instant] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.OffsetDateTime.parse(str).toInstant)) private[v0] implicit val encodeInstant: Encoder[_root_.java.time.Instant] = Encoder.encodeString.contramap[_root_.java.time.Instant](_.toString) private[v0] implicit val decodeLocalDate: Decoder[_root_.java.time.LocalDate] = Decoder.decodeString.emapTry(str => Try(_root_.java.time.LocalDate.parse(str))) private[v0] implicit val encodeLocalDate: Encoder[_root_.java.time.LocalDate] = Encoder.encodeString.contramap[_root_.java.time.LocalDate](_.toString) implicit val jsonDecoderPagerdutyApiEventType: Decoder[com.speedwing.pagerduty.api.v0.models.EventType] = Decoder.decodeString.map(com.speedwing.pagerduty.api.v0.models.EventType(_)) implicit val jsonEncoderPagerdutyApiEventType: Encoder[com.speedwing.pagerduty.api.v0.models.EventType] = Encoder.encodeString.contramap[com.speedwing.pagerduty.api.v0.models.EventType](_.toString) implicit def decodePagerdutyApiCreateEvent: Decoder[CreateEvent] = Decoder.instance { c => for { serviceKey <- c.downField("service_key").as[String] eventType <- c.downField("event_type").as[com.speedwing.pagerduty.api.v0.models.EventType] incidentKey <- c.downField("incident_key").as[Option[String]] description <- c.downField("description").as[Option[String]] details <- c.downField("details").as[Option[Map[String, _root_.io.circe.Json]]] client <- c.downField("client").as[Option[String]] clientUrl <- c.downField("client_url").as[Option[String]] contexts <- c.downField("contexts").as[Option[Map[String, _root_.io.circe.Json]]] } yield { CreateEvent( serviceKey = serviceKey, eventType = eventType, incidentKey = incidentKey, description = description, details = details, client = client, clientUrl = clientUrl, contexts = contexts ) } } implicit def encodePagerdutyApiCreateEvent: Encoder[CreateEvent] = Encoder.instance { t => Json.fromFields(Seq( Some("service_key" -> t.serviceKey.asJson), Some("event_type" -> t.eventType.asJson), t.incidentKey.map(t => "incident_key" -> t.asJson), t.description.map(t => "description" -> t.asJson), t.details.map(t => "details" -> t.asJson), t.client.map(t => "client" -> t.asJson), t.clientUrl.map(t => "client_url" -> t.asJson), t.contexts.map(t => "contexts" -> t.asJson) ).flatten) } } }