io.circe.generic.semiauto.deriveDecoder Scala Examples
The following examples show how to use io.circe.generic.semiauto.deriveDecoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: ServiceDescribeRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceDescribeRequest( appId: AppId, managerId: Option[String], packageName: Option[String], packageVersion: Option[universe.v3.model.Version] ) object ServiceDescribeRequest { implicit val encode: Encoder[ServiceDescribeRequest] = deriveEncoder implicit val decode: Decoder[ServiceDescribeRequest] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceDescribeRequest] = MediaTypedEncoder(MediaTypes.ServiceDescribeRequest) implicit val mediaTypedRequestDecoder: MediaTypedRequestDecoder[ServiceDescribeRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ServiceDescribeRequest)) }
Example 2
Source File: SlackJson.scala From gospeak with Apache License 2.0 | 5 votes |
package gospeak.libs.slack import java.time.Instant import cats.implicits._ import gospeak.libs.slack.domain._ import gospeak.libs.scala.CirceUtils.decodeSingleValueClass import io.circe.Decoder import io.circe.generic.semiauto.deriveDecoder object SlackJson { private val _: Decoder[SlackChannel.Id] = decodeSingleValueClass // to keep gospeak.infra.utils.CirceUtils._ import private implicit val instantDecoder: Decoder[Instant] = Decoder.decodeLong.emap { timestampSecs => Either.catchNonFatal(Instant.ofEpochSecond(timestampSecs)).leftMap(e => s"Bad Instant: ${e.getMessage}") } implicit val slackErrorDecoder: Decoder[SlackError] = deriveDecoder[SlackError] implicit val slackInfoDecoder: Decoder[SlackTokenInfo] = deriveDecoder[SlackTokenInfo] private implicit val slackChannelPurposeDecoder: Decoder[SlackChannel.Purpose] = deriveDecoder[SlackChannel.Purpose] private implicit val slackChannelTopicDecoder: Decoder[SlackChannel.Topic] = deriveDecoder[SlackChannel.Topic] private implicit val slackChannelDecoder: Decoder[SlackChannel] = deriveDecoder[SlackChannel] implicit val slackChannelSingleDecoder: Decoder[SlackChannel.Single] = deriveDecoder[SlackChannel.Single] implicit val slackChannelListDecoder: Decoder[SlackChannel.List] = deriveDecoder[SlackChannel.List] private implicit val slackUserProfileDecoder: Decoder[SlackUser.Profile] = deriveDecoder[SlackUser.Profile] private implicit val slackUserDecoder: Decoder[SlackUser] = deriveDecoder[SlackUser] implicit val slackUserListDecoder: Decoder[SlackUser.List] = deriveDecoder[SlackUser.List] private implicit val slackMessageDecoder: Decoder[SlackMessage] = deriveDecoder[SlackMessage] implicit val slackMessagePostedDecoder: Decoder[SlackMessage.Posted] = deriveDecoder[SlackMessage.Posted] }
Example 3
Source File: MeetupJson.scala From gospeak with Apache License 2.0 | 5 votes |
package gospeak.libs.meetup import gospeak.libs.meetup.domain._ import io.circe.Decoder import io.circe.generic.semiauto.deriveDecoder object MeetupJson { implicit val meetupTokenDecoder: Decoder[MeetupToken] = deriveDecoder[MeetupToken] implicit val meetupPhotoDecoder: Decoder[MeetupPhoto] = deriveDecoder[MeetupPhoto] implicit val meetupPhotoAltDecoder: Decoder[MeetupPhoto.Alt] = deriveDecoder[MeetupPhoto.Alt] implicit val meetupUserDecoder: Decoder[MeetupUser] = deriveDecoder[MeetupUser] implicit val meetupUserAltDecoder: Decoder[MeetupUser.Alt] = deriveDecoder[MeetupUser.Alt] implicit val meetupUserBasicDecoder: Decoder[MeetupUser.Basic] = deriveDecoder[MeetupUser.Basic] implicit val meetupUserMemberGroupDetailsDecoder: Decoder[MeetupUser.Member.GroupDetails] = deriveDecoder[MeetupUser.Member.GroupDetails] implicit val meetupUserMemberGroupProfileDecoder: Decoder[MeetupUser.Member.GroupProfile] = deriveDecoder[MeetupUser.Member.GroupProfile] implicit val meetupUserMemberDecoder: Decoder[MeetupUser.Member] = deriveDecoder[MeetupUser.Member] implicit val meetupVenueDecoder: Decoder[MeetupVenue] = deriveDecoder[MeetupVenue] implicit val meetupVenueBasicDecoder: Decoder[MeetupVenue.Basic] = deriveDecoder[MeetupVenue.Basic] implicit val meetupGroupDecoder: Decoder[MeetupGroup] = deriveDecoder[MeetupGroup] implicit val meetupGroupBasicDecoder: Decoder[MeetupGroup.Basic] = deriveDecoder[MeetupGroup.Basic] implicit val meetupEventDecoder: Decoder[MeetupEvent] = deriveDecoder[MeetupEvent] implicit val meetupAttendeeMemberDecoder: Decoder[MeetupAttendee.Member] = deriveDecoder[MeetupAttendee.Member] implicit val meetupAttendeeContextDecoder: Decoder[MeetupAttendee.Context] = deriveDecoder[MeetupAttendee.Context] implicit val meetupAttendeeRsvpDecoder: Decoder[MeetupAttendee.Rsvp] = deriveDecoder[MeetupAttendee.Rsvp] implicit val meetupAttendeeDecoder: Decoder[MeetupAttendee] = deriveDecoder[MeetupAttendee] implicit val meetupLocationDecoder: Decoder[MeetupLocation] = deriveDecoder[MeetupLocation] implicit val meetupErrorDecoder: Decoder[MeetupError] = deriveDecoder[MeetupError] implicit val meetupErrorNotAuthorizedDecoder: Decoder[MeetupError.NotAuthorized] = deriveDecoder[MeetupError.NotAuthorized] implicit val meetupErrorCodeDecoder: Decoder[MeetupError.Code] = deriveDecoder[MeetupError.Code] implicit val meetupErrorMultiDecoder: Decoder[MeetupError.Multi] = deriveDecoder[MeetupError.Multi] }
Example 4
Source File: ServiceDescribeResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceDescribeResponse( `package`: universe.v4.model.PackageDefinition, upgradesTo: List[universe.v3.model.Version], downgradesTo: List[universe.v3.model.Version], resolvedOptions: Option[JsonObject], userProvidedOptions: Option[JsonObject] ) object ServiceDescribeResponse { implicit val encode: Encoder[ServiceDescribeResponse] = deriveEncoder implicit val decode: Decoder[ServiceDescribeResponse] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceDescribeResponse] = MediaTypedEncoder(MediaTypes.ServiceDescribeResponse) implicit val dispatchingMediaTypedEncoder: DispatchingMediaTypedEncoder[ServiceDescribeResponse] = DispatchingMediaTypedEncoder(MediaTypes.ServiceDescribeResponse) }
Example 5
Source File: InstallResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallResponse( packageName: String, packageVersion: PackageDetailsVersion, appId: AppId ) object InstallResponse { implicit val encodeInstallResponse: Encoder[InstallResponse] = deriveEncoder[InstallResponse] implicit val decodeInstallResponse: Decoder[InstallResponse] = deriveDecoder[InstallResponse] implicit val packageInstallV1Encoder: DispatchingMediaTypedEncoder[InstallResponse] = DispatchingMediaTypedEncoder(MediaTypes.V1InstallResponse) }
Example 6
Source File: DescribeRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class DescribeRequest( packageName: String, packageVersion: Option[PackageDetailsVersion] ) object DescribeRequest { implicit val encodeDescribeRequest: Encoder[DescribeRequest] = deriveEncoder[DescribeRequest] implicit val decodeDescribeRequest: Decoder[DescribeRequest] = deriveDecoder[DescribeRequest] implicit val packageDescribeDecoder: MediaTypedRequestDecoder[DescribeRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.DescribeRequest)) }
Example 7
Source File: InstalledPackageInformationPackageDetails.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstalledPackageInformationPackageDetails( packagingVersion: universe.v2.model.PackagingVersion, name: String, version: universe.v2.model.PackageDetailsVersion, maintainer: String, description: String, tags: List[String] = Nil, selected: Option[Boolean] = None, scm: Option[String] = None, website: Option[String] = None, framework: Option[Boolean] = None, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[universe.v2.model.License]] = None ) object InstalledPackageInformationPackageDetails { implicit val encodeInstalledPackageInformationPackageDetails: Encoder[InstalledPackageInformationPackageDetails] = { deriveEncoder[InstalledPackageInformationPackageDetails] } implicit val decodeInstalledPackageInformationPackageDetails: Decoder[InstalledPackageInformationPackageDetails] = { deriveDecoder[InstalledPackageInformationPackageDetails] } }
Example 8
Source File: UninstallResult.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class UninstallResult( packageName: String, appId: AppId, packageVersion: Option[PackageDetailsVersion], postUninstallNotes: Option[String] ) object UninstallResult { implicit val encodeUninstallResult: Encoder[UninstallResult] = deriveEncoder[UninstallResult] implicit val decodeUninstallResult: Decoder[UninstallResult] = deriveDecoder[UninstallResult] }
Example 9
Source File: RenderRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class RenderRequest( packageName: String, packageVersion: Option[PackageDetailsVersion] = None, options: Option[JsonObject] = None, appId: Option[AppId] = None ) object RenderRequest{ implicit val encodeRenderRequest: Encoder[RenderRequest] = deriveEncoder[RenderRequest] implicit val decodeRenderRequest: Decoder[RenderRequest] = deriveDecoder[RenderRequest] implicit val packageRenderDecoder: MediaTypedRequestDecoder[RenderRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.RenderRequest)) }
Example 10
Source File: InstallRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe.v2.model.PackageDetailsVersion import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallRequest( packageName: String, packageVersion: Option[PackageDetailsVersion], options: Option[JsonObject], appId: Option[AppId], managerId: Option[String] ) object InstallRequest { implicit val encodeInstallRequest: Encoder[InstallRequest] = deriveEncoder[InstallRequest] implicit val decodeInstallRequest: Decoder[InstallRequest] = deriveDecoder[InstallRequest] implicit val packageInstallDecoder: MediaTypedRequestDecoder[InstallRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.InstallRequest)) }
Example 11
Source File: SearchResult.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class SearchResult( name: String, currentVersion: universe.v3.model.Version, versions: Map[universe.v3.model.Version, universe.v3.model.ReleaseVersion], description: String, framework: Boolean, tags: List[universe.v3.model.Tag], selected: Option[Boolean] = None, images: Option[universe.v3.model.Images] = None ) object SearchResult { implicit val encodeSearchResult: Encoder[SearchResult] = deriveEncoder[SearchResult] implicit val decodeSearchResult: Decoder[SearchResult] = deriveDecoder[SearchResult] }
Example 12
Source File: ListRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListRequest( packageName: Option[String] = None, appId: Option[AppId] = None ) object ListRequest { implicit val encodeListRequest: Encoder[ListRequest] = deriveEncoder[ListRequest] implicit val decodeListRequest: Decoder[ListRequest] = deriveDecoder[ListRequest] implicit val packageListDecoder: MediaTypedRequestDecoder[ListRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ListRequest)) }
Example 13
Source File: ListVersionsResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe.v2.model.{PackageDetailsVersion, ReleaseVersion} import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListVersionsResponse( results: Map[PackageDetailsVersion, ReleaseVersion] ) object ListVersionsResponse { implicit val encodeListVersionsResponse: Encoder[ListVersionsResponse] = deriveEncoder[ListVersionsResponse] implicit val decodeListVersionsResponse: Decoder[ListVersionsResponse] = deriveDecoder[ListVersionsResponse] implicit val packageListVersionsEncoder: DispatchingMediaTypedEncoder[ListVersionsResponse] = DispatchingMediaTypedEncoder(MediaTypes.ListVersionsResponse) }
Example 14
Source File: TargetSettings.scala From scylla-migrator with Apache License 2.0 | 5 votes |
package com.scylladb.migrator.config import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } case class TargetSettings(host: String, port: Int, credentials: Option[Credentials], keyspace: String, table: String, connections: Option[Int]) object TargetSettings { implicit val encoder: Encoder[TargetSettings] = deriveEncoder[TargetSettings] implicit val decoder: Decoder[TargetSettings] = deriveDecoder[TargetSettings] }
Example 15
Source File: ListVersionsRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ListVersionsRequest( packageName: String, includePackageVersions: Boolean ) object ListVersionsRequest { implicit val encodeListVersionsRequest: Encoder[ListVersionsRequest] = deriveEncoder[ListVersionsRequest] implicit val decodeListVersionsRequest: Decoder[ListVersionsRequest] = deriveDecoder[ListVersionsRequest] implicit val packageListVersionsDecoder: MediaTypedRequestDecoder[ListVersionsRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ListVersionsRequest)) }
Example 16
Source File: ServiceUpdateResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.DispatchingMediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceUpdateResponse( `package`: universe.v4.model.PackageDefinition, resolvedOptions: JsonObject, marathonDeploymentId: String ) object ServiceUpdateResponse { implicit val encode: Encoder[ServiceUpdateResponse] = deriveEncoder implicit val decode: Decoder[ServiceUpdateResponse] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceUpdateResponse] = MediaTypedEncoder(MediaTypes.ServiceUpdateResponse) implicit val dispatchingMediaTypedEncoder: DispatchingMediaTypedEncoder[ServiceUpdateResponse] = DispatchingMediaTypedEncoder(MediaTypes.ServiceUpdateResponse) }
Example 17
Source File: ErrorResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.error.CosmosError import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ErrorResponse( `type`: String, message: String, data: Option[JsonObject] = None ) object ErrorResponse { implicit val encode: Encoder[ErrorResponse] = deriveEncoder implicit val decode: Decoder[ErrorResponse] = deriveDecoder def apply(error: CosmosError) : ErrorResponse = { ErrorResponse( error.getClass.getSimpleName, error.message, error.data ) } }
Example 18
Source File: ServiceUpdateRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedEncoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class ServiceUpdateRequest( appId: AppId, packageVersion: Option[universe.v3.model.Version], options: Option[JsonObject], replace: Boolean, managerId: Option[String], packageName: Option[String], currentPackageVersion: Option[universe.v3.model.Version] ) object ServiceUpdateRequest { implicit val encode: Encoder[ServiceUpdateRequest] = deriveEncoder implicit val decode: Decoder[ServiceUpdateRequest] = deriveDecoder implicit val mediaTypedEncoder: MediaTypedEncoder[ServiceUpdateRequest] = MediaTypedEncoder(MediaTypes.ServiceUpdateRequest) implicit val mediaTypedRequestDecoder: MediaTypedRequestDecoder[ServiceUpdateRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.ServiceUpdateRequest)) }
Example 19
Source File: UninstallRequest.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v1.model import com.mesosphere.cosmos.finch.MediaTypedDecoder import com.mesosphere.cosmos.finch.MediaTypedRequestDecoder import com.mesosphere.cosmos.rpc.MediaTypes import com.mesosphere.cosmos.thirdparty import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class UninstallRequest( packageName: String, appId: Option[thirdparty.marathon.model.AppId], all: Option[Boolean], managerId: Option[String], packageVersion: Option[universe.v3.model.Version] ) object UninstallRequest { implicit val encodeUninstallRequest: Encoder[UninstallRequest] = deriveEncoder[UninstallRequest] implicit val decodeUninstallRequest: Decoder[UninstallRequest] = deriveDecoder[UninstallRequest] implicit val packageUninstallDecoder: MediaTypedRequestDecoder[UninstallRequest] = MediaTypedRequestDecoder(MediaTypedDecoder(MediaTypes.UninstallRequest)) }
Example 20
Source File: DescribeResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v2.model import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class DescribeResponse( packagingVersion: universe.v3.model.PackagingVersion, name: String, version: universe.v3.model.Version, maintainer: String, description: String, tags: List[universe.v3.model.Tag] = Nil, selected: Boolean = false, scm: Option[String] = None, website: Option[String] = None, framework: Boolean = false, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[universe.v3.model.License]] = None, minDcosReleaseVersion: Option[universe.v3.model.DcosReleaseVersion] = None, marathon: Option[universe.v3.model.Marathon] = None, resource: Option[universe.v3.model.V3Resource] = None, config: Option[JsonObject] = None, command: Option[universe.v3.model.Command] = None ) object DescribeResponse { implicit val encodeV2DescribeResponse: Encoder[DescribeResponse] = { deriveEncoder[DescribeResponse] } implicit val decodeV2DescribeResponse: Decoder[DescribeResponse] = { deriveDecoder[DescribeResponse] } }
Example 21
Source File: InstallResponse.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.cosmos.rpc.v2.model import com.mesosphere.cosmos.rpc import com.mesosphere.cosmos.thirdparty.marathon.model.AppId import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class InstallResponse( packageName: String, packageVersion: universe.v3.model.Version, appId: Option[AppId] = None, postInstallNotes: Option[String] = None, cli: Option[universe.v3.model.Cli] = None ) object InstallResponse { implicit val encodeV2InstallResponse: Encoder[rpc.v2.model.InstallResponse] = { deriveEncoder[rpc.v2.model.InstallResponse] } implicit val decodeV2InstallResponse: Decoder[InstallResponse] = deriveDecoder[InstallResponse] }
Example 22
Source File: PackageCoordinate.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v1.model import fastparse.all._ import com.mesosphere.cosmos.circe.Decoders.decode import com.mesosphere.error.ResultOps import com.mesosphere.universe import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder import io.circe.syntax._ import java.nio.charset.StandardCharsets import org.apache.commons.codec.binary.Base32 import scala.util.Try final case class PackageCoordinate(name: String, version: universe.v3.model.Version) { override def toString(): String = { PackageCoordinate.toString(this) } } object PackageCoordinate { private[this] val base32 = new Base32() implicit val encodePackageCoordinate: Encoder[PackageCoordinate] = deriveEncoder[PackageCoordinate] implicit val decodePackageCoordinate: Decoder[PackageCoordinate] = deriveDecoder[PackageCoordinate] def parse(string: String): Option[PackageCoordinate] = { parser.parse(string).fold( (_, _, _) => None, (pc, _) => Some(pc) ) } val parser: Parser[PackageCoordinate] = { CharIn('a' to 'z', '0' to '9').rep(1).!.flatMap { string => Try { val coordinate = new String( base32.decode(string.toUpperCase), StandardCharsets.UTF_8 ) decode[PackageCoordinate](coordinate).getOrThrow } fold ( _ => Fail, pc => PassWith(pc) ) } } def toString(pc: PackageCoordinate): String = { base32.encodeAsString( pc.asJson.noSpaces.getBytes(StandardCharsets.UTF_8) ).toLowerCase.replace("=", "") } }
Example 23
Source File: PackageFiles.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v2.model import io.lemonlabs.uri.Uri import io.circe.Decoder import io.circe.Encoder import io.circe.JsonObject import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder import com.mesosphere.cosmos.circe.Encoders.encodeUri import com.mesosphere.cosmos.circe.Decoders.decodeUri case class PackageFiles( revision: String, sourceUri: Uri, packageJson: PackageDetails, marathonJsonMustache: String, commandJson: Option[Command] = None, configJson: Option[JsonObject] = None, resourceJson: Option[Resource] = None ) object PackageFiles { implicit val encodeV2PackageFiles: Encoder[PackageFiles] = deriveEncoder[PackageFiles] implicit val decodeV2PackageFiles: Decoder[PackageFiles] = deriveDecoder[PackageFiles] }
Example 24
Source File: PackageDetails.scala From cosmos with Apache License 2.0 | 5 votes |
package com.mesosphere.universe.v2.model import io.circe.Decoder import io.circe.Encoder import io.circe.generic.semiauto.deriveDecoder import io.circe.generic.semiauto.deriveEncoder case class PackageDetails( packagingVersion: PackagingVersion, name: String, version: PackageDetailsVersion, maintainer: String, description: String, tags: List[String] = Nil, selected: Option[Boolean] = None, scm: Option[String] = None, website: Option[String] = None, framework: Option[Boolean] = None, preInstallNotes: Option[String] = None, postInstallNotes: Option[String] = None, postUninstallNotes: Option[String] = None, licenses: Option[List[License]] = None ) object PackageDetails { implicit val encodeV2PackageDetails: Encoder[PackageDetails] = deriveEncoder[PackageDetails] implicit val decodeV2PackageDetails: Decoder[PackageDetails] = deriveDecoder[PackageDetails] }
Example 25
Source File: Event.scala From cuttle with Apache License 2.0 | 5 votes |
package com.criteo.cuttle.events import java.time.Instant import com.criteo.cuttle.Auth.User import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.java8.time._ sealed trait Event { def created: Instant } case class JobSuccessForced(created: Instant, createdBy: User, jobId: String, intervalStart: Instant, intervalEnd: Instant) extends Event object JobSuccessForced { implicit val encoder: Encoder[JobSuccessForced] = deriveEncoder implicit val decoder: Decoder[JobSuccessForced] = deriveDecoder } object Event { implicit val encoder: Encoder[Event] = deriveEncoder implicit val decoder: Decoder[Event] = deriveDecoder }
Example 26
Source File: GameManager.scala From telegram with Apache License 2.0 | 5 votes |
package com.bot4s.telegram.api import java.net.URLDecoder import java.nio.charset.StandardCharsets import java.util.Base64 import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.{Directive1, Route} import com.bot4s.telegram.marshalling import com.bot4s.telegram.methods.{GetGameHighScores, SetGameScore} import com.bot4s.telegram.models.{CallbackQuery, ChatId, User} import com.bot4s.telegram.future.BotExecutionContext import io.circe.generic.extras.semiauto._ import io.circe.generic.semiauto.deriveDecoder import io.circe.{Decoder, Encoder} import scala.concurrent.Future import scala.util.{Failure, Success} case class Payload( user : User, chatId : Option[ChatId] = None, messageId : Option[Int] = None, inlineMessageId : Option[String] = None, gameManagerHost : String, gameShortName : String) { def toGetGameHighScores = GetGameHighScores(user.id, chatId, messageId, inlineMessageId) def base64Encode: String = { val payloadJson = marshalling.toJson[Payload](this) val encodedPayload = Base64.getEncoder.encodeToString( payloadJson.getBytes(StandardCharsets.UTF_8)) encodedPayload } } object Payload { def base64Decode(encodedPayload: String): Payload = { val base64payload = URLDecoder.decode(encodedPayload, "UTF-8") val jsonPayload = new String(Base64.getDecoder.decode(base64payload), StandardCharsets.UTF_8) val payload = marshalling.fromJson[Payload](jsonPayload) payload } def forCallbackQuery(gameManagerHost: String)(implicit cbq: CallbackQuery): Payload = { Payload( cbq.from, cbq.message.map(_.source), cbq.message.map(_.messageId), cbq.inlineMessageId, gameManagerHost, cbq.gameShortName.get) // throws if not a game callback } import marshalling._ implicit val payloadEncoder: Encoder[Payload] = deriveEncoder[Payload] implicit val payloadDecoder: Decoder[Payload] = deriveDecoder[Payload] }
Example 27
Source File: ChatMember.scala From canoe with MIT License | 5 votes |
package canoe.models import canoe.models.MemberStatus.MemberStatus import io.circe.Decoder import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveDecoder sealed trait ChatMember { def user: User } object ChatMember { implicit val chatMemberDecoder: Decoder[ChatMember] = Decoder.instance[ChatMember] { cursor => cursor .get[MemberStatus]("status") .map { case MemberStatus.Creator => deriveDecoder[ChatCreator] case MemberStatus.Administrator => deriveDecoder[ChatAdministrator] case MemberStatus.Member => deriveDecoder[OrdinaryMember] case MemberStatus.Restricted => deriveDecoder[RestrictedMember] case MemberStatus.Left => deriveDecoder[LeftMember] case MemberStatus.Kicked => deriveDecoder[KickedMember] } .flatMap(_.tryDecode(cursor)) } } final case class ChatCreator(user: User) extends ChatMember final case class OrdinaryMember(user: User) extends ChatMember final case class LeftMember(user: User) extends ChatMember final case class KickedMember(user: User, untilDate: Option[Int]) extends ChatMember final case class ChatAdministrator(user: User, customTitle: Option[String], canBeEdited: Option[Boolean], canChangeInfo: Option[Boolean], canPostMessages: Option[Boolean], canEditMessages: Option[Boolean], canDeleteMessages: Option[Boolean], canRestrictMembers: Option[Boolean], canPromoteMembers: Option[Boolean], canInviteUsers: Option[Boolean], canPinMessages: Option[Boolean]) extends ChatMember final case class RestrictedMember(user: User, untilDate: Option[Int], isMember: Option[Boolean], canChangeInfo: Option[Boolean], canInviteUsers: Option[Boolean], canPinMessages: Option[Boolean], canSendMessages: Option[Boolean], canSendMediaMessages: Option[Boolean], canSendOtherMessages: Option[Boolean], canAddWebPagePreviews: Option[Boolean]) extends ChatMember
Example 28
Source File: UserMessage.scala From canoe with MIT License | 5 votes |
package canoe.models.messages import canoe.models.{Chat, User} import cats.syntax.functor._ import io.circe.Decoder import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveDecoder trait UserMessage extends TelegramMessage { def from: Option[User] def forwardFrom: Option[User] def forwardFromChat: Option[Chat] def forwardFromMessageId: Option[Int] def forwardSignature: Option[String] def forwardSenderName: Option[String] def forwardDate: Option[Int] def replyToMessage: Option[TelegramMessage] def editDate: Option[Int] def authorSignature: Option[String] } object UserMessage { implicit val userMessageDecoder: Decoder[UserMessage] = List[Decoder[UserMessage]]( deriveDecoder[AnimationMessage].widen, deriveDecoder[AudioMessage].widen, deriveDecoder[ContactMessage].widen, deriveDecoder[DocumentMessage].widen, deriveDecoder[GameMessage].widen, deriveDecoder[InvoiceMessage].widen, deriveDecoder[LocationMessage].widen, deriveDecoder[PhotoMessage].widen, deriveDecoder[PollMessage].widen, deriveDecoder[StickerMessage].widen, deriveDecoder[TextMessage].widen, deriveDecoder[VenueMessage].widen, deriveDecoder[VideoMessage].widen, deriveDecoder[VideoNoteMessage].widen, deriveDecoder[VoiceMessage].widen ).reduceLeft(_.or(_)) }
Example 29
Source File: SystemMessage.scala From canoe with MIT License | 5 votes |
package canoe.models.messages import canoe.models.{Chat, DiceResult, PhotoSize, SuccessfulPayment, User} import cats.syntax.functor._ import io.circe.Decoder import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveDecoder sealed trait SystemMessage extends TelegramMessage with Product object SystemMessage { implicit val systemMessageDecoder: Decoder[SystemMessage] = List[Decoder[SystemMessage]]( deriveDecoder[MessagePinned].widen, deriveDecoder[ChatMemberAdded].widen, deriveDecoder[ChannelCreated].widen, deriveDecoder[ChatMemberLeft].widen, deriveDecoder[ChatPhotoChanged].widen, deriveDecoder[ChatPhotoDeleted].widen, deriveDecoder[ChatTitleChanged].widen, deriveDecoder[MigratedFromGroup].widen, deriveDecoder[MigratedToSupergroup].widen, deriveDecoder[SuccessfulPaymentMessage].widen, deriveDecoder[GroupChatCreated].widen, deriveDecoder[SupergroupCreated].widen, deriveDecoder[WebsiteConnected].widen, deriveDecoder[DiceThrownMessage].widen ).reduceLeft(_.or(_)) } final case class MessagePinned(messageId: Int, chat: Chat, date: Int, pinnedMessage: TelegramMessage) extends SystemMessage final case class ChannelCreated(messageId: Int, chat: Chat, date: Int, channelChatCreated: Boolean) extends SystemMessage final case class ChatMemberAdded(messageId: Int, chat: Chat, date: Int, newChatMembers: Seq[User]) extends SystemMessage final case class ChatMemberLeft(messageId: Int, chat: Chat, date: Int, leftChatMember: User) extends SystemMessage final case class ChatPhotoChanged(messageId: Int, chat: Chat, date: Int, newChatPhoto: Seq[PhotoSize]) extends SystemMessage final case class ChatPhotoDeleted(messageId: Int, chat: Chat, date: Int, deleteChatPhoto: Boolean) extends SystemMessage final case class ChatTitleChanged(messageId: Int, chat: Chat, date: Int, newChatTitle: String) extends SystemMessage final case class MigratedFromGroup(messageId: Int, chat: Chat, date: Int, migrateFromChatId: Long) extends SystemMessage final case class MigratedToSupergroup(messageId: Int, chat: Chat, date: Int, migrateToChatId: Long) extends SystemMessage final case class GroupChatCreated(messageId: Int, chat: Chat, date: Int, groupChatCreated: Boolean) extends SystemMessage final case class SupergroupCreated(messageId: Int, chat: Chat, date: Int, supergroupChatCreated: Boolean) extends SystemMessage final case class SuccessfulPaymentMessage(messageId: Int, chat: Chat, date: Int, successfulPayment: SuccessfulPayment) extends SystemMessage final case class WebsiteConnected(messageId: Int, chat: Chat, date: Int, connectedWebsite: String) extends SystemMessage final case class DiceThrownMessage(messageId: Int, chat: Chat, date: Int, dice: DiceResult) extends SystemMessage
Example 30
Source File: Update.scala From canoe with MIT License | 5 votes |
package canoe.models import canoe.marshalling.codecs._ import canoe.models.messages.TelegramMessage import cats.syntax.functor._ import io.circe.Decoder import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveDecoder sealed trait Update { def updateId: Long } object Update { final case class Unknown(updateId: Long) extends Update implicit val updateDecoder: Decoder[Update] = List[Decoder[Update]]( deriveDecoder[MessageReceived].widen, deriveDecoder[MessageEdited].widen, deriveDecoder[ChannelPost].widen, deriveDecoder[ChannelPostEdited].widen, deriveDecoder[PollUpdated].widen, deriveDecoder[InlineQueryReceived].widen, deriveDecoder[InlineResultSelected].widen, deriveDecoder[CallbackButtonSelected].widen, deriveDecoder[ShippingQueryReceived].widen, deriveDecoder[PreCheckoutQueryReceived].widen, deriveDecoder[PollAnswerReceived].widen, deriveDecoder[Unknown].widen ).reduceLeft(_.or(_)).camelCase } final case class PollUpdated(updateId: Long, poll: Poll) extends Update
Example 31
Source File: QueriesEndpoints.scala From endpoints4s with MIT License | 5 votes |
package cqrs.queries import java.util.UUID import endpoints4s.algebra.{BuiltInErrors, MuxEndpoints, MuxRequest, circe} import io.circe.{Decoder, Encoder, Json} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} // TODO Enrich with failure information //#mux-responses sealed trait QueryResp case class MaybeResource(value: Option[Meter]) extends QueryResp case class ResourceList(value: List[Meter]) extends QueryResp //#mux-responses object QueryResp { implicit val queryDecoder: Decoder[QueryResp] = deriveDecoder implicit val queryEncoder: Encoder[QueryResp] = deriveEncoder }
Example 32
Source File: CommandsEndpoints.scala From endpoints4s with MIT License | 5 votes |
package cqrs.commands import java.time.Instant import java.util.UUID import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} //#endpoints import endpoints4s.algebra.Endpoints import endpoints4s.algebra.circe.JsonEntitiesFromCodecs trait CommandsEndpoints extends Endpoints with JsonEntitiesFromCodecs { //#microservice-endpoint-description case class AddRecord(meterId: UUID, date: Instant, value: BigDecimal) extends UpdateCommand object Command { implicit val decoder: Decoder[Command] = deriveDecoder implicit val encoder: Encoder[Command] = deriveEncoder } case class StoredEvent(timestamp: Long, event: Event) object StoredEvent { implicit val decoder: Decoder[StoredEvent] = deriveDecoder implicit val encoder: Encoder[StoredEvent] = deriveEncoder } sealed trait Event case class MeterCreated(id: UUID, label: String) extends Event case class RecordAdded(id: UUID, date: Instant, value: BigDecimal) extends Event object Event { implicit val decoder: Decoder[Event] = deriveDecoder implicit val encoder: Encoder[Event] = deriveEncoder }
Example 33
Source File: Json.scala From scala-steward with Apache License 2.0 | 5 votes |
package org.scalasteward.core.bitbucketserver.http4s import cats.data.NonEmptyList import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} import org.http4s.Uri import org.scalasteward.core.git.Sha1 import org.scalasteward.core.vcs.data.PullRequestState object Json { case class Page[A](values: List[A]) case class Repo(id: Int, name: String, forkable: Boolean, project: Project, links: Links) case class Project(key: String) type Links = Map[String, NonEmptyList[Link]] case class Link(href: Uri, name: Option[String]) case class PR(title: String, state: PullRequestState, links: Links) case class NewPR( title: String, description: String, state: PullRequestState, open: Boolean, closed: Boolean, fromRef: Ref, toRef: Ref, locked: Boolean, reviewers: List[Reviewer] ) case class Ref(id: String, repository: Repository) case class Repository(slug: String, project: Project) case class Condition(reviewers: List[DefaultReviewer]) case class DefaultReviewer(name: String) case class Reviewer(user: User) case class User(name: String) case class Branches(values: NonEmptyList[Branch]) case class Branch(id: String, latestCommit: Sha1) implicit def pageDecode[A: Decoder]: Decoder[Page[A]] = deriveDecoder implicit val repoDecode: Decoder[Repo] = deriveDecoder implicit val projectDecode: Decoder[Project] = deriveDecoder implicit val linkDecoder: Decoder[Link] = deriveDecoder implicit val uriDecoder: Decoder[Uri] = Decoder.decodeString.map(Uri.unsafeFromString) implicit val prDecoder: Decoder[PR] = deriveDecoder implicit val reviewerDecoder: Decoder[Reviewer] = deriveDecoder implicit val userDecoder: Decoder[User] = deriveDecoder implicit val defaultReviewerDecoder: Decoder[DefaultReviewer] = deriveDecoder implicit val conditionDecoder: Decoder[Condition] = deriveDecoder implicit val branchDecoder: Decoder[Branch] = deriveDecoder implicit val branchesDecoder: Decoder[Branches] = deriveDecoder implicit val encodeNewPR: Encoder[NewPR] = deriveEncoder implicit val encodeRef: Encoder[Ref] = deriveEncoder implicit val encodeRepository: Encoder[Repository] = deriveEncoder implicit val encodeProject: Encoder[Project] = deriveEncoder implicit val encodeReviewer: Encoder[Reviewer] = deriveEncoder implicit val encodeUser: Encoder[User] = deriveEncoder }
Example 34
Source File: VariableAliasing.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import org.adridadou.openlaw.OpenlawValue import org.adridadou.openlaw.parser.template.variableTypes.VariableType import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Result, Success} object VariableAliasing { implicit val variableAliasingEnc: Encoder[VariableAliasing] = deriveEncoder implicit val variableAliasingDec: Decoder[VariableAliasing] = deriveDecoder } final case class VariableAliasing(name: VariableName, expr: Expression) extends Expression with TemplatePart { def validate(executionResult: TemplateExecutionResult): Result[Unit] = if (name.isAnonymous) { Success.unit } else { expr.validate(executionResult) } override def expressionType( executionResult: TemplateExecutionResult ): Result[VariableType] = expr.expressionType(executionResult) override def evaluate( executionResult: TemplateExecutionResult ): Result[Option[OpenlawValue]] = expr.evaluate(executionResult) override def variables( executionResult: TemplateExecutionResult ): Result[List[VariableName]] = expr.variables(executionResult) override def missingInput( executionResult: TemplateExecutionResult ): Result[List[VariableName]] = expr.missingInput(executionResult) }
Example 35
Source File: SectionType.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template.variableTypes import cats.implicits._ import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.parser.decode import org.adridadou.openlaw.{OpenlawNativeValue, OpenlawString, OpenlawValue} import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} final case class SectionInfo( name: Option[String], numbering: String, value: String ) extends OpenlawNativeValue case object SectionType extends VariableType(name = "Section") with NoShowInFormButRender { private implicit val enc: Encoder[SectionInfo] = deriveEncoder private implicit val dec: Decoder[SectionInfo] = deriveDecoder override def cast( value: String, executionResult: TemplateExecutionResult ): Result[SectionInfo] = decode[SectionInfo](value).leftMap(FailureException(_)) override def internalFormat(value: OpenlawValue): Result[String] = value match { case SectionInfo(_, _, value) => Success(value) case value => VariableType.convert[OpenlawString](value) } override def defaultFormatter: Formatter = new SectionFormatter override def getTypeClass: Class[SectionInfo] = classOf[SectionInfo] override def construct( constructorParams: Parameter, executionResult: TemplateExecutionResult ): Result[Option[SectionInfo]] = constructorParams match { case Parameters(seq) => val map = seq.toMap (for { numbering <- map.get("numbering") reference <- map.get("reference value") } yield for { numberingValue <- getOneValueConstant(numbering) referenceValue <- getOneValueConstant(reference) } yield SectionInfo(None, numberingValue, referenceValue)).sequence case _ => Failure("""Section requires parameters, not a unique value or a list""") } def thisType: VariableType = SectionType private def getOneValueConstant(value: Parameter): Result[String] = value match { case OneValueParameter(StringConstant(v)) => Success(v) case _ => Failure("""Section requires "numbering" argument.""") } } class SectionFormatter extends Formatter { override def format( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[List[AgreementElement]] = VariableType.convert[SectionInfo](value) map { case SectionInfo(_, _, referenceValue) => List(FreeText(Text(referenceValue))) } override def missingValueFormat( expression: Expression ): List[AgreementElement] = List(FreeText(Text(s"[[$expression]]"))) override def stringFormat( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[String] = VariableType.convert[SectionInfo](value) map { case SectionInfo(_, _, referenceValue) => referenceValue } override def missingValueString( expression: Expression ): String = ??? }
Example 36
Source File: LinkType.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.parser.template.variableTypes import cats.implicits._ import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.parser.decode import org.adridadou.openlaw.{OpenlawNativeValue, OpenlawString, OpenlawValue} import org.adridadou.openlaw.parser.template.formatters.Formatter import org.adridadou.openlaw.parser.template._ import org.adridadou.openlaw.parser.template.expressions.Expression import org.adridadou.openlaw.result.{Failure, FailureException, Result, Success} object LinkInfo { implicit val linkInfoEnc: Encoder[LinkInfo] = deriveEncoder implicit val linkInfoDec: Decoder[LinkInfo] = deriveDecoder } final case class LinkInfo(label: String, url: String) extends OpenlawNativeValue case object LinkType extends VariableType(name = "Link") with NoShowInFormButRender { override def cast( value: String, executionResult: TemplateExecutionResult ): Result[LinkInfo] = decode[LinkInfo](value).leftMap(FailureException(_)) override def internalFormat(value: OpenlawValue): Result[String] = VariableType.convert[OpenlawString](value) override def defaultFormatter: Formatter = new LinkFormatter override def getTypeClass: Class[LinkInfo] = classOf[LinkInfo] override def construct( constructorParams: Parameter, executionResult: TemplateExecutionResult ): Result[Option[LinkInfo]] = constructorParams match { case Parameters(seq) => val map = seq.toMap for { label <- map.get("label").traverse(getOneValueConstant) url <- map.get("url").traverse(getOneValueConstant) } yield (label, url) mapN { LinkInfo(_, _) } case _ => Failure("""Link requires parameters, not a unique value or a list""") } def thisType: VariableType = LinkType private def getOneValueConstant(value: Parameter): Result[String] = value match { case OneValueParameter(StringConstant(v)) => Success(v) case _ => Failure("""Link requires "label" argument.""") } } class LinkFormatter extends Formatter { override def format( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[List[AgreementElement]] = VariableType.convert[LinkInfo](value) map { case LinkInfo(labelValue, urlValue) => List(Link(labelValue, urlValue)) } override def missingValueFormat( expression: Expression ): List[AgreementElement] = List(FreeText(Text(s"[[$expression]]"))) override def stringFormat( expression: Expression, value: OpenlawValue, executionResult: TemplateExecutionResult ): Result[String] = VariableType.convert[LinkInfo](value) map { case LinkInfo(labelValue, urlValue) => s"$labelValue[$urlValue]" } }
Example 37
Source File: TemplateId.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.values import cats.Eq import io.circe.{Decoder, Encoder, HCursor, Json, KeyDecoder, KeyEncoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import cats.implicits._ import org.adridadou.openlaw.parser.template.variableTypes.EthereumAddress final case class TemplateId(id: String = "") extends Comparable[TemplateId] { override def toString: String = id override def compareTo(o: TemplateId): Int = id.compareTo(o.id) } object TemplateId { def apply(data: Array[Byte]): TemplateId = TemplateId(EthereumAddress.bytes2hex(data)) implicit val templateIdEnc: Encoder[TemplateId] = deriveEncoder implicit val templateIdDec: Decoder[TemplateId] = deriveDecoder implicit val eq: Eq[TemplateId] = Eq.by(_.id) } final case class TemplateIdentifier(title: TemplateTitle, version: Int) final case class TemplateTitle(originalTitle: String, title: String) { override def toString: String = title override def equals(obj: Any): Boolean = obj match { case other: TemplateTitle => this === other case _ => false } override def hashCode(): Int = this.title.hashCode } object TemplateTitle { def apply(): TemplateTitle = TemplateTitle("") def apply(title: String): TemplateTitle = TemplateTitle(originalTitle = title, title = title.toLowerCase()) implicit val eq: Eq[TemplateTitle] = (x: TemplateTitle, y: TemplateTitle) => x.title === y.title implicit val templateTitleEnc: Encoder[TemplateTitle] = (a: TemplateTitle) => Json.fromString(a.originalTitle) implicit val templateTitleDec: Decoder[TemplateTitle] = (c: HCursor) => (for { title <- c.downField("title").as[String] } yield TemplateTitle(title)) match { case Right(title) => Right(title) case Left(_) => c.as[String].map(TemplateTitle(_)) } implicit val templateTitleKeyEnc: KeyEncoder[TemplateTitle] = (key: TemplateTitle) => key.title implicit val templateTitleKeyDec: KeyDecoder[TemplateTitle] = (key: String) => Some(TemplateTitle(key)) }
Example 38
Source File: ContractId.scala From openlaw-core with Apache License 2.0 | 5 votes |
package org.adridadou.openlaw.values import cats.Eq import io.circe.{Decoder, Encoder} import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import org.adridadou.openlaw.oracles.CryptoService import org.adridadou.openlaw.parser.template.variableTypes.{ EthereumAddress, EthereumData } @SerialVersionUID(7843732947346776640L) final case class ContractId(id: String) { def stopContract(cryptoService: CryptoService): EthereumData = executionId("_stop_contract", cryptoService) def data: EthereumData = EthereumData(id) def resumeContract(cryptoService: CryptoService): EthereumData = executionId("_resume_contract", cryptoService) def executionId(command: String, crypto: CryptoService): EthereumData = EthereumData(id + EthereumData(crypto.sha256("_" + command)).toString) override def toString(): String = id } @SerialVersionUID(7843732947346776640L) object ContractId { def apply(data: Array[Byte]): ContractId = ContractId(EthereumAddress.bytes2hex(data)) implicit val contractIdEnc: Encoder[ContractId] = deriveEncoder implicit val contractIdDec: Decoder[ContractId] = deriveDecoder implicit val contractEq: Eq[ContractId] = Eq.fromUniversalEquals }
Example 39
Source File: Chat.scala From canoe with MIT License | 5 votes |
package canoe.models import canoe.models.ChatType.ChatType import io.circe.Decoder import io.circe.generic.auto._ import io.circe.generic.semiauto.deriveDecoder sealed trait Chat { def id: Long } object Chat { implicit val chatDecoder: Decoder[Chat] = Decoder.instance[Chat] { cursor => cursor .get[ChatType]("type") .map { case ChatType.Private => deriveDecoder[PrivateChat] case ChatType.Group => deriveDecoder[Group] case ChatType.Supergroup => deriveDecoder[Supergroup] case ChatType.Channel => deriveDecoder[Channel] } .flatMap(_.tryDecode(cursor)) } } final case class PrivateChat(id: Long, username: Option[String], firstName: Option[String], lastName: Option[String]) extends Chat final case class Group(id: Long, title: Option[String]) extends Chat final case class Supergroup(id: Long, title: Option[String], username: Option[String]) extends Chat final case class Channel(id: Long, title: Option[String], username: Option[String]) extends Chat
Example 40
Source File: ProjectClient.scala From nexus with Apache License 2.0 | 5 votes |
package ch.epfl.bluebrain.nexus.cli.clients import cats.effect.concurrent.Ref import cats.effect.{Sync, Timer} import cats.implicits._ import ch.epfl.bluebrain.nexus.cli.config.EnvConfig import ch.epfl.bluebrain.nexus.cli.sse.{OrgLabel, OrgUuid, ProjectLabel, ProjectUuid} import ch.epfl.bluebrain.nexus.cli.{ClientErrOr, Console} import io.circe.Decoder import io.circe.generic.semiauto.deriveDecoder import org.http4s.client.Client import org.http4s.{Headers, Request} trait ProjectClient[F[_]] { final def apply[F[_]: Sync: Timer]( client: Client[F], env: EnvConfig, cache: Ref[F, Map[(OrgUuid, ProjectUuid), (OrgLabel, ProjectLabel)]], console: Console[F] ): ProjectClient[F] = { implicit val c: Console[F] = console new LiveProjectClient[F](client, env, cache) } private class LiveProjectClient[F[_]: Timer: Console: Sync]( client: Client[F], env: EnvConfig, cache: Ref[F, Map[(OrgUuid, ProjectUuid), (OrgLabel, ProjectLabel)]] ) extends AbstractHttpClient[F](client, env) with ProjectClient[F] { override def labels(org: OrgUuid, proj: ProjectUuid): F[ClientErrOr[(OrgLabel, ProjectLabel)]] = cache.get.flatMap { map => map.get((org, proj)) match { // value in cache, return case Some(value) => F.pure(Right(value)) // value not in cache, fetch, update and return case None => get(org, proj).flatMap { // propagate error case l @ Left(_) => F.pure(l) // success, update cache and return case r @ Right(value) => cache.modify(m => (m.updated((org, proj), value), value)) *> F.pure(r) } } } private def get(org: OrgUuid, proj: ProjectUuid): F[ClientErrOr[(OrgLabel, ProjectLabel)]] = { val uri = env.project(org, proj) val req = Request[F](uri = uri, headers = Headers(env.authorizationHeader.toList)) executeParse[NexusAPIProject](req).map { case Right(NexusAPIProject(orgLabel, projectLabel)) => Right((orgLabel, projectLabel)) case Left(err) => Left(err) } } } final private[ProjectClient] case class NexusAPIProject(`_organizationLabel`: OrgLabel, `_label`: ProjectLabel) private[ProjectClient] object NexusAPIProject { implicit val nexusAPIProjectDecoder: Decoder[NexusAPIProject] = deriveDecoder[NexusAPIProject] } }
Example 41
Source File: Event.scala From nexus with Apache License 2.0 | 5 votes |
package ch.epfl.bluebrain.nexus.cli.sse import java.time.Instant import java.util.UUID import ch.epfl.bluebrain.nexus.cli.utils.Codecs import io.circe.generic.semiauto.deriveDecoder import io.circe.{Decoder, Json} import org.http4s.Uri final case class Event( eventType: EventType, resourceId: Uri, rev: Long, organization: OrgUuid, project: ProjectUuid, resourceTypes: Set[Uri], instant: Instant, raw: Json ) object Event extends Codecs { final private[Event] case class APIEvent( `_organizationUuid`: UUID, `_projectUuid`: UUID, `@type`: EventType, `_types`: Option[Set[Uri]], `_resourceId`: Uri, `_rev`: Option[Long], `_instant`: Instant ) { def asEvent(raw: Json): Event = Event( `@type`, `_resourceId`, `_rev`.getOrElse(1L), OrgUuid(`_organizationUuid`), ProjectUuid(`_projectUuid`), `_types`.getOrElse(Set.empty[Uri]), `_instant`, raw ) } private[Event] object APIEvent { implicit val apiEventDecoder: Decoder[APIEvent] = deriveDecoder[APIEvent] } implicit final val eventDecoder: Decoder[Event] = Decoder.instance { cursor => cursor.as[APIEvent].map(_.asEvent(cursor.value)) } }
Example 42
Source File: HeroFragmentQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroFragmentQuery { object HeroFragmentQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroFragmentQuery { hero { ...CharacterInfo } human(id: "Lea") { ...CharacterInfo } } fragment CharacterInfo on Character { name }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero, human: Option[Human]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String]) extends CharacterInfo object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } case class Human(name: Option[String]) extends CharacterInfo object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } } }
Example 43
Source File: EpisodeEnumTypes.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } object types { sealed trait Episode object Episode { case object NEWHOPE extends Episode case object EMPIRE extends Episode case object JEDI extends Episode implicit val jsonDecoder: Decoder[Episode] = Decoder.decodeString.emap({ case "NEWHOPE" => Right(NEWHOPE) case "EMPIRE" => Right(EMPIRE) case "JEDI" => Right(JEDI) case other => Left("invalid enum value: " + other) }) implicit val jsonEncoder: Encoder[Episode] = Encoder.encodeString.contramap({ case NEWHOPE => "NEWHOPE" case EMPIRE => "EMPIRE" case JEDI => "JEDI" }) } }
Example 44
Source File: HeroAndFriends.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroAndFriends { object HeroAndFriends extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroAndFriends { hero { name friends { name friends { name friends { name friends { name } } } } } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String], friends: Option[List[Option[Hero.Friends]]]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String], friends: Option[List[Option[Friends.Friends]]]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] case class Friends(name: Option[String]) object Friends { implicit val jsonDecoder: Decoder[Friends] = deriveDecoder[Friends] implicit val jsonEncoder: Encoder[Friends] = deriveEncoder[Friends] } } } } } } }
Example 45
Source File: InputVariables.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object InputVariables { object InputVariables extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query InputVariables($$humanId: String!) { human(id: $$humanId) { name homePlanet } }""" case class Variables(humanId: String) object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(human: Option[Human]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Human(name: Option[String], homePlanet: Option[String]) object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } } }
Example 46
Source File: SearchQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object SearchQuery { object SearchQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query SearchQuery($$text: String!) { search(text: $$text) { __typename ... on Human { name secretBackstory } ... on Droid { name primaryFunction } ... on Starship { name } } }""" case class Variables(text: String) object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(search: List[Search]) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } sealed trait Search { def __typename: String def name: Option[String] } object Search { case class Human(__typename: String, name: Option[String], secretBackstory: Option[String]) extends Search object Human { implicit val jsonDecoder: Decoder[Human] = deriveDecoder[Human] implicit val jsonEncoder: Encoder[Human] = deriveEncoder[Human] } case class Droid(__typename: String, name: Option[String], primaryFunction: Option[String]) extends Search object Droid { implicit val jsonDecoder: Decoder[Droid] = deriveDecoder[Droid] implicit val jsonEncoder: Encoder[Droid] = deriveEncoder[Droid] } case class Starship(__typename: String, name: Option[String]) extends Search object Starship { implicit val jsonDecoder: Decoder[Starship] = deriveDecoder[Starship] implicit val jsonEncoder: Encoder[Starship] = deriveEncoder[Starship] } implicit val jsonDecoder: Decoder[Search] = for (typeDiscriminator <- Decoder[String].prepare(_.downField("__typename")); value <- typeDiscriminator match { case "Human" => Decoder[Human] case "Droid" => Decoder[Droid] case "Starship" => Decoder[Starship] case other => Decoder.failedWithMessage("invalid type: " + other) }) yield value } } }
Example 47
Source File: HeroNameQuery.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object HeroNameQuery { object HeroNameQuery extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query HeroNameQuery { hero { name } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } } }
Example 48
Source File: EpisodeEnum.scala From sbt-graphql with Apache License 2.0 | 5 votes |
import io.circe.{ Decoder, Encoder } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import sangria.macros._ import types._ object EpisodeEnum { object EpisodeEnum extends GraphQLQuery { val document: sangria.ast.Document = graphql"""query EpisodeEnum { hero { name appearsIn } }""" case class Variables() object Variables { implicit val jsonEncoder: Encoder[Variables] = deriveEncoder[Variables] } case class Data(hero: Hero) object Data { implicit val jsonDecoder: Decoder[Data] = deriveDecoder[Data] } case class Hero(name: Option[String], appearsIn: Option[List[Option[Episode]]]) object Hero { implicit val jsonDecoder: Decoder[Hero] = deriveDecoder[Hero] implicit val jsonEncoder: Encoder[Hero] = deriveEncoder[Hero] } } }
Example 49
Source File: ColorBar.scala From evilplot with BSD 3-Clause "New" or "Revised" License | 5 votes |
package com.cibo.evilplot.colors import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} import io.circe.{Decoder, Encoder} sealed trait ColorBar { val nColors: Int def getColor(z: Int): Color } // Use when one color is wanted but a ColorBar is needed. case class SingletonColorBar(color: Color) extends ColorBar { val nColors: Int = 1 def getColor(z: Int): Color = { require(z == 1) color } } // Map a sequence of colors to a continuous variable z. case class ScaledColorBar(colorSeq: Seq[Color], zMin: Double, zMax: Double) extends ColorBar { val nColors: Int = colorSeq.length private val zWidth = (zMax - zMin) / nColors.toFloat def getColor(i: Int): Color = colorSeq(i) def getColor(z: Double): Color = getColor(colorIndex(z)) def colorIndex(z: Double): Int = math.min(math.round(math.floor(math.max(z - zMin, 0.0) / zWidth)).toInt, nColors - 1) def colorValue(i: Int): Double = i * zWidth + zMin } object ColorBar { implicit val encoder: Encoder[ColorBar] = deriveEncoder[ColorBar] implicit val decoder: Decoder[ColorBar] = deriveDecoder[ColorBar] }
Example 50
Source File: MigratorConfig.scala From scylla-migrator with Apache License 2.0 | 5 votes |
package com.scylladb.migrator.config import cats.implicits._ import com.datastax.spark.connector.rdd.partitioner.dht.{ BigIntToken, LongToken, Token } import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder } import io.circe.syntax._ import io.circe.yaml.parser import io.circe.yaml.syntax._ import io.circe.{ Decoder, DecodingFailure, Encoder, Error, Json } case class MigratorConfig(source: SourceSettings, target: TargetSettings, renames: List[Rename], savepoints: Savepoints, skipTokenRanges: Set[(Token[_], Token[_])], validation: Validation) { def render: String = this.asJson.asYaml.spaces2 } object MigratorConfig { implicit val tokenEncoder: Encoder[Token[_]] = Encoder.instance { case LongToken(value) => Json.obj("type" := "long", "value" := value) case BigIntToken(value) => Json.obj("type" := "bigint", "value" := value) } implicit val tokenDecoder: Decoder[Token[_]] = Decoder.instance { cursor => for { tpe <- cursor.get[String]("type").right result <- tpe match { case "long" => cursor.get[Long]("value").right.map(LongToken(_)) case "bigint" => cursor.get[BigInt]("value").right.map(BigIntToken(_)) case otherwise => Left(DecodingFailure(s"Unknown token type '$otherwise'", Nil)) } } yield result } implicit val migratorConfigDecoder: Decoder[MigratorConfig] = deriveDecoder[MigratorConfig] implicit val migratorConfigEncoder: Encoder[MigratorConfig] = deriveEncoder[MigratorConfig] def loadFrom(path: String): MigratorConfig = { val configData = scala.io.Source.fromFile(path).mkString parser .parse(configData) .leftWiden[Error] .flatMap(_.as[MigratorConfig]) .valueOr(throw _) } }