rebrandly

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 13 Imported by: 0

README

Rebrandly

GoDoc Go Report Card

Rebrandly API golang bindings.

Quickstart

// Init
rebapi := rebrandly.New(apiKey)
// rebapi.SetWorkspace("workspace")
// rebapi.SetUserAgent("whatever")

// Create
link, err := rebapi.LinksCreate(rebrandly.LinkCreationPayload{
    Destination: "https://github.com/hekmon/rebrandly",
    SlashTag:    "rebrandly-golang",
    Title:       "Rebrandly Golang bindings library",
    // Domain:      &domain,
})

Each endpoint supports golang contextes, just suffix Ctx to it: rebapi.LinksCreateCtx(ctx, rebrandly.LinkCreationPayload{...

Enpoints

Basic endpoints
Advanced endpoints

not planned, feel free to fork or PR !

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID           string    `json:"id"`
	CreatedAt    time.Time `json:"createdAt"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	FullName     string    `json:"fullName"`
	AvatarURL    string    `json:"avatarUrl"`
	MyCname      string    `json:"myCname"`
	Subscription struct {
		Category  string    `json:"category"`
		CreatedAt time.Time `json:"createdAt"`
		Billing   struct {
			Cycle struct {
				Price struct {
					Full int `json:"full"`
					Net  int `json:"net"`
					Vat  int `json:"vat"`
				} `json:"price"`
				ResetsAt time.Time `json:"resetsAt"`
			} `json:"cycle"`
			Extra struct {
				Cycle struct {
				} `json:"cycle"`
			} `json:"extra"`
		} `json:"billing"`
		Limits struct {
			Links struct {
				Used     int `json:"used"`
				Included int `json:"included"`
				Blocked  int `json:"blocked"`
			} `json:"links"`
			Domains struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"domains"`
			Teammates struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"teammates"`
			Workspaces struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"workspaces"`
			Teams struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"teams"`
			Cycle struct {
				Clicks struct {
					Used     int `json:"used"`
					Included int `json:"included"`
				} `json:"clicks"`
			} `json:"cycle"`
			Tags struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"tags"`
			Scripts struct {
				Used     int `json:"used"`
				Included int `json:"included"`
			} `json:"scripts"`
		} `json:"limits"`
		Features struct {
			Links struct {
				Scripts bool `json:"scripts"`
				Tags    bool `json:"tags"`
				Qrcode  bool `json:"qrcode"`
				Emoji   bool `json:"emoji"`
				Utm     bool `json:"utm"`
				Notes   bool `json:"notes"`
				Rules   bool `json:"rules"`
				Import  bool `json:"import"`
				Export  bool `json:"export"`
				Jobs    bool `json:"jobs"`
			} `json:"links"`
			Workspaces bool `json:"workspaces"`
			Teams      bool `json:"teams"`
			Teammates  bool `json:"teammates"`
			Domains    struct {
				Whitelabeled bool `json:"whitelabeled"`
			} `json:"domains"`
			Clicks struct {
				Total bool `json:"total"`
				Last  bool `json:"last"`
			} `json:"clicks"`
			Reports struct {
				Links  bool `json:"links"`
				Custom bool `json:"custom"`
				Public bool `json:"public"`
			} `json:"reports"`
			TwoFactorAuth bool `json:"twoFactorAuth"`
		} `json:"features"`
	} `json:"subscription"`
	Clicks      int       `json:"clicks"`
	Sessions    int       `json:"sessions"`
	LastClickAt time.Time `json:"lastClickAt"`
}

Account represents all the metadata related to the api key account

type Controller

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

Controller abstracts the access to the cpg API

func New

func New(APIKey string) *Controller

New returns an initialized and ready to use Controller

func (*Controller) Account

func (c *Controller) Account() (account Account, err error)

Account returns the current account metata

func (*Controller) AccountCtx

func (c *Controller) AccountCtx(ctx context.Context) (account Account, err error)

AccountCtx returns the current account metata

func (*Controller) ClearWorkspace

func (c *Controller) ClearWorkspace()

ClearWorkspace allows to reset the controller on the default workspace

func (*Controller) DomainsCount

func (c *Controller) DomainsCount(filters *DomainsCountFilters) (nbDomains int, err error)

DomainsCount returns the number of domains

func (*Controller) DomainsCountCtx

func (c *Controller) DomainsCountCtx(ctx context.Context, filters *DomainsCountFilters) (nbDomains int, err error)

DomainsCountCtx returns the number of domains

func (*Controller) DomainsGet

func (c *Controller) DomainsGet(filters *DomainsFilters) (domains Domains, err error)

DomainsGet returns the list of domains

func (*Controller) DomainsGetByID

func (c *Controller) DomainsGetByID(id string) (domain Domain, err error)

DomainsGetByID return the domains details represented by id

func (*Controller) DomainsGetByIDCtx

func (c *Controller) DomainsGetByIDCtx(ctx context.Context, id string) (domain Domain, err error)

