/
sims_get_data.go
168 lines (122 loc) · 4.68 KB
/
sims_get_data.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Code generated by soracom-cli generate-cmd. DO NOT EDIT.
package cmd
import (
"fmt"
"net/url"
"os"
"github.com/spf13/cobra"
)
// SimsGetDataCmdLastEvaluatedKey holds value of 'last_evaluated_key' option
var SimsGetDataCmdLastEvaluatedKey string
// SimsGetDataCmdSimId holds value of 'sim_id' option
var SimsGetDataCmdSimId string
// SimsGetDataCmdSort holds value of 'sort' option
var SimsGetDataCmdSort string
// SimsGetDataCmdFrom holds value of 'from' option
var SimsGetDataCmdFrom int64
// SimsGetDataCmdLimit holds value of 'limit' option
var SimsGetDataCmdLimit int64
// SimsGetDataCmdTo holds value of 'to' option
var SimsGetDataCmdTo int64
// SimsGetDataCmdPaginate indicates to do pagination or not
var SimsGetDataCmdPaginate bool
// SimsGetDataCmdOutputJSONL indicates to output with jsonl format
var SimsGetDataCmdOutputJSONL bool
func InitSimsGetDataCmd() {
SimsGetDataCmd.Flags().StringVar(&SimsGetDataCmdLastEvaluatedKey, "last-evaluated-key", "", TRAPI("Key in the last data entry retrieved in the previous page. The key for data entries in this API is '${UNIX time in milliseconds}_${IMSI}'. By specifying this parameter, you can continue to retrieve the list from the next page onward."))
SimsGetDataCmd.Flags().StringVar(&SimsGetDataCmdSimId, "sim-id", "", TRAPI("SIM ID of the target SIM."))
SimsGetDataCmd.Flags().StringVar(&SimsGetDataCmdSort, "sort", "desc", TRAPI("Sort order of the data entries. Either descending (latest data entry first) or ascending (oldest data entry first)."))
SimsGetDataCmd.Flags().Int64Var(&SimsGetDataCmdFrom, "from", 0, TRAPI("Start time for the data entries search range (UNIX time in milliseconds)."))
SimsGetDataCmd.Flags().Int64Var(&SimsGetDataCmdLimit, "limit", 0, TRAPI("Maximum number of data entries to retrieve (value range is 1 to 1000). The default is '10'."))
SimsGetDataCmd.Flags().Int64Var(&SimsGetDataCmdTo, "to", 0, TRAPI("End time for the data entries search range (UNIX time in milliseconds)."))
SimsGetDataCmd.Flags().BoolVar(&SimsGetDataCmdPaginate, "fetch-all", false, TRCLI("cli.common_params.paginate.short_help"))
SimsGetDataCmd.Flags().BoolVar(&SimsGetDataCmdOutputJSONL, "jsonl", false, TRCLI("cli.common_params.jsonl.short_help"))
SimsGetDataCmd.RunE = SimsGetDataCmdRunE
SimsCmd.AddCommand(SimsGetDataCmd)
}
// SimsGetDataCmd defines 'get-data' subcommand
var SimsGetDataCmd = &cobra.Command{
Use: "get-data",
Short: TRAPI("/sims/{sim_id}/data:get:summary"),
Long: TRAPI(`/sims/{sim_id}/data:get:description`) + "\n\n" + createLinkToAPIReference("Sim", "getDataFromSim"),
}
func SimsGetDataCmdRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("unexpected arguments passed => %v", args)
}
opt := &apiClientOptions{
BasePath: "/v1",
Language: getSelectedLanguage(),
}
ac := newAPIClient(opt)
if v := os.Getenv("SORACOM_VERBOSE"); v != "" {
ac.SetVerbose(true)
}
err := ac.getAPICredentials()
if err != nil {
cmd.SilenceUsage = true
return err
}
param, err := collectSimsGetDataCmdParams(ac)
if err != nil {
return err
}
body, err := ac.callAPI(param)
if err != nil {
cmd.SilenceUsage = true
return err
}
if body == "" {
return nil
}
if rawOutput {
_, err = os.Stdout.Write([]byte(body))
} else {
if SimsGetDataCmdOutputJSONL {
return printStringAsJSONL(body)
}
return prettyPrintStringAsJSON(body)
}
return err
}
func collectSimsGetDataCmdParams(ac *apiClient) (*apiParams, error) {
var parsedBody interface{}
var err error
err = checkIfRequiredStringParameterIsSupplied("sim_id", "sim-id", "path", parsedBody, SimsGetDataCmdSimId)
if err != nil {
return nil, err
}
return &apiParams{
method: "GET",
path: buildPathForSimsGetDataCmd("/sims/{sim_id}/data"),
query: buildQueryForSimsGetDataCmd(),
doPagination: SimsGetDataCmdPaginate,
paginationKeyHeaderInResponse: "x-soracom-next-key",
paginationRequestParameterInQuery: "last_evaluated_key",
noRetryOnError: noRetryOnError,
}, nil
}
func buildPathForSimsGetDataCmd(path string) string {
escapedSimId := url.PathEscape(SimsGetDataCmdSimId)
path = strReplace(path, "{"+"sim_id"+"}", escapedSimId, -1)
return path
}
func buildQueryForSimsGetDataCmd() url.Values {
result := url.Values{}
if SimsGetDataCmdLastEvaluatedKey != "" {
result.Add("last_evaluated_key", SimsGetDataCmdLastEvaluatedKey)
}
if SimsGetDataCmdSort != "desc" {
result.Add("sort", SimsGetDataCmdSort)
}
if SimsGetDataCmdFrom != 0 {
result.Add("from", sprintf("%d", SimsGetDataCmdFrom))
}
if SimsGetDataCmdLimit != 0 {
result.Add("limit", sprintf("%d", SimsGetDataCmdLimit))
}
if SimsGetDataCmdTo != 0 {
result.Add("to", sprintf("%d", SimsGetDataCmdTo))
}
return result
}