github.com/mfridman/srfax

A Go (golang) client for interacting with the SRFax API


Keywords
client, golang, srfax, srfax-api, srfax-operation
License
MIT
Install
go get github.com/mfridman/srfax

Documentation

srfax

srfax is a Go client library for interacting with the SRFax API service. The client supports all official operations and provides convenience functions for ease-of-use.

The official SRFax API documentation can be found here

Important, this library will handle Result errors in a Go like manner. Instead of mixing error messages with real results like so:

{
    "Status": "",
    "Result": "",
}

This client will always return an operation-specific response (suffixed with Resp) composed of the following:

{
    "Status": "Success or Failed", 
    "Result": "result will be specific to the operation performed", 
    "ResultError": "error will be empty unless there was an error"
}

It is the caller's responsibility to check the Error value prior to using Result. If Error is not an empty string assume something has gone wrong and Result should not be used.

If SRFax had publically availble errors then could compose error types, but for now it'll be a string.

Installation

go get -u github.com/mfridman/srfax

Usage

Import the library.

To begin using the client initialize a ClientCfg and pass it to NewClient.

cfg := srfax.ClientCfg{
    ID:  00001,
    PWD: "password",
    // URL: optional, defaults to https://www.srfax.com/SRF_SecWebSvc.php
}

client, err := srfax.NewClient(cfg)
if err != nil {
    // check errors
}

With a *Client one runs all SRFax operations.

Example:

resp, err := client.GetFaxUsage() // resp is a pointer to a FaxUsageResp.
if err != nil {
    // check errors
}

// for testing purposes use convenience func PP to pretty print the response to terminal
PP(resp) 

Output:

{
    "Status": "Success",
    "Result": [{
        "Period": "ALL",
        "ClientName": "mike",
        "BillingNumber": "m@frid.io",
        "UserID": 00001,
        "SubUserID": 0,
        "NumberOfFaxes": 140,
        "NumberOfPages": 40
    }],
    "ResultError": ""
}