pastemystgo

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

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

Go to latest
Published: Jun 27, 2021 License: MIT Imports: 7 Imported by: 0

README

Logo

Build status GitHub issues

A small, fast, reliable pastemyst API wrapper written in Golang.
Official pastemyst API docs found here.

PasteMystGo provides low-level, stable, and fast bindings for the PasteMyst API.
To get started check out the library docs

Documentation

Index

Constants

View Source
const (
	EndpointBase = "https://paste.myst.rs/api/v2/"
	EndpointData = EndpointBase + "data/" // Value: https://paste.myst.rs/api/v2/data/
	EndpointTime = EndpointBase + "time/" // Value: https://paste.myst.rs/api/v2/time/
	EndpointUser = EndpointBase + "user/" // Value: https://paste.myst.rs/api/v2/user/

	EndpointSelfUser       = EndpointUser + "self/"      // Value: https://paste.myst.rs/api/v2/user/self/
	EndpointSelfUserPastes = EndpointSelfUser + "pastes" // Value: https://paste.myst.rs/api/v2/user/self/pastes
)

All the pastemyst API endpoints that can be accessed

Variables

View Source
var (
	// EndpointPaste - Value: https://paste.myst.rs/api/v2/paste/{pasteId}
	EndpointPaste = func(pasteId string) string {
		return fmt.Sprintf("%spaste/%s", EndpointBase, pasteId)
	}
	// DataLanguageByName - Value:
	// https://paste.myst.rs/api/v2/data/language?name={name}
	DataLanguageByName = func(name string) string {
		return fmt.Sprintf("%slanguage?name=%s", EndpointData, url.QueryEscape(name))
	}

	// DataLanguageByExt - Value:
	// https://paste.myst.rs/api/v2/data/languageExt?extension={extension}
	DataLanguageByExt = func(extension string) string {
		return fmt.Sprintf("%slanguageExt?extension=%s", EndpointData, url.QueryEscape(extension))
	}

	// TimeExpiresInToUnix - Value:
	// https://paste.myst.rs/api/v2/time/expiresInToUnixTime/?createdAt={createdAt}&expiresIn={expiresIn}
	TimeExpiresInToUnix = func(createdAt uint64, expires string) string {
		return fmt.Sprintf("%sexpiresInToUnixTime?createdAt=%d&expiresIn=%s", EndpointTime, createdAt, expires)
	}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Token *string
}

Client represents a backend client with a token used for registration of a new context

func NewClient

func NewClient(tok string) *Client

NewClient registers a new Client to use in the backend for API operations.

Returns:

(*Client)

func (*Client) BulkDeletePastes

func (c *Client) BulkDeletePastes(pastes []string) error

BulkDeletePastes deletes X amount of pastes with a given string array of paste Ids. you must specify an account token -- mandatory

You can only delete pastes that are on your account

Params:

(pastes []string)

Returns:

(error)

func (*Client) CreatePaste

func (c *Client) CreatePaste(createInfo PasteCreateInfo) (paste *Paste, err error)

CreatePaste creates a new paste with the given PasteCreateInfo

