redmed

package module
v0.0.0-...-789b2b2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: MIT Imports: 15 Imported by: 0

README

redmed

redmed is a redit API wrapper for posting media (image, video, videogif) submissions.

Why?

Existing Reddit API clients, such as go-reddit, only support link and self posts.

redmed used alongside existing tools gives you a more complete Reddit API wrapper.

Usage (see examples)

Create a client
reddit := redmed.New(userAgent, clientID, secret, username, password)

With HTTP Client

c := &http.Client{Timeout: time.Second * 30}
reddit := redmed.New(userAgent, clientID, secret, username, password, redmed.WithHTTPClient(c))

With gorilla Websocket Dialer

d := websocket.DefaultDialer
d.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
reddit := redmed.New(userAgent, clientID, secret, username, password, redmed.WithWebsocketDialer(d))
Post an image

Supported image types:

  • .png
  • .jpg
  • .jpeg
  • .gif
Post image from local machine
req := redmed.PostImageRequest{
    NSWF: false,
    Path: "/path/to/image.jpeg",
    Resubmit: true,
    SendReplies: true,
    Spoiler: false,
    Subreddit: "subreddit",
    Title: "image from local path",
}

name, err := reddit.PostImage(context.Background(), req)
if err != nil {
    fmt.Println(err)
}
Post image from link
req := redmed.PostImageRequest{
    NSWF: false,
    Path: "https://host.com/image.jpeg",
    Resubmit: true,
    SendReplies: true,
    Spoiler: false,
    Subreddit: "subreddit",
    Title: "image from local path",
}

name, err := reddit.PostImage(context.Background(), req)
if err != nil {
    fmt.Println(err)
}
Post image gallery
req := redmed.PostGalleryRequest{
    NSWF: false,
	Paths: []string{"/path/to/image.jpeg", "https://host.com/image.jpeg"},
	SendReplies: true,
	Spoiler: false,
	Subreddit: "subreddit",
	Title: "gallery from local path and link",
}

name, err := reddit.PostGallery(context.Background(), req)
if err != nil {
    fmt.Println(err)
}
Post a video

Supported image types:

  • .mp4
  • .mov
Post video from local machine with thumbnail image from link
req := redmed.PostVideoRequest{
	Kind: "video", // or videogif for silent video
	NSWF: false,
	VideoPath: "/path/to/video.mp4",
	Resubmit: true,
	SendReplies: true,
	Spoiler: false,
	Subreddit: "subreddit",
	Title: "video from local path",
	ThumbnailPath: "https://host.com/image.jpeg",
}

name, err := reddit.PostVideo(context.Background(), req)
if err != nil {
    fmt.Println(err)
}
Post video from link with thumbnail image from local path
req := redmed.PostVideoRequest{
	Kind: "video", // or videogif for silent video
	NSWF: false,
	VideoPath: "https://host.com/video.mp4",
	Resubmit: true,
	SendReplies: true,
	Spoiler: false,
	Subreddit: "subreddit",
	Title: "video from link",
	ThumbnailPath: "/path/to/image.jpeg",
}

name, err := reddit.PostVideo(context.Background(), req)
if err != nil {
    fmt.Println(err)
}

The name returned from submitting posts is the fullname of the post, such as t3_x2dx7f.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	PostImage(ctx context.Context, req PostImageRequest) (string, error)
	PostVideo(ctx context.Context, req PostVideoRequest) (string, error)
	PostGallery(ctx context.Context, req PostGalleryRequest) (string, error)
}

func New

func New(userAgent, clientID, secret, username, password string, options ...Option) Client

type Option

type Option func(*client)

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

func WithWebsocketDialer

func WithWebsocketDialer(dialer *websocket.Dialer) Option

type PostGalleryRequest

type PostGalleryRequest struct {
	FlairID     string
	FlairText   string
	NSWF        bool
	Paths       []string
	SendReplies bool
	Spoiler     bool
	Subreddit   string
	Title       string
}

type PostImageRequest

type PostImageRequest struct {
	FlairID     string
	FlairText   string
	NSWF        bool
	Path        string
	Resubmit    bool
	SendReplies bool
	Spoiler     bool
	Subreddit   string
	Title       string
}

type PostVideoRequest

type PostVideoRequest struct {
	FlairID       string
	FlairText     string
	Kind          string
	NSWF          bool
	VideoPath     string
	Resubmit      bool
	SendReplies   bool
	Spoiler       bool
	Subreddit     string
	ThumbnailPath string
	Title         string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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