-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
77 lines (62 loc) · 1.91 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package radarr
import (
"errors"
"net/http"
"net/url"
"time"
)
// HTTPClientInterface interface for the http.Client
type HTTPClientInterface interface {
Get(url string) (resp *http.Response, err error)
Do(req *http.Request) (*http.Response, error)
}
// ClientOptions describe optional value to create a Radarr client
type ClientOptions struct {
Verbose bool
}
// New Create a Radarr client
// Optionnally specify an http.Client
func New(radarrURL, apiKey string, client HTTPClientInterface, opts ...*ClientOptions) (*Service, error) {
valid, err := url.ParseRequestURI(radarrURL)
if err != nil {
return nil, errors.New("Please specify a valid URL")
}
if apiKey == "" {
return nil, errors.New("Please specify your Radarr API key")
}
var verbose bool = false
if len(opts) > 0 {
verbose = opts[0].Verbose
}
// if client not specified, defaulting to default http client with our tansport
if client == nil {
client = &http.Client{
Transport: newTransport(apiKey, verbose),
Timeout: time.Second * 10,
}
}
s := &Service{client: client, url: valid.String()}
s.Movies = newMovieService(s)
s.SystemStatus = newSystemStatusService(s)
s.Diskspace = newDiskspaceService(s)
s.Command = newCommandService(s)
s.History = newHistoryService(s)
return s, nil
}
// Service containing all availables operations
type Service struct {
client HTTPClientInterface
url string // Radarr base URL
// https://github.com/Radarr/Radarr/wiki/API:Calendar
// https://github.com/Radarr/Radarr/wiki/API:Movie
// https://github.com/Radarr/Radarr/wiki/API:Movie-Lookup
Movies *MovieService
// https://github.com/Radarr/Radarr/wiki/API:System-Status
SystemStatus *SystemStatusService
// https://github.com/Radarr/Radarr/wiki/API:Diskspace
Diskspace *DiskspaceService
// https://github.com/Radarr/Radarr/wiki/API:Command
Command *CommandService
// https://github.com/Radarr/Radarr/wiki/API:History
History *HistoryService
}