Posts new pastes to (https://paste.myst.rs/api/v2/paste)

Params:

(createInfo PasteCreateInfo)

Returns:

(*Paste, error)

func (*Client) DeleteClient

func (c *Client) DeleteClient()

DeleteClient marks a Client for deletion by assigning it to nil, allowing it to be handled by the Garbage Collector.

Params:

(client *Client)

Remarks: This function should be called when you're done using the client, ensure that cleanup is executed.

func (*Client) DeletePaste

func (c *Client) DeletePaste(pasteId string) error

DeletePaste deletes a paste with a specified account token -- mandatory

You can only delete pastes on the account of the token that has been passed.

A token is required for deleting a paste because this is an account feature.

This action is irreversible.

Params:

(pasteId string)

Returns:

(error)

func (*Client) EditPaste

func (c *Client) EditPaste(paste *Paste) (*Paste, error)

EditPaste edits a paste with a specified account token -- mandatory

You can only edit pastes on the account of the token that has been passed.

A token is required for editing a paste because this is an account feature.

To edit values of a paste you must send back the exact same paste except with the adjusted values, you cannot edit expiration date, any result will have no effect.

Params:

(paste *Paste)

Returns:

(*Paste, error)

func (*Client) ExpiresInToUnixTime

func (c *Client) ExpiresInToUnixTime(createdAt uint64, expires ExpiresIn) (uint64, error)

ExpiresInToUnixTime returns the created at time in unix format. Will error out and return 0 if the request was malformed.

Params:

(createdAt uint64, expires ExpiresIn)

Returns:

(uint64, error)

func (*Client) GetLanguageByExtension

func (c *Client) GetLanguageByExtension(extension string) (language *Language, err error)

GetLanguageByExtension gets a language based on its extension

Params:

(extension string)

Returns:

(*Language, error)

BUG(r): Some languages will not return properly, and will error out.

func (*Client) GetLanguageByName

func (c *Client) GetLanguageByName(name string) (language *Language, err error)

GetLanguageByName gets a language based on its pretty name

Uses url encoding to convert it into a url friendly value returns a Language and error if applicable.

Language will be nil if error is returned.

Params:

(name string)

Returns:

(*Language, error)

BUG(r): Some languages will not return properly, and will error out.

func (*Client) GetPaste

func (c *Client) GetPaste(pasteId string) (paste *Paste, err error)

GetPaste gets a paste based on Id, a token is mandatory for accessing private pastes

Params:

(pasteId string)

Returns:

(*Paste, error)

func (*Client) GetSelfPasteIds

func (c *Client) GetSelfPasteIds() (pastes []string, err error)

GetSelfPasteIds gets all of the currently logged in users paste Ids, this function is not available if no token is available

Returns:

([]string, error)

Remarks: this will return ALL paste ids, use with caution.

func (*Client) GetSelfPasteIdsByAmount

func (c *Client) GetSelfPasteIdsByAmount(amount uint) (pastes []string, err error)

GetSelfPasteIdsByAmount gets a specific amount of the currently logged in user paste ids, this function is not available if no token is available

Params:

(amount uint)

Returns:

([]string, error)

Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.

Addendum: uint parameter because there will never be negative pastes on your account

func (*Client) GetSelfPastes

func (c *Client) GetSelfPastes() (pastes []*Paste, err error)

GetSelfPastes gets all of the currently logged in users pastes, this function is not available if no token is available

Returns:

([]*Paste, error)

Remarks: this is a HEAVY function depending on the amount of pastes you have on your account, it will fetch all the paste ids, and convert them into actual paste objects. use with caution, you will be rate-limited.

func (*Client) GetSelfPastesByAmount

func (c *Client) GetSelfPastesByAmount(amount uint) (pastes []*Paste, err error)

GetSelfPastesByAmount gets a specific amount of the currently logged in users pastes, this function is not available if no token is available

Params:

(amount uint)

Returns:

([]*Paste, error)

Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.

Addendum: uint parameter because there will never be negative pastes on your account

func (*Client) GetSelfUser

func (c *Client) GetSelfUser() (user *User, err error)

GetSelfUser gets the currently logged in user, this function is not available if no token is available

Returns:

(*User, error)

func (*Client) GetUser

func (c *Client) GetUser(username string) (user *User, err error)

GetUser gets a user by their username

User will be nil if they don't have a public profile.

Params:

(username string)

Returns:

(*User, error)

func (*Client) IsAuthorized

func (c *Client) IsAuthorized() bool

func (*Client) PasteExists

func (c *Client) PasteExists(pasteId string) bool

PasteExists checks to see if a given paste exists from a pasteId

Params:

(pasteId string)

Returns:

(bool)

func (*Client) TryBulkDeletePastes

func (c *Client) TryBulkDeletePastes(pastes []string) bool

TryBulkDeletePastes attempts to delete X amount of pastes with a given string array of paste Ids. you must specify an account token -- mandatory

You can only delete pastes that are on your account

Params:

(pastes []string)

Returns:

(bool)

func (*Client) TryCreatePaste

func (c *Client) TryCreatePaste(createInfo PasteCreateInfo) (paste *Paste, ok bool)

TryCreatePaste attempts to create a new paste with the given PasteCreateInfo

Posts new pastes to (https://paste.myst.rs/api/v2/paste)

Params:

(createInfo PasteCreateInfo)

Returns:

(*Paste, bool)

func (*Client) TryDeletePaste

func (c *Client) TryDeletePaste(pasteId string) bool

TryDeletePaste attempts to delete a paste with a specified account token -- mandatory

You can only delete pastes on the account of the token that has been passed.

A token is required for deleting a paste because this is an account feature.

This action is irreversible.

Params:

(pasteId string)

Returns:

(bool)

func (*Client) TryEditPaste

func (c *Client) TryEditPaste(paste *Paste) (*Paste, bool)

TryEditPaste attempts to edit a paste with a specified account token -- mandatory

You can only edit pastes on the account of the token that has been passed.

A token is required for editing a paste because this is an account feature.

To edit values of a paste you must send back the exact same paste except with the adjusted values, you cannot edit expiration date, any result will have no effect.

Params:

(paste *Paste)

Returns:

(*Paste, bool)

func (*Client) TryGetLanguageByExtension

func (c *Client) TryGetLanguageByExtension(extension string) (language *Language, ok bool)

TryGetLanguageByExtension attempts to get a language based on its extension

Params:

(extension string)

Returns:

(*Language, error)

BUG(r): Some languages will not return properly, and will error out.

func (*Client) TryGetLanguageByName

func (c *Client) TryGetLanguageByName(name string) (language *Language, ok bool)

TryGetLanguageByName attempts to get a language based on its pretty name

Uses url encoding to convert it into a url friendly value returns a Language and error if applicable.

Language will be nil if error is returned.

Params:

(name string)

Returns:

(*Language, error)

BUG(r): Some languages will not return properly, and will error out.

func (*Client) TryGetPaste

func (c *Client) TryGetPaste(pasteId string) (paste *Paste, ok bool)

TryGetPaste attempts to get a paste based on Id, a token is mandatory for accessing private pastes.

Params:

(pasteId string)

Returns:

(*Paste, bool)

func (*Client) TryGetSelfPasteIds

func (c *Client) TryGetSelfPasteIds() (pastes []string, ok bool)

TryGetSelfPasteIds attempts to get all of the currently logged in users paste Ids, this function is not available if no token is available

Returns:

([]string, bool)

Remarks: this will return ALL paste ids, use with caution.

func (*Client) TryGetSelfPasteIdsByAmount

func (c *Client) TryGetSelfPasteIdsByAmount(amount uint) (pastes []string, ok bool)

TryGetSelfPasteIdsByAmount attempts to get a specific amount of the currently logged in user paste ids, this function is not available if no token is available

Params:

(amount uint)

Returns:

([]string, bool)

Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.

Addendum: uint parameter because there will never be negative pastes on your account

func (*Client) TryGetSelfPastes

func (c *Client) TryGetSelfPastes() (pastes []*Paste, ok bool)

TryGetSelfPastes attempts to get all of the currently logged in users pastes, this function is not available if no token is available

Returns:

([]*Paste, bool)

Remarks: this is a HEAVY function depending on the amount of pastes you have on your account, it will fetch all the paste ids, and convert them into actual paste objects. use with caution, you will be rate-limited.

func (*Client) TryGetSelfPastesByAmount

func (c *Client) TryGetSelfPastesByAmount(amount uint) (pastes []*Paste, ok bool)

TryGetSelfPastesByAmount attempts to get a specific amount of the currently logged in users pastes, this function is not available if no token is available

Params:

(amount uint)

Returns:

([]*Paste, error)

Remarks: this is a HEAVY function depending on the amount of pastes you specify, use with caution, you will be rate-limited.

Addendum: uint parameter because there will never be negative pastes on your account

func (*Client) TryGetSelfUser

func (c *Client) TryGetSelfUser() (user *User, ok bool)

TryGetSelfUser attempts to get the currently logged in user, this function is not available if no token is available

Returns:

(*User, bool)

func (*Client) TryGetUser

func (c *Client) TryGetUser(username string) (*User, bool)

TryGetUser attempts to get a user by their username

User will be nil if they don't have a public profile.

Params:

(username string)

Returns:

(*User, bool)

func (*Client) UserExists

func (c *Client) UserExists(username string) (bool, error)

UserExists checks if a given user exists based on a username

Params:

(username string)

Returns:

(bool, error)

Remarks: the user account MUST be public, or you must be accessing your own account while signed in with your API token.

type Edit

type Edit struct {
	// Unique id of the edit
	Id string `json:"_id"`
	// Edit id, multiple edits can share the same id
	// to show that multiple properties were edited
	// at the same time
	EditId uint64 `json:"editId"`
	// Type of edit (incomplete)
	EditType uint64 `json:"editType"`
	// Various metadata, most used case - storing which pasty was edited
	Metadata []string `json:"metadata"`
	// The actual data of the edit, typically stores old data
	Edit string `json:"edit"`
	// Unix time of when the edit was executed
	EditedAt uint64 `json:"editedAt"`
}

Edit holds information about a given edit based in 'id'.

You can only edit pastes on your account, so you must provide the Authorization header.

type ExpiresIn

type ExpiresIn int

ExpiresIn represents all the possible time formats for when a paste will expire.

const (
	Never    ExpiresIn = iota // string form -> "never"
	OneHour                   // string form -> "1h"
	TwoHours                  // string form -> "2h"
	TenHours                  // string form -> "10h"
	OneDay                    // string form -> "1d"
	TwoDays                   // string form -> "2d"
	OneWeek                   // string form -> "1w"
	OneMonth                  // string form -> "1m"
	OneYear                   // string form -> "1y"
)

type Language

type Language struct {
	// Name represents the name of the language
	Name string `json:"name"`
	// Language represents the language mode for the online editor (codemirror)
	Mode string `json:"mode"`
	// Mimes represents all supported mimes in a slice
	Mimes []string `json:"mimes"`
	// Extensions represents all extensions for a language with a given name
	Extensions []string `json:"ext,omitempty"`
	// Color represents the color language, not guaranteed for every language,
	// Default will be #FFFFFF if the language doesn't have one.
	Color string `json:"color,omitempty"`
}

Language represents a language request

type Paste

type Paste struct {
	// Paste Id
	Id string `json:"_id"`
	// Owner of the paste, if none then will be " "
	OwnerId string `json:"ownerId"`
	// Title of the paste
	Title string `json:"title,omitempty"`
	// Date in unix time when the paste was created
	CreatedAt uint64 `json:"createdAt"`
	// When the paste expires
	ExpiresIn string `json:"expiresIn,omitempty"`
	// Date in unix time when the paste will be deleted
	DeletesAt uint64 `json:"deletesAt"`
	// Amount of stars the paste has
	Stars uint64 `json:"stars"`
	// Is the paste private?
	IsPrivate bool `json:"isPrivate,omitempty"`
	// Is the paste public?
	IsPublic bool `json:"isPublic,omitempty"`
	// Is the paste encrypted?
	IsEncrypted bool `json:"encrypted"`
	// Slices of all tags for this paste
	Tags []string `json:"tags,omitempty"`
	// Slice of all the pasties on the paste
	Pasties []Pasty `json:"pasties"`
	// Slice of all edits
	Edits []Edit `json:"edits"`
}

Paste represents a single paste, containing all edits and pasties attached.

If you're accessing a private paste you need to provide the Authorization header.

type PasteCreateInfo

type PasteCreateInfo struct {
	// Title represents the title of the paste -- optional
	Title string `json:"title,omitempty"`
	// ExpiresIn represents when the paste will expire -- optional
	ExpiresIn string `json:"expiresIn,omitempty"`
	// IsPrivate represents if it is accessible by the owner -- optional
	IsPrivate bool `json:"isPrivate,omitempty"`
	// IsPublic represents if it is displayed on the owners public profile -- optional
	IsPublic bool `json:"isPublic,omitempty"`
	// Tags represents comma separated paste tags -- optional
	Tags string `json:"tags,omitempty"`
	// Pasties represents a slice of pasties -- mandatory
	Pasties []PastyCreateInfo `json:"pasties"`
}

PasteCreateInfo represents the information needed to create a new paste

type Pasty

type Pasty struct {
	// Id of the pasty
	Id string `json:"_id"`
	// Title of the pasty
	Title string `json:"title"`
	// Language of the pasty
	Language string `json:"language"`
	// Code of the pasty
	Code string `json:"code"`
}

Pasty represents a single pasty, could also be perceived as a "file" on the PasteMyst website, contains language, code, and title.

type PastyCreateInfo

type PastyCreateInfo struct {
	// Title represents the title of a pasty
	Title string `json:"title"`
	// Language represents the language of the pasty,
	// stores the name of the language, not the mode or MIME type.
	Language string `json:"language"`
	// Code represents the code of the pasty
	Code string `json:"code"`
}

PastyCreateInfo represents the information needed to created a new pasty

type RequestMethod

type RequestMethod int
const (
	GET RequestMethod = iota
	POST
	PATCH
	DELETE
)

type User

type User struct {
	// Id of the user
	Id string `json:"_id"`
	// Username of the user
	Username string `json:"username"`
	// Url of the avatar
	AvatarUrl string `json:"avatarUrl"`
	// The users default language
	DefaultLang string `json:"defaultLang"`
	// Specifies if their profile is public
	PublicProfile bool `json:"publicProfile"`
	// Specifies how long the user has been a support for, 0 if not a supporter
	SupporterLength uint64 `json:"supporterLength"`
	// Specifies if the user is a contributor
	IsContributor bool `json:"contributor"`

	// Stars represents a list of paste ids the user has starred
	Stars []string `json:"stars,omitempty"`
	// ServiceIds represents user ids of the service the user used to create an account
	ServiceIds map[string]string `json:"serviceIds,omitempty"`
}

User represents a single pastemyst user

Notes

Bugs

  • Some languages will not return properly, and will error out.

  • Some languages will not return properly, and will error out.

  • Some languages will not return properly, and will error out.

  • Some languages will not return properly, and will error out.

Jump to

Keyboard shortcuts

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