httpsms

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 11 Imported by: 1

README

httpsms-go

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

This package provides a generic go client template for the Http SMS Api

Installation

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

go get github.com/NdoleStudio/httpsms-go

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

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

Implemented

  • Messages
    • POST /v1/messages/send: Send a new SMS Message

Usage

Initializing the Client

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

package main

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

func main()  {
	client := htpsms.New(htpsms.WithDelay(200))
}
Error handling

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

_, response, err := client.Messages.Send(context.Background())
if err != nil {
    //handle error
}
Messages
POST /v1/messages/send: Send a new SMS Message
message, response, err := client.Messages.Send(context.Background(), &MessageSendParams{
  Content: "This is a sample text message",
  From:    "+18005550199",
  To:      "+18005550100",
})

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

log.Println(message.Code) // 202

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 {
	Messages *messagesService
	// 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 Message

type Message struct {
	Contact           string    `json:"contact"`
	Content           string    `json:"content"`
	CreatedAt         time.Time `json:"created_at"`
	FailureReason     string    `json:"failure_reason"`
	ID                string    `json:"id"`
	LastAttemptedAt   time.Time `json:"last_attempted_at"`
	OrderTimestamp    time.Time `json:"order_timestamp"`
	Owner             string    `json:"owner"`
	ReceivedAt        time.Time `json:"received_at"`
	RequestReceivedAt time.Time `json:"request_received_at"`
	SendTime          int       `json:"send_time"`
	SentAt            time.Time `json:"sent_at"`
	Status            string    `json:"status"`
	Type              string    `json:"type"`
	UpdatedAt         time.Time `json:"updated_at"`
	UserID            string    `json:"user_id"`
}

Message represents and incoming or outgoing SMS message

type MessageResponse

type MessageResponse struct {
	Data    Message `json:"data"`
	Message string  `json:"message"`
	Status  string  `json:"status"`
}

MessageResponse is the response gotten with a message content

type MessageSendParams

type MessageSendParams struct {
	Content string `json:"content"`
	From    string `json:"from"`
	To      string `json:"to"`
}

MessageSendParams is the request payload for sending a message

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 the api key for the httpsms API

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the base url for the httpsms 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

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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