/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.2-dev * User agent: apibuilder app.apibuilder.io/mard/mard2p-api/0.0.2-dev/ning_1_9_client */ package payp.mard2p.api.v0.models { /** * Account is defined by the app specifically to manage users transactions. * * @param accountid Internal unique identifier for this account. * @param ownerid The username registered in the application * @param totalAmount The amount specific to the debit and sold account. This field allows the process * transactions. * @param currency The currency specific to location. * @param sold The amount specific to the balance account. This field allows the process * transactions. * @param debit The amount specific to the money merchant have to collect and pay. This field * allows the process transactions. */ final case class Account( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double ) /** * @param accountid Internal unique identifier for this account. * @param ownerid The username registered in the application. * @param totalAmount The amount specific to the debit and sold account. This field allows the process * transactions. * @param sold The amount specific to the balance account. This field allows the process * transactions. * @param debit The amount specific to the money merchant have to collect and pay. This field * allows the process transactions. * @param currency The currency specific to location. */ final case class AccountForm( accountid: Long, ownerid: String, totalAmount: _root_.scala.Option[Double] = None, sold: Double, debit: _root_.scala.Option[Double] = None, currency: String ) /** * Deposit describes a way a payment is handled. It depends of Payment Resource * * @param depid Internal unique identifier for this account. * @param paymentid The added paymentid used to proceed the deposit transaction. */ final case class Deposit( depid: Long, paymentid: Long ) /** * Payment is defined by the app specifically to emit users transactions. * * @param payid Internal unique identifier for this payment. * @param actorid The username registered in the application * @param amount The amount to send. This field allowed the processing transactions. * @param refAccountid The accountid to use to send money to the specific account. * @param paymentMethod The type of payment to use [Mobile Money or Credit Card]. * @param operatorid The operator specified the type of payment if Mobile Money. * @param phone The phone identifying specific account of consumer. * @param pin The code used to validate the transaction. * @param currency The phone identifying specific account of consumer. * @param paymentContext This field specify the type of transaction [Buying, Deposit, Withdraw]. */ final case class Payment( payid: Long, actorid: String, amount: Double, refAccountid: Long, paymentMethod: String, operatorid: String, phone: Long, pin: Int, currency: String, paymentContext: String ) /** * @param payid Internal unique identifier for this payment. * @param actorid The username registered in the application * @param amount The amount to send. This field allowed the processing transactions. * @param refAccountid The accountid to use to send money to the specific account. * @param paymentMethod The type of payment to use [Mobile Money or Credit Card]. * @param operatorid The operator specified the type of payment if Mobile Money. * @param phone The phone identifying specific account of consumer. * @param pin The code used to validate the transaction. * @param currency The phone identifying specific account of consumer. * @param paymentContext This field specify the type of transaction [Buying, Deposit, Withdraw]. */ final case class PaymentForm( payid: Long, actorid: String, amount: Double, refAccountid: Long, paymentMethod: String, operatorid: String, phone: Long, pin: Int, currency: String, paymentContext: String ) /** * Transfer is defined by the app specifically to manage users transactions * (sending and receiving). * * @param transferid Internal unique identifier for this account. * @param senderid The username registered in the application * @param amount The amount to be send. This field allows the process transactions. * @param refAccountidReceiver The accountid to use to send money and referencing the receiver. * @param refAccountidSender The accountid to use to send money and referencing the sender. * @param currency The currency specific to a country. */ final case class Transfer( transferid: Long, senderid: String, amount: Double, refAccountidReceiver: Long, refAccountidSender: Long, currency: String ) /** * @param transferid Internal unique identifier for this account. * @param senderid The username registered in the application. * @param amount The amount to be send. This field allows the process transactions. * @param refAccountidReceiver The accountid to use to send money and referencing the receiver. * @param refAccountidSender The accountid to use to send money and referencing the sender. * @param currency The currency specific to a country. */ final case class TransferForm( transferid: Long, senderid: String, amount: Double, refAccountidReceiver: Long, refAccountidSender: Long, currency: String ) /** * Used only to validate json files - used as a resource where http status code * defines success * * @param valid If true, the json schema is valid. If false, there is at least one validation * error. * @param errors Contains any validation errors that result from parsing the json document. If * empty, the document is valid. */ final case class Validation( valid: Boolean, errors: Seq[String] = Nil ) /** * Withdraw describes a way a payment is handled. It depends of Payment Resource * * @param wdwid Internal unique identifier for this account. * @param paymentid The added paymentid used to proceed the deposit transaction. */ final case class Withdraw( wdwid: Long, paymentid: Long ) sealed trait AppSortBy extends _root_.scala.Product with _root_.scala.Serializable object AppSortBy { case object Created extends AppSortBy { override def toString = "created" } case object Edited extends AppSortBy { override def toString = "edited" } /** * 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 AppSortBy /** * 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[AppSortBy] = scala.List(Created, Edited) private val byName: Map[String, AppSortBy] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): AppSortBy = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[AppSortBy] = byName.get(value.toLowerCase) } sealed trait OriginalType extends _root_.scala.Product with _root_.scala.Serializable object OriginalType { /** * The original is in the api.json format */ case object ApiJson extends OriginalType { override def toString = "api_json" } /** * 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 OriginalType /** * 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[OriginalType] = scala.List(ApiJson) private val byName: Map[String, OriginalType] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): OriginalType = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[OriginalType] = byName.get(value.toLowerCase) } /** * A publication represents something that a user can subscribe to. An example * would be subscribing to an email alert whenever a new version of an application * is created. */ sealed trait Publication extends _root_.scala.Product with _root_.scala.Serializable object Publication { /** * For organizations for which I am an administrator, email me whenever a user * applies to join the org. */ case object MembershipRequestsCreate extends Publication { override def toString = "membership_requests.create" } /** * For organizations for which I am a member, email me whenever a user joins the * org. */ case object MembershipsCreate extends Publication { override def toString = "memberships.create" } /** * For organizations for which I am a member, email me whenever an application is * created. */ case object ApplicationsCreate extends Publication { override def toString = "applications.create" } /** * For applications that I watch, email me whenever a version is created. */ case object VersionsCreate extends Publication { override def toString = "versions.create" } /** * 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 Publication /** * 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[Publication] = scala.List(MembershipRequestsCreate, MembershipsCreate, ApplicationsCreate, VersionsCreate) private val byName: Map[String, Publication] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Publication = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Publication] = byName.get(value.toLowerCase) } sealed trait SortOrder extends _root_.scala.Product with _root_.scala.Serializable object SortOrder { case object Asc extends SortOrder { override def toString = "asc" } case object Desc extends SortOrder { override def toString = "desc" } /** * 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 SortOrder /** * 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[SortOrder] = scala.List(Asc, Desc) private val byName: Map[String, SortOrder] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): SortOrder = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[SortOrder] = byName.get(value.toLowerCase) } /** * Controls who is able to view this version */ sealed trait Visibility extends _root_.scala.Product with _root_.scala.Serializable object Visibility { /** * Anybody, including non logged in users, can view this application */ case object Public extends Visibility { override def toString = "public" } /** * 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 Visibility /** * 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[Visibility] = scala.List(Public) private val byName: Map[String, Visibility] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Visibility = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Visibility] = byName.get(value.toLowerCase) } } package payp.mard2p.api.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import io.apibuilder.common.v0.models.json._ import io.apibuilder.generator.v0.models.json._ import io.apibuilder.spec.v0.models.json._ import payp.mard2p.api.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsMard2pAPIAppSortBy: play.api.libs.json.Reads[payp.mard2p.api.v0.models.AppSortBy] = new play.api.libs.json.Reads[payp.mard2p.api.v0.models.AppSortBy] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[payp.mard2p.api.v0.models.AppSortBy] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.AppSortBy(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.AppSortBy(v)) case _: play.api.libs.json.JsError => (js \ "app_sort_by").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.AppSortBy(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesMard2pAPIAppSortBy(obj: payp.mard2p.api.v0.models.AppSortBy) = { play.api.libs.json.JsString(obj.toString) } def jsObjectAppSortBy(obj: payp.mard2p.api.v0.models.AppSortBy) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesMard2pAPIAppSortBy: play.api.libs.json.Writes[AppSortBy] = { (obj: payp.mard2p.api.v0.models.AppSortBy) => { payp.mard2p.api.v0.models.json.jsonWritesMard2pAPIAppSortBy(obj) } } implicit val jsonReadsMard2pAPIOriginalType: play.api.libs.json.Reads[payp.mard2p.api.v0.models.OriginalType] = new play.api.libs.json.Reads[payp.mard2p.api.v0.models.OriginalType] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[payp.mard2p.api.v0.models.OriginalType] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.OriginalType(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.OriginalType(v)) case _: play.api.libs.json.JsError => (js \ "original_type").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.OriginalType(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesMard2pAPIOriginalType(obj: payp.mard2p.api.v0.models.OriginalType) = { play.api.libs.json.JsString(obj.toString) } def jsObjectOriginalType(obj: payp.mard2p.api.v0.models.OriginalType) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesMard2pAPIOriginalType: play.api.libs.json.Writes[OriginalType] = { (obj: payp.mard2p.api.v0.models.OriginalType) => { payp.mard2p.api.v0.models.json.jsonWritesMard2pAPIOriginalType(obj) } } implicit val jsonReadsMard2pAPIPublication: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Publication] = new play.api.libs.json.Reads[payp.mard2p.api.v0.models.Publication] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[payp.mard2p.api.v0.models.Publication] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Publication(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Publication(v)) case _: play.api.libs.json.JsError => (js \ "publication").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Publication(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesMard2pAPIPublication(obj: payp.mard2p.api.v0.models.Publication) = { play.api.libs.json.JsString(obj.toString) } def jsObjectPublication(obj: payp.mard2p.api.v0.models.Publication) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesMard2pAPIPublication: play.api.libs.json.Writes[Publication] = { (obj: payp.mard2p.api.v0.models.Publication) => { payp.mard2p.api.v0.models.json.jsonWritesMard2pAPIPublication(obj) } } implicit val jsonReadsMard2pAPISortOrder: play.api.libs.json.Reads[payp.mard2p.api.v0.models.SortOrder] = new play.api.libs.json.Reads[payp.mard2p.api.v0.models.SortOrder] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[payp.mard2p.api.v0.models.SortOrder] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.SortOrder(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.SortOrder(v)) case _: play.api.libs.json.JsError => (js \ "sort_order").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.SortOrder(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesMard2pAPISortOrder(obj: payp.mard2p.api.v0.models.SortOrder) = { play.api.libs.json.JsString(obj.toString) } def jsObjectSortOrder(obj: payp.mard2p.api.v0.models.SortOrder) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesMard2pAPISortOrder: play.api.libs.json.Writes[SortOrder] = { (obj: payp.mard2p.api.v0.models.SortOrder) => { payp.mard2p.api.v0.models.json.jsonWritesMard2pAPISortOrder(obj) } } implicit val jsonReadsMard2pAPIVisibility: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Visibility] = new play.api.libs.json.Reads[payp.mard2p.api.v0.models.Visibility] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[payp.mard2p.api.v0.models.Visibility] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Visibility(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Visibility(v)) case _: play.api.libs.json.JsError => (js \ "visibility").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(payp.mard2p.api.v0.models.Visibility(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesMard2pAPIVisibility(obj: payp.mard2p.api.v0.models.Visibility) = { play.api.libs.json.JsString(obj.toString) } def jsObjectVisibility(obj: payp.mard2p.api.v0.models.Visibility) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesMard2pAPIVisibility: play.api.libs.json.Writes[Visibility] = { (obj: payp.mard2p.api.v0.models.Visibility) => { payp.mard2p.api.v0.models.json.jsonWritesMard2pAPIVisibility(obj) } } implicit def jsonReadsMard2pAPIAccount: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Account] = { for { accountid <- (__ \ "accountid").read[Long] ownerid <- (__ \ "ownerid").read[String] totalAmount <- (__ \ "total_amount").read[Double] currency <- (__ \ "currency").read[String] sold <- (__ \ "sold").read[Double] debit <- (__ \ "debit").read[Double] } yield Account(accountid, ownerid, totalAmount, currency, sold, debit) } def jsObjectAccount(obj: payp.mard2p.api.v0.models.Account): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "accountid" -> play.api.libs.json.JsNumber(obj.accountid), "ownerid" -> play.api.libs.json.JsString(obj.ownerid), "total_amount" -> play.api.libs.json.JsNumber(obj.totalAmount), "currency" -> play.api.libs.json.JsString(obj.currency), "sold" -> play.api.libs.json.JsNumber(obj.sold), "debit" -> play.api.libs.json.JsNumber(obj.debit) ) } implicit def jsonWritesMard2pAPIAccount: play.api.libs.json.Writes[Account] = { (obj: payp.mard2p.api.v0.models.Account) => { payp.mard2p.api.v0.models.json.jsObjectAccount(obj) } } implicit def jsonReadsMard2pAPIAccountForm: play.api.libs.json.Reads[payp.mard2p.api.v0.models.AccountForm] = { for { accountid <- (__ \ "accountid").read[Long] ownerid <- (__ \ "ownerid").read[String] totalAmount <- (__ \ "total_amount").readNullable[Double] sold <- (__ \ "sold").read[Double] debit <- (__ \ "debit").readNullable[Double] currency <- (__ \ "currency").read[String] } yield AccountForm(accountid, ownerid, totalAmount, sold, debit, currency) } def jsObjectAccountForm(obj: payp.mard2p.api.v0.models.AccountForm): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "accountid" -> play.api.libs.json.JsNumber(obj.accountid), "ownerid" -> play.api.libs.json.JsString(obj.ownerid), "sold" -> play.api.libs.json.JsNumber(obj.sold), "currency" -> play.api.libs.json.JsString(obj.currency) ) ++ (obj.totalAmount match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("total_amount" -> play.api.libs.json.JsNumber(x)) }) ++ (obj.debit match { case None => play.api.libs.json.Json.obj() case Some(x) => play.api.libs.json.Json.obj("debit" -> play.api.libs.json.JsNumber(x)) }) } implicit def jsonWritesMard2pAPIAccountForm: play.api.libs.json.Writes[AccountForm] = { (obj: payp.mard2p.api.v0.models.AccountForm) => { payp.mard2p.api.v0.models.json.jsObjectAccountForm(obj) } } implicit def jsonReadsMard2pAPIDeposit: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Deposit] = { for { depid <- (__ \ "depid").read[Long] paymentid <- (__ \ "paymentid").read[Long] } yield Deposit(depid, paymentid) } def jsObjectDeposit(obj: payp.mard2p.api.v0.models.Deposit): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "depid" -> play.api.libs.json.JsNumber(obj.depid), "paymentid" -> play.api.libs.json.JsNumber(obj.paymentid) ) } implicit def jsonWritesMard2pAPIDeposit: play.api.libs.json.Writes[Deposit] = { (obj: payp.mard2p.api.v0.models.Deposit) => { payp.mard2p.api.v0.models.json.jsObjectDeposit(obj) } } implicit def jsonReadsMard2pAPIPayment: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Payment] = { for { payid <- (__ \ "payid").read[Long] actorid <- (__ \ "actorid").read[String] amount <- (__ \ "amount").read[Double] refAccountid <- (__ \ "ref_accountid").read[Long] paymentMethod <- (__ \ "payment_method").read[String] operatorid <- (__ \ "operatorid").read[String] phone <- (__ \ "phone").read[Long] pin <- (__ \ "pin").read[Int] currency <- (__ \ "currency").read[String] paymentContext <- (__ \ "payment_context").read[String] } yield Payment(payid, actorid, amount, refAccountid, paymentMethod, operatorid, phone, pin, currency, paymentContext) } def jsObjectPayment(obj: payp.mard2p.api.v0.models.Payment): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "payid" -> play.api.libs.json.JsNumber(obj.payid), "actorid" -> play.api.libs.json.JsString(obj.actorid), "amount" -> play.api.libs.json.JsNumber(obj.amount), "ref_accountid" -> play.api.libs.json.JsNumber(obj.refAccountid), "payment_method" -> play.api.libs.json.JsString(obj.paymentMethod), "operatorid" -> play.api.libs.json.JsString(obj.operatorid), "phone" -> play.api.libs.json.JsNumber(obj.phone), "pin" -> play.api.libs.json.JsNumber(obj.pin), "currency" -> play.api.libs.json.JsString(obj.currency), "payment_context" -> play.api.libs.json.JsString(obj.paymentContext) ) } implicit def jsonWritesMard2pAPIPayment: play.api.libs.json.Writes[Payment] = { (obj: payp.mard2p.api.v0.models.Payment) => { payp.mard2p.api.v0.models.json.jsObjectPayment(obj) } } implicit def jsonReadsMard2pAPIPaymentForm: play.api.libs.json.Reads[payp.mard2p.api.v0.models.PaymentForm] = { for { payid <- (__ \ "payid").read[Long] actorid <- (__ \ "actorid").read[String] amount <- (__ \ "amount").read[Double] refAccountid <- (__ \ "ref_accountid").read[Long] paymentMethod <- (__ \ "payment_method").read[String] operatorid <- (__ \ "operatorid").read[String] phone <- (__ \ "phone").read[Long] pin <- (__ \ "pin").read[Int] currency <- (__ \ "currency").read[String] paymentContext <- (__ \ "payment_context").read[String] } yield PaymentForm(payid, actorid, amount, refAccountid, paymentMethod, operatorid, phone, pin, currency, paymentContext) } def jsObjectPaymentForm(obj: payp.mard2p.api.v0.models.PaymentForm): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "payid" -> play.api.libs.json.JsNumber(obj.payid), "actorid" -> play.api.libs.json.JsString(obj.actorid), "amount" -> play.api.libs.json.JsNumber(obj.amount), "ref_accountid" -> play.api.libs.json.JsNumber(obj.refAccountid), "payment_method" -> play.api.libs.json.JsString(obj.paymentMethod), "operatorid" -> play.api.libs.json.JsString(obj.operatorid), "phone" -> play.api.libs.json.JsNumber(obj.phone), "pin" -> play.api.libs.json.JsNumber(obj.pin), "currency" -> play.api.libs.json.JsString(obj.currency), "payment_context" -> play.api.libs.json.JsString(obj.paymentContext) ) } implicit def jsonWritesMard2pAPIPaymentForm: play.api.libs.json.Writes[PaymentForm] = { (obj: payp.mard2p.api.v0.models.PaymentForm) => { payp.mard2p.api.v0.models.json.jsObjectPaymentForm(obj) } } implicit def jsonReadsMard2pAPITransfer: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Transfer] = { for { transferid <- (__ \ "transferid").read[Long] senderid <- (__ \ "senderid").read[String] amount <- (__ \ "amount").read[Double] refAccountidReceiver <- (__ \ "ref_accountid_receiver").read[Long] refAccountidSender <- (__ \ "ref_accountid_sender").read[Long] currency <- (__ \ "currency").read[String] } yield Transfer(transferid, senderid, amount, refAccountidReceiver, refAccountidSender, currency) } def jsObjectTransfer(obj: payp.mard2p.api.v0.models.Transfer): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "transferid" -> play.api.libs.json.JsNumber(obj.transferid), "senderid" -> play.api.libs.json.JsString(obj.senderid), "amount" -> play.api.libs.json.JsNumber(obj.amount), "ref_accountid_receiver" -> play.api.libs.json.JsNumber(obj.refAccountidReceiver), "ref_accountid_sender" -> play.api.libs.json.JsNumber(obj.refAccountidSender), "currency" -> play.api.libs.json.JsString(obj.currency) ) } implicit def jsonWritesMard2pAPITransfer: play.api.libs.json.Writes[Transfer] = { (obj: payp.mard2p.api.v0.models.Transfer) => { payp.mard2p.api.v0.models.json.jsObjectTransfer(obj) } } implicit def jsonReadsMard2pAPITransferForm: play.api.libs.json.Reads[payp.mard2p.api.v0.models.TransferForm] = { for { transferid <- (__ \ "transferid").read[Long] senderid <- (__ \ "senderid").read[String] amount <- (__ \ "amount").read[Double] refAccountidReceiver <- (__ \ "ref_accountid_receiver").read[Long] refAccountidSender <- (__ \ "ref_accountid_sender").read[Long] currency <- (__ \ "currency").read[String] } yield TransferForm(transferid, senderid, amount, refAccountidReceiver, refAccountidSender, currency) } def jsObjectTransferForm(obj: payp.mard2p.api.v0.models.TransferForm): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "transferid" -> play.api.libs.json.JsNumber(obj.transferid), "senderid" -> play.api.libs.json.JsString(obj.senderid), "amount" -> play.api.libs.json.JsNumber(obj.amount), "ref_accountid_receiver" -> play.api.libs.json.JsNumber(obj.refAccountidReceiver), "ref_accountid_sender" -> play.api.libs.json.JsNumber(obj.refAccountidSender), "currency" -> play.api.libs.json.JsString(obj.currency) ) } implicit def jsonWritesMard2pAPITransferForm: play.api.libs.json.Writes[TransferForm] = { (obj: payp.mard2p.api.v0.models.TransferForm) => { payp.mard2p.api.v0.models.json.jsObjectTransferForm(obj) } } implicit def jsonReadsMard2pAPIValidation: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Validation] = { for { valid <- (__ \ "valid").read[Boolean] errors <- (__ \ "errors").read[Seq[String]] } yield Validation(valid, errors) } def jsObjectValidation(obj: payp.mard2p.api.v0.models.Validation): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "valid" -> play.api.libs.json.JsBoolean(obj.valid), "errors" -> play.api.libs.json.Json.toJson(obj.errors) ) } implicit def jsonWritesMard2pAPIValidation: play.api.libs.json.Writes[Validation] = { (obj: payp.mard2p.api.v0.models.Validation) => { payp.mard2p.api.v0.models.json.jsObjectValidation(obj) } } implicit def jsonReadsMard2pAPIWithdraw: play.api.libs.json.Reads[payp.mard2p.api.v0.models.Withdraw] = { for { wdwid <- (__ \ "wdwid").read[Long] paymentid <- (__ \ "paymentid").read[Long] } yield Withdraw(wdwid, paymentid) } def jsObjectWithdraw(obj: payp.mard2p.api.v0.models.Withdraw): play.api.libs.json.JsObject = { play.api.libs.json.Json.obj( "wdwid" -> play.api.libs.json.JsNumber(obj.wdwid), "paymentid" -> play.api.libs.json.JsNumber(obj.paymentid) ) } implicit def jsonWritesMard2pAPIWithdraw: play.api.libs.json.Writes[Withdraw] = { (obj: payp.mard2p.api.v0.models.Withdraw) => { payp.mard2p.api.v0.models.json.jsObjectWithdraw(obj) } } } } package payp.mard2p.api.v0 { import com.ning.http.client.{AsyncCompletionHandler, AsyncHttpClient, Realm, Request, RequestBuilder, Response, AsyncHttpClientConfig} object Constants { val BaseUrl = "https://api.apibuilder.io" val Namespace = "payp.mard2p.api.v0" val UserAgent = "apibuilder app.apibuilder.io/mard/mard2p-api/0.0.2-dev/ning_1_9_client" val Version = "0.0.2-dev" val VersionMajor = 0 } class Client( val baseUrl: String = "https://api.apibuilder.io", auth: scala.Option[payp.mard2p.api.v0.Authorization] = None, defaultHeaders: Seq[(String, String)] = Nil, asyncHttpClient: AsyncHttpClient = Client.defaultAsyncHttpClient ) extends interfaces.Client { import org.slf4j.{Logger, LoggerFactory} import io.apibuilder.common.v0.models.json._ import io.apibuilder.generator.v0.models.json._ import io.apibuilder.spec.v0.models.json._ import payp.mard2p.api.v0.models.json._ def closeAsyncHttpClient(): Unit = { asyncHttpClient.close() } val logger = LoggerFactory.getLogger(getClass) def accounts: Accounts = Accounts def deposits: Deposits = Deposits def payments: Payments = Payments def transfers: Transfers = Transfers def validations: Validations = Validations def withdraws: Withdraws = Withdraws object Accounts extends Accounts { override def postCreate( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] = { val payload = play.api.libs.json.Json.obj( "accountid" -> play.api.libs.json.Json.toJson(accountid), "ownerid" -> play.api.libs.json.Json.toJson(ownerid), "total_amount" -> play.api.libs.json.Json.toJson(totalAmount), "sold" -> play.api.libs.json.Json.toJson(sold), "debit" -> play.api.libs.json.Json.toJson(debit), "currency" -> play.api.libs.json.Json.toJson(currency) ) _executeRequest("POST", s"/accounts/create", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Account", r, _.validate[payp.mard2p.api.v0.models.Account]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def putUpdateByAccountid( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] = { val payload = play.api.libs.json.Json.obj( "ownerid" -> play.api.libs.json.Json.toJson(ownerid), "total_amount" -> play.api.libs.json.Json.toJson(totalAmount), "currency" -> play.api.libs.json.Json.toJson(currency), "sold" -> play.api.libs.json.Json.toJson(sold), "debit" -> play.api.libs.json.Json.toJson(debit) ) _executeRequest("PUT", s"/accounts/update/${accountid}", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Account", r, _.validate[payp.mard2p.api.v0.models.Account]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def deleteDeleteByAccountid( accountid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] = { _executeRequest("DELETE", s"/accounts/delete/${accountid}", requestHeaders = requestHeaders).map { case r if r.getStatusCode == 204 => () case r if r.getStatusCode == 401 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 204, 401, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByAccountid( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] = { val queryParameters = Seq( Some("ownerid" -> ownerid), Some("total_amount" -> totalAmount.toString), Some("sold" -> sold.toString), Some("debit" -> debit.toString), Some("currency" -> currency) ).flatten _executeRequest("GET", s"/accounts/${accountid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Account", r, _.validate[payp.mard2p.api.v0.models.Account]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getList( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Account]] = { val queryParameters = Seq( Some("accountid" -> accountid.toString), Some("ownerid" -> ownerid), Some("total_amount" -> totalAmount.toString), Some("currency" -> currency), Some("sold" -> sold.toString), Some("debit" -> debit.toString) ).flatten _executeRequest("GET", s"/accounts/list", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("Seq[payp.mard2p.api.v0.models.Account]", r, _.validate[Seq[payp.mard2p.api.v0.models.Account]]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } } object Deposits extends Deposits { override def deleteDeleteByDepid( depid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] = { _executeRequest("DELETE", s"/deposits/delete/${depid}", requestHeaders = requestHeaders).map { case r if r.getStatusCode == 204 => () case r if r.getStatusCode == 401 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 204, 401, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByDepid( depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val queryParameters = Seq( Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/deposits/${depid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] = { val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/deposits/list", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("Seq[payp.mard2p.api.v0.models.Payment]", r, _.validate[Seq[payp.mard2p.api.v0.models.Payment]]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } } object Payments extends Payments { override def postCreate( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, currency: String, phone: Long, pin: Int, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val payload = play.api.libs.json.Json.obj( "payid" -> play.api.libs.json.Json.toJson(payid), "payment_method" -> play.api.libs.json.Json.toJson(paymentMethod), "actorid" -> play.api.libs.json.Json.toJson(actorid), "ref_accountid" -> play.api.libs.json.Json.toJson(refAccountid), "operatorid" -> play.api.libs.json.Json.toJson(operatorid), "amount" -> play.api.libs.json.Json.toJson(amount), "currency" -> play.api.libs.json.Json.toJson(currency), "phone" -> play.api.libs.json.Json.toJson(phone), "pin" -> play.api.libs.json.Json.toJson(pin), "payment_context" -> play.api.libs.json.Json.toJson(paymentContext) ) _executeRequest("POST", s"/payments/create", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def putUpdateByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val payload = play.api.libs.json.Json.obj( "payment_method" -> play.api.libs.json.Json.toJson(paymentMethod), "actorid" -> play.api.libs.json.Json.toJson(actorid), "ref_accountid" -> play.api.libs.json.Json.toJson(refAccountid), "operatorid" -> play.api.libs.json.Json.toJson(operatorid), "amount" -> play.api.libs.json.Json.toJson(amount), "phone" -> play.api.libs.json.Json.toJson(phone), "pin" -> play.api.libs.json.Json.toJson(pin), "currency" -> play.api.libs.json.Json.toJson(currency), "payment_context" -> play.api.libs.json.Json.toJson(paymentContext) ) _executeRequest("PUT", s"/payments/update/${payid}", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def deleteDeleteByPayid( payid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] = { _executeRequest("DELETE", s"/payments/delete/${payid}", requestHeaders = requestHeaders).map { case r if r.getStatusCode == 204 => () case r if r.getStatusCode == 401 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 204, 401, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val queryParameters = Seq( Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/payments/${payid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByRefAccountid( refAccountid: Long, payid: Long, paymentMethod: String, actorid: String, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/payments/${refAccountid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] = { val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/payments/list", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("Seq[payp.mard2p.api.v0.models.Payment]", r, _.validate[Seq[payp.mard2p.api.v0.models.Payment]]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } } object Transfers extends Transfers { override def postCreate( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Transfer] = { val payload = play.api.libs.json.Json.obj( "transferid" -> play.api.libs.json.Json.toJson(transferid), "senderid" -> play.api.libs.json.Json.toJson(senderid), "amount" -> play.api.libs.json.Json.toJson(amount), "currency" -> play.api.libs.json.Json.toJson(currency), "ref_accountid_receiver" -> play.api.libs.json.Json.toJson(refAccountidReceiver), "ref_accountid_sender" -> play.api.libs.json.Json.toJson(refAccountidSender) ) _executeRequest("POST", s"/transfers/create", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Transfer", r, _.validate[payp.mard2p.api.v0.models.Transfer]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def putUpdateByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Transfer] = { val payload = play.api.libs.json.Json.obj( "senderid" -> play.api.libs.json.Json.toJson(senderid), "amount" -> play.api.libs.json.Json.toJson(amount), "currency" -> play.api.libs.json.Json.toJson(currency), "ref_accountid_receiver" -> play.api.libs.json.Json.toJson(refAccountidReceiver), "ref_accountid_sender" -> play.api.libs.json.Json.toJson(refAccountidSender) ) _executeRequest("PUT", s"/transfers/update/${transferid}", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Transfer", r, _.validate[payp.mard2p.api.v0.models.Transfer]) case r if r.getStatusCode == 409 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 409", requestUri = Some(r.getUri.toJavaNetURI)) } } override def deleteDeleteByTransferid( transferid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] = { _executeRequest("DELETE", s"/transfers/delete/${transferid}", requestHeaders = requestHeaders).map { case r if r.getStatusCode == 204 => () case r if r.getStatusCode == 401 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 204, 401, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] = { val queryParameters = Seq( Some("senderid" -> senderid), Some("amount" -> amount.toString), Some("currency" -> currency), Some("ref_accountid_receiver" -> refAccountidReceiver.toString), Some("ref_accountid_sender" -> refAccountidSender.toString) ).flatten _executeRequest("GET", s"/transfers/${transferid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Account", r, _.validate[payp.mard2p.api.v0.models.Account]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getList( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Account]] = { val queryParameters = Seq( Some("transferid" -> transferid.toString), Some("senderid" -> senderid), Some("amount" -> amount.toString), Some("currency" -> currency), Some("ref_accountid_receiver" -> refAccountidReceiver.toString), Some("ref_accountid_sender" -> refAccountidSender.toString) ).flatten _executeRequest("GET", s"/transfers/list", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("Seq[payp.mard2p.api.v0.models.Account]", r, _.validate[Seq[payp.mard2p.api.v0.models.Account]]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } } object Validations extends Validations { override def post( value: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Validation] = { val payload = play.api.libs.json.Json.toJson(value) _executeRequest("POST", s"/validations", body = Some(payload), requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Validation", r, _.validate[payp.mard2p.api.v0.models.Validation]) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200", requestUri = Some(r.getUri.toJavaNetURI)) } } } object Withdraws extends Withdraws { override def deleteDeleteByWdwid( wdwid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] = { _executeRequest("DELETE", s"/withdraws/delete/${wdwid}", requestHeaders = requestHeaders).map { case r if r.getStatusCode == 204 => () case r if r.getStatusCode == 401 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 204, 401, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getByWdwid( wdwid: Long, depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] = { val queryParameters = Seq( Some("depid" -> depid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/withdraws/${wdwid}", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("payp.mard2p.api.v0.models.Payment", r, _.validate[payp.mard2p.api.v0.models.Payment]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } override def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] = { val queryParameters = Seq( Some("payid" -> payid.toString), Some("payment_method" -> paymentMethod), Some("actorid" -> actorid), Some("ref_accountid" -> refAccountid.toString), Some("operatorid" -> operatorid), Some("amount" -> amount.toString), Some("phone" -> phone.toString), Some("pin" -> pin.toString), Some("currency" -> currency), Some("payment_context" -> paymentContext) ).flatten _executeRequest("GET", s"/withdraws/list", queryParameters = queryParameters, requestHeaders = requestHeaders).map { case r if r.getStatusCode == 200 => _root_.payp.mard2p.api.v0.Client.parseJson("Seq[payp.mard2p.api.v0.models.Payment]", r, _.validate[Seq[payp.mard2p.api.v0.models.Payment]]) case r if r.getStatusCode == 404 => throw payp.mard2p.api.v0.errors.UnitResponse(r.getStatusCode) case r => throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Unsupported response code[${r.getStatusCode}]. Expected: 200, 404", requestUri = Some(r.getUri.toJavaNetURI)) } } } def _logRequest(request: Request): Unit = { if (logger.isInfoEnabled) { logger.info("_logRequest: " + request) } } def _logResponse(response: Response): Unit = { if (logger.isInfoEnabled) { logger.info("_logResponse: status=" + response.getStatusCode + ", responseBody: " + response.getResponseBody("UTF-8")) } } def _requestBuilder(method: String, path: String, requestHeaders: Seq[(String, String)]): RequestBuilder = { val builder = new RequestBuilder(method) .setUrl(baseUrl + path) .addHeader("User-Agent", Constants.UserAgent) .addHeader("X-Apidoc-Version", Constants.Version) .addHeader("X-Apidoc-Version-Major", Constants.VersionMajor.toString) defaultHeaders.foreach { h => builder.addHeader(h._1, h._2) } requestHeaders.foreach { h => builder.addHeader(h._1, h._2) } auth.fold(builder) { case Authorization.Basic(username, passwordOpt) => { builder.setRealm( new Realm.RealmBuilder() .setPrincipal(username) .setPassword(passwordOpt.getOrElse("")) .setUsePreemptiveAuth(true) .setScheme(Realm.AuthScheme.BASIC) .build() ) } case a => sys.error("Invalid authorization scheme[" + a.getClass + "]") } } def _executeRequest( method: String, path: String, queryParameters: Seq[(String, String)] = Nil, requestHeaders: Seq[(String, String)] = Nil, body: Option[play.api.libs.json.JsValue] = None )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[com.ning.http.client.Response] = { val allHeaders = body match { case None => requestHeaders case Some(_) => _withJsonContentType(requestHeaders) } val request = _requestBuilder(method, path, allHeaders) queryParameters.foreach { pair => request.addQueryParam(pair._1, pair._2) } val requestWithParamsAndBody = body.fold(request) { b => val serialized = play.api.libs.json.Json.stringify(b) request.setBody(serialized) } val finalRequest = requestWithParamsAndBody.build() _logRequest(finalRequest) val result = scala.concurrent.Promise[com.ning.http.client.Response]() asyncHttpClient.executeRequest(finalRequest, new AsyncCompletionHandler[Unit]() { override def onCompleted(r: com.ning.http.client.Response) = { _logResponse(r) result.success(r) } override def onThrowable(t: Throwable) = result.failure(t) } ) result.future } /** * Adds a Content-Type: application/json header unless the specified requestHeaders * already contain a Content-Type header */ def _withJsonContentType(headers: Seq[(String, String)]): Seq[(String, String)] = { headers.find { _._1.toUpperCase == "CONTENT-TYPE" } match { case None => headers ++ Seq(("Content-Type" -> "application/json; charset=UTF-8")) case Some(_) => headers } } } object Client { private lazy val defaultAsyncHttpClient = { new AsyncHttpClient( new AsyncHttpClientConfig.Builder() .setExecutorService(java.util.concurrent.Executors.newCachedThreadPool()) .build() ) } def parseJson[T]( className: String, r: _root_.com.ning.http.client.Response, f: (play.api.libs.json.JsValue => play.api.libs.json.JsResult[T]) ): T = { f(play.api.libs.json.Json.parse(r.getResponseBody("UTF-8"))) match { case play.api.libs.json.JsSuccess(x, _) => x case play.api.libs.json.JsError(errors) => { throw payp.mard2p.api.v0.errors.FailedRequest(r.getStatusCode, s"Invalid json for class[" + className + "]: " + errors.mkString(" "), requestUri = Some(r.getUri.toJavaNetURI)) } } } } sealed trait Authorization extends _root_.scala.Product with _root_.scala.Serializable object Authorization { final case class Basic(username: String, password: Option[String] = None) extends Authorization } package interfaces { trait Client { def baseUrl: String def accounts: payp.mard2p.api.v0.Accounts def deposits: payp.mard2p.api.v0.Deposits def payments: payp.mard2p.api.v0.Payments def transfers: payp.mard2p.api.v0.Transfers def validations: payp.mard2p.api.v0.Validations def withdraws: payp.mard2p.api.v0.Withdraws } } trait Accounts { /** * Used to create an account. */ def postCreate( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] /** * Used to update an account. */ def putUpdateByAccountid( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] /** * Delete some account. */ def deleteDeleteByAccountid( accountid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] /** * Find account by its id */ def getByAccountid( accountid: Long, ownerid: String, totalAmount: Double, sold: Double, debit: Double, currency: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] /** * Find all the accounts. */ def getList( accountid: Long, ownerid: String, totalAmount: Double, currency: String, sold: Double, debit: Double, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Account]] } trait Deposits { /** * Delete some deposit. */ def deleteDeleteByDepid( depid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] /** * Find deposit by its id. */ def getByDepid( depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * List all the deposits */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] } trait Payments { /** * Used to create a payment. */ def postCreate( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, currency: String, phone: Long, pin: Int, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * Used to update a payment. */ def putUpdateByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * Delete some payment. */ def deleteDeleteByPayid( payid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] /** * Find payment by its id. */ def getByPayid( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * Find payment by id accountid */ def getByRefAccountid( refAccountid: Long, payid: Long, paymentMethod: String, actorid: String, operatorid: String, amount: Double, phone: Long, pin: Int, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * List all the payments */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] } trait Transfers { /** * Used to create a transfer resource. */ def postCreate( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Transfer] /** * Used to update a transfer resource. */ def putUpdateByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Transfer] /** * Delete some transfer. */ def deleteDeleteByTransferid( transferid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] /** * Find transfer by its id */ def getByTransferid( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Account] /** * Find all the transfers. */ def getList( transferid: Long, senderid: String, amount: Double, currency: String, refAccountidReceiver: Long, refAccountidSender: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Account]] } trait Validations { def post( value: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Validation] } trait Withdraws { /** * Delete some withdraw. */ def deleteDeleteByWdwid( wdwid: Long, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Unit] /** * Find withdraw by its id. */ def getByWdwid( wdwid: Long, depid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[payp.mard2p.api.v0.models.Payment] /** * List all the withdraws */ def getList( payid: Long, paymentMethod: String, actorid: String, refAccountid: Long, operatorid: String, amount: Double, phone: Long, pin: Long, currency: String, paymentContext: String, requestHeaders: Seq[(String, String)] = Nil )(implicit ec: scala.concurrent.ExecutionContext): scala.concurrent.Future[Seq[payp.mard2p.api.v0.models.Payment]] } package errors { import io.apibuilder.common.v0.models.json._ import io.apibuilder.generator.v0.models.json._ import io.apibuilder.spec.v0.models.json._ import payp.mard2p.api.v0.models.json._ final case class UnitResponse(status: Int) extends Exception(s"HTTP $status") final case class FailedRequest(responseCode: Int, message: String, requestUri: Option[_root_.java.net.URI] = None) extends _root_.java.lang.Exception(s"HTTP $responseCode: $message") } object PathSegment { // See https://github.com/playframework/playframework/blob/2.3.x/framework/src/play/src/main/scala/play/utils/UriEncoding.scala def encode(s: String, inputCharset: String): String = { val in = s.getBytes(inputCharset) val out = new java.io.ByteArrayOutputStream() for (b <- in) { val allowed = segmentChars.get(b & 0xFF) if (allowed) { out.write(b) } else { out.write('%') out.write(upperHex((b >> 4) & 0xF)) out.write(upperHex(b & 0xF)) } } out.toString("US-ASCII") } private def upperHex(x: Int): Int = { // Assume 0 <= x < 16 if (x < 10) (x + '0') else (x - 10 + 'A') } private val segmentChars: java.util.BitSet = membershipTable(pchar) private def pchar: Seq[Char] = { val alphaDigit = for ((min, max) <- Seq(('a', 'z'), ('A', 'Z'), ('0', '9')); c <- min to max) yield c val unreserved = alphaDigit ++ Seq('-', '.', '_', '~') val subDelims = Seq('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=') unreserved ++ subDelims ++ Seq(':', '@') } private def membershipTable(chars: Seq[Char]): java.util.BitSet = { val bits = new java.util.BitSet(256) for (c <- chars) { bits.set(c.toInt) } bits } } }