Skip to content

Commit 78e2048

Browse files
committed
Add ping endpoints
1 parent 0fcc5e5 commit 78e2048

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

lidarr/lidarr.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package lidarr
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57

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

4345
return &Lidarr{APIer: config}
4446
}
47+
48+
// bp means base path. You'll see it a lot in these files.
49+
const bpPing = "/ping" // ping has no api or version prefix.
50+
51+
// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
52+
func (l *Lidarr) Ping() error {
53+
return l.PingContext(context.Background())
54+
}
55+
56+
// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
57+
func (l *Lidarr) PingContext(ctx context.Context) error {
58+
req := starr.Request{URI: bpPing}
59+
60+
resp, err := l.Get(ctx, req)
61+
if err != nil {
62+
return fmt.Errorf("api.Get(%s): %w", &req, err)
63+
}
64+
defer resp.Body.Close()
65+
66+
return nil
67+
}

prowlarr/prowlarr.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package prowlarr
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57

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

2527
return &Prowlarr{APIer: config}
2628
}
29+
30+
// bp means base path. You'll see it a lot in these files.
31+
const bpPing = "/ping" // ping has no api or version prefix.
32+
33+
// Ping returns an error if the Prowlarr instance does not respond with a 200 to an HTTP /ping request.
34+
func (p *Prowlarr) Ping() error {
35+
return p.PingContext(context.Background())
36+
}
37+
38+
// PingContext returns an error if the Prowlarr instance does not respond with a 200 to an HTTP /ping request.
39+
func (p *Prowlarr) PingContext(ctx context.Context) error {
40+
req := starr.Request{URI: bpPing}
41+
42+
resp, err := p.Get(ctx, req)
43+
if err != nil {
44+
return fmt.Errorf("api.Get(%s): %w", &req, err)
45+
}
46+
defer resp.Body.Close()
47+
48+
return nil
49+
}

radarr/radarr.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package radarr
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57

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

4244
return &Radarr{APIer: config}
4345
}
46+
47+
// bp means base path. You'll see it a lot in these files.
48+
const bpPing = "ping" // ping has no api or version prefix.
49+
50+
// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
51+
func (r *Radarr) Ping() error {
52+
return r.PingContext(context.Background())
53+
}
54+
55+
// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
56+
func (r *Radarr) PingContext(ctx context.Context) error {
57+
req := starr.Request{URI: bpPing}
58+
59+
resp, err := r.Get(ctx, req)
60+
if err != nil {
61+
return fmt.Errorf("api.Get(%s): %w", &req, err)
62+
}
63+
defer resp.Body.Close()
64+
65+
return nil
66+
}

readarr/readarr.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package readarr
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57

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

4345
return &Readarr{APIer: config}
4446
}
47+
48+
// bp means base path. You'll see it a lot in these files.
49+
const bpPing = "/ping" // ping has no api or version prefix.
50+
51+
// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
52+
func (r *Readarr) Ping() error {
53+
return r.PingContext(context.Background())
54+
}
55+
56+
// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
57+
func (r *Readarr) PingContext(ctx context.Context) error {
58+
req := starr.Request{URI: bpPing}
59+
60+
resp, err := r.Get(ctx, req)
61+
if err != nil {
62+
return fmt.Errorf("api.Get(%s): %w", &req, err)
63+
}
64+
defer resp.Body.Close()
65+
66+
return nil
67+
}

sonarr/sonarr.go

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package sonarr
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57

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

4042
return &Sonarr{APIer: config}
4143
}
44+
45+
// bp means base path. You'll see it a lot in these files.
46+
const bpPing = "/ping" // ping has no api or version prefix.
47+
48+
// Ping returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
49+
func (s *Sonarr) Ping() error {
50+
return s.PingContext(context.Background())
51+
}
52+
53+
// PingContext returns an error if the starr instance does not respond with a 200 to an HTTP /ping request.
54+
func (s *Sonarr) PingContext(ctx context.Context) error {
55+
req := starr.Request{URI: bpPing}
56+
57+
resp, err := s.Get(ctx, req)
58+
if err != nil {
59+
return fmt.Errorf("api.Get(%s): %w", &req, err)
60+
}
61+
defer resp.Body.Close()
62+
63+
return nil
64+
}

0 commit comments

Comments
 (0)