smsto

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 11 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	SMS *smsService
	// contains filtered or unexported fields
}

Client is the campay API client. Do not instantiate this client with Client{}. Use the New method instead.

func New

func New(options ...Option) *Client

New creates and returns a new campay.Client from a slice of campay.ClientOption.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is options for constructing a client

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets your API Key, You can get it from sms.to account

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL set's the base url for the sms.to API

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient sets the underlying HTTP client used for API requests. By default, http.DefaultClient is used.

type Response

type Response struct {
	HTTPResponse *http.Response
	Body         *[]byte
}

Response captures the http response

func (*Response) Error

func (r *Response) Error() error

Error ensures that the response can be decoded into a string inc ase it's an error response

type SmsMessage added in v0.0.2

type SmsMessage struct {
	ID                int         `json:"id"`
	SecondaryID       string      `json:"_id"`
	CampaignID        interface{} `json:"campaign_id"`
	UserID            int         `json:"user_id"`
	SenderID          string      `json:"sender_id"`
	Message           string      `json:"message"`
	To                string      `json:"to"`
	Status            string      `json:"status"`
	ClientCost        float64     `json:"client_cost"`
	CallbackURL       string      `json:"callback_url"`
	ScheduledFor      interface{} `json:"scheduled_for"`
	Timezone          interface{} `json:"timezone"`
	CreatedAt         time.Time   `json:"created_at"`
	UpdatedAt         time.Time   `json:"updated_at"`
	SentAt            string      `json:"sent_at"`
	MessageID         interface{} `json:"message_id"`
	SmsCount          int         `json:"sms_count"`
	FinalCallbackSent int         `json:"final_callback_sent"`
	IsAPI             int         `json:"is_api"`
	A2Code            interface{} `json:"a2_code"`
	OptOut            interface{} `json:"optout"`
	FailedReason      string      `json:"failed_reason"`
	Campaign          interface{} `json:"campaign"`
	Provider          interface{} `json:"provider"`
}

SmsMessage is the details of an SMS message that was sent out

type SmsSendSingleRequest

type SmsSendSingleRequest struct {
	Message      string  `json:"message"`
	To           string  `json:"to"`
	BypassOptOut *bool   `json:"bypass_optout,omitempty"`
	SenderID     *string `json:"sender_id,omitempty"`
	CallbackURL  *string `json:"callback_url,omitempty"`
}

SmsSendSingleRequest are parameters for sending a single SMS message

type SmsSendSingleResponse

type SmsSendSingleResponse struct {
	Message   string `json:"message"`
	Success   bool   `json:"success"`
	MessageID string `json:"message_id"`
}

SmsSendSingleResponse is the response after sending a single SMS message

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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