com.gu.zuora.soap.actions.Action.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of membership-common_2.12 Show documentation
Show all versions of membership-common_2.12 Show documentation
Scala library for common Guardian Membership/Subscriptions functionality.
package com.gu.zuora.soap.actions
import com.gu.zuora.soap.models.Results.Authentication
import com.gu.zuora.soap.models.Result
import scala.xml.{Elem, NodeSeq}
trait Action[T <: Result] { self =>
protected val body: Elem
val authRequired = true
val singleTransaction = false
val enableLogging: Boolean = true
def logInfo: Map[String, String] = Map("Action" -> self.getClass.getSimpleName)
def additionalLogInfo: Map[String, String] = Map.empty
def prettyLogInfo = (logInfo ++ additionalLogInfo).map { case (k, v) => s" - $k: $v" } .mkString("\n")
def xml(authentication: Option[Authentication]) = {
{sessionHeader(authentication)}
{
if (singleTransaction) {
true
}
}
{body}
}
def sanitized = body.toString()
private def sessionHeader(authOpt: Option[Authentication]):NodeSeq =
authOpt.fold(NodeSeq.Empty) { auth =>
{auth.token}
}
}