client

package module
v0.0.0-...-09fe6f4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2023 License: MIT Imports: 10 Imported by: 0

README

Kyivstar Open Telecom API Client for Go

This is unofficial a Go client for the Kyivstar API, which allows you to interact with the Kyivstar Open Telecom API https://api-gateway.kyivstar.ua

Installation

To install the Kyivstar API client, use the go get command:

go get github.com/iamgoroot/kyivstar-opentelecom-go

Before you start

In order to use the API, you need to register at https://api-market.kyivstar.ua and obtain client_id and client_secret.

Usage

Here's a simple example of how to use the Kyivstar API client:


package main

import (
	"context"
	"fmt"
	ksOpen "github.com/iamgoroot/kyivstar-opentelecom-go"
)

func main() {
    conf := ksOpen.Config{
        ServerUrl:    ksOpen.Gateway,
        ServerMode:   ksOpen.ServerModeMock,
        ClientID:     "your_client_id",
        ClientSecret: "your_client_secret",
    }
    ctx := context.Background()
    ksClient := ksOpen.New(ctx, conf)
    const destinationPhoneNumber = "380670000200"
	
    // Send SMS msg
    sendMsgResp, err := ksClient.Send(
        ksOpen.SmsSendReq{
            From: "messagedesk",
            To:   destinationPhoneNumber,
            Text: "Hello World!",
        })
    fmt.Println("Sent", sendMsgResp, err)
    
    // Check SMS Status
    check, err := ksClient.Check(sendMsgResp.MsgId)
    fmt.Println("Check", check.Status, err)
    
    // Scoring
    scoring, err := ksClient.Scoring(destinationPhoneNumber, 0)
    fmt.Println("Scored:", scoring, err)
    
    // Verify sim
    sim, err := ksClient.VerifySim(destinationPhoneNumber, ksOpen.VerifySimReq{
        ActivationHours: 48,
    })
    fmt.Printf("Verify sim: changed=%d, active=%d, err=%v", sim.SimChanged, sim.IsActive, err)
}

Documentation

For more detailed information on how to use the client, please refer to the official documentation.

Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

If you have any questions or need assistance, please open an issue on this repository or contact the maintainers directly.

Documentation

Index

Constants

View Source
const (
	Gateway                      = "https://api-gateway.kyivstar.ua"
	ServerModeLive    serverMode = ""
	ServerModeMock    serverMode = "mock"
	ServerModeSandbox serverMode = "sandbox"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Sms
	VerifySim
	Scoring
}

func New

func New(ctx context.Context, conf Config) Client

func Wrap

func Wrap(ctx context.Context, client *http.Client, conf Config) Client

type Config

type Config struct {
	ServerUrl    string     `json:"serverUrl,omitempty" yaml:"serverUrl"`
	ClientID     string     `json:"clientId,omitempty" yaml:"clientId"`
	ClientSecret string     `json:"clientSecret,omitempty" yaml:"clientSecret"`
	ServerMode   serverMode `json:"serverMode,omitempty" yaml:"serverMode"`
	DebugEnabled bool       `json:"debugEnabled" yaml:"debugEnabled"`
}

type Err

type Err struct {
	ReqId      string `json:"reqId"`
	ErrorCode  int    `json:"errorCode"`
	ErrorMsg   string `json:"errorMsg"`
	HttpStatus int    `json:"httpStatus"`
}

func (Err) Error

func (e Err) Error() string

type Scoring

type Scoring interface {
	Scoring(phoneNumber string, modelId int) (ScoringResp, error)
}

type ScoringResp

type ScoringResp struct {
	Score int `json:"score"`
}

type Sms

type Sms interface {
	Send(req SmsSendReq) (SmsSendResp, error)
	Check(msgID string) (SmsCheckResp, error)
}

type SmsCheckResp

type SmsCheckResp struct {
	ReqId  string     `json:"reqId"`
	MsgId  string     `json:"msgId"`
	Status string     `json:"status"`
	Date   *time.Time `json:"date"`
}

type SmsSendReq

type SmsSendReq struct {
	From string `json:"from"`
	To   string `json:"to"`
	Text string `json:"text"`
}

type SmsSendResp

type SmsSendResp struct {
	ReqId string `json:"reqId"`
	MsgId string `json:"msgId"`
}

type VerifySim

type VerifySim interface {
	VerifySim(phoneNumber string, params VerifySimReq) (VerifySimResp, error)
}

type VerifySimReq

type VerifySimReq struct {
	ActivationHours int `json:"activationHours"`
}

type VerifySimResp

type VerifySimResp struct {
	SimChanged int `json:"simChanged"`
	IsActive   int `json:"isActive"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL