kokatto

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 12 Imported by: 0

README

kokatto

Unofficial Kokatto Go Client

go report card GoDoc Actions Status

Example

Setup client

client, err  := kokatto.NewClient(kokatto.Params{
    ClientID:   "kokatto-client-id",
    PrivateKey: "kokatto-private-key",
})

Sending OTP, OTP generated by Kokatto

rsp, err := client.SendOTP("080000xxxx")

Sending OTP, OTP specified by client

rsp, err := client.SendOTP("080000xxxx", kokatto.WithOTP("1234"))

Get delivery status

status, err := client.DeliveryStatus(rsp.RequestID)

Error handling

rsp, err := client.SendOTP("080000xxxx")
if err != nil {
    if kerr, ok := err.(*kokatto.Error); ok {
        // handler error from Kokatto
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingParam = errors.New("missing params")
)

Error in kokatto client

Functions

func Sign

func Sign(req Signer, secret []byte) error

Sign request using HMAC-SHA256 private key signature = HMAC-SHA256(MD5(QueryString), secret)

Types

type Client added in v0.1.1

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

Client for kokatto

func NewClient

func NewClient(p Params) (*Client, error)

NewClient will return a new kokatto client instance.

func (*Client) DeliveryStatus added in v0.1.1

func (c *Client) DeliveryStatus(reqID string) (rsp DeliveryStatusResponse, err error)

DeliveryStatus will get delivery status of OTP based on reqID.

func (*Client) SendOTP added in v0.1.1

func (c *Client) SendOTP(phoneNumber string, opts ...Option) (rsp OTPResponse, err error)

SendOTP will call kokatto request OTP

type DeliveryData added in v0.1.4

type DeliveryData struct {
	RequestID            string `json:"requestId"`
	DestinationAddress   string `json:"destinationAddress"`
	OTPCode              string `json:"otpCode"`
	OTPStatus            string `json:"otpStatus"`
	OTPStatusDescription string `json:"otpStatusDescription"`
}

DeliveryData attribute

type DeliveryStatusRequest

type DeliveryStatusRequest struct {
	Request
	ClientID  string `url:"clientId"`
	AppType   string `url:"appType"`
	RequestID string `url:"requestId"`
	Timestamp string `url:"timestamp"`
}

DeliveryStatusRequest attribute

func (*DeliveryStatusRequest) QueryString

func (d *DeliveryStatusRequest) QueryString() (string, error)

QueryString return DeliveryStatusRequest object as query string

type DeliveryStatusResponse

type DeliveryStatusResponse struct {
	Status       string       `json:"status"`
	StatusCode   string       `json:"statusCode"`
	Message      string       `json:"message"`
	ErrorMessage string       `json:"errorMessage"`
	Data         DeliveryData `json:"data"`
}

DeliveryStatusResponse attribute

type Error

type Error struct {
	Status       string `json:"status"`
	StatusCode   string `json:"statusCode"`
	ErrorMessage string `json:"errorMessage"`
}

Error from kokatto API

func (*Error) Error

func (e *Error) Error() string

Error return error message string

type OTPRequest

type OTPRequest struct {
	Request
	ClientID    string `url:"clientId"`
	AppType     string `url:"appType"`
	MediaType   string `url:"mediaType"`
	PhoneNumber string `url:"phoneNumber"`
	OTPMCode    string `url:"otpmCode,omitempty"`
	Timestamp   string `url:"timestamp"`
}

OTPRequest attribute

func (*OTPRequest) QueryString

func (o *OTPRequest) QueryString() (string, error)

QueryString return OTPRequest object as query string

type OTPResponse

type OTPResponse struct {
	Status       string `json:"status"`
	StatusCode   string `json:"statusCode"`
	RequestID    string `json:"requestId"`
	OTPM         string `json:"otpm"`
	Message      string `json:"message"`
	ErrorMessage string `json:"errorMessage"`
}

OTPResponse attribute

type Option

type Option func(*options)

Option for OTP

func WithOTP

func WithOTP(otpCode string) Option

WithOTP will set OTP code to send.

type Params

type Params struct {
	ClientID   string
	PrivateKey string
	AppType    string
	MediaType  string
}

Params for kokatto client

type Request

type Request struct {
	Signature string `url:"signature,omitempty"`
}

Request helper for kokatto

func (*Request) QueryString

func (r *Request) QueryString(obj interface{}) (string, error)

QueryString return object as query string

func (*Request) SetSignature

func (r *Request) SetSignature(signature string)

SetSignature will set request signature

func (*Request) Validate

func (r *Request) Validate(signature string) bool

Validate will return true if signature matched

type Signer

type Signer interface {
	QueryString() (string, error)
	SetSignature(string)
	Validate(string) bool
}

Signer interface for signed request

Jump to

Keyboard shortcuts

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