@@ -179,45 +179,33 @@ type CreateTestAuditLogRequest struct {
179
179
180
180
// AuditLogs retrieves audit logs from the given page.
181
181
func (c * Client ) AuditLogs (ctx context.Context , req AuditLogsRequest ) (AuditLogResponse , error ) {
182
- res , err := c .Request (ctx , http .MethodGet , "/api/v2/audit" , nil , req .Pagination .asRequestOption (), func (r * http.Request ) {
183
- q := r .URL .Query ()
184
- var params []string
185
- if req .SearchQuery != "" {
186
- params = append (params , req .SearchQuery )
187
- }
188
- q .Set ("q" , strings .Join (params , " " ))
189
- r .URL .RawQuery = q .Encode ()
182
+ return makeSDKRequest [AuditLogResponse ](ctx , c , sdkRequestArgs {
183
+ Method : http .MethodGet ,
184
+ URL : "/api/v2/audit" ,
185
+ ReqOpts : []RequestOption {
186
+ req .Pagination .asRequestOption (),
187
+ func (r * http.Request ) {
188
+ q := r .URL .Query ()
189
+ var params []string
190
+ if req .SearchQuery != "" {
191
+ params = append (params , req .SearchQuery )
192
+ }
193
+ q .Set ("q" , strings .Join (params , " " ))
194
+ r .URL .RawQuery = q .Encode ()
195
+ },
196
+ },
197
+ ExpectCode : http .StatusOK ,
190
198
})
191
- if err != nil {
192
- return AuditLogResponse {}, err
193
- }
194
- defer res .Body .Close ()
195
-
196
- if res .StatusCode != http .StatusOK {
197
- return AuditLogResponse {}, ReadBodyAsError (res )
198
- }
199
-
200
- var logRes AuditLogResponse
201
- err = json .NewDecoder (res .Body ).Decode (& logRes )
202
- if err != nil {
203
- return AuditLogResponse {}, err
204
- }
205
-
206
- return logRes , nil
207
199
}
208
200
209
201
// CreateTestAuditLog creates a fake audit log. Only owners of the organization
210
202
// can perform this action. It's used for testing purposes.
211
203
func (c * Client ) CreateTestAuditLog (ctx context.Context , req CreateTestAuditLogRequest ) error {
212
- res , err := c .Request (ctx , http .MethodPost , "/api/v2/audit/testgenerate" , req )
213
- if err != nil {
214
- return err
215
- }
216
- defer res .Body .Close ()
217
-
218
- if res .StatusCode != http .StatusNoContent {
219
- return err
220
- }
221
-
222
- return nil
204
+ _ , err := makeSDKRequest [noResponse ](ctx , c , sdkRequestArgs {
205
+ Method : http .MethodPost ,
206
+ URL : "/api/v2/audit/testgenerate" ,
207
+ Body : req ,
208
+ ExpectCode : http .StatusNoContent ,
209
+ })
210
+ return err
223
211
}
0 commit comments