-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfpl_api.go
More file actions
60 lines (51 loc) · 1.84 KB
/
fpl_api.go
File metadata and controls
60 lines (51 loc) · 1.84 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package api
import (
"github.com/SecurityDo/ingext_api/client"
"github.com/SecurityDo/ingext_api/model"
)
// FPLService provides helpers for calling FPL report/task/result endpoints.
type FPLService struct {
client *client.IngextClient
}
// NewFPLService constructs an FPLService instance backed by the provided client.
func NewFPLService(client *client.IngextClient) *FPLService {
return &FPLService{client: client}
}
func (s *FPLService) call(function string, payload interface{}, out interface{}) error {
return ApiCall(s.client, function, payload, out)
}
// FPLIDRequest is the kargs payload for get_fpl_task and get_fpl_result.
type FPLIDRequest struct {
ID uint `json:"id"`
FPL bool `json:"fpl"`
}
// RunFPLV2ReportResponse is the response from run_fplv2_report (task id).
type RunFPLV2ReportResponse struct {
ID uint `json:"taskID"`
}
// RunReport calls /api/ds/run_fplv2_report with the given request and returns the task id.
func (s *FPLService) RunReport(req *model.RunFPLV2Report) (uint, error) {
var resp RunFPLV2ReportResponse
if err := s.call("run_fplv2_report", req, &resp); err != nil {
return 0, err
}
return resp.ID, nil
}
// GetTaskByID calls /api/ds/get_fpl_task with kargs {id: id} and returns the task response.
func (s *FPLService) GetTaskByID(id uint) (*model.GetTaskResponse, error) {
req := &FPLIDRequest{ID: id, FPL: true}
var resp model.GetTaskResponse
if err := s.call("get_fplv2_task", req, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// GetResultsByID calls /api/ds/get_fpl_result with kargs {id: id} and returns the metric result.
func (s *FPLService) GetResultsByID(id uint) (*model.GetMetricFPLResultResponse, error) {
req := &FPLIDRequest{ID: id, FPL: true}
var resp model.GetMetricFPLResultResponse
if err := s.call("get_fplv2_result", req, &resp); err != nil {
return nil, err
}
return &resp, nil
}