diff --git a/haivision/auth.go b/haivision/auth.go index 315ab5a..190235f 100644 --- a/haivision/auth.go +++ b/haivision/auth.go @@ -5,6 +5,7 @@ import ( "gopkg.in/validator.v2" + "github.com/Allan-Nava/Haivision-go-sdk/haivision/device" "github.com/Allan-Nava/Haivision-go-sdk/haivision/session" ) @@ -29,7 +30,7 @@ Response } } */ -func (o *Haivision) InitSession(username string, password string) (*BaseResponseInitSession, error) { +func (o *Haivision) InitSession(username string, password string) (*session.BaseResponseInitSession, error) { var requestBody session.RequestInitSession // if errs := validator.Validate(requestBody); errs != nil { @@ -40,7 +41,7 @@ func (o *Haivision) InitSession(username string, password string) (*BaseResponse if err != nil { return nil, err } - var obj BaseResponseInitSession + var obj session.BaseResponseInitSession if err := json.Unmarshal(resp.Body(), &obj); err != nil { return nil, err } @@ -73,12 +74,12 @@ Response ] */ -func (o *Haivision) GetDeviceInfo() (*BaseResponseDeviceInfo, error) { +func (o *Haivision) GetDeviceInfo() (*device.BaseResponseDeviceInfo, error) { resp, err := o.restyGet(DEVICE_INFO, nil) if err != nil { return nil, err } - var obj BaseResponseDeviceInfo + var obj device.BaseResponseDeviceInfo if err := json.Unmarshal(resp.Body(), &obj); err != nil { return nil, err } diff --git a/haivision/device/request.go b/haivision/device/request.go new file mode 100644 index 0000000..76a9bfa --- /dev/null +++ b/haivision/device/request.go @@ -0,0 +1 @@ +package device diff --git a/haivision/device/response.go b/haivision/device/response.go new file mode 100644 index 0000000..7108c94 --- /dev/null +++ b/haivision/device/response.go @@ -0,0 +1,39 @@ +package device + +type BaseResponseDeviceInfo struct { + Responses []ResponseDeviceInfo +} + +/* + { + "_id": "[Device ID]", + "type": "gateway", + "ip": "127.0.0.1", + "name": "Haivision Gateway", + "lastConnectedAt": [Date/time shown in Unix time], + "statusCode": "ok", + "status": "Online", + "statusDetails": "Connection has been established in the last 1 minutes.", + "serialNumber": null, + "firmware": "5.0.180611.1530", + "hasAdminError": false, + "pendingSync": false, + "lastConnection": "<1m" + } +*/ +type ResponseDeviceInfo struct { + ID string `json:"_id" validate:"nonzero"` + Type string `json:"type" validate:"nonzero"` + IP string `json:"ip" validate:"nonzero"` + Name string `json:"name" validate:"nonzero"` + LastConnectedAt int64 `json:"lastConnectedAt" validate:"nonzero"` + StatusCode string `json:"statusCode" validate:"nonzero"` + Status string `json:"status" validate:"nonzero"` + StatusDetails string `json:"statusDetails" validate:"nonzero"` + SerialNumber string `json:"serialNumber" validate:"nonzero"` + Firmware string `json:"firmware" validate:"nonzero"` + HasAdminError bool `json:"hasAdminError" validate:"nonzero"` + PendingSync bool `json:"pendingSync" validate:"nonzero"` + LastConnection string `json:"lastConnection" validate:"nonzero"` + LastConnectionAt string `json:"lastConnectionAt" validate:"nonzero"` +} diff --git a/haivision/haivision.go b/haivision/haivision.go index 37c7854..00bcb04 100644 --- a/haivision/haivision.go +++ b/haivision/haivision.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + "github.com/Allan-Nava/Haivision-go-sdk/haivision/device" + "github.com/Allan-Nava/Haivision-go-sdk/haivision/session" "github.com/go-resty/resty/v2" ) @@ -18,9 +20,9 @@ type IHaivisionClient interface { HealthCheck() error IsDebug() bool // auth stuff - InitSession(username string, password string) (*BaseResponseInitSession, error) - GetSessionInfo() (*ResponseSessionInfo, error) - GetDeviceInfo() (*BaseResponseDeviceInfo, error) + InitSession(username string, password string) (*session.BaseResponseInitSession, error) + GetSessionInfo() (*session.ResponseSessionInfo, error) + GetDeviceInfo() (*device.BaseResponseDeviceInfo, error) // Streaming GetRoutes(deviceId string) error // CreateRoute() error diff --git a/haivision/request.go b/haivision/request.go index 2095a41..bc9bfea 100644 --- a/haivision/request.go +++ b/haivision/request.go @@ -12,17 +12,6 @@ type RequestSourceModelUDPandRTP struct { Fec string `json:"fec" required:"true" validate:"nonnil,min=1"` } -// https://doc.haivision.com/HMG3.7.5/rest-api-integrator-s-reference/rest-api-reference/object-model-reference/source-object-model?activetab=SRT%7EUDPandRTP - -type RequestSourceModelSRT struct { - Name string `json:"name" required:"true" validate:"nonnil,min=1"` - ID string `json:"id" required:"true" validate:"nonnil,min=1"` - Address string `json:"address" required:"true" validate:"nonnil,min=1"` - Protocol string `json:"protocol" required:"true" validate:"nonnil,min=1"` - Port int `json:"port" required:"true" validate:"nonnil,min=1"` - NetworkInterface string `json:"networkInterface" required:"true" validate:"nonnil,min=1"` -} - /* { "action": "create", diff --git a/haivision/response.go b/haivision/response.go deleted file mode 100644 index de5e712..0000000 --- a/haivision/response.go +++ /dev/null @@ -1,89 +0,0 @@ -package haivision - -/* - { - "response": { - "type": "Session", - "message": "Session successfully started for haiadmin", - "sessionID": "[Session ID]", - "lastLoginDate": 1536777877871, - "numLoginFailures": 0 - } - } -*/ -type BaseResponseInitSession struct { - Response ResponseInitSession `json:"response" validate:"nonzero"` -} - -type ResponseInitSession struct { - Type string `json:"type" validate:"nonzero"` - Message string `json:"message" validate:"nonzero"` - SessionID string `json:"sessionID" validate:"nonzero"` - LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"` - NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"` -} - -/* - { - "sessionID": "[Session ID]", - "displayName": "Administrator", - "email": "haiadmin@localhost", - "roles": [ - "Administrator" - ], - "startAt": 1536937838919, - "expireAt": 1536938857529, - "lastLoginDate": null, - "numLoginFailures": null, - "isLicensed": true - } -*/ -type ResponseSessionInfo struct { - SessionID string `json:"sessionID" validate:"nonzero"` - DisplayName string `json:"displayName" validate:"nonzero"` - Email string `json:"email" validate:"nonzero"` - Roles []string `json:"roles" validate:"nonzero"` - StartAt int64 `json:"startAt" validate:"nonzero"` - ExpireAt int64 `json:"expireAt" validate:"nonzero"` - LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"` - NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"` - IsLicensed bool `json:"isLicensed" validate:"nonzero"` -} - -type BaseResponseDeviceInfo struct { - Responses []ResponseDeviceInfo -} - -/* - { - "_id": "[Device ID]", - "type": "gateway", - "ip": "127.0.0.1", - "name": "Haivision Gateway", - "lastConnectedAt": [Date/time shown in Unix time], - "statusCode": "ok", - "status": "Online", - "statusDetails": "Connection has been established in the last 1 minutes.", - "serialNumber": null, - "firmware": "5.0.180611.1530", - "hasAdminError": false, - "pendingSync": false, - "lastConnection": "<1m" - } -*/ -type ResponseDeviceInfo struct { - ID string `json:"_id" validate:"nonzero"` - Type string `json:"type" validate:"nonzero"` - IP string `json:"ip" validate:"nonzero"` - Name string `json:"name" validate:"nonzero"` - LastConnectedAt int64 `json:"lastConnectedAt" validate:"nonzero"` - StatusCode string `json:"statusCode" validate:"nonzero"` - Status string `json:"status" validate:"nonzero"` - StatusDetails string `json:"statusDetails" validate:"nonzero"` - SerialNumber string `json:"serialNumber" validate:"nonzero"` - Firmware string `json:"firmware" validate:"nonzero"` - HasAdminError bool `json:"hasAdminError" validate:"nonzero"` - PendingSync bool `json:"pendingSync" validate:"nonzero"` - LastConnection string `json:"lastConnection" validate:"nonzero"` - LastConnectionAt string `json:"lastConnectionAt" validate:"nonzero"` -} diff --git a/haivision/session/response.go b/haivision/session/response.go index ab87616..fc7024d 100644 --- a/haivision/session/response.go +++ b/haivision/session/response.go @@ -1 +1,51 @@ package session + +/* + { + "response": { + "type": "Session", + "message": "Session successfully started for haiadmin", + "sessionID": "[Session ID]", + "lastLoginDate": 1536777877871, + "numLoginFailures": 0 + } + } +*/ +type BaseResponseInitSession struct { + Response ResponseInitSession `json:"response" validate:"nonzero"` +} + +type ResponseInitSession struct { + Type string `json:"type" validate:"nonzero"` + Message string `json:"message" validate:"nonzero"` + SessionID string `json:"sessionID" validate:"nonzero"` + LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"` + NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"` +} + +/* + { + "sessionID": "[Session ID]", + "displayName": "Administrator", + "email": "haiadmin@localhost", + "roles": [ + "Administrator" + ], + "startAt": 1536937838919, + "expireAt": 1536938857529, + "lastLoginDate": null, + "numLoginFailures": null, + "isLicensed": true + } +*/ +type ResponseSessionInfo struct { + SessionID string `json:"sessionID" validate:"nonzero"` + DisplayName string `json:"displayName" validate:"nonzero"` + Email string `json:"email" validate:"nonzero"` + Roles []string `json:"roles" validate:"nonzero"` + StartAt int64 `json:"startAt" validate:"nonzero"` + ExpireAt int64 `json:"expireAt" validate:"nonzero"` + LastLoginDate int64 `json:"lastLoginDate" validate:"nonzero"` + NumLoginFailures int `json:"numLoginFailures" validate:"nonzero"` + IsLicensed bool `json:"isLicensed" validate:"nonzero"` +} diff --git a/haivision/srt/request.go b/haivision/srt/request.go index a0320e6..7313678 100644 --- a/haivision/srt/request.go +++ b/haivision/srt/request.go @@ -1 +1,12 @@ package srt + +// https://doc.haivision.com/HMG3.7.5/rest-api-integrator-s-reference/rest-api-reference/object-model-reference/source-object-model?activetab=SRT%7EUDPandRTP + +type RequestSourceModelSRT struct { + Name string `json:"name" required:"true" validate:"nonnil,min=1"` + ID string `json:"id" required:"true" validate:"nonnil,min=1"` + Address string `json:"address" required:"true" validate:"nonnil,min=1"` + Protocol string `json:"protocol" required:"true" validate:"nonnil,min=1"` + Port int `json:"port" required:"true" validate:"nonnil,min=1"` + NetworkInterface string `json:"networkInterface" required:"true" validate:"nonnil,min=1"` +}