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

feat(sonarr): download client #63

Merged
merged 7 commits into from
Sep 23, 2022
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
12 changes: 6 additions & 6 deletions lidarr/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
Fuochi marked this conversation as resolved.
Show resolved Hide resolved
ExpectedMethod: "GET",
ResponseStatus: 200,
WithRequest: 1,
Expand All @@ -74,7 +74,7 @@ func TestGetTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 404,
WithRequest: 1,
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestUpdateTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 200,
WithRequest: &starr.Tag{
Expand All @@ -168,7 +168,7 @@ func TestUpdateTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 404,
WithRequest: &starr.Tag{
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestDeleteTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 200,
Expand All @@ -210,7 +210,7 @@ func TestDeleteTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, lidarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 404,
Expand Down
12 changes: 6 additions & 6 deletions prowlarr/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 200,
WithRequest: 1,
Expand All @@ -74,7 +74,7 @@ func TestGetTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 404,
WithRequest: 1,
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestUpdateTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 200,
WithRequest: &starr.Tag{
Expand All @@ -168,7 +168,7 @@ func TestUpdateTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 404,
WithRequest: &starr.Tag{
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestDeleteTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 200,
Expand All @@ -210,7 +210,7 @@ func TestDeleteTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, prowlarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 404,
Expand Down
12 changes: 6 additions & 6 deletions radarr/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 200,
WithRequest: 1,
Expand All @@ -74,7 +74,7 @@ func TestGetTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 404,
WithRequest: 1,
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestUpdateTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 200,
WithRequest: &starr.Tag{
Expand All @@ -168,7 +168,7 @@ func TestUpdateTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 404,
WithRequest: &starr.Tag{
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestDeleteTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 200,
Expand All @@ -210,7 +210,7 @@ func TestDeleteTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, radarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 404,
Expand Down
12 changes: 6 additions & 6 deletions readarr/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 200,
WithRequest: 1,
Expand All @@ -74,7 +74,7 @@ func TestGetTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "GET",
ResponseStatus: 404,
WithRequest: 1,
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestUpdateTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 200,
WithRequest: &starr.Tag{
Expand All @@ -168,7 +168,7 @@ func TestUpdateTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "PUT",
ResponseStatus: 404,
WithRequest: &starr.Tag{
Expand Down Expand Up @@ -201,7 +201,7 @@ func TestDeleteTag(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 200,
Expand All @@ -210,7 +210,7 @@ func TestDeleteTag(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag/1"),
ExpectedPath: path.Join("/", starr.API, readarr.APIver, "tag", "1"),
ExpectedMethod: "DELETE",
WithRequest: 1,
ResponseStatus: 404,
Expand Down
8 changes: 4 additions & 4 deletions sonarr/delayprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (s *Sonarr) GetDelayProfilesContext(ctx context.Context) ([]*DelayProfile,
}

// GetDelayProfile returns a single delay profile.
func (s *Sonarr) GetDelayProfile(profileID int) (*DelayProfile, error) {
func (s *Sonarr) GetDelayProfile(profileID int64) (*DelayProfile, error) {
return s.GetDelayProfileContext(context.Background(), profileID)
}

// GetDelayProfileContext returns a single delay profile.
func (s *Sonarr) GetDelayProfileContext(ctx context.Context, profileID int) (*DelayProfile, error) {
func (s *Sonarr) GetDelayProfileContext(ctx context.Context, profileID int64) (*DelayProfile, error) {
var output DelayProfile

req := starr.Request{URI: path.Join(bpDelayProfile, fmt.Sprint(profileID))}
Expand Down Expand Up @@ -105,12 +105,12 @@ func (s *Sonarr) UpdateDelayProfileContext(ctx context.Context, profile *DelayPr
}

// DeleteDelayProfile removes a single delay profile.
func (s *Sonarr) DeleteDelayProfile(profileID int) error {
func (s *Sonarr) DeleteDelayProfile(profileID int64) error {
return s.DeleteDelayProfileContext(context.Background(), profileID)
}

// DeleteDelayProfileContext removes a single delay profile.
func (s *Sonarr) DeleteDelayProfileContext(ctx context.Context, profileID int) error {
func (s *Sonarr) DeleteDelayProfileContext(ctx context.Context, profileID int64) error {
req := starr.Request{URI: path.Join(bpDelayProfile, fmt.Sprint(profileID))}
if err := s.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
Expand Down
143 changes: 143 additions & 0 deletions sonarr/downloadclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package sonarr

import (
"bytes"
"context"
"encoding/json"
"fmt"
"path"

"golift.io/starr"
)

// Define Base Path for download client calls.
const bpDownloadClient = APIver + "/downloadClient"

// DownloadClientInput is the input for a new or updated download client.
type DownloadClientInput struct {
Enable bool `json:"enable"`
RemoveCompletedDownloads bool `json:"removeCompletedDownloads"`
RemoveFailedDownloads bool `json:"removeFailedDownloads"`
Priority int `json:"priority"`
ID int64 `json:"id,omitempty"`
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldInput `json:"fields"`
}

// DownloadClientOutput is the output from the download client methods.
type DownloadClientOutput struct {
Enable bool `json:"enable"`
RemoveCompletedDownloads bool `json:"removeCompletedDownloads"`
RemoveFailedDownloads bool `json:"removeFailedDownloads"`
Priority int `json:"priority"`
ID int64 `json:"id,omitempty"`
ConfigContract string `json:"configContract"`
Implementation string `json:"implementation"`
ImplementationName string `json:"implementationName"`
InfoLink string `json:"infoLink"`
Name string `json:"name"`
Protocol string `json:"protocol"`
Tags []int `json:"tags"`
Fields []*starr.FieldOutput `json:"fields"`
}

// GetDownloadClients returns all configured download clients.
func (s *Sonarr) GetDownloadClients() ([]*DownloadClientOutput, error) {
return s.GetDownloadClientsContext(context.Background())
}

// GetDownloadClientsContext returns all configured download clients.
func (s *Sonarr) GetDownloadClientsContext(ctx context.Context) ([]*DownloadClientOutput, error) {
var output []*DownloadClientOutput

req := starr.Request{URI: bpDownloadClient}
if err := s.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}

// GetDownloadClient returns a single download client.
func (s *Sonarr) GetDownloadClient(downloadclientID int64) (*DownloadClientOutput, error) {
return s.GetDownloadClientContext(context.Background(), downloadclientID)
}

// GetDownloadClientContext returns a single download client.
func (s *Sonarr) GetDownloadClientContext(ctx context.Context, downloadclientID int64) (*DownloadClientOutput, error) {
var output DownloadClientOutput

req := starr.Request{URI: path.Join(bpDownloadClient, fmt.Sprint(downloadclientID))}
if err := s.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return &output, nil
}

// AddDownloadClient creates a download client.
func (s *Sonarr) AddDownloadClient(downloadclient *DownloadClientInput) (*DownloadClientOutput, error) {
return s.AddDownloadClientContext(context.Background(), downloadclient)
}

// AddDownloadClientContext creates a download client.
func (s *Sonarr) AddDownloadClientContext(ctx context.Context,
client *DownloadClientInput,
) (*DownloadClientOutput, error) {
var output DownloadClientOutput

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(client); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClient, err)
}

req := starr.Request{URI: bpDownloadClient, Body: &body}
if err := s.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}

return &output, nil
}

// UpdateDownloadClient updates the download client.
func (s *Sonarr) UpdateDownloadClient(downloadclient *DownloadClientInput) (*DownloadClientOutput, error) {
return s.UpdateDownloadClientContext(context.Background(), downloadclient)
}

// UpdateDownloadClientContext updates the download client.
func (s *Sonarr) UpdateDownloadClientContext(ctx context.Context,
client *DownloadClientInput,
) (*DownloadClientOutput, error) {
var output DownloadClientOutput

var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(client); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClient, err)
}

req := starr.Request{URI: path.Join(bpDownloadClient, fmt.Sprint(client.ID)), Body: &body}
if err := s.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
}

// DeleteDownloadClient removes a single download client.
func (s *Sonarr) DeleteDownloadClient(downloadclientID int64) error {
return s.DeleteDownloadClientContext(context.Background(), downloadclientID)
}

// DeleteDownloadClientContext removes a single download client.
func (s *Sonarr) DeleteDownloadClientContext(ctx context.Context, downloadclientID int64) error {
req := starr.Request{URI: path.Join(bpDownloadClient, fmt.Sprint(downloadclientID))}
if err := s.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}

return nil
}
Loading