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 ping endpoints #142

Merged
merged 2 commits into from
Mar 1, 2024
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
23 changes: 23 additions & 0 deletions lidarr/lidarr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package lidarr

import (
"context"
"fmt"
"strings"

"golift.io/starr"
Expand Down Expand Up @@ -42,3 +44,24 @@ func New(config *starr.Config) *Lidarr {

return &Lidarr{APIer: config}
}

// bp means base path. You'll see it a lot in these files.
const bpPing = "/ping" // ping has no api or version prefix.

// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (l *Lidarr) Ping() error {
return l.PingContext(context.Background())
}

// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (l *Lidarr) PingContext(ctx context.Context) error {
req := starr.Request{URI: bpPing}

resp, err := l.Get(ctx, req)
if err != nil {
return fmt.Errorf("api.Get(%s): %w", &req, err)
}
defer resp.Body.Close()

return nil
}
23 changes: 23 additions & 0 deletions prowlarr/prowlarr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package prowlarr

import (
"context"
"fmt"
"strings"

"golift.io/starr"
Expand All @@ -24,3 +26,24 @@ func New(config *starr.Config) *Prowlarr {

return &Prowlarr{APIer: config}
}

// bp means base path. You'll see it a lot in these files.
const bpPing = "/ping" // ping has no api or version prefix.

// Ping returns an error if the Prowlarr instance does not respond with a 200 to an HTTP /ping request.
func (p *Prowlarr) Ping() error {
return p.PingContext(context.Background())
}

// PingContext returns an error if the Prowlarr instance does not respond with a 200 to an HTTP /ping request.
func (p *Prowlarr) PingContext(ctx context.Context) error {
req := starr.Request{URI: bpPing}

resp, err := p.Get(ctx, req)
if err != nil {
return fmt.Errorf("api.Get(%s): %w", &req, err)
}
defer resp.Body.Close()

return nil
}
23 changes: 23 additions & 0 deletions radarr/radarr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package radarr

import (
"context"
"fmt"
"strings"

"golift.io/starr"
Expand Down Expand Up @@ -41,3 +43,24 @@ func New(config *starr.Config) *Radarr {

return &Radarr{APIer: config}
}

// bp means base path. You'll see it a lot in these files.
const bpPing = "/ping" // ping has no api or version prefix.

// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (r *Radarr) Ping() error {
return r.PingContext(context.Background())
}

// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (r *Radarr) PingContext(ctx context.Context) error {
req := starr.Request{URI: bpPing}

resp, err := r.Get(ctx, req)
if err != nil {
return fmt.Errorf("api.Get(%s): %w", &req, err)
}
defer resp.Body.Close()

return nil
}
23 changes: 23 additions & 0 deletions readarr/readarr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package readarr

import (
"context"
"fmt"
"strings"

"golift.io/starr"
Expand Down Expand Up @@ -42,3 +44,24 @@ func New(config *starr.Config) *Readarr {

return &Readarr{APIer: config}
}

// bp means base path. You'll see it a lot in these files.
const bpPing = "/ping" // ping has no api or version prefix.

// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (r *Readarr) Ping() error {
return r.PingContext(context.Background())
}

// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (r *Readarr) PingContext(ctx context.Context) error {
req := starr.Request{URI: bpPing}

resp, err := r.Get(ctx, req)
if err != nil {
return fmt.Errorf("api.Get(%s): %w", &req, err)
}
defer resp.Body.Close()

return nil
}
23 changes: 23 additions & 0 deletions sonarr/sonarr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sonarr

import (
"context"
"fmt"
"strings"

"golift.io/starr"
Expand Down Expand Up @@ -39,3 +41,24 @@ func New(config *starr.Config) *Sonarr {

return &Sonarr{APIer: config}
}

// bp means base path. You'll see it a lot in these files.
const bpPing = "/ping" // ping has no api or version prefix.

// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (s *Sonarr) Ping() error {
return s.PingContext(context.Background())
}

// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
func (s *Sonarr) PingContext(ctx context.Context) error {
req := starr.Request{URI: bpPing}

resp, err := s.Get(ctx, req)
if err != nil {
return fmt.Errorf("api.Get(%s): %w", &req, err)
}
defer resp.Body.Close()

return nil
}
Loading