tpns

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 12 Imported by: 0

README

Using the TPNS client

package main

import (
        "fmt"
        "time"
        "github.com/philips-software/go-hsdp-api/tpns"
)

func main() {
        client, err := tpns.NewClient(&tpns.Config{
                Username: "Foo",
                Password: "YourP@ssword!",
                TPNSURL:  "https://tpns.foo.com",
        })
        if err != nil {
            fmt.Printf("Error creating client: %v\n", err)
            return
        } 
        ok, resp, err := tpns.Messages.Push(&tpns.Message{
            Content:       "YAY! It is working!",
            PropositionID: "XYZ",
            MessageType:   "Push",
            Targets:       []string{"5b78e5f8-d73f-4712-aae0-355f6fa91752"},
        })
        if err != nil {
            fmt.Printf("Error pushing: %v\n", err)
            return
        }
        if !ok {
            fmt.Printf("Error pushing: %d\n", resp.StatusCode)
            return
        }
        fmt.Printf("Push success: %d\n", resp.StatusCode)
}

Documentation

Overview

Package tpns provides an interface for HSDP Third Party Notification Service (TPNS)

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBaseTPNSCannotBeEmpty = errors.New("TPNS base URL cannot be empty")
)

Errors

Functions

This section is empty.

Types

type Client

type Client struct {

	// User agent used when communicating with the HSDP IAM API.
	UserAgent string

	Messages *MessagesService
	// contains filtered or unexported fields
}

A Client manages communication with HSDP IAM API

func NewClient

func NewClient(httpClient *http.Client, config *Config) (*Client, error)

NewClient returns a new HSDP TDR API client. If a nil httpClient is provided, http.DefaultClient will be used. A configured IAM client must be provided as well

func (*Client) Close

func (c *Client) Close()

Close releases allocated resources of clients

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*Response, error)

Do executes a http request. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewTPNSRequest

func (c *Client) NewTPNSRequest(method, path string, opt interface{}, options []OptionFunc) (*http.Request, error)

NewTPNSRequest creates an new TPNS API request. A relative URL path can be provided in urlStr, in which case it is resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) SetBaseTPNSURL

func (c *Client) SetBaseTPNSURL(urlStr string) error

SetBaseTPNSURL sets the base URL for API requests to a custom endpoint. urlStr should always be specified with a trailing slash.

type Code added in v0.30.0

type Code struct {
	Coding []Coding `json:"coding"`
}

Code describes a coding

type Coding added in v0.30.0

type Coding struct {
	System       string `json:"system,omitempty"`
	Version      string `json:"version,omitempty"`
	Code         string `json:"code,omitempty"`
	Display      string `json:"display,omitempty"`
	UserSelected *bool  `json:"userSelected,omitempty"`
}

type Config

type Config struct {
	TPNSURL  string
	Username string
	Password string
	Debug    bool
	DebugLog string
}

Config contains the configuration of a client

type ErrorResponse added in v0.30.0

type ErrorResponse struct {
	Response *http.Response `json:"-"`
	Code     string         `json:"responseCode"`
	Message  string         `json:"responseMessage"`
}

ErrorResponse represents an IAM errors response containing a code and a human readable message

func (*ErrorResponse) Error added in v0.30.0

func (e *ErrorResponse) Error() string

type Issue added in v0.30.0

type Issue struct {
	Severity string `json:"Severity"`
	Details  string `json:"Details"`
	Code     Code   `json:"Code"`
}

Issue describes an issue

type IssueResponse added in v0.30.0

type IssueResponse struct {
	Issues []Issue `json:"issue"`
}

IssueResponse encapsulates one or more issues

type Message

type Message struct {
	MessageType      string            `json:"MessageType"`
	PropositionID    string            `json:"PropositionId"`
	CustomProperties map[string]string `json:"CustomProperties"`
	Lookup           bool              `json:"Lookup"`
	Content          string            `json:"Content"`
	Targets          []string          `json:"Targets"`
}

Message describes a push message

type MessagesService

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

MessagesService provides operations on TPNS messages

func (*MessagesService) Push

func (m *MessagesService) Push(msg *Message) (bool, *Response, error)

Push pushes a message to a mobile client

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

type Response

type Response struct {
	*http.Response
}

Response is a HSDP TPNS API response. This wraps the standard http.Response returned from HSDP TPNS and provides convenient access to things like errors

Jump to

Keyboard shortcuts

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