From 3dccbe5a0ebeddf46badd7b149b1ab3c02556bcd Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Thu, 25 Jul 2024 15:52:29 +0000 Subject: [PATCH] feat(specs): add v2 endpoints for ingestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/algolia/api-clients-automation/pull/3416 Co-authored-by: algolia-bot Co-authored-by: Clément Vannicatte --- algolia/ingestion/api_ingestion.go | 151 ++++++++++++++++++ algolia/ingestion/model_action.go | 75 +++++++++ algolia/ingestion/model_batch_request.go | 103 ++++++++++++ algolia/ingestion/model_batch_write_params.go | 71 ++++++++ 4 files changed, 400 insertions(+) create mode 100644 algolia/ingestion/model_action.go create mode 100644 algolia/ingestion/model_batch_request.go create mode 100644 algolia/ingestion/model_batch_write_params.go diff --git a/algolia/ingestion/api_ingestion.go b/algolia/ingestion/api_ingestion.go index bfc80ff98..344a8856f 100644 --- a/algolia/ingestion/api_ingestion.go +++ b/algolia/ingestion/api_ingestion.go @@ -5740,6 +5740,157 @@ func (c *APIClient) ListTransformations(r ApiListTransformationsRequest, opts .. return returnValue, nil } +func (r *ApiPushTaskRequest) UnmarshalJSON(b []byte) error { + req := map[string]json.RawMessage{} + err := json.Unmarshal(b, &req) + if err != nil { + return fmt.Errorf("cannot unmarshal request: %w", err) + } + if v, ok := req["taskID"]; ok { + err = json.Unmarshal(v, &r.taskID) + if err != nil { + err = json.Unmarshal(b, &r.taskID) + if err != nil { + return fmt.Errorf("cannot unmarshal taskID: %w", err) + } + } + } + if v, ok := req["batchWriteParams"]; ok { + err = json.Unmarshal(v, &r.batchWriteParams) + if err != nil { + err = json.Unmarshal(b, &r.batchWriteParams) + if err != nil { + return fmt.Errorf("cannot unmarshal batchWriteParams: %w", err) + } + } + } else { + err = json.Unmarshal(b, &r.batchWriteParams) + if err != nil { + return fmt.Errorf("cannot unmarshal body parameter batchWriteParams: %w", err) + } + } + + return nil +} + +// ApiPushTaskRequest represents the request with all the parameters for the API call. +type ApiPushTaskRequest struct { + taskID string + batchWriteParams *BatchWriteParams +} + +// NewApiPushTaskRequest creates an instance of the ApiPushTaskRequest to be used for the API call. +func (c *APIClient) NewApiPushTaskRequest(taskID string, batchWriteParams *BatchWriteParams) ApiPushTaskRequest { + return ApiPushTaskRequest{ + taskID: taskID, + batchWriteParams: batchWriteParams, + } +} + +/* +PushTask calls the API and returns the raw response from it. + + Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the observability endpoints. + + Required API Key ACLs: + - addObject + - deleteIndex + - editSettings + + Request can be constructed by NewApiPushTaskRequest with parameters below. + @param taskID string - Unique identifier of a task. + @param batchWriteParams BatchWriteParams - Request body of a Search API `batch` request that will be pushed in the Connectors pipeline. + @param opts ...RequestOption - Optional parameters for the API call + @return *http.Response - The raw response from the API + @return []byte - The raw response body from the API + @return error - An error if the API call fails +*/ +func (c *APIClient) PushTaskWithHTTPInfo(r ApiPushTaskRequest, opts ...RequestOption) (*http.Response, []byte, error) { + requestPath := "/2/tasks/{taskID}/push" + requestPath = strings.ReplaceAll(requestPath, "{taskID}", url.PathEscape(utils.ParameterToString(r.taskID))) + + if r.taskID == "" { + return nil, nil, reportError("Parameter `taskID` is required when calling `PushTask`.") + } + + if r.batchWriteParams == nil { + return nil, nil, reportError("Parameter `batchWriteParams` is required when calling `PushTask`.") + } + + conf := config{ + context: context.Background(), + queryParams: url.Values{}, + headerParams: map[string]string{}, + } + + // optional params if any + for _, opt := range opts { + opt.apply(&conf) + } + + var postBody any + + // body params + postBody = r.batchWriteParams + req, err := c.prepareRequest(conf.context, requestPath, http.MethodPost, postBody, conf.headerParams, conf.queryParams) + if err != nil { + return nil, nil, err + } + + return c.callAPI(req, false) +} + +/* +PushTask casts the HTTP response body to a defined struct. + +Push a `batch` request payload through the Pipeline. You can check the status of task pushes with the observability endpoints. + +Required API Key ACLs: + - addObject + - deleteIndex + - editSettings + +Request can be constructed by NewApiPushTaskRequest with parameters below. + + @param taskID string - Unique identifier of a task. + @param batchWriteParams BatchWriteParams - Request body of a Search API `batch` request that will be pushed in the Connectors pipeline. + @return RunResponse +*/ +func (c *APIClient) PushTask(r ApiPushTaskRequest, opts ...RequestOption) (*RunResponse, error) { + var returnValue *RunResponse + + res, resBody, err := c.PushTaskWithHTTPInfo(r, opts...) + if err != nil { + return returnValue, err + } + if res == nil { + return returnValue, reportError("res is nil") + } + + if res.StatusCode >= 300 { + newErr := &APIError{ + Message: string(resBody), + Status: res.StatusCode, + } + + var v ErrorBase + err = c.decode(&v, resBody) + if err != nil { + newErr.Message = err.Error() + return returnValue, newErr + } + + return returnValue, newErr + } + + err = c.decode(&returnValue, resBody) + if err != nil { + return returnValue, reportError("cannot decode result: %w", err) + } + + return returnValue, nil +} + func (r *ApiRunTaskRequest) UnmarshalJSON(b []byte) error { req := map[string]json.RawMessage{} err := json.Unmarshal(b, &req) diff --git a/algolia/ingestion/model_action.go b/algolia/ingestion/model_action.go new file mode 100644 index 000000000..fe1a18f8e --- /dev/null +++ b/algolia/ingestion/model_action.go @@ -0,0 +1,75 @@ +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. +package ingestion + +import ( + "encoding/json" + "fmt" +) + +// Action Type of indexing operation. +type Action string + +// List of action. +const ( + ACTION_ADD_OBJECT Action = "addObject" + ACTION_UPDATE_OBJECT Action = "updateObject" + ACTION_PARTIAL_UPDATE_OBJECT Action = "partialUpdateObject" + ACTION_PARTIAL_UPDATE_OBJECT_NO_CREATE Action = "partialUpdateObjectNoCreate" + ACTION_DELETE_OBJECT Action = "deleteObject" + ACTION_DELETE Action = "delete" + ACTION_CLEAR Action = "clear" +) + +// All allowed values of Action enum. +var AllowedActionEnumValues = []Action{ + "addObject", + "updateObject", + "partialUpdateObject", + "partialUpdateObjectNoCreate", + "deleteObject", + "delete", + "clear", +} + +func (v *Action) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return fmt.Errorf("failed to unmarshal value '%s' for enum 'Action': %w", string(src), err) + } + enumTypeValue := Action(value) + for _, existing := range AllowedActionEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid Action", value) +} + +// NewActionFromValue returns a pointer to a valid Action +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewActionFromValue(v string) (*Action, error) { + ev := Action(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for Action: valid values are %v", v, AllowedActionEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v Action) IsValid() bool { + for _, existing := range AllowedActionEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to action value. +func (v Action) Ptr() *Action { + return &v +} diff --git a/algolia/ingestion/model_batch_request.go b/algolia/ingestion/model_batch_request.go new file mode 100644 index 000000000..dc53d3c2a --- /dev/null +++ b/algolia/ingestion/model_batch_request.go @@ -0,0 +1,103 @@ +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. +package ingestion + +import ( + "encoding/json" + "fmt" +) + +// BatchRequest struct for BatchRequest. +type BatchRequest struct { + Action Action `json:"action"` + // Operation arguments (varies with specified `action`). + Body map[string]any `json:"body"` +} + +// NewBatchRequest instantiates a new BatchRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchRequest(action Action, body map[string]any) *BatchRequest { + this := &BatchRequest{} + this.Action = action + this.Body = body + return this +} + +// NewEmptyBatchRequest return a pointer to an empty BatchRequest object. +func NewEmptyBatchRequest() *BatchRequest { + return &BatchRequest{} +} + +// GetAction returns the Action field value. +func (o *BatchRequest) GetAction() Action { + if o == nil { + var ret Action + return ret + } + + return o.Action +} + +// GetActionOk returns a tuple with the Action field value +// and a boolean to check if the value has been set. +func (o *BatchRequest) GetActionOk() (*Action, bool) { + if o == nil { + return nil, false + } + return &o.Action, true +} + +// SetAction sets field value. +func (o *BatchRequest) SetAction(v Action) *BatchRequest { + o.Action = v + return o +} + +// GetBody returns the Body field value. +func (o *BatchRequest) GetBody() map[string]any { + if o == nil { + var ret map[string]any + return ret + } + + return o.Body +} + +// GetBodyOk returns a tuple with the Body field value +// and a boolean to check if the value has been set. +func (o *BatchRequest) GetBodyOk() (map[string]any, bool) { + if o == nil { + return nil, false + } + return o.Body, true +} + +// SetBody sets field value. +func (o *BatchRequest) SetBody(v map[string]any) *BatchRequest { + o.Body = v + return o +} + +func (o BatchRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]any{} + if true { + toSerialize["action"] = o.Action + } + if true { + toSerialize["body"] = o.Body + } + serialized, err := json.Marshal(toSerialize) + if err != nil { + return nil, fmt.Errorf("failed to marshal BatchRequest: %w", err) + } + + return serialized, nil +} + +func (o BatchRequest) String() string { + out := "" + out += fmt.Sprintf(" action=%v\n", o.Action) + out += fmt.Sprintf(" body=%v\n", o.Body) + return fmt.Sprintf("BatchRequest {\n%s}", out) +} diff --git a/algolia/ingestion/model_batch_write_params.go b/algolia/ingestion/model_batch_write_params.go new file mode 100644 index 000000000..af713c070 --- /dev/null +++ b/algolia/ingestion/model_batch_write_params.go @@ -0,0 +1,71 @@ +// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. +package ingestion + +import ( + "encoding/json" + "fmt" +) + +// BatchWriteParams Batch parameters. +type BatchWriteParams struct { + Requests []BatchRequest `json:"requests"` +} + +// NewBatchWriteParams instantiates a new BatchWriteParams object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewBatchWriteParams(requests []BatchRequest) *BatchWriteParams { + this := &BatchWriteParams{} + this.Requests = requests + return this +} + +// NewEmptyBatchWriteParams return a pointer to an empty BatchWriteParams object. +func NewEmptyBatchWriteParams() *BatchWriteParams { + return &BatchWriteParams{} +} + +// GetRequests returns the Requests field value. +func (o *BatchWriteParams) GetRequests() []BatchRequest { + if o == nil { + var ret []BatchRequest + return ret + } + + return o.Requests +} + +// GetRequestsOk returns a tuple with the Requests field value +// and a boolean to check if the value has been set. +func (o *BatchWriteParams) GetRequestsOk() ([]BatchRequest, bool) { + if o == nil { + return nil, false + } + return o.Requests, true +} + +// SetRequests sets field value. +func (o *BatchWriteParams) SetRequests(v []BatchRequest) *BatchWriteParams { + o.Requests = v + return o +} + +func (o BatchWriteParams) MarshalJSON() ([]byte, error) { + toSerialize := map[string]any{} + if true { + toSerialize["requests"] = o.Requests + } + serialized, err := json.Marshal(toSerialize) + if err != nil { + return nil, fmt.Errorf("failed to marshal BatchWriteParams: %w", err) + } + + return serialized, nil +} + +func (o BatchWriteParams) String() string { + out := "" + out += fmt.Sprintf(" requests=%v\n", o.Requests) + return fmt.Sprintf("BatchWriteParams {\n%s}", out) +}