aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--call.go5
-rw-r--r--client.go46
-rw-r--r--go.mod5
-rw-r--r--go.sum6
-rw-r--r--status.go42
5 files changed, 104 insertions, 0 deletions
diff --git a/call.go b/call.go
new file mode 100644
index 0000000..50bafd2
--- /dev/null
+++ b/call.go
@@ -0,0 +1,5 @@
+package inwx
+
+type Call interface {
+ expectedStatus() []Status
+}
diff --git a/client.go b/client.go
new file mode 100644
index 0000000..ec9b44e
--- /dev/null
+++ b/client.go
@@ -0,0 +1,46 @@
+package inwx
+
+import (
+ "net/http"
+ "net/http/cookiejar"
+ "time"
+
+ "github.com/ybbus/jsonrpc/v3"
+)
+
+// An Endpoint is the server to communicate with.
+type Endpoint string
+
+const (
+ Production Endpoint = "https://api.domrobot.com/jsonrpc/"
+ Sandbox = "https://api.ote.domrobot.com/jsonrpc/"
+)
+
+const requestTimeout = 30 * time.Second
+
+// A Client is a session handle for the API.
+type Client struct {
+ rpcClient jsonrpc.RPCClient
+ endpoint Endpoint
+}
+
+func NewClient(endpoint Endpoint) (*Client, error) {
+ jar, err := cookiejar.New(&cookiejar.Options{})
+ if err != nil {
+ return nil, err
+ }
+
+ httpClient := &http.Client{
+ Jar: jar,
+ Timeout: requestTimeout,
+ }
+
+ clt := &Client{
+ rpcClient: jsonrpc.NewClientWithOpts(string(endpoint), &jsonrpc.RPCClientOpts{
+ HTTPClient: httpClient,
+ }),
+ endpoint: endpoint,
+ }
+
+ return clt, nil
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..8a69f67
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module github.com/HimbeerserverDE/inwx
+
+go 1.19
+
+require github.com/ybbus/jsonrpc/v3 v3.1.1
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..c8a0086
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,6 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/ybbus/jsonrpc/v3 v3.1.1 h1:8xJu2oEz1vfDQq83QGQkK2fZqYDqIvE2j0iQpMbeCeo=
+github.com/ybbus/jsonrpc/v3 v3.1.1/go.mod h1:NJ8vURh8jndl+F1dVplHr538HNnwnV89sEhcDsZL/bw=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
diff --git a/status.go b/status.go
new file mode 100644
index 0000000..257d060
--- /dev/null
+++ b/status.go
@@ -0,0 +1,42 @@
+package inwx
+
+// A Status contains basic information
+// about whether and how a Call was processed.
+type Status int
+
+const (
+ Success Status = 1000
+ SuccessPending = 1001
+ SuccessNoMsgs = 1300
+ SuccessDequeue = 1301
+ SuccessClosing = 1500
+ WrongPasswd = 1200
+ UnknownCall = 2000
+ SyntaxErr = 2001
+ UseErr = 2002
+ MissingParam = 2003
+ WrongParamRange = 2004
+ ParamSyntaxErr = 2005
+ UnimplementedCall = 2101
+ UnimplementedOpt = 2102
+ UnimplementedExt = 2103
+ BillingErr = 2104
+ DenyRenewal = 2105
+ DenyTransfer = 2106
+ AuthError = 2200
+ AuthzError = 2201
+ InvalidAuthzInfo = 2202
+ PendingTransfer = 2300
+ NotPendingTransfer = 2301
+ Exists = 2302
+ NotExist = 2303
+ StatusProhibitsOp = 2304
+ AssocProhibitsOp = 2305
+ ParamPolicyErr = 2306
+ UnimplementedService = 2307
+ DataMgmtPolicyErr = 2308
+ CmdErr = 2400
+ CmdErrClosing = 2500
+ AuthErrClosing = 2501
+ SessionOverClosing = 2502
+)