gravatar

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

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

Go to latest
Published: Mar 6, 2022 License: MIT Imports: 9 Imported by: 0

README

gravatar

A Go wrapper for Gravatar

Install

go get -u github.com/brunom4ciel/gravatar

Examples

Profile URL
url := gravatar.New("mail@example.org").URL()
Avatar URL with parameters
url := gravatar.New("mail@example.org").
		Size(200).
		Default(gravatar.NotFound).
		Rating(gravatar.Pg).
		AvatarURL()
Avatar URL with default image
url := gravatar.New("mail@example.org").
        DefaultURL("http://example.org/image.png").
        AvatarURL()
Force default avatar
url := gravatar.New("mail@example.org").ForceDefault(true).AvatarURL()
JSON profile data URL
url := gravatar.New("mail@example.org").JSONURL()
JSON profile data URL with callback
url := gravatar.New("mail@example.org").JSONURLCallback("alert")
Parsed profile data
profile, err := gravatar.New("mail@example.org").Profiles()

License

MIT licensed. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultValue

type DefaultValue string

DefaultValue is a value suitable for the default parameter

const (
	NoDefault  DefaultValue = ""
	NotFound   DefaultValue = "404"
	MysteryMan DefaultValue = "mm"
	Identicon  DefaultValue = "identicon"
	Monsterid  DefaultValue = "monsterid"
	Wavatar    DefaultValue = "wavatar"
	Retro      DefaultValue = "retro"
	Blank      DefaultValue = "blank"
)

See https://de.gravatar.com/site/implement/images/#default-image

type Gravatar

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

Gravatar is a struct for configuring and generating a Gravatar-URL

func New

func New(email string) *Gravatar

New creates a new Gravatar instance based on the given E-Mail

func (*Gravatar) AvatarURL

func (g *Gravatar) AvatarURL() string

AvatarURL generates the URL to get the avatar of the user based on the given configuration

func (*Gravatar) Default

func (g *Gravatar) Default(value DefaultValue) *Gravatar

Default sets a default value to be used if no image is available

func (*Gravatar) DefaultURL

func (g *Gravatar) DefaultURL(urlString string) *Gravatar

DefaultURL sets a URL to use as default image (See https://de.gravatar.com/site/implement/images/#default-image) An invalid URL will be ignored

func (*Gravatar) ForceDefault

func (g *Gravatar) ForceDefault(force bool) *Gravatar

ForceDefault sets if the default avatar should be forced o be returned

func (*Gravatar) JSONURL

func (g *Gravatar) JSONURL() string

JSONURL generates the URL to fetch profile data as json

func (*Gravatar) JSONURLCallback

func (g *Gravatar) JSONURLCallback(callback string) string

JSONURLCallback returns the URL to fetch profile data as json and sets the callback parameter (See https://de.gravatar.com/site/implement/profiles/json/#request-options)

func (*Gravatar) Profiles

func (g *Gravatar) Profiles() (*Profiles, error)

Profiles fetches and parses the profile data

func (*Gravatar) Rating

func (g *Gravatar) Rating(rating Rating) *Gravatar

Rating sets the rating appropriate for your audience

func (*Gravatar) Size

func (g *Gravatar) Size(size int) *Gravatar

Size sets the size of the requested image If size is zero the parameter is not used Valid sizes are from 1px up to 2048px

func (*Gravatar) URL

func (g *Gravatar) URL() string

URL generates the URL to the Gravatar profile of the given email

type Photo

type Photo struct {
	Value string
	Type  string
}

Photo represents a single photo entry

type Profile

type Profile struct {
	ID                string   `json:"id"`
	Hash              string   `json:"hash"`
	RequestHash       string   `json:"requestHash"`
	ProfileURL        string   `json:"profileUrl"`
	PreferredUsername string   `json:"prefferedUsername"`
	ThumbnailURL      string   `json:"thumbnailUrl"`
	Photos            []Photo  `json:"photos"`
	Name              []string `json:"name"`
	DisplayName       string   `json:"displayName"`
	Urls              []string `json:"urls"`
}

Profile represents a single profile

type Profiles

type Profiles struct {
	Entry []Profile
}

Profiles is a wrapper for the response

type Rating

type Rating string

Rating is a value suitable for the rating parameter

const (
	NoRating Rating = ""
	G        Rating = "g"
	Pg       Rating = "pg"
	R        Rating = "r"
	X        Rating = "x"
)

See https://de.gravatar.com/site/implement/images/#rating

Jump to

Keyboard shortcuts

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