Skip to content

Commit

Permalink
added new api
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Feb 6, 2023
1 parent 44e72be commit 2019ffb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 21 deletions.
92 changes: 88 additions & 4 deletions mist/mist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ type IMistGoClient interface {
IsDebug() bool
//debugPrint(data interface{})
// Auth
Authenticate(auth AuthorizeCommand) (*ResponseAuth, error)
Authenticate(auth AuthorizeCommand) (*ResponseBase, error)
// Capabilities
GetCapabilities() (*ResponseBase, error)
// Stream
AddStream(streamName string, source string) (*ResponseBase, error)
ActiveStreams() (*ResponseBase, error)
//
}

/*func NewMistGoClient(url string, debug bool) *mistGo {
Expand All @@ -45,7 +50,7 @@ func (o *mistGo) IsDebug() bool {
return o.debug
}

func (o *mistGo) Authenticate(auth AuthorizeCommand) (*ResponseAuth, error) {
func (o *mistGo) Authenticate(auth AuthorizeCommand) (*ResponseBase, error) {
//
if errs := validator.Validate(auth); errs != nil {
// values not valid, deal with errors here
Expand All @@ -68,7 +73,85 @@ func (o *mistGo) Authenticate(auth AuthorizeCommand) (*ResponseAuth, error) {
}
o.debugPrint(resp)
//
var obj ResponseAuth
var obj ResponseBase
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
return &obj, nil
}

func (o *mistGo) GetCapabilities() (*ResponseBase, error) {
rBody := &CapabilitiesCommand{
Capabilites: true,
}
b, err := json.Marshal(rBody)
if err != nil {
return nil, err
}
request := map[string]string{
"command": string(b),
}
resp, err := o.restyGet(COMMAND_URL, request)
if err != nil {
return nil, err
}
o.debugPrint(resp)
//
var obj ResponseBase
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
return &obj, nil
}

func (o *mistGo) AddStream(streamName string, source string) (*ResponseBase, error) {
rBody := &AddStreamCommand{
AddStream: map[string]interface{}{
streamName: struct {
Source string `json:"source"`
}{
Source: source,
},
},
}
b, err := json.Marshal(rBody)
if err != nil {
return nil, err
}
request := map[string]string{
"command": string(b),
}
resp, err := o.restyGet(COMMAND_URL, request)
if err != nil {
return nil, err
}
o.debugPrint(resp)
//
var obj ResponseBase
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
return &obj, nil
}

func (o *mistGo) ActiveStreams() (*ResponseBase, error) {
rBody := &ActiveStreamsCommand{
ActiveStreams: "",
}
b, err := json.Marshal(rBody)
if err != nil {
return nil, err
}
request := map[string]string{
"command": string(b),
}
resp, err := o.restyGet(COMMAND_URL, request)
if err != nil {
return nil, err
}
o.debugPrint(resp)
//
var obj ResponseBase
if err := json.Unmarshal(resp.Body(), &obj); err != nil {
return nil, err
}
Expand All @@ -77,7 +160,7 @@ func (o *mistGo) Authenticate(auth AuthorizeCommand) (*ResponseAuth, error) {

// Resty Methods

func (o *mistGo) restyPost(url string, body interface{}) (*resty.Response, error) {
/*func (o *mistGo) restyPost(url string, body interface{}) (*resty.Response, error) {
resp, err := o.restClient.R().
SetHeader("Accept", "application/json").
SetBody(body).
Expand All @@ -93,6 +176,7 @@ func (o *mistGo) restyPost(url string, body interface{}) (*resty.Response, error
}
return resp, nil
}
*/

func (o *mistGo) restyGet(url string, queryParams map[string]string) (*resty.Response, error) {
resp, err := o.restClient.R().
Expand Down
13 changes: 7 additions & 6 deletions mist/request.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mist_go

/*
{"authorize":{"username":"","password":""}}
{"authorize":{"username":"","password":""}}
*/
type AuthCommand struct {
Authorize AuthorizeCommand `json:"authorize"`
Expand All @@ -11,6 +11,7 @@ type AuthorizeCommand struct {
Username string `json:"username"`
Password string `json:"password"`
}

//

/*
Expand Down Expand Up @@ -63,15 +64,15 @@ type PushListCommand struct {
"outputs",
"views",
"viewseconds",
"upbytes",
"downbytes",
"upbytes",
"downbytes",
"packsent",
"packloss",
"packretrans",
"zerounix",
"health",
"tracks",
"health",
"tracks",
"status"
]
}
*/
*/
21 changes: 10 additions & 11 deletions mist/response.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package mist_go


/*
{
"authorize": {
"challenge": "",
"status": "CHALL"
}
}
{
"authorize": {
"challenge": "",
"status": "CHALL"
}
}
*/
type ResponseAuth struct {
type ResponseBase struct {
Authorize Authorize `json:"authorize"`
}

type Authorize struct {
Challenge string `json:"challenge"`
Status string `json:"status"`
}
Challenge string `json:"challenge"`
Status string `json:"status"`
}

0 comments on commit 2019ffb

Please sign in to comment.