DomainsGetByIDCtx return the domains details represented by id

func (*Controller) DomainsGetCtx

func (c *Controller) DomainsGetCtx(ctx context.Context, filters *DomainsFilters) (domains Domains, err error)

DomainsGetCtx returns the list of domains

func (*Controller) GetUserAgent

func (c *Controller) GetUserAgent() (ua string)

GetUserAgent returns the current user agent configured. If empty, golang default ua will be used.

func (*Controller) GetWorkspace

func (c *Controller) GetWorkspace() (workspace string)

GetWorkspace returns the current workspace on which the controller work against. Empty means default workspace.

func (*Controller) LinksCount

func (c *Controller) LinksCount(filters *LinksCountFilters) (nbLinks int, err error)

LinksCount returns the number of links

func (*Controller) LinksCountCtx

func (c *Controller) LinksCountCtx(ctx context.Context, filters *LinksCountFilters) (nbLinks int, err error)

LinksCountCtx returns the number of links

func (*Controller) LinksCreate

func (c *Controller) LinksCreate(payload LinkCreationPayload) (link Link, err error)

LinksCreate creates a link

func (*Controller) LinksCreateCtx

func (c *Controller) LinksCreateCtx(ctx context.Context, payload LinkCreationPayload) (link Link, err error)

LinksCreateCtx creates a link

func (*Controller) LinksDelete

func (c *Controller) LinksDelete(id string) (link Link, err error)

LinksDelete deletes a link identified by id.

func (*Controller) LinksDeleteCtx

func (c *Controller) LinksDeleteCtx(ctx context.Context, id string) (link Link, err error)

LinksDeleteCtx deletes a link identified by id.

func (*Controller) LinksGet

func (c *Controller) LinksGet(filters *LinksFilters) (links Links, err error)

LinksGet returns the list of links

func (*Controller) LinksGetAll added in v1.1.0

func (c *Controller) LinksGetAll(filters *LinksFilters) (links Links, err error)

LinksGetAll returns the list of links

func (*Controller) LinksGetAllCtx added in v1.1.0

func (c *Controller) LinksGetAllCtx(ctx context.Context, filters *LinksFilters) (links Links, err error)

LinksGetAllCtx recursively retreive all the links (not limited by max)

func (*Controller) LinksGetByID

func (c *Controller) LinksGetByID(id string) (link Link, err error)

LinksGetByID returns the link details of link id.

func (*Controller) LinksGetByIDCtx

func (c *Controller) LinksGetByIDCtx(ctx context.Context, id string) (link Link, err error)

LinksGetByIDCtx returns the link details of link id.

func (*Controller) LinksGetCtx

func (c *Controller) LinksGetCtx(ctx context.Context, filters *LinksFilters) (links Links, err error)

LinksGetCtx returns the list of links

func (*Controller) LinksUpdate

func (c *Controller) LinksUpdate(id string, payload LinkUpdatePayload) (link Link, err error)

LinksUpdate allows to update a link title and destination by its id.

func (*Controller) LinksUpdateCtx

func (c *Controller) LinksUpdateCtx(ctx context.Context, id string, payload LinkUpdatePayload) (link Link, err error)

LinksUpdateCtx allows to update a link title and destination by its id.

func (*Controller) SetUserAgent

func (c *Controller) SetUserAgent(ua string)

SetUserAgent allows tu customize the user agent used by the controller when performing http requests.

func (*Controller) SetWorkspace

func (c *Controller) SetWorkspace(workspace string)

SetWorkspace changes the workspace on which the controller will work against.

type Domain

