movidersms

package module
v0.0.0-...-a19d7af Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 11 Imported by: 0

README

Movider API Client

Go

How to Use It

package main

import (
	"context"
	"log"

	"github.com/royge/movidersms"
)

func main() {
	creds := movidersms.Credentials{"api-key", "api-secret"}
	sender := movidersms.NewSender(creds, []string{})

	res, err := sender.SendMessage(
		context.Background(),
		[]string{"6392612345678"},
		"Test Message",
	)
	if err != nil {
		panic(err)
	}

	log.Printf("Result: %+v\n", res)
}

Documentation

Index

Constants

View Source
const (
	MoviderAPIURL  = "https://api.movider.co/v1"
	MaxPhoneLength = 15
)

Variables

View Source
var (
	ErrNoDestination      = errors.New("no destination number")
	ErrInvalidDestination = errors.New("recipient number is more than 15 characters")
	ErrNoText             = errors.New("no text message")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	APIURL            string
	Creds             Credentials
	AllowedRecipients []string
}

type Credentials

type Credentials struct {
	APIKey    string `json:"api_key"`
	APISecret string `json:"api_secret"`
}

type Error

type Error struct {
	Code        int    `json:"code"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

func (*Error) Error

func (err *Error) Error() string

type SendMessageRequest

type SendMessageRequest struct {
	Credentials

	To   []string `json:"to"`
	Text string   `json:"text"`
}

func (*SendMessageRequest) Encode

func (smr *SendMessageRequest) Encode() []byte

func (*SendMessageRequest) Validate

func (smr *SendMessageRequest) Validate() error

type SendMessageResponse

type SendMessageResponse struct {
	RemainingBalance float64 `json:"remaining_balance"`
	TotalSMS         int     `json:"total_sms"`
	Error            *Error  `json:"error"`
}

type Sender

type Sender struct {
	Config
}

func NewSender

func NewSender(creds Credentials, allowedRecipients []string) *Sender

func (*Sender) SendMessage

func (s *Sender) SendMessage(
	ctx context.Context, recipient []string, message string,
) (interface{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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