trustpilot

package module
v0.0.0-...-4228555 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 10 Imported by: 0

README

go-trustpilot

Trustpilot API client library for Go.

ci GoDoc

This library does not implement full Trustpilot API.

Getting Started

The client library can be configured using ClientOption as functional options.

func ExampleNewClient() {
	authConfig := &trustpilot.PasswordGrantConfig{
		ClientID:     "1a9SsZ2XJKraw1Prl8m+gvq",
		ClientSecret: "AxLoJhlAcbWiVA8cHW2fINep",
		Username:     "apiuser@example.com",
		Password:     "6X2hQa1lPHu9dVjikUr0FbRt",
	}

	client, err := trustpilot.NewClient(
		trustpilot.AuthConfig(authConfig),
		trustpilot.Debug(true),
	)

	if err != nil {
		// TODO handle the error.
	}

	_ = client
}

Authentication

This client supports Trustpilot's oauth 2.0 password grant type. Other Trustpilot-supported grant types may be added.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("NOT_FOUND")
	ErrInvalidArgument = errors.New("INVALID_ARGUMENT")
	ErrInternal        = errors.New("INTERNAL")
	ErrUnauthenticated = errors.New("UNAUTHENTICATED")
)

Functions

This section is empty.

Types

type Client

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

Client implements Trustpilot API.

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient sets up a new Trustpilot client.

Example
authConfig := &trustpilot.PasswordGrantConfig{
	ClientID:     "1a9SsZ2XJKraw1Prl8m+gvq",
	ClientSecret: "AxLoJhlAcbWiVA8cHW2fINep",
	Username:     "apiuser@example.com",
	Password:     "6X2hQa1lPHu9dVjikUr0FbRt",
}

client, err := trustpilot.NewClient(
	trustpilot.AuthConfig(authConfig),
	trustpilot.Debug(true),
)

if err != nil {
	// TODO handle the error.
}

_ = client
Output:

func (*Client) CreateInvitation

func (*Client) ListTemplates

func (c *Client) ListTemplates(ctx context.Context, r *ListTemplatesRequest) (*ListTemplatesResponse, error)

type ClientOption

type ClientOption func(*Client) error

ClientOption is a functional option for configuring the API client.

func APIBaseURL

func APIBaseURL(u *url.URL) ClientOption

APIBaseURL allows to change the default API base url.

func AuthConfig

func AuthConfig(conf *PasswordGrantConfig) ClientOption

AuthConfig is a functional option for configuring oauth 2.0 password grant credentials.

func Debug

func Debug(b bool) ClientOption

Debug is a functional option for configuring client debug.

func HTTPClient

func HTTPClient(h *http.Client) ClientOption

HTTPClient is a functional option for configuring http client.

func InvitationAPIBaseURL

func InvitationAPIBaseURL(u *url.URL) ClientOption

InvitationAPIBaseURL allows to change the default Invitation API base url.

func TokenURL

func TokenURL(u *url.URL) ClientOption

TokenURL allows to change the default API oauth 2.0 token url.

type CreateInvitationRequest

type CreateInvitationRequest struct {
	BusinessUnitID  string // Required.
	ConsumerEmail   string `json:"consumerEmail"` // Required.
	ReplyTo         string `json:"replyTo,omitempty"`
	ReferenceNumber string `json:"referenceNumber,omitempty"` // The customer’s internal reference number.
	ConsumerName    string `json:"consumerName,omitempty"`
	Locale          string `json:"locale,omitempty"`
	LocationID      string `json:"locationId,omitempty"`
	SenderEmail     string `json:"senderEmail,omitempty"`
	SenderName      string `json:"senderName,omitempty"`

	ServiceReviewInvitation *ServiceReviewInvitation `json:"serviceReviewInvitation,omitempty"`
}

type CreateInvitationResponse

type CreateInvitationResponse struct {
}

type ErrorResponse

type ErrorResponse struct {
	Message       string `json:"message,omitempty"`
	ErrorCode     int    `json:"errorCode,omitempty"`
	Details       string `json:"details,omitempty"`
	CorrelationID string `json:"correlationId,omitempty"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ListTemplatesRequest

type ListTemplatesRequest struct {
	BusinessUnitID string // Required.
}

type ListTemplatesResponse

type ListTemplatesResponse struct {
	Templates []Template `json:"templates"`
}

type PasswordGrantConfig

type PasswordGrantConfig struct {
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
}

PasswordGrantConfig configuration for the oauth2 password grant type. Use TokenURL client option to set oauth2 token url.

type ServiceReviewInvitation

type ServiceReviewInvitation struct {
	PreferredSendTime string   `json:"preferredSendTime,omitempty"` // ISO8601 UTC.
	RedirectURI       string   `json:"redirectUri,omitempty"`
	Tags              []string `json:"tags,omitempty"`
	TemplateID        string   `json:"templateId,omitempty"`
}

type Template

type Template struct {
	ID                string `json:"id"`
	Name              string `json:"name"`
	IsDefaultTemplate bool   `json:"isDefaultTemplate"`
	Locale            string `json:"locale,omitempty"`
	Type              string `json:"type"`
}

type Trustpilot

type Trustpilot interface {
	CreateInvitation(ctx context.Context, r *CreateInvitationRequest) (*CreateInvitationResponse, error)
	ListTemplates(ctx context.Context, r *ListTemplatesRequest) (*ListTemplatesResponse, error)
}

Trustpilot defines the Trustpilot API client interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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