teal

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

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

Go to latest
Published: Sep 15, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

README

teal

godoc pkg.go.dev pxl-gophers contributions and bug requests

This is a simple library for pxl.blue, an image hosting site. Consider this library extremely unstable as pxl.blue and this library are still very early in development.

Examples

Logging in, and uploading a file
package main

import (
	"fmt"
	"os"
	"git.pxl.blue/webb/teal"
)

func main() {
	client, _ := teal.Login("username", "password")
	file, _ := os.Open("glenda.png")
	image, _ := client.UploadFile(file, "glenda.png")
	fmt.Println(image)
}
Getting an upload key with username and password
package main

import (
	"fmt"
	"git.pxl.blue/webb/teal"
)

func main() {
	client, _ := teal.Login("username", "password")
	fmt.Println(client.UploadKey)
}
Manually creating a barebones client and uploading a file
package main

import (
	"fmt"
	"os"
	"git.pxl.blue/webb/teal"
)

func main() {
	client := &teal.Client{
		UserAgent: "teal",
		UploadKey: "key",
	}

	file, _ := os.Open("glenda.png")
	url, _ := client.UploadFile(file, "glenda.png")
	fmt.Println(url)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	UploadKey string
	Session   string
	UserAgent string
	User      User
}

Client represents the client used for making http requests, including the session if used.

func Login

func Login(username string, password string) (*Client, error)

Login will login to an account with the provided credentials and give you a Client with user info back

func (*Client) GetDomains

func (c *Client) GetDomains() ([]Domain, error)

GetDomains gets an array of uploadable domains

func (*Client) UpdateAccountInfo

func (c *Client) UpdateAccountInfo() error

UpdateAccountInfo is a wrapper for GetAccountInfo() that replaces user info automatically

func (*Client) UploadFile

func (c *Client) UploadFile(ir io.Reader, name string) (string, error)

UploadFile attempts to upload file from io.Reader and returns the response

type Domain

type Domain struct {
	Hostname string `json:"domain"`
	ID       int    `json:"id"`
	Public   bool   `json:"public"`
	System   bool   `json:"system"`
	OwnerID  int    `json:"ownerId"`
	Disabled bool   `json:"disabled"`
}

Domain represents a pxl.blue host.

type User

type User struct {
	ID               int    `json:"id"`
	Username         string `json:"username"`
	Email            string `json:"Email"`
	RegistrationDate string `json:"registrationDate"`
	LastLogin        string `json:"lastLogin"`
	UploadKey        string `json:"uploadKey"`
	RegistrationIP   string `json:"registrationIp"`
	Moderator        bool   `json:"moderator"`
	Admin            bool   `json:"admin"`
	Banned           bool   `json:"banned"`
	BanReason        string `json:"banReason"`
	ImageCount       int    `json:"imageCount"`
}

User holds all of the information about a user that is accessible from the profile page

func GetAccountInfo

func GetAccountInfo(session string) (User, error)

GetAccountInfo gets info of a user of a given authenticated session

Jump to

Keyboard shortcuts

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