All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.payu.notification.client.NotificationClient Maven / Gradle / Ivy

The newest version!
package com.payu.notification.client;

import com.payu.common.client.rest.AbstractRestClient;
import com.payu.notification.client.model.SmsNotificationPattern;
import com.payu.notification.client.model.request.SmsRequest;
import com.payu.notification.client.model.response.SmsResponse;
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

public class NotificationClient extends AbstractRestClient implements SmsNotificationPattern {
  public static final String STRING_FORMAT_2_ARGS = "%s/%s";
  public static final String SMS_PATH = "sms";
  public static final String SEND_SMS_PATH = SMS_PATH + "/send";

  public NotificationClient(final RestTemplate restTemplate, final String baseUrl) {
    super(restTemplate, baseUrl);
  }

  @Override
  public SmsResponse sendSms(SmsRequest smsRequest) {
    String getUrl = String.format(STRING_FORMAT_2_ARGS, getBaseUrl(), SEND_SMS_PATH);
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    HttpEntity requestEntity = new HttpEntity<>(smsRequest, headers);

    return getRestTemplate()
        .exchange(getUrl, HttpMethod.POST, requestEntity, SmsResponse.class)
        .getBody();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy