Created
July 10, 2018 02:41
-
-
Save iboss-ptk/2df6eac83f9873ee5ef1221e71c5e6cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // creating a wrapper around static method | |
| @Component | |
| class MessageWrapper { | |
| fun creator(phoneNumber: PhoneNumber, messageServiceSid: String, text: String) = | |
| Message.creator(phoneNumber, messageServiceSid, text) | |
| } | |
| @Service | |
| class NotificationService( | |
| private val restClient: TwilioRestClient, | |
| private val secretRepository: SecretRepository, | |
| // Inject the wrapper | |
| private val messageWrapper: MessageWrapper | |
| ) { | |
| fun notify(notificationRequest: NotificationRequest): NotificationResponse { | |
| val (countryCode, phoneNumber, text) = notificationRequest | |
| val messagingServiceId = secretRepository.getTwilloMessagingServiceId() | |
| // Using wrapper | |
| val messageCreator = messageWrapper.creator( | |
| PhoneNumber(countryCode + phoneNumber), | |
| messagingServiceId, | |
| text) | |
| val message = messageCreator.create(restClient) | |
| return when (message.status){ | |
| Message.Status.FAILED -> | |
| NotificationFailed( | |
| message.errorCode, | |
| message.errorMessage) | |
| else -> | |
| NotificationSuccess | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment