GithubHelp home page GithubHelp logo

bsgworld / java-rest-api Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 32 KB

This repository contains the open source Java client for BSG's REST API. SMS, Viber and HLR.

Home Page: https://bsg.world/developers/

License: BSD 2-Clause "Simplified" License

Java 100.00%
bsg free-sms-sender java java-sms sms sms-api sms-gateway sms-gateway-api sms-java

java-rest-api's Introduction

BSG REST API. Free SMS API - Java com.bsg.rest

The library enables working with the BSG REST service. It supports automatic serialization/deserialization into Java objects The BSG API enables to send mass SMS campaigns, send single transactional SMS, Viber campaigns, and verify phone numbers using HLR requests. There are no charges for API usage, you only pay fors for the messages sent.

Pricing

Prices for sending messages can be found here: Prices

Requirements

Java 1.7+

How to use API

Installation

This library is accompanied by a pom.xml file, which allows using Maven to install it into the local repository.

mvn install:install-file -Dfile=RestClient-1.0.jar You can also install it by downloading the package's source code as a Zip archive or cloning this repository. All components of this library automatically download dependencies.

To use the library, you need to add dependencies to your pom.xml file.

    <dependency>
        <groupId>com.bsg</groupId>
        <artifactId>RestClient</artifactId>
        <version>1.0</version>
    </dependency>

Dependencies

Example

try (SmsClient smsClient = new SmsClient("YOUR_API_KEY")) {
	//Log response
	smsClient.getJerseyClient().register(new LoggingFilter());
	//Sms prices
	PricesData smsPrices = smsClient.getSmsPrices(9);
	//Multiple sms
	MultipleSmsRequest multipleSmsRequest = new MultipleSmsRequest();
	multipleSmsRequest.setBody("Some text");
	multipleSmsRequest.setOriginator("me");
	multipleSmsRequest.setTariff(null);
	multipleSmsRequest.setValidity(1);
	List<Phone> phones = new ArrayList();
	phones.add(new Phone("79991234567", UUID.randomUUID().toString().substring(0, 13)));
	phones.add(new Phone("79991234568", UUID.randomUUID().toString().substring(0, 13)));
	multipleSmsRequest.setPhones(phones);
	MultipleSmsData data = smsClient.createSms(multipleSmsRequest);
	//Sms info by task id
	SmsTaskInfo smsTaskInfo = smsClient.getSmsTaskInfo(data.getTaskId());
	//Sms info by id
	MessageInfo smsInfo = smsClient.getSmsInfo(data.getSmses().get(0).getId());
	//Sms info by external id
	MessageInfo smsInfo2 = smsClient.getSmsInfoByReference(data.getSmses().get(0).getReference());
	//Single sms
	SingleSmsData singleSms = smsClient.createSms("me", "Some text", "79991234567", UUID.randomUUID().toString().substring(0, 13), 1, null);
}
try (ViberClient viberClient = new ViberClient("YOUR_API_KEY")) {
	//Log response
	viberClient.getJerseyClient().register(new LoggingFilter());
	//Viber prices
	PricesData viberPrices = viberClient.getViberPrices(9);
	//Viber message
	ViberMessageRequest viberMessageRequest = new ViberMessageRequest();
	viberMessageRequest.setTariff(null);
	viberMessageRequest.setValidity(1);
	Message message = new Message();
	List<Message> messages = new ArrayList<>();
	viberMessageRequest.setMessages(messages);
	message.setAlphaName("BSG");
	message.setIsPromotional(false);
	message.setText("111");
	message.setOptions(new Options(new SenderViber("1", "1", "1")));
	messages.add(message);
	List<Recipient> recipients = new ArrayList<>();
	Recipient recipient = new Recipient("79991234567", UUID.randomUUID().toString().substring(0, 13));
	recipients.add(recipient);
	message.setRecipients(recipients);
	ViberMessageData createViberMessage = viberClient.createViberMessage(viberMessageRequest);
	//Viber info by id
	MessageInfo viberMessageInfo = viberClient.getViberMessageInfo(createViberMessage.getViberMessages().get(0).getId());
	//Viber info by external id
	MessageInfo viberMessageInfo1 = viberClient.getViberMessageInfoByReference(createViberMessage.getViberMessages().get(0).getReference());
}
try (HlrClient restClient = new HlrClient("YOUR_API_KEY")) {
	//Log response
	restClient.getJerseyClient().register(new LoggingFilter());
	//Balance
	Balance balance = restClient.getBalance();
	//Hlr prices
	PricesData hlrPrices = restClient.getHlrPrices(9);
	//Create HLR
	HlrData hlr = restClient.createHlr("380972920000", UUID.randomUUID().toString().substring(0, 13), null, "http://someurl.com/callback");
	//Hlr info by ID
	HlrInfo hlrInfo = restClient.getHlrInfo(hlr.getHlrs().get(0).getId());
	//Hlr info by external ID
	HlrInfo hlrInfo2 = restClient.getHlrInfoByReference(hlr.getHlrs().get(0).getReference());
	//Hlr batch
	List<HlrRequest> hlrRequests = new ArrayList<>();
	hlrRequests.add(new HlrRequest("380972920001", UUID.randomUUID().toString().substring(0, 13), null, "http://someurl.com/callback"));
	hlrRequests.add(new HlrRequest("380972920001", UUID.randomUUID().toString().substring(0, 13), null, "http://someurl.com/callback"));
	HlrData createHlr = restClient.createHlr(hlrRequests);
}

Support

If you encounter any difficulties or have questions regarding the use of the package, create a discussion in this repository or send an email.

Documentation

You can obtain the API documentation from the source code of the package.

java-rest-api's People

Contributors

8razel8 avatar argestgroup avatar naurzalin avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

java-rest-api's Issues

Schedule the campaign

Check the possibility of Schedule the campaign by adding the parameters "name" and "Schedule the campaign at"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.