Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queue delete methods. #120

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lidarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lidarr
import (
"context"
"fmt"
"path"
"time"

"golift.io/starr"
Expand Down Expand Up @@ -105,3 +106,18 @@ func (l *Lidarr) GetQueuePageContext(ctx context.Context, params *starr.PageReq)

return &output, nil
}

// DeleteQueue deletes an item from the Activity Queue.
func (l *Lidarr) DeleteQueue(queueID int64, opts *starr.QueueDeleteOpts) error {
return l.DeleteQueueContext(context.Background(), queueID, opts)
}

// DeleteQueueContext deletes an item from the Activity Queue.
func (l *Lidarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *starr.QueueDeleteOpts) error {
req := starr.Request{URI: path.Join(bpQueue, fmt.Sprint(queueID)), Query: opts.Values()}
if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
16 changes: 16 additions & 0 deletions radarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package radarr
import (
"context"
"fmt"
"path"
"time"

"golift.io/starr"
Expand Down Expand Up @@ -106,3 +107,18 @@ func (r *Radarr) GetQueuePageContext(ctx context.Context, params *starr.PageReq)

return &output, nil
}

// DeleteQueue deletes an item from the Activity Queue.
func (r *Radarr) DeleteQueue(queueID int64, opts *starr.QueueDeleteOpts) error {
return r.DeleteQueueContext(context.Background(), queueID, opts)
}

// DeleteQueueContext deletes an item from the Activity Queue.
func (r *Radarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *starr.QueueDeleteOpts) error {
req := starr.Request{URI: path.Join(bpQueue, fmt.Sprint(queueID)), Query: opts.Values()}
if err := r.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
16 changes: 16 additions & 0 deletions readarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package readarr
import (
"context"
"fmt"
"path"
"time"

"golift.io/starr"
Expand Down Expand Up @@ -107,3 +108,18 @@ func (r *Readarr) GetQueuePageContext(ctx context.Context, params *starr.PageReq

return &output, nil
}

// DeleteQueue deletes an item from the Activity Queue.
func (r *Readarr) DeleteQueue(queueID int64, opts *starr.QueueDeleteOpts) error {
return r.DeleteQueueContext(context.Background(), queueID, opts)
}

// DeleteQueueContext deletes an item from the Activity Queue.
func (r *Readarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *starr.QueueDeleteOpts) error {
req := starr.Request{URI: path.Join(bpQueue, fmt.Sprint(queueID)), Query: opts.Values()}
if err := r.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
32 changes: 32 additions & 0 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package starr
import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -199,6 +201,36 @@ type BackupFile struct {
Size int64 `json:"size"`
}

// QueueDeleteOpts are the extra inputs when deleting an item from the Activity Queue.
// Set these appropriately for your expectations. All inputs are the same in all apps.
type QueueDeleteOpts struct {
// Default True, use starr.False() to change it.
RemoveFromClient *bool
// Default False
BlockList bool
// Default False
SkipRedownload bool
}

// Values turns delete options into http get query parameters.
func (o *QueueDeleteOpts) Values() url.Values {
params := make(url.Values)
params.Set("removeFromClient", "true")

if o == nil {
return params
}

params.Set("blocklist", fmt.Sprint(o.BlockList))
params.Set("skipRedownload", fmt.Sprint(o.SkipRedownload))

if o.RemoveFromClient != nil {
params.Set("removeFromClient", fmt.Sprint(*o.RemoveFromClient))
}

return params
}

// PlayTime is used in at least Sonarr, maybe other places.
// Holds a string duration converted from hh:mm:ss.
type PlayTime struct { //nolint:musttag
Expand Down
30 changes: 30 additions & 0 deletions shared_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package starr_test

import (
"testing"

"github.com/stretchr/testify/assert"
"golift.io/starr"
)

func TestQueueDeleteOpts_Values(t *testing.T) {
t.Parallel()
assert := assert.New(t)

var opts *starr.QueueDeleteOpts

params := opts.Values() // it's nil.
assert.Equal(params.Encode(), "removeFromClient=true",
"default queue delete parameters encoded incorrectly")

opts = &starr.QueueDeleteOpts{
BlockList: true,
RemoveFromClient: starr.False(),
SkipRedownload: true,
}
params = opts.Values()

assert.Equal("false", params.Get("removeFromClient"), "delete parameters encoded incorrectly")
assert.Equal("true", params.Get("blocklist"), "delete parameters encoded incorrectly")
assert.Equal("true", params.Get("skipRedownload"), "delete parameters encoded incorrectly")
}
16 changes: 16 additions & 0 deletions sonarr/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sonarr
import (
"context"
"fmt"
"path"
"time"

"golift.io/starr"
Expand Down Expand Up @@ -107,3 +108,18 @@ func (s *Sonarr) GetQueuePageContext(ctx context.Context, params *starr.PageReq)

return &output, nil
}

// DeleteQueue deletes an item from the Activity Queue.
func (s *Sonarr) DeleteQueue(queueID int64, opts *starr.QueueDeleteOpts) error {
return s.DeleteQueueContext(context.Background(), queueID, opts)
}

// DeleteQueueContext deletes an item from the Activity Queue.
func (s *Sonarr) DeleteQueueContext(ctx context.Context, queueID int64, opts *starr.QueueDeleteOpts) error {
req := starr.Request{URI: path.Join(bpQueue, fmt.Sprint(queueID)), Query: opts.Values()}
if err := s.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
Loading