pastefy

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

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

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 12 Imported by: 0

README

Pastefy Go API Client

package main

import pastefy "github.com/interaapps/pastefy-go-api"

func main() {

	client := pastefy.NewClient()

	// Not required for just fetching pastes or folders
	client.SetApiToken("...")

	createPaste := pastefy.Paste{
		Title:     "test.js",
		Content:   `console.log("Hey");`,
	}
	createdPaste, _ := client.CreatePaste(createPaste)
	println(createdPaste.RawUrl)
	
	paste, _ := client.GetPaste("ZA8U8CCQ")
	println(paste.Content)
	paste.Content += `\nconsole.log("There!")`
	client.SavePaste(paste)
	
	// Getting folder
	folder, _ := client.GetFolder("abcdefgh")
	for _, folderPaste := range folder.Pastes {
		println(folderPaste.Title)
	}


	// Getting current logged in user
	user, _ := client.GetUser()
	if user.LoggedIn {
		println("Hello: " + user.Name)
	}
	
	
	// Edit encrypted pastes
	password := "password"
	paste, _ = paste.Decrypt(password)
	paste.Content = "Hey"
	paste, _ = paste.Encrypt(password)
	_, err := client.SavePaste(paste) // (edited paste, error)
	if err == nil {
		println("Successful!")
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PasteType = struct {
	MULTI_PASTE string
	PASTE       string
}{
	MULTI_PASTE: "MULTI_PASTE",
	PASTE:       "PASTE",
}

Functions

func AesDecrypt

func AesDecrypt(cipherText string, password string) (string, error)

func AesEncrypt

func AesEncrypt(content string, password string) (string, error)

func DefaultEvpKDF

func DefaultEvpKDF(password []byte, salt []byte) (key []byte, iv []byte, err error)

func EvpKDF

func EvpKDF(password []byte, salt []byte, keySize int, iterations int, hashAlgorithm string) ([]byte, error)

func PKCS5Padding

func PKCS5Padding(src []byte, blockSize int) []byte

Types

type Error

type Error struct {
	Exception string `json:"exception"`
	Success   bool   `json:"success"`
	Exists    bool   `json:"exists"`
	Error     bool   `json:"error"`
}

type Folder

type Folder struct {
	UserId   string   `json:"user_id"`
	Name     string   `json:"name"`
	Exists   bool     `json:"exists"`
	Id       string   `json:"id"`
	Pastes   []Paste  `json:"pastes,omitempty"`
	Children []Folder `json:"children,omitempty"`
}

type MultiPastePart

type MultiPastePart struct {
	Name     string `json:"name"`
	Contents string `json:"contents"`
}

type Notifcation

type Notifcation struct {
	UpdatedAt   string `json:"updated_at"`
	UserId      string `json:"user_id"`
	AlreadyRead bool   `json:"already_read"`
	CreatedAt   string `json:"created_at"`
	Received    bool   `json:"received"`
	Id          int    `json:"id"`
	Message     string `json:"message"`
	Url         string `json:"url"`
}

type Overview

type Overview struct {
	Folder []Folder `json:"folder"`
	Pastes []Paste  `json:"pastes"`
}

type Paste

type Paste struct {
	Id        string `json:"id"`
	Created   string `json:"created"`
	Encrypted bool   `json:"encrypted"`
	UserId    string `json:"user_id,omitempty"`
	Exists    bool   `json:"exists"`
	Title     string `json:"title"`
	Type      string `json:"type,omitempty"`
	FolderId  string `json:"folder,omitempty"`
	Content   string `json:"content"`
	RawUrl    string `json:"raw_url,omitempty"`
}

func (Paste) Decrypt

func (paste Paste) Decrypt(password string) (Paste, error)

func (Paste) Encrypt

func (paste Paste) Encrypt(password string) (Paste, error)

func (Paste) GetMultiPasteParts

func (paste Paste) GetMultiPasteParts() []MultiPastePart

type PastefyApiClient

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

func NewClient

func NewClient() PastefyApiClient

func NewClientWithBaseURL

func NewClientWithBaseURL(baseURL string) PastefyApiClient

func (PastefyApiClient) AddFriendToPaste

func (apiClient PastefyApiClient) AddFriendToPaste(paste string, friend string) error

func (PastefyApiClient) CreateFolder

func (apiClient PastefyApiClient) CreateFolder(folder Folder) (*Folder, error)

func (PastefyApiClient) CreatePaste

func (apiClient PastefyApiClient) CreatePaste(paste Paste) (*Paste, error)

func (PastefyApiClient) DeleteFolder

func (apiClient PastefyApiClient) DeleteFolder(id string) error

func (PastefyApiClient) DeletePaste

func (apiClient PastefyApiClient) DeletePaste(id string) error

func (PastefyApiClient) GetFolder

func (apiClient PastefyApiClient) GetFolder(id string) (Folder, error)

func (PastefyApiClient) GetOverview

func (apiClient PastefyApiClient) GetOverview() (Overview, error)

func (PastefyApiClient) GetPaste

func (apiClient PastefyApiClient) GetPaste(id string) (Paste, error)

func (PastefyApiClient) GetUser

func (apiClient PastefyApiClient) GetUser() (User, error)

func (PastefyApiClient) GetUserFolders

func (apiClient PastefyApiClient) GetUserFolders() ([]Folder, error)

func (PastefyApiClient) GetUserNotifications

func (apiClient PastefyApiClient) GetUserNotifications() ([]Notifcation, error)

func (PastefyApiClient) GetUserPastes

func (apiClient PastefyApiClient) GetUserPastes() ([]Paste, error)

func (PastefyApiClient) GetUserSharedPastes

func (apiClient PastefyApiClient) GetUserSharedPastes() ([]Paste, error)

func (PastefyApiClient) MarkAllNotificationsAsRead

func (apiClient PastefyApiClient) MarkAllNotificationsAsRead() error

func (PastefyApiClient) Request

func (apiClient PastefyApiClient) Request(method string, url string, body interface{}) (*http.Response, error)

func (PastefyApiClient) RequestMap

func (apiClient PastefyApiClient) RequestMap(method string, url string, body interface{}, ma interface{}) (*http.Response, error)

func (PastefyApiClient) SaveFolder

func (apiClient PastefyApiClient) SaveFolder(folder Folder) (*Folder, error)

func (PastefyApiClient) SavePaste

func (apiClient PastefyApiClient) SavePaste(paste Paste) (*Paste, error)

func (*PastefyApiClient) SetApiToken

func (apiClient *PastefyApiClient) SetApiToken(token string)

func (*PastefyApiClient) SetBaseURL

func (apiClient *PastefyApiClient) SetBaseURL(baseURL string)

func (PastefyApiClient) UpdateFolder

func (apiClient PastefyApiClient) UpdateFolder(id string, folder Folder) (*Folder, error)

func (PastefyApiClient) UpdatePaste

func (apiClient PastefyApiClient) UpdatePaste(id string, paste Paste) (*Paste, error)

type Response

type Response struct {
	Success bool `json:"success"`
}

type User

type User struct {
	AuthTypes      []string `json:"auth_types"`
	AuthType       string   `json:"auth_type"`
	Color          string   `json:"color"`
	LoggedIn       bool     `json:"logged_in"`
	Name           string   `json:"name"`
	ProfilePicture string   `json:"profile_picture"`
	Id             string   `json:"id"`
}

Jump to

Keyboard shortcuts

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