delighted

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

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

Go to latest
Published: Feb 1, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

README

delighted-go

Circle CI

About

Simple Golang API Client for Delighted. Currently supports the following.

  • People

    • Adding a person to a survey.
    • Unsubscribing a person from a survey.
    • Deleting pending survey requests.
  • Survey

    • Listing all survey responses.
  • Metrics

    • Getting metrics.
Installation
go get github.com/jonnonz/delighted-go
import github.com/jonnonz/delighted-go
Examples
Create a client
client, err := delighted.NewClient("DELIGHTED_API_KEY", nil)
if err != nil {
	fmt.Println("Doh!", err)
}

Note: You can specify a http.Client instead of nil, this is useful for mocking during testing.

Add a person to a survey
p := delighted.Person{Email: "test@test.com", Name: "John Doe"}
r, err := client.PersonService.Create(&p)
if err != nil {
	fmt.Println("Doh!", err)
}
fmt.Printf("#%v",r)

Note: Email is required when adding a person to a survey.

Unsubscribing a person from a survey
p := delighted.Person{Email: "test@test.com"}
_, err := client.PersonService.Unsubscribe(&p) // returns a bool.
if err != nil {
	fmt.Println("Doh!", err)
}

Listing all survey responses
sr := delighted.SurveyResponses{PerPage: 100, Since: 12345678910}
r, err := client.SurveyService.GetAll(&sr)
if err != nil {
	fmt.Println("Doh!", err)
}
fmt.Printf("#%v",r)
Get metrics
m := delighted.Metrics{Since: 12345678910, Until: 10987654321}
r, err := client.MetricService.Get(&m)
if err != nil {
	fmt.Println("Jar Jar Binks!", err)
}
fmt.Printf("#%v",r)
Backwards Compatibility

As of 01/02/2016, This is currently under active development. Although I will try my best, there is definitely no garantee of me not breaking BC during the early stages of my work. Use fully at your own risk.

Documentation

Index

Constants

View Source
const (
	// LibVersion used to be sent with User-Agent
	LibVersion = "0.2beta"
)

Variables

View Source
var (
	// DelightedAPIKey for delighted.
	DelightedAPIKey string
	BaseURL         string = "https://api.delighted.com/v1/%s"
)

Functions

func HandleResponse

func HandleResponse(r *http.Response) error

HandleResponse from delighted app.

Types

type Client

type Client struct {
	UserAgent string

	PersonService *PersonService
	SurveyService *SurveyService
	MetricService *MetricService
	// contains filtered or unexported fields
}

Client handles communication between lib and delighted api.

func NewClient

func NewClient(APIKey string, httpClient *http.Client) (*Client, error)

NewClient returns a new client.

func (*Client) Do

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

Do request

func (*Client) NewRequest

func (c *Client) NewRequest(method, uri string, body interface{}) (*http.Request, error)

NewRequest to delighted api.

type MetricResponse

type MetricResponse struct {
	NPS               int `json:"nps,omitempty"`
	PromoterCount     int `json:"promoter_count,omitempty"`
	PromoterPercent   int `json:"promoter_percent,omitemty"`
	PassiveCount      int `json:"passive_count,omitempty"`
	PassivePercent    int `json:"passive_percent,omitempty"`
	DectractorCount   int `json:"detractor_count,omitempty"`
	DectractorPercent int `json:"detractor_percent,omitempty"`
	ResponseCount     int `json:"response_count,omitempty"`
}

MetricResponse payload from delighted

type MetricService

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

MetricService struct

func (*MetricService) Get

func (s *MetricService) Get(m *Metrics) (*MetricResponse, error)

Get metrics from delighted.

type Metrics

type Metrics struct {
	Since int    `url:"since,omitempty"`
	Until int    `url:"until,omitempty"`
	Trend string `url:"trend,omitempty"`
}

Metrics endpoint query options

type Person

type Person struct {
	ID         string            `json:"id,omitempty"`
	Email      string            `json:"email"`
	Name       string            `json:"name,omitempty"`
	Delay      int               `json:"delay,omitempty"`
	Properties map[string]string `json:"properties,omitempty"`
	Send       bool              `json:"send,omitempty"`
	LastSentAt int               `json:"last_sent_at,omitempty"`
}

Person representation in golang.

type PersonService

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

PeopleService struct

func (*PersonService) Create

func (s *PersonService) Create(p *Person) (*Person, error)

Create a new person for a survey.

func (*PersonService) RemovePendingSurvey

func (s *PersonService) RemovePendingSurvey(p *Person) (bool, error)

RemovePendingSurvey from a person who already has a pending survey

func (*PersonService) Unsubscribe

func (s *PersonService) Unsubscribe(p *Person) (bool, error)

Unsubscribe a person from a survey, returns true of false if person was sucessfully Unsubscribed

type PersonSurveyResponse

type PersonSurveyResponse struct {
	Ok string `json:"ok,omitempty"`
}

PersonSurveyResponse from action against a person's survey

type PersonUnsubscribePayload

type PersonUnsubscribePayload struct {
	Email string `json:"person_email"`
}

PersonUnsubscribePayload for unsubscribing a person.

type Survey

type Survey struct {
	ID               string            `json:"id"`
	PersonID         int               `json:"person"`
	Score            int               `json:"score"`
	Comment          string            `json:"comment,omitempty"`
	Permalink        string            `json:"permalink"`
	CreatedAt        int               `json:"created_at"`
	UpdatedAt        int               `json:"updated_at"`
	PersonProperties map[string]string `json:"person_properties,omitemtpy"`
	Notes            []surveyNotes     `json:"notes"`
	Tags             []surveyTags      `json:"tags"`
}

Survey single representation of a survery comment in responses.

type SurveyResponses

type SurveyResponses struct {
	PerPage      int    `url:"per_page,omitempty"`
	Page         int    `url:"page,omitempty"`
	Since        int    `url:"since,omitempty"`
	Until        int    `url:"until,omitempty"`
	UpdatedSince int    `url:"updated_since,omitempty"`
	UpdatedUntil int    `url:"updated_until,omitempty"`
	Trend        string `url:"trend,omitempty"`
	PersonID     string `url:"person_id,omitempty"`
	PersonEmail  string `url:"person_email,omitempty"` // find response(s) by email
}

SurveyResponses endpoint in delighted, allows you to set query options which is transformed into a query string.

type SurveyService

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

SurveyService struct

func (*SurveyService) GetAll

func (s *SurveyService) GetAll(sr *SurveyResponses) (*[]Survey, error)

GetAll survey responses. Default limit is set to 20 per page.

Jump to

Keyboard shortcuts

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