Skip to content

Commit

Permalink
add operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabrin committed Oct 21, 2024
1 parent 7072544 commit d0e21d5
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions operations.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
package disk

// TODO
import (
"context"
"encoding/json"
"fmt"
"net/http"
)

// func (c *Client) Status(ctx context.Context, operationId string, params *QueryParams) (*Operation, *ErrorResponse) {
// return nil, nil
// }
// TODO: add tests and use generics instead of interface{}
func (c *Client) OperationStatus(ctx context.Context, operationID string) (interface{}, *http.Response, error) {
resp, err := c.doRequest(ctx, GET, fmt.Sprintf("operations/operation_id=%s", operationID), nil)
if err != nil {
return nil, nil, fmt.Errorf("failed to make request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
var errorResp ErrorResponse
if err := json.NewDecoder(resp.Body).Decode(&errorResp); err != nil {
return nil, resp, fmt.Errorf("failed to decode error response: %w", err)
}
return &errorResp, resp, nil
}

var operation Operation
if err := json.NewDecoder(resp.Body).Decode(&operation); err != nil {
return nil, resp, fmt.Errorf("failed to decode operation: %w", err)
}

return &operation, resp, nil
}

0 comments on commit d0e21d5

Please sign in to comment.