Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Created July 10, 2018 02:41
Show Gist options
  • Select an option

  • Save iboss-ptk/2df6eac83f9873ee5ef1221e71c5e6cc to your computer and use it in GitHub Desktop.

Select an option

Save iboss-ptk/2df6eac83f9873ee5ef1221e71c5e6cc to your computer and use it in GitHub Desktop.
// 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