1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.crm 21 22 import java.nio.file.{Path, Paths} 23 import akka.Done 24 import enumeratum.values.{StringEnum, StringEnumEntry} 25 import io.circe.Decoder 26 import org.make.api.technical.crm.ManageContactAction.{AddNoForce, Remove} 27 import org.make.api.technical.job.JobActor.Protocol.Response.JobAcceptance 28 import org.make.core.Order 29 import org.make.core.technical.Pagination 30 31 import scala.concurrent.Future 32 33 trait CrmService { 34 def sendEmail(messages: SendMessages): Future[SendEmailResponse] 35 def synchronizeList(formattedDate: String, list: CrmList, csvDirectory: Path): Future[Done] 36 def createCrmUsers(): Future[Unit] 37 def anonymize(): Future[Unit] 38 def synchronizeContactsWithCrm(): Future[JobAcceptance] 39 def getUsersMailFromList( 40 listId: Option[String] = None, 41 sort: Option[String] = None, 42 order: Option[Order] = None, 43 countOnly: Option[Boolean] = None, 44 limit: Pagination.Limit, 45 offset: Pagination.Offset = Pagination.Offset(0) 46 ): Future[GetUsersMail] 47 def deleteRecipient(email: String): Future[Unit] 48 } 49 50 trait CrmServiceComponent { 51 def crmService: CrmService 52 } 53 54 final case class GetUsersMail(count: Int, total: Int, data: Seq[ContactMail]) 55 object GetUsersMail { 56 implicit val decoder: Decoder[GetUsersMail] = Decoder.forProduct3("Count", "Total", "Data")(GetUsersMail.apply) 57 } 58 59 final case class ContactMail(email: String, contactId: Long) 60 object ContactMail { 61 implicit val decoder: Decoder[ContactMail] = Decoder.forProduct2("Email", "ID")(ContactMail.apply) 62 } 63 64 sealed abstract class CrmList(val value: String) extends StringEnumEntry { 65 def hardBounced: Boolean 66 def unsubscribed: Option[Boolean] 67 68 def targetDirectory(csvDirectory: String): Path = { 69 Paths.get(csvDirectory, value) 70 } 71 72 def actionOnHardBounce: ManageContactAction 73 def actionOnOptIn: ManageContactAction 74 def actionOnOptOut: ManageContactAction 75 } 76 77 object CrmList extends StringEnum[CrmList] { 78 case object HardBounce extends CrmList("hardBounce") { 79 override val hardBounced: Boolean = true 80 override val unsubscribed: Option[Boolean] = None 81 82 override val actionOnHardBounce: ManageContactAction = AddNoForce 83 override val actionOnOptIn: ManageContactAction = Remove 84 override val actionOnOptOut: ManageContactAction = Remove 85 } 86 87 case object OptIn extends CrmList("optIn") { 88 override val hardBounced: Boolean = false 89 override val unsubscribed: Option[Boolean] = Some(false) 90 91 override val actionOnHardBounce: ManageContactAction = Remove 92 override val actionOnOptIn: ManageContactAction = AddNoForce 93 override val actionOnOptOut: ManageContactAction = Remove 94 } 95 96 case object OptOut extends CrmList("optOut") { 97 override val hardBounced: Boolean = false 98 override val unsubscribed: Option[Boolean] = Some(true) 99 100 override val actionOnHardBounce: ManageContactAction = Remove 101 override val actionOnOptIn: ManageContactAction = Remove 102 override val actionOnOptOut: ManageContactAction = AddNoForce 103 } 104 105 override val values: IndexedSeq[CrmList] = findValues 106 final val swaggerAllowableValues = "hardBounce,optIn,optOut" 107 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 56 | 28751 | 2054 - 2054 | ApplyToImplicitArgs | io.circe.Decoder.decodeSeq | circe.this.Decoder.decodeSeq[org.make.api.technical.crm.ContactMail](crm.this.ContactMail.decoder) | |
| 56 | 28278 | 2009 - 2074 | ApplyToImplicitArgs | io.circe.ProductDecoders.forProduct3 | io.circe.Decoder.forProduct3[org.make.api.technical.crm.GetUsersMail, Int, Int, Seq[org.make.api.technical.crm.ContactMail]]("Count", "Total", "Data")(((count: Int, total: Int, data: Seq[org.make.api.technical.crm.ContactMail]) => GetUsersMail.apply(count, total, data)))(circe.this.Decoder.decodeInt, circe.this.Decoder.decodeInt, circe.this.Decoder.decodeSeq[org.make.api.technical.crm.ContactMail](crm.this.ContactMail.decoder)) | |
| 56 | 28974 | 2054 - 2054 | Select | io.circe.Decoder.decodeInt | circe.this.Decoder.decodeInt | |
| 56 | 29728 | 2029 - 2036 | Literal | <nosymbol> | "Count" | |
| 56 | 30251 | 2047 - 2053 | Literal | <nosymbol> | "Data" | |
| 56 | 29572 | 2054 - 2054 | Select | org.make.api.technical.crm.ContactMail.decoder | crm.this.ContactMail.decoder | |
| 56 | 28830 | 2038 - 2045 | Literal | <nosymbol> | "Total" | |
| 56 | 30403 | 2054 - 2054 | Select | io.circe.Decoder.decodeInt | circe.this.Decoder.decodeInt | |
| 56 | 29488 | 2055 - 2073 | Apply | org.make.api.technical.crm.GetUsersMail.apply | GetUsersMail.apply(count, total, data) | |
| 61 | 29457 | 2241 - 2241 | Select | io.circe.Decoder.decodeString | circe.this.Decoder.decodeString | |
| 61 | 30407 | 2207 - 2260 | ApplyToImplicitArgs | io.circe.ProductDecoders.forProduct2 | io.circe.Decoder.forProduct2[org.make.api.technical.crm.ContactMail, String, Long]("Email", "ID")(((email: String, contactId: Long) => ContactMail.apply(email, contactId)))(circe.this.Decoder.decodeString, circe.this.Decoder.decodeLong) | |
| 61 | 29683 | 2227 - 2234 | Literal | <nosymbol> | "Email" | |
| 61 | 28980 | 2241 - 2241 | Select | io.circe.Decoder.decodeLong | circe.this.Decoder.decodeLong | |
| 61 | 28815 | 2236 - 2240 | Literal | <nosymbol> | "ID" | |
| 61 | 30256 | 2242 - 2259 | Apply | org.make.api.technical.crm.ContactMail.apply | ContactMail.apply(email, contactId) | |
| 69 | 29504 | 2485 - 2490 | Select | org.make.api.technical.crm.CrmList.value | CrmList.this.value | |
| 69 | 28686 | 2461 - 2491 | Apply | java.nio.file.Paths.get | java.nio.file.Paths.get(csvDirectory, CrmList.this.value) | |
| 79 | 30083 | 2771 - 2775 | Literal | <nosymbol> | true | |
| 80 | 29691 | 2825 - 2829 | Select | scala.None | scala.None | |
| 82 | 28817 | 2890 - 2900 | Select | org.make.api.technical.crm.ManageContactAction.AddNoForce | org.make.api.technical.crm.ManageContactAction.AddNoForce | |
| 83 | 30189 | 2955 - 2961 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 84 | 29482 | 3017 - 3023 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 88 | 28989 | 3116 - 3121 | Literal | <nosymbol> | false | |
| 89 | 30431 | 3171 - 3182 | Apply | scala.Some.apply | scala.Some.apply[Boolean](false) | |
| 91 | 29509 | 3243 - 3249 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 92 | 28675 | 3304 - 3314 | Select | org.make.api.technical.crm.ManageContactAction.AddNoForce | org.make.api.technical.crm.ManageContactAction.AddNoForce | |
| 93 | 30171 | 3370 - 3376 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 97 | 29699 | 3471 - 3476 | Literal | <nosymbol> | false | |
| 98 | 28919 | 3526 - 3536 | Apply | scala.Some.apply | scala.Some.apply[Boolean](true) | |
| 100 | 30192 | 3597 - 3603 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 101 | 29451 | 3658 - 3664 | Select | org.make.api.technical.crm.ManageContactAction.Remove | org.make.api.technical.crm.ManageContactAction.Remove | |
| 102 | 29059 | 3720 - 3730 | Select | org.make.api.technical.crm.ManageContactAction.AddNoForce | org.make.api.technical.crm.ManageContactAction.AddNoForce | |
| 106 | 30434 | 3829 - 3854 | Literal | <nosymbol> | "hardBounce,optIn,optOut" |