smsc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 7 Imported by: 0

README

smsc

smsc is an HTTP API client for smsc.ru.

go get -u github.com/ikeberlein/smsc

Example

package main

import (
	"log"
	"github.com/ikeberlein/smsc"
)

func main() {
	c, err := smsc.New(smsc.Config{Login: "me", Password: "secret"})
	if err != nil {
		log.Fatal(err)
	}
	_, err = c.Send("How are you?", []string{"+71234567890"})
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

View Source
const DefaultURL = "https://smsc.ru/sys/send.php"

Variables

View Source
var (
	ErrLongText = errors.New("smsc: too long text to send")
	ErrNoPhones = errors.New("smsc: empty phones list")
)
View Source
var ErrBadValid = errors.New("smsc: invalid period for valid")
View Source
var ErrNoLoginPassword = errors.New("smsc: empty login or password")

Functions

func CountBytes

func CountBytes(text string) int

CountBytes returns a number of bytes for text to be send in SMS.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client has methods for API calls.

func New

func New(cfg Config) (*Client, error)

New initializes a Client.

func (*Client) Send

func (c *Client) Send(text string, phones []string, opts ...Opt) (*Result, error)

type Config

type Config struct {
	URL         string
	Login       string
	Password    string
	PasswordMD5 string
	Opt         Opt
	Client      *http.Client
}

Config is a Client config.

type Cost

type Cost int

Cost defines whether API should send a Result with cost information.

const (
	CostWithoutSend Cost = iota + 1
	CostCount
	CostCountBalance
)

type ErrOpt

type ErrOpt int

ErrOpt controls whether Response must include information about failed phone numbers.

const Err ErrOpt = 1

type Error

type Error struct {
	Code int    `json:"error_code"`
	Desc string `json:"error"`
	ID   *int   `json:"id"`
}

func (*Error) Error

func (e *Error) Error() string

type OpOpt

type OpOpt int

OpOpt controls whether Response must contain information about all phone numbers.

const Op OpOpt = 1

type Opt

type Opt func(*message)

Opt configures a send message and a Result.

func Sender

func Sender(s string) Opt

Sender sets the author of SMS.

Sender value must be registered on the account settings page.

func Valid

func Valid(h, m int) Opt

func With

func With(v ...interface{}) Opt

With returns an Opt from option values v.

type Phone

type Phone struct {
	Phone  string  `json:"phone"`
	Mccmnc string  `json:"mccmnc"`
	Cost   string  `json:"cost"`
	Status *string `json:"status"`
	Error  *string `json:"error"`
}

type Result

type Result struct {
	ID      int     `json:"id"`
	Count   int     `json:"cnt"`
	Cost    *string `json:"cost"`
	Balance *string `json:"balance"`
	Phones  []Phone `json:"phones"`
}

func (*Result) String

func (r *Result) String() string

type TranslitOpt

type TranslitOpt int
const (
	Translit TranslitOpt = iota + 1
	TranslitKlinopis
)

Jump to

Keyboard shortcuts

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