type Domain struct {
	ID             string    `json:"id"`
	FullName       string    `json:"fullName"`
	TopLevelDomain string    `json:"topLevelDomain"`
	Level          int       `json:"level"`
	CreationDate   time.Time `json:"creationDate"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
	OwnerID        string    `json:"ownerId"`
	Type           string    `json:"type"`
	Subdomains     int       `json:"subdomains"`
	Managed        bool      `json:"managed"`
	Status         struct {
		DNS        string `json:"dns"`
		Encryption string `json:"encryption"`
	} `json:"status"`
	HTTPS       bool      `json:"https"`
	Active      bool      `json:"active"`
	Clicks      int       `json:"clicks"`
	Sessions    int       `json:"sessions"`
	LastClickAt time.Time `json:"lastClickAt"`
	Correlation struct {
		Status string `json:"status"`
	} `json:"correlation"`
}

Domain represents a single custom domain

type Domains

type Domains []Domain

Domains represents a list domains

type DomainsCountFilters

type DomainsCountFilters struct {
	Active *bool        `urlQuery:"active"`
	Type   *DomainsType `urlQuery:"active"`
}

DomainsCountFilters represents the filer usable within a DomainsCount request

type DomainsFilters

type DomainsFilters struct {
	Active   *bool        `urlQuery:"active"`
	Type     *DomainsType `urlQuery:"type"`
	OrderBy  *OrderBy     `urlQuery:"orderBy"`
	OrderDir *OrderDir    `urlQuery:"orderDir"`
	Limit    *int         `urlQuery:"limit"`
	Last     *string      `urlQuery:"last"`
}

DomainsFilters represents the filters used to make a Domains query. https://developers.rebrandly.com/docs/domains-list-endpoint

type DomainsType

type DomainsType string

DomainsType represent a domain type

const (
	// DomainsTypeUser represents the "user" type for a DomainsType
	DomainsTypeUser DomainsType = "user"
	// DomainsTypeService represents the "service" type for DomainsType
	DomainsTypeService DomainsType = "service"
)

type Error

type Error struct {
	Message string `json:"message"`
	Code    string `json:"code"`
	Source  string `json:"source"`
	Errors  []struct {
		Code     string `json:"code"`
		Property string `json:"property"`
		Message  string `json:"message"`
		Verbose  string `json:"verbose"`
	} `json:"errors"`
}

Error represents an error returned by rebrandly

func (Error) Error

func (e Error) Error() string
type Link struct {
	ID            string    `json:"id"`
	Title         string    `json:"title"`
	Slashtag      string    `json:"slashtag"`
	Destination   string    `json:"destination"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
	Status        string    `json:"status"`
	Clicks        int       `json:"clicks"`
	Sessions      int       `json:"sessions"`
	LastClickDate time.Time `json:"lastClickDate"`
	LastClickAt   time.Time `json:"lastClickAt"`
	IsPublic      bool      `json:"isPublic"`
	ShortURL      string    `json:"shortUrl"`
	DomainID      string    `json:"domainId"`
	DomainName    string    `json:"domainName"`
	Domain        struct {
		ID       string `json:"id"`
		Ref      string `json:"ref"`
		FullName string `json:"fullName"`
		Active   bool   `json:"active"`
	} `json:"domain"`
	HTTPS     bool `json:"https"`
	Favourite bool `json:"favourite"`
	Creator   struct {
		ID        string `json:"id"`
		FullName  string `json:"fullName"`
		AvatarURL string `json:"avatarUrl"`
	} `json:"creator"`
	Integrated bool `json:"integrated"`
}

Link represents a registered rebrandly link

type LinkCreationPayload

type LinkCreationPayload struct {
	Destination string  `json:"destination"`
	SlashTag    string  `json:"slashtag,omitempty"`
	Title       string  `json:"title,omitempty"`
	Domain      *Domain `json:"domain,omitempty"`
}

LinkCreationPayload represents the payload used to create a link

type LinkUpdatePayload

type LinkUpdatePayload struct {
	Destination string `json:"destination"`
	Title       string `json:"title"`
}

LinkUpdatePayload contains all the data needed to update a link

type Links []Link

Links represents a collection of Link

type LinksCountFilters

type LinksCountFilters struct {
	Favourite *bool   `urlQuery:"favourite"`
	DomainID  *string `urlQuery:"domain.id"`
}

LinksCountFilters represents the filters usable on the LinksCount query

type LinksFilters

type LinksFilters struct {
	DomainID       *string   `urlQuery:"domain.id"`
	DomainFullName *string   `urlQuery:"domain.fullName"`
	SlashTag       *string   `urlQuery:"slashtag"`
	CreatorID      *string   `urlQuery:"creator.id"`
	OrderBy        *OrderBy  `urlQuery:"orderBy"`
	OrderDir       *OrderDir `urlQuery:"orderDir"`
	Limit          *int      `urlQuery:"limit"`
	Last           *string   `urlQuery:"last"`
}

LinksFilters represents all filters usable on Links queries

type OrderBy

type OrderBy string

OrderBy represent a given ordering

const (
	// OrderByCreatedAt represents the "createdAt" ordering for an OrderBy. Valid for Domains, Links.
	OrderByCreatedAt OrderBy = "createdAt"
	// OrderByUpdatedAt represents the "updatedAt" ordering for an OrderBy. Valid for Domains.
	OrderByUpdatedAt OrderBy = "updatedAt"
	// OrderByFullName represents the "fullName" ordering for an OrderBy. Valid for Domains.
	OrderByFullName OrderBy = "fullName"
	// OrderByTitle represents the "title" ordering for an OrderBy. Valid for Links.
	OrderByTitle OrderBy = "title"
	// OrderBySlashTag represents the "slashtag" ordering for an OrderBy. Valid for Links.
	OrderBySlashTag OrderBy = "slashtag"
)

type OrderDir

type OrderDir string

OrderDir represents the sorting direction

const (
	// OrderDirDesc represents the "desc" sorting direction for a OrderDir.
	OrderDirDesc OrderDir = "desc"
	// OrderDirAsc represents the "asc" sorting direction for a OrderDir.
	OrderDirAsc OrderDir = "asc"
)

Jump to

Keyboard shortcuts

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