snapas

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 12 Imported by: 1

README

go-snapas

godoc

Official Snap.as Go client library.

Installation

go get github.com/snapas/go-snapas

Documentation

See all functionality and usages in the API documentation.

Example usage
import (
	"github.com/snapas/go-snapas"
	"github.com/writeas/go-writeas/v2"
	"log"
)

func main() {
	// Authenticate with Write.as
	wc := writeas.NewClient()
	u, err := wc.LogIn("demo", "demo")
	if err != nil {
		log.Fatal(err)
	}

	// Upload to Snap.as
	sc := snapas.NewClient(u.AccessToken)
	p, err := sc.UploadPhoto(&snapas.PhotoParams{
		FileName: "image.jpg",
	})
	if err != nil {
		wc.LogOut()
		log.Fatal(err)
	}

	// Output final domain
	log.Println(p.URL)

	// Clean up
	wc.LogOut()
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	Created  time.Time      `json:"created"`
	Title    string         `json:"title"`
	Body     *string        `json:"body"`
	HTMLBody *template.HTML `json:"html_body"`
	Alias    string         `json:"alias"`
	Views    int64          `json:"views"`
	Photos   []Photo        `json:"photos"`
}

Album represents a Snap.as photo album / gallery.

type Client

type Client struct {
	as.Client
}

Client is used to interact with the Snap.as API.

func NewClient

func NewClient(token string) *Client

NewClient creates a new API client. All requests must be authenticated, so you should supply a user access token returned from the Write.as API library (github.com/writeas/go-writeas/v2)

wc := writeas.NewClient()
u, err := wc.LogIn("username", "password")
if err != nil {
    // Handle error...
}
sc := snapas.NewClient(u.AccessToken)

func NewClientWith

func NewClientWith(cfg *as.ClientConfig, token string) *Client

NewClientWith builds a new API client with the provided configuration.

func NewDevClient

func NewDevClient(token string) *Client

NewDevClient creates a new API client for development and testing. It will communicate with our development servers, and SHOULD NOT be used in production.

func (*Client) UploadPhoto

func (c *Client) UploadPhoto(sp *PhotoParams) (*Photo, error)

UploadPhoto uploads a photo, and returns a Snap.as Photo. See: https://developers.snap.as/docs/api/#upload-a-photo

type Photo

type Photo struct {
	ID       string    `json:"id"`
	Created  time.Time `json:"created"`
	Body     *string   `json:"body"`
	Filename string    `json:"filename"`
	Size     int64     `json:"size"`
	URL      string    `json:"url"`
	Album    *Album    `json:"album"`
}

Photo represents a photo on Snap.as.

type PhotoParams

type PhotoParams struct {
	FileName string
}

PhotoParams holds valid values for uploading photos.

Jump to

Keyboard shortcuts

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