Skip to content

NdoleStudio/smsto-go

Repository files navigation

smsto-go

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides a go client for the SMS.to HTTP API https://developers.sms.to

Installation

smsto-go is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/smsto-go

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/smsto-go"

Implemented

  • SMS
    • POST /sms/send: Send single message to a number
    • GET /last/message: Get the last message that you have sent

Usage

Initializing the Client

An instance of the client can be created using New().

package main

import (
  "github.com/NdoleStudio/smsto-go"
)

func main()  {
    client := smsto.New(smsto.WithAPIKey(/* API KEY */))
}

Error handling

All API calls return an error as the last return object. All successful calls will return a nil error.

result, response, err := client.SMS.SendSingle(context.Background(), &smsto.SmsSendSingleRequest{})
if err != nil {
    //handle error
}

SMS

POST /sms/send: Send single message to a number

result, response, err := client.SMS.SendSingle(context.Background(), &SmsSendSingleRequest{
    Message: "This is test and \n this is a new line",
    To:      "+35799999999999",
})

if err != nil {
    log.Fatal(err)
}

log.Println(result.Success) // true

GET /last/message: Get the last message that you have sent

message, response, err := client.SMS.LastMessage(context.Background())

if err != nil {
    log.Fatal(err)
}

log.Println(message.Id) // 302050741

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details