-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscenario.go
79 lines (62 loc) · 2.03 KB
/
scenario.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package autify
import (
"context"
"fmt"
"time"
)
type ScenarioList struct {
ID int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ProjectURL string `json:"project_url,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Scenario struct {
Name string `json:"name,omitempty"`
CreatedAt time.Time `json:"created_at"`
ProjectURL string `json:"project_url,omitempty"`
Steps []Step `json:"steps,omitempty"`
}
type Step struct {
ID int64 `json:"id,omitempty"`
RowOrder int `json:"row_order,omitempty"`
SourceType string `json:"source_type,omitempty"`
StepKeyword StepKeyword `json:"step_keyword,omitempty"`
}
type StepKeyword struct {
ID int64 `json:"id,omitempty"`
StepArguments []StepArgument `json:"step_arguments,omitempty"`
TranslatedKeyword TranslatedKeyword `json:"translated_keyword,omitempty"`
}
type TranslatedKeyword struct {
ID int64 `json:"id,omitempty"`
AbstractTemplate string `json:"abstract_template,omitempty"`
CreatedAt time.Time `json:"created_at"`
Name string `json:"name,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}
type StepArgument struct {
ID int64 `json:"id,omitempty"`
Value string `json:"value,omitempty"`
}
func (c *Client) ListScenario(ctx context.Context, projectID int64, page int) ([]ScenarioList, error) {
url := fmt.Sprintf("projects/%d/scenarios", projectID)
if params := buildQuery(Page(&page)); params != "" {
url += "?" + params
}
var targetScenarios []ScenarioList
err := c.get(ctx, url, &targetScenarios)
if err != nil {
return []ScenarioList{}, err
}
return targetScenarios, nil
}
func (c *Client) Scenario(ctx context.Context, projectID int64, id int64) (*Scenario, error) {
url := fmt.Sprintf("projects/%d/scenarios/%d", projectID, id)
var result Scenario
err := c.get(ctx, url, &result)
if err != nil {
return nil, nil
}
return &result, nil
}