Skip to content

atye/redmed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published

Languages