-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathloopia.go
45 lines (38 loc) · 937 Bytes
/
loopia.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
package loopia
import (
"github.com/kolo/xmlrpc"
)
// APIURL - where API is hosted
const APIURL string = "https://api.loopia.se/RPCSERV"
// API Struct to store runtime info
type API struct {
Username string
Password string
RPCEndpoint string
}
// XMLRPCClient to interact with Loopia XMLRPC
func (api *API) XMLRPCClient() *xmlrpc.Client {
client, _ := xmlrpc.NewClient(api.RPCEndpoint, nil)
return client
}
func (api *API) getAuthenticationArgs() []interface{} {
return []interface{}{
api.Username,
api.Password,
}
}
func (api *API) Call(serviceMethod string, args []interface{}, reply interface{}) error {
return api.XMLRPCClient().Call(
serviceMethod,
append(api.getAuthenticationArgs(), args...),
reply,
)
}
// New returns a loopia.API instance
func New(username string, password string) (*API, error) {
return &API{
RPCEndpoint: APIURL,
Username: username,
Password: password,
}, nil
}