Skip to content

bsgworld/bsg-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

com.bsg.rest

Библиотека позволяет работать с REST сервисом BSG. Поддерживается автоматическая сериализация/десериализация

Requirements

Go runtime

Installation

go mod init bsg-go
go get github.com/bsgworld/bsg-go@latest
go run src/example/main.go 

Dependencies

  • net/http
  • log
  • encoding/json
  • strconv
  • bytes

Example

// ====== HLR =======

// HLR Client
var hlrClient = bsgrest.NewHlrClient("https://api.bsg.world/rest", "YOUR_API_KEY")

// Get Balance
var balance = hlrClient.GetBalance()
log.Println(balance)

// Get HLR Prices
var hlrPrices = hlrClient.GetHlrPricesById(9)
log.Println(hlrPrices)

// Send Single HLR
var hlr = hlrClient.CreateHlrWithParameters("380972920000", "ext_"+RandStringRunes(9), nil, "http://someurl.com/callback")
log.Println(hlr)

// Send Multiple HLR
var tariff = "9"
var hlr2 = hlrClient.CreateHlrs(
	[]bsgrest.HlrRequest{bsgrest.HlrRequest{Tariff:nil, Reference:"ext_" + RandStringRunes(9), Msisdn:"380972920001", CallbackUrl:"http://someurl.com/callback"},
				 {Tariff:&tariff, Reference:"ext_" + RandStringRunes(9), Msisdn:"380972920002", CallbackUrl:"http://someurl.com/callback"}})
log.Println(hlr2)

// Get HLR info by id
var hlrInfo = hlrClient.GetHlrInfoById(hlr.Hlrs[0].ID)
log.Println(hlrInfo)

// Get HLR info by external id
var hlrInfo2 = hlrClient.GetHlrInfoByReference(hlr2.Hlrs[1].Reference)
log.Println(hlrInfo2)

// ====== SMS =======

// SMS Client
var smsClient = bsgrest.NewSmsClient("https://api.bsg.world/rest", "YOUR_API_KEY")

// Get SMS Prices
var smsPrices = smsClient.GetSmsPrices()
log.Println(smsPrices)

// Send Single SMS
var oneSms = smsClient.CreateSms("1", nil, "me", "123", &bsgrest.SmsPhone{Msisdn:"79999999999", Reference:"ext_" + RandStringRunes(9)})
log.Println(oneSms)

// Send Batch SMS
var twoSms = smsClient.CreateMultipleSms(bsgrest.MultipleSmsRequest{
	Body:      "123",
	Originator:"me",
	Validity:  "1",
	Phones:    []bsgrest.SmsPhone{{Msisdn:"79999999999", Reference:"ext_" + RandStringRunes(9)},
					  {Msisdn:"79999999998", Reference:"ext_" + RandStringRunes(9)}}})
log.Println(twoSms)

// Get SMS info by task id
var taskInfo = smsClient.GetSmsInfoByTaskId(twoSms.TaskID)
log.Println(taskInfo)

// Get SMS info by id
var smsInfo = smsClient.GetSmsInfoById(twoSms.Smses[0].ID)
log.Println(smsInfo)

// Get SMS info by external id
var smsInfo2 = smsClient.GetSmsInfoByReference(oneSms.Sms.Reference)
log.Println(smsInfo2)

// ====== Viber =======

// Viber Client
var viberClient = bsgrest.NewViberClient("https://api.bsg.world/rest", "YOUR_API_KEY")

// Get Prices
var viberPrices = viberClient.GetViberPrices()
log.Println(viberPrices)

// Send Viber message
var viber = viberClient.CreateViber(
	bsgrest.ViberRequest{
		Validity:           "1",
		ViberMessages:      []bsgrest.ViberMessage{{AlphaName:"BSG",
			IsPromotional:                                false,
			Text:                                         "123",
			Options:                                      bsgrest.ViberOptions{Viber: bsgrest.ViberOptionsContainer{Img: "123", Caption: "123", Action: "123"}},
			Recipients:                                   []bsgrest.Recipient{{Msisdn:"79999999999", Reference:"ext_" + RandStringRunes(9)}}}}})
log.Println(viber)

// Get Viber info by id
var viberInfo = viberClient.GetViberInfoById(viber.Messages[0].ID)
log.Println(viberInfo)

// Get Viber info by external id
var viberInfo2 = viberClient.GetViberInfoByReference(viber.Messages[0].Reference)
log.Println(viberInfo2)

Support

Если у вас возникли сложности или вопросы по использованию пакета, создайте обсуждение в данном репозитории или напишите на электронную почту support@bsg.world.

Documentation

Документацию API можно получить из исходных кодов пакета

About

The open source GO client for BSG's REST API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages