Skip to content

Commit

Permalink
refactor buildHaivision
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Feb 7, 2023
1 parent ac46e8e commit c823669
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
16 changes: 14 additions & 2 deletions haivision/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Response
}
}
*/
func (o *Haivision) InitSession(username string, password string) (*session.BaseResponseInitSession, error) {
func (o *haivisionSdk) InitSession(username string, password string) (*session.BaseResponseInitSession, error) {
requestBody := &session.RequestInitSession{
Username: username,
Password: password,
Expand Down Expand Up @@ -78,7 +78,7 @@ Response
]
*/
func (o *Haivision) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) {
func (o *haivisionSdk) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) {
resp, err := o.restyGet(DEVICE_INFO, nil)
if err != nil {
return nil, err
Expand All @@ -93,3 +93,15 @@ func (o *Haivision) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) {
}

//

func (o *haivisionSdk) GetSessionInfo() (*session.ResponseSessionInfo, error) {
resp, err := o.restyGet(SESSION, nil)
if err != nil {
return nil, err
}
var obj session.ResponseSessionInfo
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
return &obj, nil
}
6 changes: 3 additions & 3 deletions haivision/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

// Builder is used to build a new haivision client
func BuildHaivision(url string, debug bool, username string, password string, header *HeaderConfigurator, insecure *bool) (*Haivision, error) {
func BuildHaivision(url string, debug bool, username string, password string, header *HeaderConfigurator, insecure *bool) (IHaivisionClient, error) {
// init haivision
haivisionClient := &Haivision{
haivisionClient := &haivisionSdk{
Url: url,
restClient: resty.New(),
}
Expand Down Expand Up @@ -57,7 +57,7 @@ func BuildHaivision(url string, debug bool, username string, password string, he
return haivisionClient, nil
}

func (o *Haivision) debugPrint(data interface{}) {
func (o *haivisionSdk) debugPrint(data interface{}) {
if o.debug {
log.Println(data)
}
Expand Down
10 changes: 5 additions & 5 deletions haivision/haivision.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
udprtp "github.com/Allan-Nava/Haivision-go-sdk/haivision/udp_rtp"
)

type Haivision struct {
type haivisionSdk struct {
Url string
restClient *resty.Client
DeviceID string
Expand Down Expand Up @@ -57,7 +57,7 @@ type IHaivisionClient interface {
//
}

func (o *Haivision) HealthCheck() error {
func (o *haivisionSdk) HealthCheck() error {
_, err := o.restyGet(o.Url, nil)
if err != nil {
return nil
Expand All @@ -67,13 +67,13 @@ func (o *Haivision) HealthCheck() error {

//

func (o *Haivision) IsDebug() bool {
func (o *haivisionSdk) IsDebug() bool {
return o.debug
}

// Resty Methods

func (o *Haivision) restyPost(url string, body interface{}) (*resty.Response, error) {
func (o *haivisionSdk) restyPost(url string, body interface{}) (*resty.Response, error) {
resp, err := o.restClient.R().
SetHeader("Accept", "application/json").
SetBody(body).
Expand All @@ -91,7 +91,7 @@ func (o *Haivision) restyPost(url string, body interface{}) (*resty.Response, er
}

// get request
func (o *Haivision) restyGet(url string, queryParams map[string]string) (*resty.Response, error) {
func (o *haivisionSdk) restyGet(url string, queryParams map[string]string) (*resty.Response, error) {
resp, err := o.restClient.R().
SetQueryParams(queryParams).
Get(url)
Expand Down
21 changes: 15 additions & 6 deletions haivision/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (o *Haivision) GetRoutesUdpRtp(deviceId string) (*route.ResponseRoutes[udpr
return nil, nil
}*/

func (o *Haivision) GetRoutes(deviceId string) (*resty.Response, error) {
func (o *haivisionSdk) GetRoutes(deviceId string) (*resty.Response, error) {
log.Println("GetRoutes ", deviceId)
resp, err := o.restyGet(GET_LIST_OF_ROUTES(deviceId), nil)
if err != nil {
Expand All @@ -62,6 +62,15 @@ func (o *Haivision) GetRoutes(deviceId string) (*resty.Response, error) {
return resp, nil
}

func (o *haivisionSdk) GetRouteConfiguration(deviceId string, routeId string) (*resty.Response, error) {
log.Println("GetRouteConfiguration ", deviceId, routeId)
resp, err := o.restyGet(GET_ROUTE_CONFIGURATION(deviceId, routeId), nil)
if err != nil {
return nil, err
}
return resp, nil
}

/*
Use this command to create an individual route.
Expand Down Expand Up @@ -94,7 +103,7 @@ Response
}
*/

func (o *Haivision) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt.RequestSourceModelSRT, srt.RequestDestinationModelSrt]) (*route.ResponseCreateRoute, error) {
func (o *haivisionSdk) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt.RequestSourceModelSRT, srt.RequestDestinationModelSrt]) (*route.ResponseCreateRoute, error) {
log.Println("CreateRouteSrt ", deviceId)

if errs := validator.Validate(rBody); errs != nil {
Expand All @@ -112,7 +121,7 @@ func (o *Haivision) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt.
}
return &obj, nil
}
func (o *Haivision) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtmp.RequestSourceModelRTMP, rtmp.RequestDestinationModelRtmp]) (*route.ResponseCreateRoute, error) {
func (o *haivisionSdk) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtmp.RequestSourceModelRTMP, rtmp.RequestDestinationModelRtmp]) (*route.ResponseCreateRoute, error) {
log.Println("CreateRouteRtmp ", deviceId)
if errs := validator.Validate(rBody); errs != nil {
// values not valid, deal with errors here
Expand All @@ -129,7 +138,7 @@ func (o *Haivision) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtm
}
return &obj, nil
}
func (o *Haivision) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rtsp.RequestSourceModelRTSP, rtsp.RequestDestinationModelRtsp]) (*route.ResponseCreateRoute, error) {
func (o *haivisionSdk) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rtsp.RequestSourceModelRTSP, rtsp.RequestDestinationModelRtsp]) (*route.ResponseCreateRoute, error) {
log.Println("CreateRouteRtsp ", deviceId)
if errs := validator.Validate(rBody); errs != nil {
// values not valid, deal with errors here
Expand All @@ -147,7 +156,7 @@ func (o *Haivision) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rts
return &obj, nil
}

func (o *Haivision) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[udprtp.RequestSourceModelUdpRtp, udprtp.RequestDestinationModelUdpRtp]) (*route.ResponseCreateRoute, error) {
func (o *haivisionSdk) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[udprtp.RequestSourceModelUdpRtp, udprtp.RequestDestinationModelUdpRtp]) (*route.ResponseCreateRoute, error) {
log.Println("CreateRouteUdpRtp ", deviceId)
if errs := validator.Validate(rBody); errs != nil {
// values not valid, deal with errors here
Expand All @@ -165,7 +174,7 @@ func (o *Haivision) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[u
}

// Start or Stop a route
func (o *Haivision) StartOrStopRoute(deviceId string, routeId string, command string) (*route.ResponseStartOrRoute, error) {
func (o *haivisionSdk) StartOrStopRoute(deviceId string, routeId string, command string) (*route.ResponseStartOrRoute, error) {
log.Println("StartOrStopRoute ", deviceId, routeId, command)
if command != route.START_ROUTE && command != route.STOP_ROUTE {
return nil, errors.New("command must be start-route or stop-route")
Expand Down
10 changes: 5 additions & 5 deletions haivision/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ GET /api/gateway/[Device ID]/statistics?routeID=[Route ID]
cookie: sessionID: [Session ID]
*/

func (o *Haivision) GetRouteStatistics(deviceId string, routeId string) (*stats.ResponseRouteStatistics, error) {
func (o *haivisionSdk) GetRouteStatistics(deviceId string, routeId string) (*stats.ResponseRouteStatistics, error) {
log.Println("GetStats ", deviceId, routeId)
queryParams := map[string]string{
"routeID": routeId,
Expand All @@ -34,7 +34,7 @@ GET /api/gateway/[Device ID]/statistics?routeID=[Route ID]&sourceID=[Source ID]
cookie: sessionID: [Session ID]
*/

func (o *Haivision) GetSourceStatistics(deviceId string, routeId string, sourceId string) (*stats.ResponseSourceStatistics, error) {
func (o *haivisionSdk) GetSourceStatistics(deviceId string, routeId string, sourceId string) (*stats.ResponseSourceStatistics, error) {
log.Println("GetStats ", deviceId, routeId, sourceId)
queryParams := map[string]string{
"routeID": routeId,
Expand Down Expand Up @@ -65,7 +65,7 @@ cookie: sessionID: [Session ID]
*/

func (o *Haivision) GetDestinationStatisticsById(deviceId string, routeId string, destinationID string) (*stats.ResponseDestinationStatistics, error) {
func (o *haivisionSdk) GetDestinationStatisticsById(deviceId string, routeId string, destinationID string) (*stats.ResponseDestinationStatistics, error) {
log.Println("GetStats ", deviceId, routeId, destinationID)
queryParams := map[string]string{
"routeID": routeId,
Expand All @@ -82,7 +82,7 @@ func (o *Haivision) GetDestinationStatisticsById(deviceId string, routeId string
return &obj, nil
}

func (o *Haivision) GetDestinationStatisticsByName(deviceId string, routeId string, destinationName string) (*stats.ResponseDestinationStatistics, error) {
func (o *haivisionSdk) GetDestinationStatisticsByName(deviceId string, routeId string, destinationName string) (*stats.ResponseDestinationStatistics, error) {
log.Println("GetStats ", deviceId, routeId, destinationName)
queryParams := map[string]string{
"routeID": routeId,
Expand All @@ -105,7 +105,7 @@ GET /api/gateway/[Device ID]/statistics/client?routeID=[Route ID]&destinationID=
cookie: sessionID: [Session ID]
*/

func (o *Haivision) GetSrtClientStatistics(deviceId string, routeId string, destinationID string, clientAddress string, clientPort string) (*stats.ResponseSrtClientStatistics, error) {
func (o *haivisionSdk) GetSrtClientStatistics(deviceId string, routeId string, destinationID string, clientAddress string, clientPort string) (*stats.ResponseSrtClientStatistics, error) {
log.Println("GetStats ", deviceId, routeId, destinationID)
queryParams := map[string]string{
"routeID": routeId,
Expand Down

0 comments on commit c823669

Please sign in to comment.