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

do not hard code moveFiles #87

Merged
merged 3 commits into from
Dec 5, 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
9 changes: 4 additions & 5 deletions lidarr/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ func (l *Lidarr) GetAlbumByIDContext(ctx context.Context, albumID int64) (*Album
}

// UpdateAlbum updates an album in place; the output of this is currently unknown!!!!
func (l *Lidarr) UpdateAlbum(albumID int64, album *Album) (*Album, error) {
return l.UpdateAlbumContext(context.Background(), albumID, album)
func (l *Lidarr) UpdateAlbum(albumID int64, album *Album, moveFiles bool) (*Album, error) {
return l.UpdateAlbumContext(context.Background(), albumID, album, moveFiles)
}

// UpdateAlbumContext updates an album in place; the output of this is currently unknown!!!!
func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *Album) (*Album, error) {
func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *Album, moveFiles bool) (*Album, error) {
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(album); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpAlbum, err)
Expand All @@ -156,7 +156,7 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))

if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
Expand Down Expand Up @@ -186,7 +186,6 @@ func (l *Lidarr) AddAlbumContext(ctx context.Context, album *AddAlbumInput) (*Al
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")

var output Album
if err := l.PostInto(ctx, req, &output); err != nil {
Expand Down
9 changes: 4 additions & 5 deletions readarr/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ func (r *Readarr) GetBookByIDContext(ctx context.Context, bookID int64) (*Book,
}

// UpdateBook updates a book in place.
func (r *Readarr) UpdateBook(bookID int64, book *Book) error {
return r.UpdateBookContext(context.Background(), bookID, book)
func (r *Readarr) UpdateBook(bookID int64, book *Book, moveFiles bool) error {
return r.UpdateBookContext(context.Background(), bookID, book, moveFiles)
}

// UpdateBookContext updates a book in place.
func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Book) error {
func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Book, moveFiles bool) error {
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(book); err != nil {
return fmt.Errorf("json.Marshal(%s): %w", bpBook, err)
Expand All @@ -163,7 +163,7 @@ func (r *Readarr) UpdateBookContext(ctx context.Context, bookID int64, book *Boo
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))

var output interface{} // do not know what this looks like.

Expand Down Expand Up @@ -191,7 +191,6 @@ func (r *Readarr) AddBookContext(ctx context.Context, book *AddBookInput) (*Book
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")

var output Book
if err := r.PostInto(ctx, req, &output); err != nil {
Expand Down
10 changes: 4 additions & 6 deletions sonarr/series.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ func (s *Sonarr) GetSeriesContext(ctx context.Context, tvdbID int64) ([]*Series,
}

// UpdateSeries updates a series in place.
func (s *Sonarr) UpdateSeries(series *AddSeriesInput) (*Series, error) {
return s.UpdateSeriesContext(context.Background(), series)
func (s *Sonarr) UpdateSeries(series *AddSeriesInput, moveFiles bool) (*Series, error) {
return s.UpdateSeriesContext(context.Background(), series, moveFiles)
}

// UpdateSeriesContext updates a series in place.
func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput) (*Series, error) {
func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput, moveFiles bool) (*Series, error) {
var body bytes.Buffer
if err := json.NewEncoder(&body).Encode(series); err != nil {
return nil, fmt.Errorf("json.Marshal(%s): %w", bpSeries, err)
Expand All @@ -163,7 +163,7 @@ func (s *Sonarr) UpdateSeriesContext(ctx context.Context, series *AddSeriesInput
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", "true")
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))

if err := s.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
Expand All @@ -187,8 +187,6 @@ func (s *Sonarr) AddSeriesContext(ctx context.Context, series *AddSeriesInput) (
var output Series

req := starr.Request{URI: bpSeries, Query: make(url.Values), Body: &body}
req.Query.Add("moveFiles", "true")

if err := s.PostInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Post(%s): %w", &req, err)
}
Expand Down
10 changes: 5 additions & 5 deletions sonarr/series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func TestAddSeries(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series?moveFiles=true"),
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series"),
ExpectedMethod: "POST",
ExpectedRequest: addSeries,
ResponseStatus: 200,
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestAddSeries(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series?moveFiles=true"),
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series"),
ExpectedMethod: "POST",
ExpectedRequest: addSeries,
ResponseStatus: 404,
Expand Down Expand Up @@ -1038,7 +1038,7 @@ func TestUpdateSeries(t *testing.T) {
tests := []*starr.TestMockData{
{
Name: "200",
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=true"),
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"),
ExpectedMethod: "PUT",
ExpectedRequest: updateSeries,
ResponseStatus: 200,
Expand Down Expand Up @@ -1165,7 +1165,7 @@ func TestUpdateSeries(t *testing.T) {
},
{
Name: "404",
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=true"),
ExpectedPath: path.Join("/", starr.API, sonarr.APIver, "series/1?moveFiles=false"),
ExpectedMethod: "PUT",
ExpectedRequest: updateSeries,
ResponseStatus: 404,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ func TestUpdateSeries(t *testing.T) {
t.Parallel()
mockServer := test.GetMockServer(t)
client := sonarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.UpdateSeries(test.WithRequest.(*sonarr.AddSeriesInput))
output, err := client.UpdateSeries(test.WithRequest.(*sonarr.AddSeriesInput), false)
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, output, test.WithResponse, "response is not the same as expected")
})
Expand Down