Complete CollectionService

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-08-07 01:28:53 -04:00
parent 691eb965b8
commit d8e0bfa03d
2 changed files with 182 additions and 1 deletions
+82 -1
View File
@@ -109,7 +109,6 @@ func (s *CollectionService) Create(ctx context.Context, createRequest *Collectio
path := "api/v1/collections/create_collection"
// todo: do this for multireddit stuff too
form, err := query.Values(createRequest)
if err != nil {
return nil, nil, err
@@ -191,3 +190,85 @@ func (s *CollectionService) ReorderPosts(ctx context.Context, collectionID strin
return s.client.Do(ctx, req, nil)
}
// UpdateTitle updates a collection's title.
func (s *CollectionService) UpdateTitle(ctx context.Context, id string, title string) (*Response, error) {
path := "api/v1/collections/update_collection_title"
form := url.Values{}
form.Set("collection_id", id)
form.Set("title", title)
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// UpdateDescription updates a collection's description.
func (s *CollectionService) UpdateDescription(ctx context.Context, id string, description string) (*Response, error) {
path := "api/v1/collections/update_collection_description"
form := url.Values{}
form.Set("collection_id", id)
form.Set("description", description)
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// UpdateLayout updates a collection's layout.
// layout is one of: TIMELINE, GALLERY.
func (s *CollectionService) UpdateLayout(ctx context.Context, id string, layout string) (*Response, error) {
// todo: should we validate layout?
path := "api/v1/collections/update_collection_display_layout"
form := url.Values{}
form.Set("collection_id", id)
form.Set("display_layout", layout)
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Follow follows a collection.
func (s *CollectionService) Follow(ctx context.Context, id string) (*Response, error) {
path := "api/v1/collections/follow_collection"
form := url.Values{}
form.Set("collection_id", id)
form.Set("follow", "true")
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}
// Unfollow unfollows a collection.
func (s *CollectionService) Unfollow(ctx context.Context, id string) (*Response, error) {
path := "api/v1/collections/follow_collection"
form := url.Values{}
form.Set("collection_id", id)
form.Set("follow", "false")
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}