Eskiz.uz SMS Java SDK
Hi. This is small repository just Java SDK(client) for SMS
service of Eskiz.uz provider.
Eskiz has many services like hosting, domain, SMS etc. Plugin has integrated to only SMS service.
Plugin has built for not implementing clients(RestTemplate, OpenFeign, etc.),
DTOs, Interfaces again and again. And see otp-plugin repository.
This plugin will use in there, because this plugin is part of sending otp. This plugin has built separately for providing more abstraction and reusability.
I was wondering if you could add your attention and efforts, let's scale plugin together.
Thank you for your attention.
Important
If you want to see how really works plugin, follow these steps:
- Override fields of
EskizCredentialsConstants
- Run all tests of
/src/java/test
package
- Quick start
- Main API
- Authorizer
- SMS
Template- Contact not implemented yet
- Reports not implemented yet
- Examples
- Customizing
- Integrating with Spring Boot
- Add examples
- Publish package
- Add instruction about how to publish new package
- Developers
- Todo
Follow these steps for installing package:
- Override
settings.xml
, add credentials for reading package<servers> <server> <id>github-sardorbroo-eskizuz</id> <username>${ username }</username> <password>${ password or token }</password> <configuration> <authenticationInfo> <userName>${ username }</userName> <password>${ password or token }</password> </authenticationInfo> </configuration> </server> </servers>
Note
Token for only read package, you cannot publish something new with this token. If you want to add something add connect to owner(thesardorbroo)
Important
- Get public credentials from settings.xml
- If you don't want to edit global
settings.xml
, use our already configuredsettings.xml
. You just need copy/paste and change your Intellij Idea maven user settings. See guide
-
Add repository tag to your
pom.xml
:<repositories> <!-- Other repositories --> <repository> <id>sardorbroo-github-eskizuz</id> <url>https://maven.pkg.github.com/thesardorbroo/eskiz.uz</url> </repository> </repositories>
-
Add dependency tag to
pom.xml
:<dependencyManagement> <!-- Other dependencies --> <dependency> <groupId>uz.sardorbroo</groupId> <artifactId>eskizuz</artifactId> <version>1.0.0</version> </dependency> </dependencyManagement>
-
Verify package Install the package by following command:
mvn clean install
import uz.sardorbroo.eskizuz.Eskiz;
import uz.sardorbroo.eskizuz.constants.EskizClientConstants;
import uz.sardorbroo.eskizuz.dto.sms.SendSmsRequestDto;
import uz.sardorbroo.eskizuz.dto.sms.SendSmsResponseDto;
import uz.sardorbroo.eskizuz.properties.EskizProperties;
import java.util.Optional;
public static void main(String[] args) {
EskizProperties properties = new EskizProperties();
properties.setEmail(/* Your email */);
properties.setPassword(/* Your password */);
Eskiz eskiz = new Eskiz.Builder(properties)
.build();
SendSmsRequestDto request = new SendSmsRequestDto();
request.setFrom(properties.getFrom());
request.setCallbackUrl(/* Your callback URL. It is optional */);
// If you bought tariff from Eskiz.uz you can set any message
request.setMessage(EskizClientConstants.ESKIZ_TEST_MESSAGE_UZ);
// be sure phone number doesn't contain symbol '+'
request.setMobilePhone(/* Your phone number */);
Optional<SendSmsResponseDto> responseOptional = eskiz.sms(request).send();
System.out.println(responseOptional);
}
Tip
Use Eskiz
and Eskiz.Builder
, because they have default implementations.
If you want to use own implementation, it is so easy. See guide.
This section includes, customizing and integrating SDK to Spring Boot easily
In this example we will customize SmsClient
and use it with builder of Eskiz
, and straightly. Examples:
- Customizing
SmsClient
:import java.lang.String; import java.util.Optional; import uz.sardorbroo.eskizuz.dto.sms.SendSmsResponseDto; import uz.sardorbroo.eskizuz.service.client.SmsClient; import uz.sardorbroo.eskizuz.constants.EskizClientConstants; import org.springframework.web.client.RestTemplate; import org.springframework.http.HttpMethod; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; public class RestTemplateSmsClient implements SmsClient { private static final String SEND_SMS_URL = EskizClientConstants.BASE_URL + "/api/message/sms/send"; private final RestTemplate client = new RestTemplate(); public Optional<SendSmsResponseDto> send(SendSmsRequestDto dto) { // some code like log, validation and etc HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(/* You token */); ResponseEntity<SendSmsResponseDto> response = client.exchange(SEND_SMS_URL, HttpMethod.POST, new HttpEntity<>(headers), SendSmsResponseDto.class); // check or validate response return Optional.of(response.getBody()); } }
- Add custom client to
Eskiz.Builder
:import uz.sardorbroo.eskizuz.Eskiz; import uz.sardorbroo.eskizuz.properties.EskizProperties;import uz.sardorbroo.eskizuz.service.Sms;import uz.sardorbroo.eskizuz.service.client.SmsClient;import uz.sardorbroo.eskizuz.service.impl.SmsImpl; public static void main(String[] args){ EskizProperties properties = new EskizProperties(); properties.setEmail(/* Your email */); properties.setPassword(/* Your password */); SmsClient client = new RestTemplateSmsClient(); Sms sms = new SmsImpl(client); Eskiz eskiz = new Eskiz.Builder(properties) .sms(sms) .build(); eskiz.sms().send(/* DTO */); }
- Create bean of customized client implementation:
import uz.sardorbroo.eskizuz.service.Sms; import uz.sardorbroo.eskizuz.service.client.SmsClient; @Configuration public static SmsConfig() { @Bean("RestTemplate") public SmsClient configureRestTemplateClient() { return new RestTemplateSmsClient(); } @Bean public Sms configureSms(@Qualifier("RestTemplate") SmsClient client) { return new Sms(client); } }
Name | Nick name | Stack | Contact |
---|---|---|---|
Sardor Shorahimov | Sardorbroo | Java backend | Telegram |
- Implement
Authorizer
builder - Add
Retrofit
interceptor - Publish the package to GitHub package registry
- Write documentation
- Complete send SMS tests
- Write tests
-
@Slf4j
doesn't work while working junit tests