Create LiveThreadService

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-09-15 21:41:12 -04:00
parent 77d0d257d3
commit 359f8126a1
6 changed files with 136 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package reddit
import (
"context"
"fmt"
"net/http"
)
// LiveThreadService handles communication with the live thread
// related methods of the Reddit API.
//
// Reddit API docs: https://www.reddit.com/dev/api/#section_live
type LiveThreadService struct {
client *Client
}
// LiveThread is a thread on Reddit that provides real-time updates.
type LiveThread struct {
ID string `json:"id,omitempty"`
FullID string `json:"name,omitempty"`
Created *Timestamp `json:"created_utc,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Resources string `json:"resources,omitempty"`
State string `json:"state,omitempty"`
ViewerCount int `json:"viewer_count"`
ViewerCountFuzzed bool `json:"viewer_count_fuzzed"`
WebSocketURL string `json:"websocket_url,omitempty"`
Announcement bool `json:"is_announcement"`
NSFW bool `json:"nsfw"`
}
// Get information about a live thread.
func (s *LiveThreadService) Get(ctx context.Context, id string) (*LiveThread, *Response, error) {
path := fmt.Sprintf("live/%s/about", id)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(thing)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
t, _ := root.LiveThread()
return t, resp, nil
}