io.github.eduardromanyuk.turbosms.service.impl.TsApiServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of turbosms-spring-boot-starter Show documentation
Show all versions of turbosms-spring-boot-starter Show documentation
This starter provides infrastructure for using TurboSMS sms/viber provider.
HTTP API was used for communication.
The newest version!
package io.github.eduardromanyuk.turbosms.service.impl;
import io.github.eduardromanyuk.turbosms.model.request.*;
import io.github.eduardromanyuk.turbosms.model.response.*;
import io.github.eduardromanyuk.turbosms.service.TsApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.Collections;
import java.util.List;
@RequiredArgsConstructor
public class TsApiServiceImpl implements TsApiService {
private final RestTemplate restTemplate;
@Override
public ResponseEntity>> messageSend(TsMessageSendSmsRequest smsMessage) {
return request(
TsEndpoint.MESSAGE_SEND,
Collections.singletonMap("sms", smsMessage),
new ParameterizedTypeReference>>() {}
);
}
@Override
public ResponseEntity>> messageSend(TsMessageSendViberRequest viberMessage) {
return request(
TsEndpoint.MESSAGE_SEND,
Collections.singletonMap("viber", viberMessage),
new ParameterizedTypeReference>>() {}
);
}
@Override
public ResponseEntity>> messageSend(TsMessageSendHybridRequest hybridMessage) {
return request(
TsEndpoint.MESSAGE_SEND,
hybridMessage,
new ParameterizedTypeReference>>() {}
);
}
@Override
public ResponseEntity>> messageStatus(TsMessageStatusRequest statusRequest) {
return request(
TsEndpoint.MESSAGE_STATUS,
statusRequest,
new ParameterizedTypeReference>>() {}
);
}
@Override
public ResponseEntity> userBalance() {
return request(
TsEndpoint.USER_BALANCE,
new ParameterizedTypeReference>() {}
);
}
@Override
public ResponseEntity> fileAdd(TsFileAddUrlRequest urlRequest) {
return request(
TsEndpoint.FILE_ADD,
urlRequest,
new ParameterizedTypeReference>() {}
);
}
@Override
public ResponseEntity> fileAdd(TsFileAddDataRequest dataRequest) {
return request(
TsEndpoint.FILE_ADD,
dataRequest,
new ParameterizedTypeReference>() {}
);
}
@Override
public ResponseEntity> fileDetails(TsFileDetailsRequest detailsRequest) {
return request(
TsEndpoint.FILE_DETAILS,
detailsRequest,
new ParameterizedTypeReference>() {}
);
}
private ResponseEntity request(TsEndpoint endpoint, Object body, ParameterizedTypeReference responseType) {
return restTemplate.exchange(endpoint.value(), HttpMethod.POST, new HttpEntity<>(body), responseType);
}
private ResponseEntity request(TsEndpoint endpoint, ParameterizedTypeReference responseType) {
return restTemplate.exchange(endpoint.value(), HttpMethod.POST, HttpEntity.EMPTY, responseType);
}
}