From 67383d0cfb894b639d6e65e50cb630557a124c57 Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Tue, 20 Aug 2024 09:13:51 +0000 Subject: [PATCH] refactor(abtesting): consistent naming (generated) Co-authored-by: Fernando Beck --- .../algoliasearch/Clients/AbtestingClient.cs | 68 ++++ .../Abtesting/ScheduleABTestResponse.cs | 93 +++++ .../Abtesting/ScheduleABTestsRequest.cs | 141 +++++++ .../algolia/abtesting/api_abtesting.go | 130 ++++++ .../model_schedule_ab_test_response.go | 72 ++++ .../model_schedule_ab_tests_request.go | 168 ++++++++ .../java/com/algolia/api/AbtestingClient.java | 52 +++ .../abtesting/ScheduleABTestResponse.java | 62 +++ .../abtesting/ScheduleABTestsRequest.java | 119 ++++++ .../packages/client-abtesting/model/index.ts | 2 + .../model/scheduleABTestResponse.ts | 8 + .../model/scheduleABTestsRequest.ts | 25 ++ .../client-abtesting/src/abtestingClient.ts | 57 +++ .../com/algolia/client/api/AbtestingClient.kt | 20 + .../model/abtesting/ScheduleABTestResponse.kt | 17 + .../model/abtesting/ScheduleABTestsRequest.kt | 29 ++ .../lib/Api/AbtestingClient.php | 36 ++ .../Abtesting/ScheduleABTestResponse.php | 231 +++++++++++ .../Abtesting/ScheduleABTestsRequest.php | 350 ++++++++++++++++ .../algoliasearch/abtesting/client.py | 64 +++ .../models/schedule_ab_test_response.py | 63 +++ .../models/schedule_ab_tests_request.py | 94 +++++ .../lib/algolia/api/abtesting_client.rb | 44 +++ .../abtesting/schedule_ab_test_response.rb | 214 ++++++++++ .../abtesting/schedule_ab_tests_request.rb | 270 +++++++++++++ .../abtesting/ScheduleABTestResponse.scala | 33 ++ .../abtesting/ScheduleABTestsRequest.scala | 42 ++ .../algoliasearch/api/AbtestingClient.scala | 24 ++ .../Sources/Abtesting/AbtestingClient.swift | 46 +++ .../Models/ScheduleABTestResponse.swift | 39 ++ .../Models/ScheduleABTestsRequest.swift | 60 +++ snippets/csharp/src/Abtesting.cs | 32 ++ snippets/go/src/abtesting.go | 32 ++ snippets/guides/abtesting-snippets.json | 30 ++ .../src/test/java/com/algolia/Abtesting.java | 24 ++ snippets/javascript/src/abtesting.ts | 28 ++ .../kotlin/com/algolia/snippets/Abtesting.kt | 31 ++ snippets/php/src/Abtesting.php | 33 ++ snippets/python/abtesting.py | 37 ++ snippets/ruby/abtesting.rb | 29 ++ snippets/scala/src/main/scala/Abtesting.scala | 33 ++ snippets/swift/Sources/Abtesting.swift | 21 + specs/bundled/abtesting.doc.yml | 372 ++++++++++++++++++ specs/bundled/abtesting.yml | 77 ++++ .../src/generated/requests/Abtesting.test.cs | 29 ++ .../go/tests/requests/abtesting_test.go | 22 ++ .../com/algolia/requests/Abtesting.test.java | 29 ++ .../javascript/src/requests/abtesting.test.ts | 27 ++ .../com/algolia/requests/AbtestingTest.kt | 32 ++ .../output/php/src/requests/AbtestingTest.php | 29 ++ .../python/tests/requests/abtesting_test.py | 30 ++ .../ruby/test/requests/abtesting_test.rb | 26 ++ .../requests/AbtestingTest.scala | 32 ++ .../swift/Tests/requests/AbtestingTests.swift | 38 ++ 54 files changed, 3746 insertions(+) create mode 100644 clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestResponse.cs create mode 100644 clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestsRequest.cs create mode 100644 clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_test_response.go create mode 100644 clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_tests_request.go create mode 100644 clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestResponse.java create mode 100644 clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestsRequest.java create mode 100644 clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestResponse.ts create mode 100644 clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestsRequest.ts create mode 100644 clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestResponse.kt create mode 100644 clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestsRequest.kt create mode 100644 clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestResponse.php create mode 100644 clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestsRequest.php create mode 100644 clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_test_response.py create mode 100644 clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_tests_request.py create mode 100644 clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_test_response.rb create mode 100644 clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_tests_request.rb create mode 100644 clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestResponse.scala create mode 100644 clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestsRequest.scala create mode 100644 clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestResponse.swift create mode 100644 clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestsRequest.swift diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Clients/AbtestingClient.cs b/clients/algoliasearch-client-csharp/algoliasearch/Clients/AbtestingClient.cs index 3bfa8f02709..59e3e6df007 100644 --- a/clients/algoliasearch-client-csharp/algoliasearch/Clients/AbtestingClient.cs +++ b/clients/algoliasearch-client-csharp/algoliasearch/Clients/AbtestingClient.cs @@ -231,6 +231,30 @@ public interface IAbtestingClient /// ListABTestsResponse ListABTestsResponse ListABTests(int? offset = default, int? limit = default, string indexPrefix = default, string indexSuffix = default, RequestOptions options = null, CancellationToken cancellationToken = default); + /// + /// Schedule an A/B test to be started at a later time. + /// + /// + /// Add extra http header or query parameters to Algolia. + /// Cancellation Token to cancel the request. + /// Thrown when arguments are not correct + /// Thrown when the API call was rejected by Algolia + /// Thrown when the client failed to call the endpoint + /// Task of ScheduleABTestResponse + Task ScheduleABTestAsync(ScheduleABTestsRequest scheduleABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default); + + /// + /// Schedule an A/B test to be started at a later time. (Synchronous version) + /// + /// + /// Add extra http header or query parameters to Algolia. + /// Cancellation Token to cancel the request. + /// Thrown when arguments are not correct + /// Thrown when the API call was rejected by Algolia + /// Thrown when the client failed to call the endpoint + /// ScheduleABTestResponse + ScheduleABTestResponse ScheduleABTest(ScheduleABTestsRequest scheduleABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default); + /// /// Stops an A/B test by its ID. You can't restart stopped A/B tests. /// @@ -664,6 +688,50 @@ public ListABTestsResponse ListABTests(int? offset = default, int? limit = defau AsyncHelper.RunSync(() => ListABTestsAsync(offset, limit, indexPrefix, indexSuffix, options, cancellationToken)); + /// + /// Schedule an A/B test to be started at a later time. + /// + /// + /// Required API Key ACLs: + /// - editSettings + /// + /// Add extra http header or query parameters to Algolia. + /// Cancellation Token to cancel the request. + /// Thrown when arguments are not correct + /// Thrown when the API call was rejected by Algolia + /// Thrown when the client failed to call the endpoint + /// Task of ScheduleABTestResponse + public async Task ScheduleABTestAsync(ScheduleABTestsRequest scheduleABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default) + { + + if (scheduleABTestsRequest == null) + throw new ArgumentException("Parameter `scheduleABTestsRequest` is required when calling `ScheduleABTest`."); + + var requestOptions = new InternalRequestOptions(options); + + + requestOptions.Data = scheduleABTestsRequest; + return await _transport.ExecuteRequestAsync(new HttpMethod("POST"), "/2/abtests/schedule", requestOptions, cancellationToken).ConfigureAwait(false); + } + + + /// + /// Schedule an A/B test to be started at a later time. (Synchronous version) + /// + /// + /// Required API Key ACLs: + /// - editSettings + /// + /// Add extra http header or query parameters to Algolia. + /// Cancellation Token to cancel the request. + /// Thrown when arguments are not correct + /// Thrown when the API call was rejected by Algolia + /// Thrown when the client failed to call the endpoint + /// ScheduleABTestResponse + public ScheduleABTestResponse ScheduleABTest(ScheduleABTestsRequest scheduleABTestsRequest, RequestOptions options = null, CancellationToken cancellationToken = default) => + AsyncHelper.RunSync(() => ScheduleABTestAsync(scheduleABTestsRequest, options, cancellationToken)); + + /// /// Stops an A/B test by its ID. You can't restart stopped A/B tests. /// diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestResponse.cs b/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestResponse.cs new file mode 100644 index 00000000000..04ab960e1cb --- /dev/null +++ b/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestResponse.cs @@ -0,0 +1,93 @@ +// +// 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. +// +using System; +using System.Text; +using System.Linq; +using System.Text.Json.Serialization; +using System.Collections.Generic; +using Algolia.Search.Serializer; +using System.Text.Json; + +namespace Algolia.Search.Models.Abtesting; + +/// +/// ScheduleABTestResponse +/// +public partial class ScheduleABTestResponse +{ + /// + /// Initializes a new instance of the ScheduleABTestResponse class. + /// + [JsonConstructor] + public ScheduleABTestResponse() { } + /// + /// Initializes a new instance of the ScheduleABTestResponse class. + /// + /// Unique scheduled A/B test identifier. (required). + public ScheduleABTestResponse(int abTestScheduleID) + { + AbTestScheduleID = abTestScheduleID; + } + + /// + /// Unique scheduled A/B test identifier. + /// + /// Unique scheduled A/B test identifier. + [JsonPropertyName("abTestScheduleID")] + public int AbTestScheduleID { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class ScheduleABTestResponse {\n"); + sb.Append(" AbTestScheduleID: ").Append(AbTestScheduleID).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return JsonSerializer.Serialize(this, JsonConfig.Options); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is not ScheduleABTestResponse input) + { + return false; + } + + return + (AbTestScheduleID == input.AbTestScheduleID || AbTestScheduleID.Equals(input.AbTestScheduleID)); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + hashCode = (hashCode * 59) + AbTestScheduleID.GetHashCode(); + return hashCode; + } + } + +} + diff --git a/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestsRequest.cs b/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestsRequest.cs new file mode 100644 index 00000000000..708fc896eee --- /dev/null +++ b/clients/algoliasearch-client-csharp/algoliasearch/Models/Abtesting/ScheduleABTestsRequest.cs @@ -0,0 +1,141 @@ +// +// 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. +// +using System; +using System.Text; +using System.Linq; +using System.Text.Json.Serialization; +using System.Collections.Generic; +using Algolia.Search.Serializer; +using System.Text.Json; + +namespace Algolia.Search.Models.Abtesting; + +/// +/// ScheduleABTestsRequest +/// +public partial class ScheduleABTestsRequest +{ + /// + /// Initializes a new instance of the ScheduleABTestsRequest class. + /// + [JsonConstructor] + public ScheduleABTestsRequest() { } + /// + /// Initializes a new instance of the ScheduleABTestsRequest class. + /// + /// A/B test name. (required). + /// A/B test variants. (required). + /// Date and time when the A/B test is scheduled to start, in RFC 3339 format. (required). + /// End date and time of the A/B test, in RFC 3339 format. (required). + public ScheduleABTestsRequest(string name, List variants, string scheduledAt, string endAt) + { + Name = name ?? throw new ArgumentNullException(nameof(name)); + Variants = variants ?? throw new ArgumentNullException(nameof(variants)); + ScheduledAt = scheduledAt ?? throw new ArgumentNullException(nameof(scheduledAt)); + EndAt = endAt ?? throw new ArgumentNullException(nameof(endAt)); + } + + /// + /// A/B test name. + /// + /// A/B test name. + [JsonPropertyName("name")] + public string Name { get; set; } + + /// + /// A/B test variants. + /// + /// A/B test variants. + [JsonPropertyName("variants")] + public List Variants { get; set; } + + /// + /// Date and time when the A/B test is scheduled to start, in RFC 3339 format. + /// + /// Date and time when the A/B test is scheduled to start, in RFC 3339 format. + [JsonPropertyName("scheduledAt")] + public string ScheduledAt { get; set; } + + /// + /// End date and time of the A/B test, in RFC 3339 format. + /// + /// End date and time of the A/B test, in RFC 3339 format. + [JsonPropertyName("endAt")] + public string EndAt { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.Append("class ScheduleABTestsRequest {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" Variants: ").Append(Variants).Append("\n"); + sb.Append(" ScheduledAt: ").Append(ScheduledAt).Append("\n"); + sb.Append(" EndAt: ").Append(EndAt).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + /// + /// Returns the JSON string presentation of the object + /// + /// JSON string presentation of the object + public virtual string ToJson() + { + return JsonSerializer.Serialize(this, JsonConfig.Options); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object obj) + { + if (obj is not ScheduleABTestsRequest input) + { + return false; + } + + return + (Name == input.Name || (Name != null && Name.Equals(input.Name))) && + (Variants == input.Variants || Variants != null && input.Variants != null && Variants.SequenceEqual(input.Variants)) && + (ScheduledAt == input.ScheduledAt || (ScheduledAt != null && ScheduledAt.Equals(input.ScheduledAt))) && + (EndAt == input.EndAt || (EndAt != null && EndAt.Equals(input.EndAt))); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (Name != null) + { + hashCode = (hashCode * 59) + Name.GetHashCode(); + } + if (Variants != null) + { + hashCode = (hashCode * 59) + Variants.GetHashCode(); + } + if (ScheduledAt != null) + { + hashCode = (hashCode * 59) + ScheduledAt.GetHashCode(); + } + if (EndAt != null) + { + hashCode = (hashCode * 59) + EndAt.GetHashCode(); + } + return hashCode; + } + } + +} + diff --git a/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go b/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go index 750c6c05526..290b92519c2 100644 --- a/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go +++ b/clients/algoliasearch-client-go/algolia/abtesting/api_abtesting.go @@ -1219,6 +1219,136 @@ func (c *APIClient) ListABTests(r ApiListABTestsRequest, opts ...RequestOption) return returnValue, nil } +func (r *ApiScheduleABTestRequest) 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["scheduleABTestsRequest"]; ok { + err = json.Unmarshal(v, &r.scheduleABTestsRequest) + if err != nil { + err = json.Unmarshal(b, &r.scheduleABTestsRequest) + if err != nil { + return fmt.Errorf("cannot unmarshal scheduleABTestsRequest: %w", err) + } + } + } else { + err = json.Unmarshal(b, &r.scheduleABTestsRequest) + if err != nil { + return fmt.Errorf("cannot unmarshal body parameter scheduleABTestsRequest: %w", err) + } + } + + return nil +} + +// ApiScheduleABTestRequest represents the request with all the parameters for the API call. +type ApiScheduleABTestRequest struct { + scheduleABTestsRequest *ScheduleABTestsRequest +} + +// NewApiScheduleABTestRequest creates an instance of the ApiScheduleABTestRequest to be used for the API call. +func (c *APIClient) NewApiScheduleABTestRequest(scheduleABTestsRequest *ScheduleABTestsRequest) ApiScheduleABTestRequest { + return ApiScheduleABTestRequest{ + scheduleABTestsRequest: scheduleABTestsRequest, + } +} + +/* +ScheduleABTest calls the API and returns the raw response from it. + + Schedule an A/B test to be started at a later time. + + + Required API Key ACLs: + - editSettings + + Request can be constructed by NewApiScheduleABTestRequest with parameters below. + @param scheduleABTestsRequest ScheduleABTestsRequest + @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) ScheduleABTestWithHTTPInfo(r ApiScheduleABTestRequest, opts ...RequestOption) (*http.Response, []byte, error) { + requestPath := "/2/abtests/schedule" + + if r.scheduleABTestsRequest == nil { + return nil, nil, reportError("Parameter `scheduleABTestsRequest` is required when calling `ScheduleABTest`.") + } + + 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.scheduleABTestsRequest + 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) +} + +/* +ScheduleABTest casts the HTTP response body to a defined struct. + +Schedule an A/B test to be started at a later time. + +Required API Key ACLs: + - editSettings + +Request can be constructed by NewApiScheduleABTestRequest with parameters below. + + @param scheduleABTestsRequest ScheduleABTestsRequest + @return ScheduleABTestResponse +*/ +func (c *APIClient) ScheduleABTest(r ApiScheduleABTestRequest, opts ...RequestOption) (*ScheduleABTestResponse, error) { + var returnValue *ScheduleABTestResponse + + res, resBody, err := c.ScheduleABTestWithHTTPInfo(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 *ApiStopABTestRequest) UnmarshalJSON(b []byte) error { req := map[string]json.RawMessage{} err := json.Unmarshal(b, &req) diff --git a/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_test_response.go b/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_test_response.go new file mode 100644 index 00000000000..5c6dbbdaf07 --- /dev/null +++ b/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_test_response.go @@ -0,0 +1,72 @@ +// 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 abtesting + +import ( + "encoding/json" + "fmt" +) + +// ScheduleABTestResponse struct for ScheduleABTestResponse. +type ScheduleABTestResponse struct { + // Unique scheduled A/B test identifier. + AbTestScheduleID int32 `json:"abTestScheduleID"` +} + +// NewScheduleABTestResponse instantiates a new ScheduleABTestResponse 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 NewScheduleABTestResponse(abTestScheduleID int32) *ScheduleABTestResponse { + this := &ScheduleABTestResponse{} + this.AbTestScheduleID = abTestScheduleID + return this +} + +// NewEmptyScheduleABTestResponse return a pointer to an empty ScheduleABTestResponse object. +func NewEmptyScheduleABTestResponse() *ScheduleABTestResponse { + return &ScheduleABTestResponse{} +} + +// GetAbTestScheduleID returns the AbTestScheduleID field value. +func (o *ScheduleABTestResponse) GetAbTestScheduleID() int32 { + if o == nil { + var ret int32 + return ret + } + + return o.AbTestScheduleID +} + +// GetAbTestScheduleIDOk returns a tuple with the AbTestScheduleID field value +// and a boolean to check if the value has been set. +func (o *ScheduleABTestResponse) GetAbTestScheduleIDOk() (*int32, bool) { + if o == nil { + return nil, false + } + return &o.AbTestScheduleID, true +} + +// SetAbTestScheduleID sets field value. +func (o *ScheduleABTestResponse) SetAbTestScheduleID(v int32) *ScheduleABTestResponse { + o.AbTestScheduleID = v + return o +} + +func (o ScheduleABTestResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]any{} + if true { + toSerialize["abTestScheduleID"] = o.AbTestScheduleID + } + serialized, err := json.Marshal(toSerialize) + if err != nil { + return nil, fmt.Errorf("failed to marshal ScheduleABTestResponse: %w", err) + } + + return serialized, nil +} + +func (o ScheduleABTestResponse) String() string { + out := "" + out += fmt.Sprintf(" abTestScheduleID=%v\n", o.AbTestScheduleID) + return fmt.Sprintf("ScheduleABTestResponse {\n%s}", out) +} diff --git a/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_tests_request.go b/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_tests_request.go new file mode 100644 index 00000000000..a2bf3f6e662 --- /dev/null +++ b/clients/algoliasearch-client-go/algolia/abtesting/model_schedule_ab_tests_request.go @@ -0,0 +1,168 @@ +// 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 abtesting + +import ( + "encoding/json" + "fmt" +) + +// ScheduleABTestsRequest struct for ScheduleABTestsRequest. +type ScheduleABTestsRequest struct { + // A/B test name. + Name string `json:"name"` + // A/B test variants. + Variants []AddABTestsVariant `json:"variants"` + // Date and time when the A/B test is scheduled to start, in RFC 3339 format. + ScheduledAt string `json:"scheduledAt"` + // End date and time of the A/B test, in RFC 3339 format. + EndAt string `json:"endAt"` +} + +// NewScheduleABTestsRequest instantiates a new ScheduleABTestsRequest 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 NewScheduleABTestsRequest(name string, variants []AddABTestsVariant, scheduledAt string, endAt string) *ScheduleABTestsRequest { + this := &ScheduleABTestsRequest{} + this.Name = name + this.Variants = variants + this.ScheduledAt = scheduledAt + this.EndAt = endAt + return this +} + +// NewEmptyScheduleABTestsRequest return a pointer to an empty ScheduleABTestsRequest object. +func NewEmptyScheduleABTestsRequest() *ScheduleABTestsRequest { + return &ScheduleABTestsRequest{} +} + +// GetName returns the Name field value. +func (o *ScheduleABTestsRequest) GetName() string { + if o == nil { + var ret string + return ret + } + + return o.Name +} + +// GetNameOk returns a tuple with the Name field value +// and a boolean to check if the value has been set. +func (o *ScheduleABTestsRequest) GetNameOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Name, true +} + +// SetName sets field value. +func (o *ScheduleABTestsRequest) SetName(v string) *ScheduleABTestsRequest { + o.Name = v + return o +} + +// GetVariants returns the Variants field value. +func (o *ScheduleABTestsRequest) GetVariants() []AddABTestsVariant { + if o == nil { + var ret []AddABTestsVariant + return ret + } + + return o.Variants +} + +// GetVariantsOk returns a tuple with the Variants field value +// and a boolean to check if the value has been set. +func (o *ScheduleABTestsRequest) GetVariantsOk() ([]AddABTestsVariant, bool) { + if o == nil { + return nil, false + } + return o.Variants, true +} + +// SetVariants sets field value. +func (o *ScheduleABTestsRequest) SetVariants(v []AddABTestsVariant) *ScheduleABTestsRequest { + o.Variants = v + return o +} + +// GetScheduledAt returns the ScheduledAt field value. +func (o *ScheduleABTestsRequest) GetScheduledAt() string { + if o == nil { + var ret string + return ret + } + + return o.ScheduledAt +} + +// GetScheduledAtOk returns a tuple with the ScheduledAt field value +// and a boolean to check if the value has been set. +func (o *ScheduleABTestsRequest) GetScheduledAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.ScheduledAt, true +} + +// SetScheduledAt sets field value. +func (o *ScheduleABTestsRequest) SetScheduledAt(v string) *ScheduleABTestsRequest { + o.ScheduledAt = v + return o +} + +// GetEndAt returns the EndAt field value. +func (o *ScheduleABTestsRequest) GetEndAt() string { + if o == nil { + var ret string + return ret + } + + return o.EndAt +} + +// GetEndAtOk returns a tuple with the EndAt field value +// and a boolean to check if the value has been set. +func (o *ScheduleABTestsRequest) GetEndAtOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.EndAt, true +} + +// SetEndAt sets field value. +func (o *ScheduleABTestsRequest) SetEndAt(v string) *ScheduleABTestsRequest { + o.EndAt = v + return o +} + +func (o ScheduleABTestsRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]any{} + if true { + toSerialize["name"] = o.Name + } + if true { + toSerialize["variants"] = o.Variants + } + if true { + toSerialize["scheduledAt"] = o.ScheduledAt + } + if true { + toSerialize["endAt"] = o.EndAt + } + serialized, err := json.Marshal(toSerialize) + if err != nil { + return nil, fmt.Errorf("failed to marshal ScheduleABTestsRequest: %w", err) + } + + return serialized, nil +} + +func (o ScheduleABTestsRequest) String() string { + out := "" + out += fmt.Sprintf(" name=%v\n", o.Name) + out += fmt.Sprintf(" variants=%v\n", o.Variants) + out += fmt.Sprintf(" scheduledAt=%v\n", o.ScheduledAt) + out += fmt.Sprintf(" endAt=%v\n", o.EndAt) + return fmt.Sprintf("ScheduleABTestsRequest {\n%s}", out) +} diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/AbtestingClient.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/AbtestingClient.java index 4116916c839..e12cf180ab2 100644 --- a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/AbtestingClient.java +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/AbtestingClient.java @@ -748,6 +748,58 @@ public CompletableFuture listABTestsAsync() throws AlgoliaR return this.listABTestsAsync(null, null, null, null, null); } + /** + * Schedule an A/B test to be started at a later time. + * + * @param scheduleABTestsRequest (required) + * @param requestOptions The requestOptions to send along with the query, they will be merged with + * the transporter requestOptions. + * @throws AlgoliaRuntimeException If it fails to process the API call + */ + public ScheduleABTestResponse scheduleABTest(@Nonnull ScheduleABTestsRequest scheduleABTestsRequest, RequestOptions requestOptions) + throws AlgoliaRuntimeException { + return LaunderThrowable.await(scheduleABTestAsync(scheduleABTestsRequest, requestOptions)); + } + + /** + * Schedule an A/B test to be started at a later time. + * + * @param scheduleABTestsRequest (required) + * @throws AlgoliaRuntimeException If it fails to process the API call + */ + public ScheduleABTestResponse scheduleABTest(@Nonnull ScheduleABTestsRequest scheduleABTestsRequest) throws AlgoliaRuntimeException { + return this.scheduleABTest(scheduleABTestsRequest, null); + } + + /** + * (asynchronously) Schedule an A/B test to be started at a later time. + * + * @param scheduleABTestsRequest (required) + * @param requestOptions The requestOptions to send along with the query, they will be merged with + * the transporter requestOptions. + * @throws AlgoliaRuntimeException If it fails to process the API call + */ + public CompletableFuture scheduleABTestAsync( + @Nonnull ScheduleABTestsRequest scheduleABTestsRequest, + RequestOptions requestOptions + ) throws AlgoliaRuntimeException { + Parameters.requireNonNull(scheduleABTestsRequest, "Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`."); + + HttpRequest request = HttpRequest.builder().setPath("/2/abtests/schedule").setMethod("POST").setBody(scheduleABTestsRequest).build(); + return executeAsync(request, requestOptions, new TypeReference() {}); + } + + /** + * (asynchronously) Schedule an A/B test to be started at a later time. + * + * @param scheduleABTestsRequest (required) + * @throws AlgoliaRuntimeException If it fails to process the API call + */ + public CompletableFuture scheduleABTestAsync(@Nonnull ScheduleABTestsRequest scheduleABTestsRequest) + throws AlgoliaRuntimeException { + return this.scheduleABTestAsync(scheduleABTestsRequest, null); + } + /** * Stops an A/B test by its ID. You can't restart stopped A/B tests. * diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestResponse.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestResponse.java new file mode 100644 index 00000000000..66748e73d96 --- /dev/null +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestResponse.java @@ -0,0 +1,62 @@ +// 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 com.algolia.model.abtesting; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.annotation.*; +import java.util.Objects; + +/** ScheduleABTestResponse */ +public class ScheduleABTestResponse { + + @JsonProperty("abTestScheduleID") + private Integer abTestScheduleID; + + public ScheduleABTestResponse setAbTestScheduleID(Integer abTestScheduleID) { + this.abTestScheduleID = abTestScheduleID; + return this; + } + + /** Unique scheduled A/B test identifier. */ + @javax.annotation.Nonnull + public Integer getAbTestScheduleID() { + return abTestScheduleID; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScheduleABTestResponse scheduleABTestResponse = (ScheduleABTestResponse) o; + return Objects.equals(this.abTestScheduleID, scheduleABTestResponse.abTestScheduleID); + } + + @Override + public int hashCode() { + return Objects.hash(abTestScheduleID); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ScheduleABTestResponse {\n"); + sb.append(" abTestScheduleID: ").append(toIndentedString(abTestScheduleID)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestsRequest.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestsRequest.java new file mode 100644 index 00000000000..488f89bc783 --- /dev/null +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/model/abtesting/ScheduleABTestsRequest.java @@ -0,0 +1,119 @@ +// 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 com.algolia.model.abtesting; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.annotation.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** ScheduleABTestsRequest */ +public class ScheduleABTestsRequest { + + @JsonProperty("name") + private String name; + + @JsonProperty("variants") + private List variants = new ArrayList<>(); + + @JsonProperty("scheduledAt") + private String scheduledAt; + + @JsonProperty("endAt") + private String endAt; + + public ScheduleABTestsRequest setName(String name) { + this.name = name; + return this; + } + + /** A/B test name. */ + @javax.annotation.Nonnull + public String getName() { + return name; + } + + public ScheduleABTestsRequest setVariants(List variants) { + this.variants = variants; + return this; + } + + public ScheduleABTestsRequest addVariants(AddABTestsVariant variantsItem) { + this.variants.add(variantsItem); + return this; + } + + /** A/B test variants. */ + @javax.annotation.Nonnull + public List getVariants() { + return variants; + } + + public ScheduleABTestsRequest setScheduledAt(String scheduledAt) { + this.scheduledAt = scheduledAt; + return this; + } + + /** Date and time when the A/B test is scheduled to start, in RFC 3339 format. */ + @javax.annotation.Nonnull + public String getScheduledAt() { + return scheduledAt; + } + + public ScheduleABTestsRequest setEndAt(String endAt) { + this.endAt = endAt; + return this; + } + + /** End date and time of the A/B test, in RFC 3339 format. */ + @javax.annotation.Nonnull + public String getEndAt() { + return endAt; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScheduleABTestsRequest scheduleABTestsRequest = (ScheduleABTestsRequest) o; + return ( + Objects.equals(this.name, scheduleABTestsRequest.name) && + Objects.equals(this.variants, scheduleABTestsRequest.variants) && + Objects.equals(this.scheduledAt, scheduleABTestsRequest.scheduledAt) && + Objects.equals(this.endAt, scheduleABTestsRequest.endAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, variants, scheduledAt, endAt); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ScheduleABTestsRequest {\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" variants: ").append(toIndentedString(variants)).append("\n"); + sb.append(" scheduledAt: ").append(toIndentedString(scheduledAt)).append("\n"); + sb.append(" endAt: ").append(toIndentedString(endAt)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/model/index.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/index.ts index dd5df5ad0e6..2c7d1ab83b2 100644 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/model/index.ts +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/index.ts @@ -18,6 +18,8 @@ export * from './listABTestsResponse'; export * from './minimumDetectableEffect'; export * from './outliers'; export * from './outliersFilter'; +export * from './scheduleABTestResponse'; +export * from './scheduleABTestsRequest'; export * from './status'; export * from './variant'; export * from './clientMethodProps'; diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestResponse.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestResponse.ts new file mode 100644 index 00000000000..842b8109f8e --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestResponse.ts @@ -0,0 +1,8 @@ +// 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. + +export type ScheduleABTestResponse = { + /** + * Unique scheduled A/B test identifier. + */ + abTestScheduleID: number; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestsRequest.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestsRequest.ts new file mode 100644 index 00000000000..227f2e8207a --- /dev/null +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/model/scheduleABTestsRequest.ts @@ -0,0 +1,25 @@ +// 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. + +import type { AddABTestsVariant } from './addABTestsVariant'; + +export type ScheduleABTestsRequest = { + /** + * A/B test name. + */ + name: string; + + /** + * A/B test variants. + */ + variants: AddABTestsVariant[]; + + /** + * Date and time when the A/B test is scheduled to start, in RFC 3339 format. + */ + scheduledAt: string; + + /** + * End date and time of the A/B test, in RFC 3339 format. + */ + endAt: string; +}; diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingClient.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingClient.ts index eba666ec366..a133773c07c 100644 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingClient.ts +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingClient.ts @@ -28,6 +28,8 @@ import type { StopABTestProps, } from '../model/clientMethodProps'; import type { ListABTestsResponse } from '../model/listABTestsResponse'; +import type { ScheduleABTestResponse } from '../model/scheduleABTestResponse'; +import type { ScheduleABTestsRequest } from '../model/scheduleABTestsRequest'; export const apiClientVersion = '5.0.2'; @@ -407,6 +409,61 @@ export function createAbtestingClient({ return transporter.request(request, requestOptions); }, + /** + * Schedule an A/B test to be started at a later time. + * + * Required API Key ACLs: + * - editSettings. + * + * @param scheduleABTestsRequest - The scheduleABTestsRequest object. + * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. + */ + scheduleABTest( + scheduleABTestsRequest: ScheduleABTestsRequest, + requestOptions?: RequestOptions + ): Promise { + if (!scheduleABTestsRequest) { + throw new Error( + 'Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.' + ); + } + + if (!scheduleABTestsRequest.name) { + throw new Error( + 'Parameter `scheduleABTestsRequest.name` is required when calling `scheduleABTest`.' + ); + } + if (!scheduleABTestsRequest.variants) { + throw new Error( + 'Parameter `scheduleABTestsRequest.variants` is required when calling `scheduleABTest`.' + ); + } + if (!scheduleABTestsRequest.scheduledAt) { + throw new Error( + 'Parameter `scheduleABTestsRequest.scheduledAt` is required when calling `scheduleABTest`.' + ); + } + if (!scheduleABTestsRequest.endAt) { + throw new Error( + 'Parameter `scheduleABTestsRequest.endAt` is required when calling `scheduleABTest`.' + ); + } + + const requestPath = '/2/abtests/schedule'; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; + + const request: Request = { + method: 'POST', + path: requestPath, + queryParameters, + headers, + data: scheduleABTestsRequest, + }; + + return transporter.request(request, requestOptions); + }, + /** * Stops an A/B test by its ID. You can\'t restart stopped A/B tests. * diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/api/AbtestingClient.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/api/AbtestingClient.kt index 9ecc76a5176..55dc2bff66d 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/api/AbtestingClient.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/api/AbtestingClient.kt @@ -202,6 +202,26 @@ public class AbtestingClient( ) } + /** + * Schedule an A/B test to be started at a later time. + * + * Required API Key ACLs: + * - editSettings + * @param scheduleABTestsRequest + * @param requestOptions additional request configuration. + */ + public suspend fun scheduleABTest(scheduleABTestsRequest: ScheduleABTestsRequest, requestOptions: RequestOptions? = null): ScheduleABTestResponse { + val requestConfig = RequestConfig( + method = RequestMethod.POST, + path = listOf("2", "abtests", "schedule"), + body = scheduleABTestsRequest, + ) + return requester.execute( + requestConfig = requestConfig, + requestOptions = requestOptions, + ) + } + /** * Stops an A/B test by its ID. You can't restart stopped A/B tests. * diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestResponse.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestResponse.kt new file mode 100644 index 00000000000..fd865e75b0b --- /dev/null +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestResponse.kt @@ -0,0 +1,17 @@ +/** 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 com.algolia.client.model.abtesting + +import kotlinx.serialization.* +import kotlinx.serialization.json.* + +/** + * ScheduleABTestResponse + * + * @param abTestScheduleID Unique scheduled A/B test identifier. + */ +@Serializable +public data class ScheduleABTestResponse( + + /** Unique scheduled A/B test identifier. */ + @SerialName(value = "abTestScheduleID") val abTestScheduleID: Int, +) diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestsRequest.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestsRequest.kt new file mode 100644 index 00000000000..fcbdfd70127 --- /dev/null +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/model/abtesting/ScheduleABTestsRequest.kt @@ -0,0 +1,29 @@ +/** 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 com.algolia.client.model.abtesting + +import kotlinx.serialization.* +import kotlinx.serialization.json.* + +/** + * ScheduleABTestsRequest + * + * @param name A/B test name. + * @param variants A/B test variants. + * @param scheduledAt Date and time when the A/B test is scheduled to start, in RFC 3339 format. + * @param endAt End date and time of the A/B test, in RFC 3339 format. + */ +@Serializable +public data class ScheduleABTestsRequest( + + /** A/B test name. */ + @SerialName(value = "name") val name: String, + + /** A/B test variants. */ + @SerialName(value = "variants") val variants: List, + + /** Date and time when the A/B test is scheduled to start, in RFC 3339 format. */ + @SerialName(value = "scheduledAt") val scheduledAt: String, + + /** End date and time of the A/B test, in RFC 3339 format. */ + @SerialName(value = "endAt") val endAt: String, +) diff --git a/clients/algoliasearch-client-php/lib/Api/AbtestingClient.php b/clients/algoliasearch-client-php/lib/Api/AbtestingClient.php index 5aa0ab522e9..41b8d885f04 100644 --- a/clients/algoliasearch-client-php/lib/Api/AbtestingClient.php +++ b/clients/algoliasearch-client-php/lib/Api/AbtestingClient.php @@ -7,6 +7,7 @@ use Algolia\AlgoliaSearch\Algolia; use Algolia\AlgoliaSearch\Configuration\AbtestingConfig; use Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsRequest; +use Algolia\AlgoliaSearch\Model\Abtesting\ScheduleABTestsRequest; use Algolia\AlgoliaSearch\ObjectSerializer; use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper; use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapperInterface; @@ -408,6 +409,41 @@ public function listABTests($offset = null, $limit = null, $indexPrefix = null, return $this->sendRequest('GET', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions); } + /** + * Schedule an A/B test to be started at a later time. + * + * Required API Key ACLs: + * - editSettings + * + * @param array $scheduleABTestsRequest scheduleABTestsRequest (required) + * - $scheduleABTestsRequest['name'] => (string) A/B test name. (required) + * - $scheduleABTestsRequest['variants'] => (array) A/B test variants. (required) + * - $scheduleABTestsRequest['scheduledAt'] => (string) Date and time when the A/B test is scheduled to start, in RFC 3339 format. (required) + * - $scheduleABTestsRequest['endAt'] => (string) End date and time of the A/B test, in RFC 3339 format. (required) + * + * @see ScheduleABTestsRequest + * + * @param array $requestOptions the requestOptions to send along with the query, they will be merged with the transporter requestOptions + * + * @return \Algolia\AlgoliaSearch\Model\Abtesting\ScheduleABTestResponse|array + */ + public function scheduleABTest($scheduleABTestsRequest, $requestOptions = []) + { + // verify the required parameter 'scheduleABTestsRequest' is set + if (!isset($scheduleABTestsRequest)) { + throw new \InvalidArgumentException( + 'Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`.' + ); + } + + $resourcePath = '/2/abtests/schedule'; + $queryParameters = []; + $headers = []; + $httpBody = $scheduleABTestsRequest; + + return $this->sendRequest('POST', $resourcePath, $headers, $queryParameters, $httpBody, $requestOptions); + } + /** * Stops an A/B test by its ID. You can't restart stopped A/B tests. * diff --git a/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestResponse.php b/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestResponse.php new file mode 100644 index 00000000000..d05473ffe27 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestResponse.php @@ -0,0 +1,231 @@ + 'int', + ]; + + /** + * Array of property to format mappings. Used for (de)serialization. + * + * @var string[] + */ + protected static $modelFormats = [ + 'abTestScheduleID' => null, + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name. + * + * @var string[] + */ + protected static $attributeMap = [ + 'abTestScheduleID' => 'abTestScheduleID', + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses). + * + * @var string[] + */ + protected static $setters = [ + 'abTestScheduleID' => 'setAbTestScheduleID', + ]; + + /** + * Array of attributes to getter functions (for serialization of requests). + * + * @var string[] + */ + protected static $getters = [ + 'abTestScheduleID' => 'getAbTestScheduleID', + ]; + + /** + * Associative array for storing property values. + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor. + * + * @param mixed[] $data Associated array of property values + */ + public function __construct(?array $data = null) + { + if (isset($data['abTestScheduleID'])) { + $this->container['abTestScheduleID'] = $data['abTestScheduleID']; + } + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name. + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of property to type mappings. Used for (de)serialization. + * + * @return array + */ + public static function modelTypes() + { + return self::$modelTypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization. + * + * @return array + */ + public static function modelFormats() + { + return self::$modelFormats; + } + + /** + * Array of attributes to setter functions (for deserialization of responses). + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests). + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if (!isset($this->container['abTestScheduleID']) || null === $this->container['abTestScheduleID']) { + $invalidProperties[] = "'abTestScheduleID' can't be null"; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed. + * + * @return bool True if all properties are valid + */ + public function valid() + { + return 0 === count($this->listInvalidProperties()); + } + + /** + * Gets abTestScheduleID. + * + * @return int + */ + public function getAbTestScheduleID() + { + return $this->container['abTestScheduleID'] ?? null; + } + + /** + * Sets abTestScheduleID. + * + * @param int $abTestScheduleID unique scheduled A/B test identifier + * + * @return self + */ + public function setAbTestScheduleID($abTestScheduleID) + { + $this->container['abTestScheduleID'] = $abTestScheduleID; + + return $this; + } + + /** + * Returns true if offset exists. False otherwise. + * + * @param int $offset Offset + * + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param int $offset Offset + * + * @return null|mixed + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param null|int $offset Offset + * @param mixed $value Value to be set + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param int $offset Offset + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } +} diff --git a/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestsRequest.php b/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestsRequest.php new file mode 100644 index 00000000000..9bd22a7f2c9 --- /dev/null +++ b/clients/algoliasearch-client-php/lib/Model/Abtesting/ScheduleABTestsRequest.php @@ -0,0 +1,350 @@ + 'string', + 'variants' => '\Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsVariant[]', + 'scheduledAt' => 'string', + 'endAt' => 'string', + ]; + + /** + * Array of property to format mappings. Used for (de)serialization. + * + * @var string[] + */ + protected static $modelFormats = [ + 'name' => null, + 'variants' => null, + 'scheduledAt' => null, + 'endAt' => null, + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name. + * + * @var string[] + */ + protected static $attributeMap = [ + 'name' => 'name', + 'variants' => 'variants', + 'scheduledAt' => 'scheduledAt', + 'endAt' => 'endAt', + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses). + * + * @var string[] + */ + protected static $setters = [ + 'name' => 'setName', + 'variants' => 'setVariants', + 'scheduledAt' => 'setScheduledAt', + 'endAt' => 'setEndAt', + ]; + + /** + * Array of attributes to getter functions (for serialization of requests). + * + * @var string[] + */ + protected static $getters = [ + 'name' => 'getName', + 'variants' => 'getVariants', + 'scheduledAt' => 'getScheduledAt', + 'endAt' => 'getEndAt', + ]; + + /** + * Associative array for storing property values. + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor. + * + * @param mixed[] $data Associated array of property values + */ + public function __construct(?array $data = null) + { + if (isset($data['name'])) { + $this->container['name'] = $data['name']; + } + if (isset($data['variants'])) { + $this->container['variants'] = $data['variants']; + } + if (isset($data['scheduledAt'])) { + $this->container['scheduledAt'] = $data['scheduledAt']; + } + if (isset($data['endAt'])) { + $this->container['endAt'] = $data['endAt']; + } + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name. + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of property to type mappings. Used for (de)serialization. + * + * @return array + */ + public static function modelTypes() + { + return self::$modelTypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization. + * + * @return array + */ + public static function modelFormats() + { + return self::$modelFormats; + } + + /** + * Array of attributes to setter functions (for deserialization of responses). + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests). + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if (!isset($this->container['name']) || null === $this->container['name']) { + $invalidProperties[] = "'name' can't be null"; + } + if (!isset($this->container['variants']) || null === $this->container['variants']) { + $invalidProperties[] = "'variants' can't be null"; + } + if (count($this->container['variants']) > 2) { + $invalidProperties[] = "invalid value for 'variants', number of items must be less than or equal to 2."; + } + + if (count($this->container['variants']) < 2) { + $invalidProperties[] = "invalid value for 'variants', number of items must be greater than or equal to 2."; + } + + if (!isset($this->container['scheduledAt']) || null === $this->container['scheduledAt']) { + $invalidProperties[] = "'scheduledAt' can't be null"; + } + if (!isset($this->container['endAt']) || null === $this->container['endAt']) { + $invalidProperties[] = "'endAt' can't be null"; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed. + * + * @return bool True if all properties are valid + */ + public function valid() + { + return 0 === count($this->listInvalidProperties()); + } + + /** + * Gets name. + * + * @return string + */ + public function getName() + { + return $this->container['name'] ?? null; + } + + /** + * Sets name. + * + * @param string $name A/B test name + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets variants. + * + * @return \Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsVariant[] + */ + public function getVariants() + { + return $this->container['variants'] ?? null; + } + + /** + * Sets variants. + * + * @param \Algolia\AlgoliaSearch\Model\Abtesting\AddABTestsVariant[] $variants A/B test variants + * + * @return self + */ + public function setVariants($variants) + { + if (count($variants) > 2) { + throw new \InvalidArgumentException('invalid value for $variants when calling ScheduleABTestsRequest., number of items must be less than or equal to 2.'); + } + if (count($variants) < 2) { + throw new \InvalidArgumentException('invalid length for $variants when calling ScheduleABTestsRequest., number of items must be greater than or equal to 2.'); + } + $this->container['variants'] = $variants; + + return $this; + } + + /** + * Gets scheduledAt. + * + * @return string + */ + public function getScheduledAt() + { + return $this->container['scheduledAt'] ?? null; + } + + /** + * Sets scheduledAt. + * + * @param string $scheduledAt date and time when the A/B test is scheduled to start, in RFC 3339 format + * + * @return self + */ + public function setScheduledAt($scheduledAt) + { + $this->container['scheduledAt'] = $scheduledAt; + + return $this; + } + + /** + * Gets endAt. + * + * @return string + */ + public function getEndAt() + { + return $this->container['endAt'] ?? null; + } + + /** + * Sets endAt. + * + * @param string $endAt end date and time of the A/B test, in RFC 3339 format + * + * @return self + */ + public function setEndAt($endAt) + { + $this->container['endAt'] = $endAt; + + return $this; + } + + /** + * Returns true if offset exists. False otherwise. + * + * @param int $offset Offset + * + * @return bool + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param int $offset Offset + * + * @return null|mixed + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param null|int $offset Offset + * @param mixed $value Value to be set + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param int $offset Offset + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } +} diff --git a/clients/algoliasearch-client-python/algoliasearch/abtesting/client.py b/clients/algoliasearch-client-python/algoliasearch/abtesting/client.py index c01a22572b1..edf7d29a0f5 100644 --- a/clients/algoliasearch-client-python/algoliasearch/abtesting/client.py +++ b/clients/algoliasearch-client-python/algoliasearch/abtesting/client.py @@ -17,6 +17,12 @@ from algoliasearch.abtesting.models.ab_test_response import ABTestResponse from algoliasearch.abtesting.models.add_ab_tests_request import AddABTestsRequest from algoliasearch.abtesting.models.list_ab_tests_response import ListABTestsResponse +from algoliasearch.abtesting.models.schedule_ab_test_response import ( + ScheduleABTestResponse, +) +from algoliasearch.abtesting.models.schedule_ab_tests_request import ( + ScheduleABTestsRequest, +) from algoliasearch.http.api_response import ApiResponse from algoliasearch.http.request_options import RequestOptions from algoliasearch.http.serializer import bodySerializer @@ -706,6 +712,64 @@ async def list_ab_tests( ) ).deserialize(ListABTestsResponse) + async def schedule_ab_test_with_http_info( + self, + schedule_ab_tests_request: ScheduleABTestsRequest, + request_options: Optional[Union[dict, RequestOptions]] = None, + ) -> ApiResponse[str]: + """ + Schedule an A/B test to be started at a later time. + + Required API Key ACLs: + - editSettings + + :param schedule_ab_tests_request: (required) + :type schedule_ab_tests_request: ScheduleABTestsRequest + :param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + :return: Returns the raw algoliasearch 'APIResponse' object. + """ + + if schedule_ab_tests_request is None: + raise ValueError( + "Parameter `schedule_ab_tests_request` is required when calling `schedule_ab_test`." + ) + + _data = {} + if schedule_ab_tests_request is not None: + _data = schedule_ab_tests_request + + return await self._transporter.request( + verb=Verb.POST, + path="/2/abtests/schedule", + request_options=self._request_options.merge( + data=dumps(bodySerializer(_data)), + user_request_options=request_options, + ), + use_read_transporter=False, + ) + + async def schedule_ab_test( + self, + schedule_ab_tests_request: ScheduleABTestsRequest, + request_options: Optional[Union[dict, RequestOptions]] = None, + ) -> ScheduleABTestResponse: + """ + Schedule an A/B test to be started at a later time. + + Required API Key ACLs: + - editSettings + + :param schedule_ab_tests_request: (required) + :type schedule_ab_tests_request: ScheduleABTestsRequest + :param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + :return: Returns the deserialized response in a 'ScheduleABTestResponse' result object. + """ + return ( + await self.schedule_ab_test_with_http_info( + schedule_ab_tests_request, request_options + ) + ).deserialize(ScheduleABTestResponse) + async def stop_ab_test_with_http_info( self, id: Annotated[StrictInt, Field(description="Unique A/B test identifier.")], diff --git a/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_test_response.py b/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_test_response.py new file mode 100644 index 00000000000..e73227f0b34 --- /dev/null +++ b/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_test_response.py @@ -0,0 +1,63 @@ +# coding: utf-8 + +""" +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. +""" + +from __future__ import annotations + +from json import loads +from typing import Any, Dict, Self + +from pydantic import BaseModel, ConfigDict, Field, StrictInt + + +class ScheduleABTestResponse(BaseModel): + """ + ScheduleABTestResponse + """ + + ab_test_schedule_id: StrictInt = Field( + description="Unique scheduled A/B test identifier.", alias="abTestScheduleID" + ) + + model_config = ConfigDict( + use_enum_values=True, populate_by_name=True, validate_assignment=True + ) + + def to_json(self) -> str: + return self.model_dump_json(by_alias=True, exclude_unset=True) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of ScheduleABTestResponse from a JSON string""" + return cls.from_dict(loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + _dict = self.model_dump( + by_alias=True, + exclude={}, + exclude_none=True, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Dict) -> Self: + """Create an instance of ScheduleABTestResponse from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({"abTestScheduleID": obj.get("abTestScheduleID")}) + return _obj diff --git a/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_tests_request.py b/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_tests_request.py new file mode 100644 index 00000000000..fd0b3fc3205 --- /dev/null +++ b/clients/algoliasearch-client-python/algoliasearch/abtesting/models/schedule_ab_tests_request.py @@ -0,0 +1,94 @@ +# coding: utf-8 + +""" +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. +""" + +from __future__ import annotations + +from json import loads +from typing import Annotated, Any, Dict, List, Self + +from pydantic import BaseModel, ConfigDict, Field, StrictStr + +from algoliasearch.abtesting.models.add_ab_tests_variant import AddABTestsVariant + + +class ScheduleABTestsRequest(BaseModel): + """ + ScheduleABTestsRequest + """ + + name: StrictStr = Field(description="A/B test name.") + variants: Annotated[List[AddABTestsVariant], Field(min_length=2, max_length=2)] = ( + Field(description="A/B test variants.") + ) + scheduled_at: StrictStr = Field( + description="Date and time when the A/B test is scheduled to start, in RFC 3339 format.", + alias="scheduledAt", + ) + end_at: StrictStr = Field( + description="End date and time of the A/B test, in RFC 3339 format.", + alias="endAt", + ) + + model_config = ConfigDict( + use_enum_values=True, populate_by_name=True, validate_assignment=True + ) + + def to_json(self) -> str: + return self.model_dump_json(by_alias=True, exclude_unset=True) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of ScheduleABTestsRequest from a JSON string""" + return cls.from_dict(loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + _dict = self.model_dump( + by_alias=True, + exclude={}, + exclude_none=True, + ) + _items = [] + if self.variants: + for _item in self.variants: + if _item: + _items.append(_item.to_dict()) + _dict["variants"] = _items + return _dict + + @classmethod + def from_dict(cls, obj: Dict) -> Self: + """Create an instance of ScheduleABTestsRequest from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate( + { + "name": obj.get("name"), + "variants": ( + [ + AddABTestsVariant.from_dict(_item) + for _item in obj.get("variants") + ] + if obj.get("variants") is not None + else None + ), + "scheduledAt": obj.get("scheduledAt"), + "endAt": obj.get("endAt"), + } + ) + return _obj diff --git a/clients/algoliasearch-client-ruby/lib/algolia/api/abtesting_client.rb b/clients/algoliasearch-client-ruby/lib/algolia/api/abtesting_client.rb index 55429dabb76..45bdc9b357e 100644 --- a/clients/algoliasearch-client-ruby/lib/algolia/api/abtesting_client.rb +++ b/clients/algoliasearch-client-ruby/lib/algolia/api/abtesting_client.rb @@ -409,6 +409,50 @@ def list_ab_tests(offset = nil, limit = nil, index_prefix = nil, index_suffix = @api_client.deserialize(response.body, request_options[:debug_return_type] || "Abtesting::ListABTestsResponse") end + # Schedule an A/B test to be started at a later time. + # + # Required API Key ACLs: + # - editSettings + # @param schedule_ab_tests_request [ScheduleABTestsRequest] (required) + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [Http::Response] the response + def schedule_ab_test_with_http_info(schedule_ab_tests_request, request_options = {}) + # verify the required parameter 'schedule_ab_tests_request' is set + if @api_client.config.client_side_validation && schedule_ab_tests_request.nil? + raise ArgumentError, "Parameter `schedule_ab_tests_request` is required when calling `schedule_ab_test`." + end + + path = "/2/abtests/schedule" + query_params = {} + query_params = query_params.merge(request_options[:query_params]) unless request_options[:query_params].nil? + header_params = {} + header_params = header_params.merge(request_options[:header_params]) unless request_options[:header_params].nil? + + post_body = request_options[:debug_body] || @api_client.object_to_http_body(schedule_ab_tests_request) + + new_options = request_options.merge( + :operation => :"AbtestingClient.schedule_ab_test", + :header_params => header_params, + :query_params => query_params, + :body => post_body, + :use_read_transporter => false + ) + + @api_client.call_api(:POST, path, new_options) + end + + # Schedule an A/B test to be started at a later time. + # + # Required API Key ACLs: + # - editSettings + # @param schedule_ab_tests_request [ScheduleABTestsRequest] (required) + # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) + # @return [ScheduleABTestResponse] + def schedule_ab_test(schedule_ab_tests_request, request_options = {}) + response = schedule_ab_test_with_http_info(schedule_ab_tests_request, request_options) + @api_client.deserialize(response.body, request_options[:debug_return_type] || "Abtesting::ScheduleABTestResponse") + end + # Stops an A/B test by its ID. You can't restart stopped A/B tests. # # Required API Key ACLs: diff --git a/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_test_response.rb b/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_test_response.rb new file mode 100644 index 00000000000..97dc565847f --- /dev/null +++ b/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_test_response.rb @@ -0,0 +1,214 @@ +# 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. + +require "date" +require "time" + +module Algolia + module Abtesting + class ScheduleABTestResponse + # Unique scheduled A/B test identifier. + attr_accessor :ab_test_schedule_id + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :ab_test_schedule_id => :abTestScheduleID + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.types_mapping + { + :ab_test_schedule_id => :"Integer" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ScheduleABTestResponse` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::ScheduleABTestResponse`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:ab_test_schedule_id) + self.ab_test_schedule_id = attributes[:ab_test_schedule_id] + else + self.ab_test_schedule_id = nil + end + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + ab_test_schedule_id == other.ab_test_schedule_id + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [ab_test_schedule_id].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Abtesting.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_tests_request.rb b/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_tests_request.rb new file mode 100644 index 00000000000..17db0acd362 --- /dev/null +++ b/clients/algoliasearch-client-ruby/lib/algolia/models/abtesting/schedule_ab_tests_request.rb @@ -0,0 +1,270 @@ +# 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. + +require "date" +require "time" + +module Algolia + module Abtesting + class ScheduleABTestsRequest + # A/B test name. + attr_accessor :name + + # A/B test variants. + attr_accessor :variants + + # Date and time when the A/B test is scheduled to start, in RFC 3339 format. + attr_accessor :scheduled_at + + # End date and time of the A/B test, in RFC 3339 format. + attr_accessor :end_at + + # Attribute mapping from ruby-style variable name to JSON key. + def self.attribute_map + { + :name => :name, + :variants => :variants, + :scheduled_at => :scheduledAt, + :end_at => :endAt + } + end + + # Returns all the JSON keys this model knows about + def self.acceptable_attributes + attribute_map.values + end + + # Attribute type mapping. + def self.types_mapping + { + :name => :"String", + :variants => :"Array", + :scheduled_at => :"String", + :end_at => :"String" + } + end + + # List of attributes with nullable: true + def self.openapi_nullable + Set.new( + [] + ) + end + + # Initializes the object + # @param [Hash] attributes Model attributes in the form of hash + def initialize(attributes = {}) + if (!attributes.is_a?(Hash)) + raise( + ArgumentError, + "The input argument (attributes) must be a hash in `Algolia::ScheduleABTestsRequest` initialize method" + ) + end + + # check to see if the attribute exists and convert string to symbol for hash key + attributes = attributes.each_with_object({}) { |(k, v), h| + if (!self.class.attribute_map.key?(k.to_sym)) + raise( + ArgumentError, + "`#{k}` is not a valid attribute in `Algolia::ScheduleABTestsRequest`. Please check the name to make sure it's valid. List of attributes: " + + self.class.attribute_map.keys.inspect + ) + end + + h[k.to_sym] = v + } + + if attributes.key?(:name) + self.name = attributes[:name] + else + self.name = nil + end + + if attributes.key?(:variants) + if (value = attributes[:variants]).is_a?(Array) + self.variants = value + end + else + self.variants = nil + end + + if attributes.key?(:scheduled_at) + self.scheduled_at = attributes[:scheduled_at] + else + self.scheduled_at = nil + end + + if attributes.key?(:end_at) + self.end_at = attributes[:end_at] + else + self.end_at = nil + end + end + + # Custom attribute writer method with validation + # @param [Object] variants Value to be assigned + def variants=(variants) + if variants.nil? + raise ArgumentError, "variants cannot be nil" + end + + if variants.length > 2 + raise ArgumentError, "invalid value for \"variants\", number of items must be less than or equal to 2." + end + + if variants.length < 2 + raise ArgumentError, "invalid value for \"variants\", number of items must be greater than or equal to 2." + end + + @variants = variants + end + + # Checks equality by comparing each attribute. + # @param [Object] Object to be compared + def ==(other) + return true if self.equal?(other) + self.class == other.class && + name == other.name && + variants == other.variants && + scheduled_at == other.scheduled_at && + end_at == other.end_at + end + + # @see the `==` method + # @param [Object] Object to be compared + def eql?(other) + self == other + end + + # Calculates hash code according to all attributes. + # @return [Integer] Hash code + def hash + [name, variants, scheduled_at, end_at].hash + end + + # Builds the object from hash + # @param [Hash] attributes Model attributes in the form of hash + # @return [Object] Returns the model itself + def self.build_from_hash(attributes) + return nil unless attributes.is_a?(Hash) + attributes = attributes.transform_keys(&:to_sym) + transformed_hash = {} + types_mapping.each_pair do |key, type| + if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = nil + elsif type =~ /\AArray<(.*)>/i + # check to ensure the input is an array given that the attribute + # is documented as an array but the input is not + if attributes[attribute_map[key]].is_a?(Array) + transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| + _deserialize(::Regexp.last_match(1), v) + } + end + elsif !attributes[attribute_map[key]].nil? + transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]]) + end + end + + new(transformed_hash) + end + + # Deserializes the data based on type + # @param string type Data type + # @param string value Value to be deserialized + # @return [Object] Deserialized data + def self._deserialize(type, value) + case type.to_sym + when :Time + Time.parse(value) + when :Date + Date.parse(value) + when :String + value.to_s + when :Integer + value.to_i + when :Float + value.to_f + when :Boolean + if value.to_s =~ /\A(true|t|yes|y|1)\z/i + true + else + false + end + + when :Object + # generic object (usually a Hash), return directly + value + when /\AArray<(?.+)>\z/ + inner_type = Regexp.last_match[:inner_type] + value.map { |v| _deserialize(inner_type, v) } + when /\AHash<(?.+?), (?.+)>\z/ + k_type = Regexp.last_match[:k_type] + v_type = Regexp.last_match[:v_type] + {}.tap do |hash| + value.each do |k, v| + hash[_deserialize(k_type, k)] = _deserialize(v_type, v) + end + end + # model + else + # models (e.g. Pet) or oneOf + klass = Algolia::Abtesting.const_get(type) + klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass + .build_from_hash(value) + end + end + + # Returns the string representation of the object + # @return [String] String presentation of the object + def to_s + to_hash.to_s + end + + # to_body is an alias to to_hash (backward compatibility) + # @return [Hash] Returns the object in the form of hash + def to_body + to_hash + end + + def to_json(*_args) + to_hash.to_json + end + + # Returns the object in the form of hash + # @return [Hash] Returns the object in the form of hash + def to_hash + hash = {} + self.class.attribute_map.each_pair do |attr, param| + value = send(attr) + if value.nil? + is_nullable = self.class.openapi_nullable.include?(attr) + next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) + end + + hash[param] = _to_hash(value) + end + + hash + end + + # Outputs non-array value in the form of hash + # For object, use to_hash. Otherwise, just return the value + # @param [Object] value Any valid value + # @return [Hash] Returns the value in the form of hash + def _to_hash(value) + if value.is_a?(Array) + value.compact.map { |v| _to_hash(v) } + elsif value.is_a?(Hash) + {}.tap do |hash| + value.each { |k, v| hash[k] = _to_hash(v) } + end + elsif value.respond_to?(:to_hash) + value.to_hash + else + value + end + end + + end + + end +end diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestResponse.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestResponse.scala new file mode 100644 index 00000000000..33400e8928f --- /dev/null +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestResponse.scala @@ -0,0 +1,33 @@ +/** A/B Testing API The Algolia A/B Testing API lets you manage your Algolia A/B tests to optimize your search + * experience. ## Base URLs The base URLs for requests to the A/B testing API are: - `https://analytics.us.algolia.com` + * (alias: `https://analytics.algolia.com`) - `https://analytics.de.algolia.com` Use the URL that matches your + * [analytics region](https://dashboard.algolia.com/account/infrastructure/analytics). **All requests must use HTTPS.** + * ## Availability and authentication Access to the A/B testing API is available as part of the [Premium or Elevate + * plans](https://www.algolia.com/pricing). To authenticate your API requests, add these headers: - + * `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the necessary + * permissions to make the request. The required access control list (ACL) to make a request is listed in each + * endpoint's reference. You can find your application ID and API key in the [Algolia + * dashboard](https://dashboard.algolia.com/account). ## Rate limits You can make up to **100 requests per minute per + * app** to the A/B testing API. The response includes headers with information about the limits. ## Parameters Query + * parameters must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII + * characters must be UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. ## Response status and errors The + * A/B testing API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order + * of attributes in the API response. Successful responses return a `2xx` status. Client errors return a `4xx` status. + * Server errors are indicated by a `5xx` status. Error responses have a `message` property with more information. ## + * Version The current version of the A/B Testing API is version 2, as indicated by the `/2/` in each endpoint's URL. + * + * The version of the OpenAPI document: 2.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech Do not edit the class manually. + */ +package algoliasearch.abtesting + +/** ScheduleABTestResponse + * + * @param abTestScheduleID + * Unique scheduled A/B test identifier. + */ +case class ScheduleABTestResponse( + abTestScheduleID: Int +) diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestsRequest.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestsRequest.scala new file mode 100644 index 00000000000..72c2b35aedf --- /dev/null +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/abtesting/ScheduleABTestsRequest.scala @@ -0,0 +1,42 @@ +/** A/B Testing API The Algolia A/B Testing API lets you manage your Algolia A/B tests to optimize your search + * experience. ## Base URLs The base URLs for requests to the A/B testing API are: - `https://analytics.us.algolia.com` + * (alias: `https://analytics.algolia.com`) - `https://analytics.de.algolia.com` Use the URL that matches your + * [analytics region](https://dashboard.algolia.com/account/infrastructure/analytics). **All requests must use HTTPS.** + * ## Availability and authentication Access to the A/B testing API is available as part of the [Premium or Elevate + * plans](https://www.algolia.com/pricing). To authenticate your API requests, add these headers: - + * `x-algolia-application-id`. Your Algolia application ID. - `x-algolia-api-key`. An API key with the necessary + * permissions to make the request. The required access control list (ACL) to make a request is listed in each + * endpoint's reference. You can find your application ID and API key in the [Algolia + * dashboard](https://dashboard.algolia.com/account). ## Rate limits You can make up to **100 requests per minute per + * app** to the A/B testing API. The response includes headers with information about the limits. ## Parameters Query + * parameters must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding). Non-ASCII + * characters must be UTF-8 encoded. Plus characters (`+`) are interpreted as spaces. ## Response status and errors The + * A/B testing API returns JSON responses. Since JSON doesn't guarantee any specific ordering, don't rely on the order + * of attributes in the API response. Successful responses return a `2xx` status. Client errors return a `4xx` status. + * Server errors are indicated by a `5xx` status. Error responses have a `message` property with more information. ## + * Version The current version of the A/B Testing API is version 2, as indicated by the `/2/` in each endpoint's URL. + * + * The version of the OpenAPI document: 2.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech Do not edit the class manually. + */ +package algoliasearch.abtesting + +/** ScheduleABTestsRequest + * + * @param name + * A/B test name. + * @param variants + * A/B test variants. + * @param scheduledAt + * Date and time when the A/B test is scheduled to start, in RFC 3339 format. + * @param endAt + * End date and time of the A/B test, in RFC 3339 format. + */ +case class ScheduleABTestsRequest( + name: String, + variants: Seq[AddABTestsVariant], + scheduledAt: String, + endAt: String +) diff --git a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/api/AbtestingClient.scala b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/api/AbtestingClient.scala index e89e46680fd..8928dd3928d 100644 --- a/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/api/AbtestingClient.scala +++ b/clients/algoliasearch-client-scala/src/main/scala/algoliasearch/api/AbtestingClient.scala @@ -8,6 +8,8 @@ import algoliasearch.abtesting.ABTestResponse import algoliasearch.abtesting.AddABTestsRequest import algoliasearch.abtesting.ErrorBase import algoliasearch.abtesting.ListABTestsResponse +import algoliasearch.abtesting.ScheduleABTestResponse +import algoliasearch.abtesting.ScheduleABTestsRequest import algoliasearch.abtesting._ import algoliasearch.ApiClient import algoliasearch.api.AbtestingClient.hosts @@ -261,6 +263,28 @@ class AbtestingClient( execute[ListABTestsResponse](request, requestOptions) } + /** Schedule an A/B test to be started at a later time. + * + * Required API Key ACLs: + * - editSettings + */ + def scheduleABTest(scheduleABTestsRequest: ScheduleABTestsRequest, requestOptions: Option[RequestOptions] = None)( + implicit ec: ExecutionContext + ): Future[ScheduleABTestResponse] = Future { + requireNotNull( + scheduleABTestsRequest, + "Parameter `scheduleABTestsRequest` is required when calling `scheduleABTest`." + ) + + val request = HttpRequest + .builder() + .withMethod("POST") + .withPath(s"/2/abtests/schedule") + .withBody(scheduleABTestsRequest) + .build() + execute[ScheduleABTestResponse](request, requestOptions) + } + /** Stops an A/B test by its ID. You can't restart stopped A/B tests. * * Required API Key ACLs: diff --git a/clients/algoliasearch-client-swift/Sources/Abtesting/AbtestingClient.swift b/clients/algoliasearch-client-swift/Sources/Abtesting/AbtestingClient.swift index d8b44f01f29..cdb47f9727d 100644 --- a/clients/algoliasearch-client-swift/Sources/Abtesting/AbtestingClient.swift +++ b/clients/algoliasearch-client-swift/Sources/Abtesting/AbtestingClient.swift @@ -495,6 +495,52 @@ open class AbtestingClient { ) } + /// - parameter scheduleABTestsRequest: (body) + /// - returns: ScheduleABTestResponse + @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) + open func scheduleABTest( + scheduleABTestsRequest: ScheduleABTestsRequest, + requestOptions: RequestOptions? = nil + ) async throws -> ScheduleABTestResponse { + let response: Response = try await scheduleABTestWithHTTPInfo( + scheduleABTestsRequest: scheduleABTestsRequest, + requestOptions: requestOptions + ) + + guard let body = response.body else { + throw AlgoliaError.missingData + } + + return body + } + + // Schedule an A/B test to be started at a later time. + // Required API Key ACLs: + // - editSettings + // + // - parameter scheduleABTestsRequest: (body) + // - returns: RequestBuilder + + open func scheduleABTestWithHTTPInfo( + scheduleABTestsRequest: ScheduleABTestsRequest, + requestOptions userRequestOptions: RequestOptions? = nil + ) async throws -> Response { + let resourcePath = "/2/abtests/schedule" + let body = scheduleABTestsRequest + let queryParameters: [String: Any?]? = nil + + let nillableHeaders: [String: Any?]? = nil + + let headers = APIHelper.rejectNilHeaders(nillableHeaders) + + return try await self.transporter.send( + method: "POST", + path: resourcePath, + data: body, + requestOptions: RequestOptions(headers: headers, queryParameters: queryParameters) + userRequestOptions + ) + } + /// - parameter id: (path) Unique A/B test identifier. /// - returns: ABTestResponse @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) diff --git a/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestResponse.swift b/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestResponse.swift new file mode 100644 index 00000000000..30300e528f4 --- /dev/null +++ b/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestResponse.swift @@ -0,0 +1,39 @@ +// 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. + +import Foundation +#if canImport(Core) + import Core +#endif + +public struct ScheduleABTestResponse: Codable, JSONEncodable { + /// Unique scheduled A/B test identifier. + public var abTestScheduleID: Int + + public init(abTestScheduleID: Int) { + self.abTestScheduleID = abTestScheduleID + } + + public enum CodingKeys: String, CodingKey, CaseIterable { + case abTestScheduleID + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.abTestScheduleID, forKey: .abTestScheduleID) + } +} + +extension ScheduleABTestResponse: Equatable { + public static func ==(lhs: ScheduleABTestResponse, rhs: ScheduleABTestResponse) -> Bool { + lhs.abTestScheduleID == rhs.abTestScheduleID + } +} + +extension ScheduleABTestResponse: Hashable { + public func hash(into hasher: inout Hasher) { + hasher.combine(self.abTestScheduleID.hashValue) + } +} diff --git a/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestsRequest.swift b/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestsRequest.swift new file mode 100644 index 00000000000..ebb145f341b --- /dev/null +++ b/clients/algoliasearch-client-swift/Sources/Abtesting/Models/ScheduleABTestsRequest.swift @@ -0,0 +1,60 @@ +// 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. + +import Foundation +#if canImport(Core) + import Core +#endif + +public struct ScheduleABTestsRequest: Codable, JSONEncodable { + /// A/B test name. + public var name: String + /// A/B test variants. + public var variants: [AddABTestsVariant] + /// Date and time when the A/B test is scheduled to start, in RFC 3339 format. + public var scheduledAt: String + /// End date and time of the A/B test, in RFC 3339 format. + public var endAt: String + + public init(name: String, variants: [AddABTestsVariant], scheduledAt: String, endAt: String) { + self.name = name + self.variants = variants + self.scheduledAt = scheduledAt + self.endAt = endAt + } + + public enum CodingKeys: String, CodingKey, CaseIterable { + case name + case variants + case scheduledAt + case endAt + } + + // Encodable protocol methods + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(self.name, forKey: .name) + try container.encode(self.variants, forKey: .variants) + try container.encode(self.scheduledAt, forKey: .scheduledAt) + try container.encode(self.endAt, forKey: .endAt) + } +} + +extension ScheduleABTestsRequest: Equatable { + public static func ==(lhs: ScheduleABTestsRequest, rhs: ScheduleABTestsRequest) -> Bool { + lhs.name == rhs.name && + lhs.variants == rhs.variants && + lhs.scheduledAt == rhs.scheduledAt && + lhs.endAt == rhs.endAt + } +} + +extension ScheduleABTestsRequest: Hashable { + public func hash(into hasher: inout Hasher) { + hasher.combine(self.name.hashValue) + hasher.combine(self.variants.hashValue) + hasher.combine(self.scheduledAt.hashValue) + hasher.combine(self.endAt.hashValue) + } +} diff --git a/snippets/csharp/src/Abtesting.cs b/snippets/csharp/src/Abtesting.cs index 4fb65484e3a..03034dd696f 100644 --- a/snippets/csharp/src/Abtesting.cs +++ b/snippets/csharp/src/Abtesting.cs @@ -165,6 +165,38 @@ public async Task SnippetForAbtestingClientListABTests() // SEPARATOR< } + /// + /// Snippet for the ScheduleABTest method. + /// + /// scheduleABTest with minimal parameters + /// + public async Task SnippetForAbtestingClientScheduleABTest() + { + // >SEPARATOR scheduleABTest default + // Initialize the client + var client = new AbtestingClient( + new AbtestingConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") + ); + + // Call the API + var response = await client.ScheduleABTestAsync( + new ScheduleABTestsRequest + { + EndAt = "2022-12-31T00:00:00.000Z", + ScheduledAt = "2022-11-31T00:00:00.000Z", + Name = "myABTest", + Variants = new List + { + new AddABTestsVariant( + new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30, } + ), + new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50, }) + }, + } + ); + // SEPARATOR< + } + /// /// Snippet for the StopABTest method. /// diff --git a/snippets/go/src/abtesting.go b/snippets/go/src/abtesting.go index abfe79e832b..6ceaad3ebaa 100644 --- a/snippets/go/src/abtesting.go +++ b/snippets/go/src/abtesting.go @@ -232,6 +232,38 @@ func SnippetForListABTestsOfAbtesting() { print(response) // SEPARATOR< } +func SnippetForScheduleABTestOfAbtesting() { + /* + Snippet for the scheduleABTest method. + + scheduleABTest with minimal parameters + */ + + // >SEPARATOR scheduleABTest default + // Initialize the client with your application region, eg. abtesting.YOUR_APP_ID_REGION + client, err := abtesting.NewClient("YOUR_APP_ID", "YOUR_API_KEY", abtesting.US) + if err != nil { + // The client can fail to initialize if you pass an invalid parameter. + panic(err) + } + + // Call the API + response, err := client.ScheduleABTest(client.NewApiScheduleABTestRequest( + + abtesting.NewEmptyScheduleABTestsRequest().SetEndAt("2022-12-31T00:00:00.000Z").SetScheduledAt("2022-11-31T00:00:00.000Z").SetName("myABTest").SetVariants( + []abtesting.AddABTestsVariant{*abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))}), + )) + if err != nil { + // handle the eventual error + panic(err) + } + + // use the model directly + print(response) + // SEPARATOR< +} func SnippetForStopABTestOfAbtesting() { /* Snippet for the stopABTest method. diff --git a/snippets/guides/abtesting-snippets.json b/snippets/guides/abtesting-snippets.json index 798c8104186..393febae733 100644 --- a/snippets/guides/abtesting-snippets.json +++ b/snippets/guides/abtesting-snippets.json @@ -27,6 +27,9 @@ "listABTests": { "default": "var response = await client.ListABTestsAsync();" }, + "scheduleABTest": { + "default": "var response = await client.ScheduleABTestAsync(\n new ScheduleABTestsRequest\n {\n EndAt = \"2022-12-31T00:00:00.000Z\",\n ScheduledAt = \"2022-11-31T00:00:00.000Z\",\n Name = \"myABTest\",\n Variants = new List\n {\n new AddABTestsVariant(\n new AbTestsVariant { Index = \"AB_TEST_1\", TrafficPercentage = 30, }\n ),\n new AddABTestsVariant(new AbTestsVariant { Index = \"AB_TEST_2\", TrafficPercentage = 50, })\n },\n }\n);" + }, "stopABTest": { "default": "var response = await client.StopABTestAsync(42);" }, @@ -86,6 +89,9 @@ "listABTests": { "default": "// Initialize the client with your application region, eg. abtesting.YOUR_APP_ID_REGION\nclient, err := abtesting.NewClient(\"YOUR_APP_ID\", \"YOUR_API_KEY\", abtesting.US)\nif err != nil {\n // The client can fail to initialize if you pass an invalid parameter.\n panic(err)\n}\n\n// Call the API\nresponse, err := client.ListABTests(client.NewApiListABTestsRequest())\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)\n" }, + "scheduleABTest": { + "default": "// Initialize the client with your application region, eg. abtesting.YOUR_APP_ID_REGION\nclient, err := abtesting.NewClient(\"YOUR_APP_ID\", \"YOUR_API_KEY\", abtesting.US)\nif err != nil {\n // The client can fail to initialize if you pass an invalid parameter.\n panic(err)\n}\n\n// Call the API\nresponse, err := client.ScheduleABTest(client.NewApiScheduleABTestRequest(\n\n abtesting.NewEmptyScheduleABTestsRequest().SetEndAt(\"2022-12-31T00:00:00.000Z\").SetScheduledAt(\"2022-11-31T00:00:00.000Z\").SetName(\"myABTest\").SetVariants(\n []abtesting.AddABTestsVariant{*abtesting.AbTestsVariantAsAddABTestsVariant(\n abtesting.NewEmptyAbTestsVariant().SetIndex(\"AB_TEST_1\").SetTrafficPercentage(30)), *abtesting.AbTestsVariantAsAddABTestsVariant(\n abtesting.NewEmptyAbTestsVariant().SetIndex(\"AB_TEST_2\").SetTrafficPercentage(50))}),\n))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)\n" + }, "stopABTest": { "default": "// Initialize the client with your application region, eg. abtesting.YOUR_APP_ID_REGION\nclient, err := abtesting.NewClient(\"YOUR_APP_ID\", \"YOUR_API_KEY\", abtesting.US)\nif err != nil {\n // The client can fail to initialize if you pass an invalid parameter.\n panic(err)\n}\n\n// Call the API\nresponse, err := client.StopABTest(client.NewApiStopABTestRequest(\n 42,\n))\nif err != nil {\n // handle the eventual error\n panic(err)\n}\n\n// use the model directly\nprint(response)\n" }, @@ -129,6 +135,9 @@ "listABTests": { "default": "client.listABTests();" }, + "scheduleABTest": { + "default": "client.scheduleABTest(\n new ScheduleABTestsRequest()\n .setEndAt(\"2022-12-31T00:00:00.000Z\")\n .setScheduledAt(\"2022-11-31T00:00:00.000Z\")\n .setName(\"myABTest\")\n .setVariants(\n List.of(\n new AbTestsVariant().setIndex(\"AB_TEST_1\").setTrafficPercentage(30),\n new AbTestsVariant().setIndex(\"AB_TEST_2\").setTrafficPercentage(50)\n )\n )\n);" + }, "stopABTest": { "default": "client.stopABTest(42);" }, @@ -175,6 +184,9 @@ "listABTests": { "default": "const response = await client.listABTests();\n\n// use typed response\nconsole.log(response);" }, + "scheduleABTest": { + "default": "const response = await client.scheduleABTest({\n endAt: '2022-12-31T00:00:00.000Z',\n scheduledAt: '2022-11-31T00:00:00.000Z',\n name: 'myABTest',\n variants: [\n { index: 'AB_TEST_1', trafficPercentage: 30 },\n { index: 'AB_TEST_2', trafficPercentage: 50 },\n ],\n});\n\n// use typed response\nconsole.log(response);" + }, "stopABTest": { "default": "const response = await client.stopABTest({ id: 42 });\n\n// use typed response\nconsole.log(response);" }, @@ -221,6 +233,9 @@ "listABTests": { "default": "var response = client.listABTests()\n\n// Use the response\nprintln(response)" }, + "scheduleABTest": { + "default": "var response = client.scheduleABTest(\n scheduleABTestsRequest = ScheduleABTestsRequest(\n endAt = \"2022-12-31T00:00:00.000Z\",\n scheduledAt = \"2022-11-31T00:00:00.000Z\",\n name = \"myABTest\",\n variants = listOf(\n AbTestsVariant(\n index = \"AB_TEST_1\",\n trafficPercentage = 30,\n ),\n AbTestsVariant(\n index = \"AB_TEST_2\",\n trafficPercentage = 50,\n ),\n ),\n ),\n)\n\n// Use the response\nprintln(response)" + }, "stopABTest": { "default": "var response = client.stopABTest(\n id = 42,\n)\n\n// Use the response\nprintln(response)" }, @@ -267,6 +282,9 @@ "listABTests": { "default": "$response = $client->listABTests();\n\n// play with the response\nvar_dump($response);" }, + "scheduleABTest": { + "default": "$response = $client->scheduleABTest(\n ['endAt' => '2022-12-31T00:00:00.000Z',\n 'scheduledAt' => '2022-11-31T00:00:00.000Z',\n 'name' => 'myABTest',\n 'variants' => [\n ['index' => 'AB_TEST_1',\n 'trafficPercentage' => 30,\n ],\n\n ['index' => 'AB_TEST_2',\n 'trafficPercentage' => 50,\n ],\n ],\n ],\n);\n\n// play with the response\nvar_dump($response);" + }, "stopABTest": { "default": "$response = $client->stopABTest(\n 42,\n);\n\n// play with the response\nvar_dump($response);" }, @@ -313,6 +331,9 @@ "listABTests": { "default": "response = await _client.list_ab_tests()\n\n# use the class directly\nprint(response)\n\n# print the JSON response\nprint(response.to_json())" }, + "scheduleABTest": { + "default": "response = await _client.schedule_ab_test(\n schedule_ab_tests_request={\n \"endAt\": \"2022-12-31T00:00:00.000Z\",\n \"scheduledAt\": \"2022-11-31T00:00:00.000Z\",\n \"name\": \"myABTest\",\n \"variants\": [\n {\n \"index\": \"AB_TEST_1\",\n \"trafficPercentage\": 30,\n },\n {\n \"index\": \"AB_TEST_2\",\n \"trafficPercentage\": 50,\n },\n ],\n },\n)\n\n# use the class directly\nprint(response)\n\n# print the JSON response\nprint(response.to_json())" + }, "stopABTest": { "default": "response = await _client.stop_ab_test(\n id=42,\n)\n\n# use the class directly\nprint(response)\n\n# print the JSON response\nprint(response.to_json())" }, @@ -359,6 +380,9 @@ "listABTests": { "default": "response = client.list_ab_tests\n\n# use the class directly\nputs(response)\n\n# print the JSON response\nputs(response.to_json)" }, + "scheduleABTest": { + "default": "response = client.schedule_ab_test(\n ScheduleABTestsRequest.new(\n end_at: \"2022-12-31T00:00:00.000Z\",\n scheduled_at: \"2022-11-31T00:00:00.000Z\",\n name: \"myABTest\",\n variants: [\n AbTestsVariant.new(index: \"AB_TEST_1\", traffic_percentage: 30),\n AbTestsVariant.new(index: \"AB_TEST_2\", traffic_percentage: 50)\n ]\n )\n)\n\n# use the class directly\nputs(response)\n\n# print the JSON response\nputs(response.to_json)" + }, "stopABTest": { "default": "response = client.stop_ab_test(42)\n\n# use the class directly\nputs(response)\n\n# print the JSON response\nputs(response.to_json)" }, @@ -405,6 +429,9 @@ "listABTests": { "default": "val response = client.listABTests(\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" }, + "scheduleABTest": { + "default": "val response = client.scheduleABTest(\n scheduleABTestsRequest = ScheduleABTestsRequest(\n endAt = \"2022-12-31T00:00:00.000Z\",\n scheduledAt = \"2022-11-31T00:00:00.000Z\",\n name = \"myABTest\",\n variants = Seq(\n AbTestsVariant(\n index = \"AB_TEST_1\",\n trafficPercentage = 30\n ),\n AbTestsVariant(\n index = \"AB_TEST_2\",\n trafficPercentage = 50\n )\n )\n )\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" + }, "stopABTest": { "default": "val response = client.stopABTest(\n id = 42\n)\n\n// Use the response\nval value = Await.result(response, Duration(100, \"sec\"))" }, @@ -451,6 +478,9 @@ "listABTests": { "default": "let response = try await client.listABTests()" }, + "scheduleABTest": { + "default": "let response = try await client.scheduleABTest(scheduleABTestsRequest: ScheduleABTestsRequest(\n name: \"myABTest\",\n variants: [\n AddABTestsVariant.abTestsVariant(AbTestsVariant(index: \"AB_TEST_1\", trafficPercentage: 30)),\n AddABTestsVariant.abTestsVariant(AbTestsVariant(index: \"AB_TEST_2\", trafficPercentage: 50)),\n ],\n scheduledAt: \"2022-11-31T00:00:00.000Z\",\n endAt: \"2022-12-31T00:00:00.000Z\"\n))" + }, "stopABTest": { "default": "let response = try await client.stopABTest(id: 42)" }, diff --git a/snippets/java/src/test/java/com/algolia/Abtesting.java b/snippets/java/src/test/java/com/algolia/Abtesting.java index 280c2023599..0d944f43b8f 100644 --- a/snippets/java/src/test/java/com/algolia/Abtesting.java +++ b/snippets/java/src/test/java/com/algolia/Abtesting.java @@ -122,6 +122,30 @@ void snippetForListABTests() { // SEPARATOR< } + // Snippet for the scheduleABTest method. + // + // scheduleABTest with minimal parameters + void snippetForScheduleABTest() { + // >SEPARATOR scheduleABTest default + // Initialize the client + AbtestingClient client = new AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"); + + // Call the API + client.scheduleABTest( + new ScheduleABTestsRequest() + .setEndAt("2022-12-31T00:00:00.000Z") + .setScheduledAt("2022-11-31T00:00:00.000Z") + .setName("myABTest") + .setVariants( + List.of( + new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30), + new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50) + ) + ) + ); + // SEPARATOR< + } + // Snippet for the stopABTest method. // // stopABTest diff --git a/snippets/javascript/src/abtesting.ts b/snippets/javascript/src/abtesting.ts index 205d7fd8a5b..2ae602984dd 100644 --- a/snippets/javascript/src/abtesting.ts +++ b/snippets/javascript/src/abtesting.ts @@ -172,6 +172,34 @@ export async function snippetForListABTests(): Promise { // SEPARATOR< } +// Snippet for the scheduleABTest method. +// +// scheduleABTest with minimal parameters +export async function snippetForScheduleABTest(): Promise { + // >SEPARATOR scheduleABTest default + // Initialize the client + const client = abtestingClient( + 'YOUR_APP_ID', + 'YOUR_API_KEY', + 'YOUR_APP_ID_REGION' + ); + + // Call the API + const response = await client.scheduleABTest({ + endAt: '2022-12-31T00:00:00.000Z', + scheduledAt: '2022-11-31T00:00:00.000Z', + name: 'myABTest', + variants: [ + { index: 'AB_TEST_1', trafficPercentage: 30 }, + { index: 'AB_TEST_2', trafficPercentage: 50 }, + ], + }); + + // use typed response + console.log(response); + // SEPARATOR< +} + // Snippet for the stopABTest method. // // stopABTest diff --git a/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Abtesting.kt b/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Abtesting.kt index f52d730f8bf..30616008a0f 100644 --- a/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Abtesting.kt +++ b/snippets/kotlin/src/main/kotlin/com/algolia/snippets/Abtesting.kt @@ -157,6 +157,37 @@ class SnippetAbtestingClient { exitProcess(0) } + suspend fun snippetForScheduleABTest() { + // >SEPARATOR scheduleABTest default + // Initialize the client + val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY", region = "YOUR_APP_ID_REGION") + + // Call the API + var response = client.scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = listOf( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30, + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50, + ), + ), + ), + ) + + // Use the response + println(response) + // SEPARATOR< + + exitProcess(0) + } + suspend fun snippetForStopABTest() { // >SEPARATOR stopABTest default // Initialize the client diff --git a/snippets/php/src/Abtesting.php b/snippets/php/src/Abtesting.php index c19dc3326ed..3ffce3b6744 100644 --- a/snippets/php/src/Abtesting.php +++ b/snippets/php/src/Abtesting.php @@ -188,6 +188,39 @@ public function snippetForListABTests() // SEPARATOR< } + /** + * Snippet for the ScheduleABTest method. + * + * scheduleABTest with minimal parameters + */ + public function snippetForScheduleABTest() + { + // >SEPARATOR scheduleABTest default + // Initialize the client + $client = AbtestingClient::create('', '', 'YOUR_APP_ID_REGION'); + + // Call the API + $response = $client->scheduleABTest( + ['endAt' => '2022-12-31T00:00:00.000Z', + 'scheduledAt' => '2022-11-31T00:00:00.000Z', + 'name' => 'myABTest', + 'variants' => [ + ['index' => 'AB_TEST_1', + 'trafficPercentage' => 30, + ], + + ['index' => 'AB_TEST_2', + 'trafficPercentage' => 50, + ], + ], + ], + ); + + // play with the response + var_dump($response); + // SEPARATOR< + } + /** * Snippet for the StopABTest method. * diff --git a/snippets/python/abtesting.py b/snippets/python/abtesting.py index d86eaac0f2a..c97ec5566a3 100644 --- a/snippets/python/abtesting.py +++ b/snippets/python/abtesting.py @@ -199,6 +199,43 @@ async def snippet_for_list_ab_tests(): # SEPARATOR< +async def snippet_for_schedule_ab_test(): + """ + Snippet for the scheduleABTest method. + + scheduleABTest with minimal parameters + """ + # >SEPARATOR scheduleABTest default + # Initialize the client + _client = AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") + + # Call the API + response = await _client.schedule_ab_test( + schedule_ab_tests_request={ + "endAt": "2022-12-31T00:00:00.000Z", + "scheduledAt": "2022-11-31T00:00:00.000Z", + "name": "myABTest", + "variants": [ + { + "index": "AB_TEST_1", + "trafficPercentage": 30, + }, + { + "index": "AB_TEST_2", + "trafficPercentage": 50, + }, + ], + }, + ) + + # use the class directly + print(response) + + # print the JSON response + print(response.to_json()) + # SEPARATOR< + + async def snippet_for_stop_ab_test(): """ Snippet for the stopABTest method. diff --git a/snippets/ruby/abtesting.rb b/snippets/ruby/abtesting.rb index d565e47c76a..4c5c2e5158b 100644 --- a/snippets/ruby/abtesting.rb +++ b/snippets/ruby/abtesting.rb @@ -165,6 +165,35 @@ def snippet_for_list_ab_tests # SEPARATOR< end +# Snippet for the scheduleABTest method. +# +# scheduleABTest with minimal parameters +def snippet_for_schedule_ab_test + # >SEPARATOR scheduleABTest default + # Initialize the client + client = Algolia::AbtestingClient.create("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") + + # Call the API + response = client.schedule_ab_test( + ScheduleABTestsRequest.new( + end_at: "2022-12-31T00:00:00.000Z", + scheduled_at: "2022-11-31T00:00:00.000Z", + name: "myABTest", + variants: [ + AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30), + AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50) + ] + ) + ) + + # use the class directly + puts(response) + + # print the JSON response + puts(response.to_json) + # SEPARATOR< +end + # Snippet for the stopABTest method. # # stopABTest diff --git a/snippets/scala/src/main/scala/Abtesting.scala b/snippets/scala/src/main/scala/Abtesting.scala index dce46f8105f..4fc4060b2fa 100644 --- a/snippets/scala/src/main/scala/Abtesting.scala +++ b/snippets/scala/src/main/scala/Abtesting.scala @@ -180,6 +180,39 @@ class SnippetAbtestingClient { // SEPARATOR< } + /** Snippet for the scheduleABTest method. + * + * scheduleABTest with minimal parameters + */ + def snippetForAbtestingClientScheduleABTest(): Unit = { + // >SEPARATOR scheduleABTest default + // Initialize the client + val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY", region = Option("YOUR_APP_ID_REGION")) + + // Call the API + val response = client.scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = Seq( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30 + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50 + ) + ) + ) + ) + + // Use the response + val value = Await.result(response, Duration(100, "sec")) + // SEPARATOR< + } + /** Snippet for the stopABTest method. * * stopABTest diff --git a/snippets/swift/Sources/Abtesting.swift b/snippets/swift/Sources/Abtesting.swift index 09410cba510..1ab8bca27e0 100644 --- a/snippets/swift/Sources/Abtesting.swift +++ b/snippets/swift/Sources/Abtesting.swift @@ -118,6 +118,27 @@ final class AbtestingClientSnippet { // SEPARATOR< } + /// Snippet for the scheduleABTest method. + /// + /// scheduleABTest with minimal parameters + func snippetForScheduleABTest() async throws { + // >SEPARATOR scheduleABTest default + // Initialize the client + let client = try AbtestingClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY", region: .us) + + // Call the API + let response = try await client.scheduleABTest(scheduleABTestsRequest: ScheduleABTestsRequest( + name: "myABTest", + variants: [ + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_1", trafficPercentage: 30)), + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_2", trafficPercentage: 50)), + ], + scheduledAt: "2022-11-31T00:00:00.000Z", + endAt: "2022-12-31T00:00:00.000Z" + )) + // SEPARATOR< + } + /// Snippet for the stopABTest method. /// /// stopABTest diff --git a/specs/bundled/abtesting.doc.yml b/specs/bundled/abtesting.doc.yml index e5bf1851929..0eedf32d999 100644 --- a/specs/bundled/abtesting.doc.yml +++ b/specs/bundled/abtesting.doc.yml @@ -2184,6 +2184,360 @@ paths: // Call the API let response = try await client.stopABTest(id: 42) + /2/abtests/schedule: + post: + tags: + - abtest + operationId: scheduleABTest + x-acl: + - editSettings + summary: Schedule an A/B test + description: | + Schedule an A/B test to be started at a later time. + requestBody: + required: true + content: + application/json: + schema: + title: scheduleABTestsRequest + type: object + additionalProperties: false + properties: + name: + $ref: '#/components/schemas/name' + variants: + type: array + description: A/B test variants. + minItems: 2 + maxItems: 2 + items: + $ref: '#/components/schemas/AddABTestsVariant' + scheduledAt: + $ref: '#/components/schemas/scheduledAt' + endAt: + $ref: '#/components/schemas/endAt' + required: + - name + - variants + - scheduledAt + - endAt + responses: + '200': + description: OK + headers: + x-ratelimit-limit: + $ref: '#/components/headers/x-ratelimit-limit' + x-ratelimit-remaining: + $ref: '#/components/headers/x-ratelimit-remaining' + x-ratelimit-reset: + $ref: '#/components/headers/x-ratelimit-reset' + content: + application/json: + schema: + $ref: '#/components/schemas/ScheduleABTestResponse' + '400': + $ref: '#/components/responses/BadRequest' + '402': + $ref: '#/components/responses/FeatureNotEnabled' + '403': + $ref: '#/components/responses/MethodNotAllowed' + '404': + $ref: '#/components/responses/IndexNotFound' + x-codeSamples: + - lang: csharp + label: C# + source: | + // Initialize the client + var client = new AbtestingClient( + new AbtestingConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") + ); + + // Call the API + var response = await client.ScheduleABTestAsync( + new ScheduleABTestsRequest + { + EndAt = "2022-12-31T00:00:00.000Z", + ScheduledAt = "2022-11-31T00:00:00.000Z", + Name = "myABTest", + Variants = new List + { + new AddABTestsVariant( + new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30, } + ), + new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50, }) + }, + } + ); + - lang: go + label: Go + source: > + // Initialize the client with your application region, eg. + abtesting.YOUR_APP_ID_REGION + + client, err := abtesting.NewClient("YOUR_APP_ID", "YOUR_API_KEY", + abtesting.US) + + if err != nil { + // The client can fail to initialize if you pass an invalid parameter. + panic(err) + } + + + // Call the API + + response, err := + client.ScheduleABTest(client.NewApiScheduleABTestRequest( + + abtesting.NewEmptyScheduleABTestsRequest().SetEndAt("2022-12-31T00:00:00.000Z").SetScheduledAt("2022-11-31T00:00:00.000Z").SetName("myABTest").SetVariants( + []abtesting.AddABTestsVariant{*abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))}), + )) + + if err != nil { + // handle the eventual error + panic(err) + } + + + // use the model directly + + print(response) + - lang: java + label: Java + source: > + // Initialize the client + + AbtestingClient client = new AbtestingClient("YOUR_APP_ID", + "YOUR_API_KEY", "YOUR_APP_ID_REGION"); + + + // Call the API + + client.scheduleABTest( + new ScheduleABTestsRequest() + .setEndAt("2022-12-31T00:00:00.000Z") + .setScheduledAt("2022-11-31T00:00:00.000Z") + .setName("myABTest") + .setVariants( + List.of( + new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30), + new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50) + ) + ) + ); + - lang: javascript + label: JavaScript + source: | + // Initialize the client + const client = abtestingClient( + 'YOUR_APP_ID', + 'YOUR_API_KEY', + 'YOUR_APP_ID_REGION' + ); + + // Call the API + const response = await client.scheduleABTest({ + endAt: '2022-12-31T00:00:00.000Z', + scheduledAt: '2022-11-31T00:00:00.000Z', + name: 'myABTest', + variants: [ + { index: 'AB_TEST_1', trafficPercentage: 30 }, + { index: 'AB_TEST_2', trafficPercentage: 50 }, + ], + }); + + // use typed response + console.log(response); + - lang: kotlin + label: Kotlin + source: > + // Initialize the client + + val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = + "YOUR_API_KEY", region = "YOUR_APP_ID_REGION") + + + // Call the API + + var response = client.scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = listOf( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30, + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50, + ), + ), + ), + ) + + + // Use the response + + println(response) + - lang: php + label: PHP + source: > + // Initialize the client + + $client = AbtestingClient::create('', '', + 'YOUR_APP_ID_REGION'); + + + // Call the API + + $response = $client->scheduleABTest( + ['endAt' => '2022-12-31T00:00:00.000Z', + 'scheduledAt' => '2022-11-31T00:00:00.000Z', + 'name' => 'myABTest', + 'variants' => [ + ['index' => 'AB_TEST_1', + 'trafficPercentage' => 30, + ], + + ['index' => 'AB_TEST_2', + 'trafficPercentage' => 50, + ], + ], + ], + ); + + + // play with the response + + var_dump($response); + - lang: python + label: Python + source: > + # Initialize the client + + _client = AbtestingClient("YOUR_APP_ID", "YOUR_API_KEY", + "YOUR_APP_ID_REGION") + + + # Call the API + + response = await _client.schedule_ab_test( + schedule_ab_tests_request={ + "endAt": "2022-12-31T00:00:00.000Z", + "scheduledAt": "2022-11-31T00:00:00.000Z", + "name": "myABTest", + "variants": [ + { + "index": "AB_TEST_1", + "trafficPercentage": 30, + }, + { + "index": "AB_TEST_2", + "trafficPercentage": 50, + }, + ], + }, + ) + + + # use the class directly + + print(response) + + + # print the JSON response + + print(response.to_json()) + - lang: ruby + label: Ruby + source: > + # Initialize the client + + client = Algolia::AbtestingClient.create("YOUR_APP_ID", + "YOUR_API_KEY", "YOUR_APP_ID_REGION") + + + # Call the API + + response = client.schedule_ab_test( + ScheduleABTestsRequest.new( + end_at: "2022-12-31T00:00:00.000Z", + scheduled_at: "2022-11-31T00:00:00.000Z", + name: "myABTest", + variants: [ + AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30), + AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50) + ] + ) + ) + + + # use the class directly + + puts(response) + + + # print the JSON response + + puts(response.to_json) + - lang: scala + label: Scala + source: > + // Initialize the client + + val client = AbtestingClient(appId = "YOUR_APP_ID", apiKey = + "YOUR_API_KEY", region = Option("YOUR_APP_ID_REGION")) + + + // Call the API + + val response = client.scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = Seq( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30 + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50 + ) + ) + ) + ) + + + // Use the response + + val value = Await.result(response, Duration(100, "sec")) + - lang: swift + label: Swift + source: > + // Initialize the client + + let client = try AbtestingClient(appID: "YOUR_APP_ID", apiKey: + "YOUR_API_KEY", region: .us) + + + // Call the API + + let response = try await + client.scheduleABTest(scheduleABTestsRequest: + ScheduleABTestsRequest( + name: "myABTest", + variants: [ + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_1", trafficPercentage: 30)), + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_2", trafficPercentage: 50)), + ], + scheduledAt: "2022-11-31T00:00:00.000Z", + endAt: "2022-12-31T00:00:00.000Z" + )) components: securitySchemes: appId: @@ -2774,6 +3128,24 @@ components: - abTestID - index - taskID + scheduledAt: + type: string + description: >- + Date and time when the A/B test is scheduled to start, in RFC 3339 + format. + example: '2023-06-15T15:06:44.400601Z' + abTestScheduleID: + type: integer + description: Unique scheduled A/B test identifier. + example: 224 + ScheduleABTestResponse: + type: object + additionalProperties: false + properties: + abTestScheduleID: + $ref: '#/components/schemas/abTestScheduleID' + required: + - abTestScheduleID responses: BadRequest: description: Bad request or request arguments. diff --git a/specs/bundled/abtesting.yml b/specs/bundled/abtesting.yml index 221e5103fea..f76b300e98e 100644 --- a/specs/bundled/abtesting.yml +++ b/specs/bundled/abtesting.yml @@ -443,6 +443,65 @@ paths: $ref: '#/components/responses/MethodNotAllowed' '404': $ref: '#/components/responses/IndexNotFound' + /2/abtests/schedule: + post: + tags: + - abtesting + operationId: scheduleABTest + x-acl: + - editSettings + summary: Schedule an A/B test + description: | + Schedule an A/B test to be started at a later time. + requestBody: + required: true + content: + application/json: + schema: + title: scheduleABTestsRequest + type: object + additionalProperties: false + properties: + name: + $ref: '#/components/schemas/name' + variants: + type: array + description: A/B test variants. + minItems: 2 + maxItems: 2 + items: + $ref: '#/components/schemas/AddABTestsVariant' + scheduledAt: + $ref: '#/components/schemas/scheduledAt' + endAt: + $ref: '#/components/schemas/endAt' + required: + - name + - variants + - scheduledAt + - endAt + responses: + '200': + description: OK + headers: + x-ratelimit-limit: + $ref: '#/components/headers/x-ratelimit-limit' + x-ratelimit-remaining: + $ref: '#/components/headers/x-ratelimit-remaining' + x-ratelimit-reset: + $ref: '#/components/headers/x-ratelimit-reset' + content: + application/json: + schema: + $ref: '#/components/schemas/ScheduleABTestResponse' + '400': + $ref: '#/components/responses/BadRequest' + '402': + $ref: '#/components/responses/FeatureNotEnabled' + '403': + $ref: '#/components/responses/MethodNotAllowed' + '404': + $ref: '#/components/responses/IndexNotFound' components: securitySchemes: appId: @@ -1033,6 +1092,24 @@ components: - abTestID - index - taskID + scheduledAt: + type: string + description: >- + Date and time when the A/B test is scheduled to start, in RFC 3339 + format. + example: '2023-06-15T15:06:44.400601Z' + abTestScheduleID: + type: integer + description: Unique scheduled A/B test identifier. + example: 224 + ScheduleABTestResponse: + type: object + additionalProperties: false + properties: + abTestScheduleID: + $ref: '#/components/schemas/abTestScheduleID' + required: + - abTestScheduleID responses: BadRequest: description: Bad request or request arguments. diff --git a/tests/output/csharp/src/generated/requests/Abtesting.test.cs b/tests/output/csharp/src/generated/requests/Abtesting.test.cs index 5db6e946cb2..790fa9d89be 100644 --- a/tests/output/csharp/src/generated/requests/Abtesting.test.cs +++ b/tests/output/csharp/src/generated/requests/Abtesting.test.cs @@ -602,6 +602,35 @@ public async Task ListABTestsTest1() } } + [Fact(DisplayName = "scheduleABTest with minimal parameters")] + public async Task ScheduleABTestTest() + { + await client.ScheduleABTestAsync( + new ScheduleABTestsRequest + { + EndAt = "2022-12-31T00:00:00.000Z", + ScheduledAt = "2022-11-31T00:00:00.000Z", + Name = "myABTest", + Variants = new List + { + new AddABTestsVariant( + new AbTestsVariant { Index = "AB_TEST_1", TrafficPercentage = 30, } + ), + new AddABTestsVariant(new AbTestsVariant { Index = "AB_TEST_2", TrafficPercentage = 50, }) + }, + } + ); + + var req = _echo.LastResponse; + Assert.Equal("/2/abtests/schedule", req.Path); + Assert.Equal("POST", req.Method.ToString()); + JsonAssert.EqualOverrideDefault( + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"scheduledAt\":\"2022-11-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}", + req.Body, + new JsonDiffConfig(false) + ); + } + [Fact(DisplayName = "stopABTest")] public async Task StopABTestTest() { diff --git a/tests/output/go/tests/requests/abtesting_test.go b/tests/output/go/tests/requests/abtesting_test.go index 95bc978b670..cc48760ada7 100644 --- a/tests/output/go/tests/requests/abtesting_test.go +++ b/tests/output/go/tests/requests/abtesting_test.go @@ -476,6 +476,28 @@ func TestAbtesting_ListABTests(t *testing.T) { }) } +func TestAbtesting_ScheduleABTest(t *testing.T) { + client, echo := createAbtestingClient(t) + _ = echo + + t.Run("scheduleABTest with minimal parameters", func(t *testing.T) { + _, err := client.ScheduleABTest(client.NewApiScheduleABTestRequest( + + abtesting.NewEmptyScheduleABTestsRequest().SetEndAt("2022-12-31T00:00:00.000Z").SetScheduledAt("2022-11-31T00:00:00.000Z").SetName("myABTest").SetVariants( + []abtesting.AddABTestsVariant{*abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_1").SetTrafficPercentage(30)), *abtesting.AbTestsVariantAsAddABTestsVariant( + abtesting.NewEmptyAbTestsVariant().SetIndex("AB_TEST_2").SetTrafficPercentage(50))}), + )) + require.NoError(t, err) + + require.Equal(t, "/2/abtests/schedule", echo.Path) + require.Equal(t, "POST", echo.Method) + + ja := jsonassert.New(t) + ja.Assertf(*echo.Body, `{"endAt":"2022-12-31T00:00:00.000Z","scheduledAt":"2022-11-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}`) + }) +} + func TestAbtesting_StopABTest(t *testing.T) { client, echo := createAbtestingClient(t) _ = echo diff --git a/tests/output/java/src/test/java/com/algolia/requests/Abtesting.test.java b/tests/output/java/src/test/java/com/algolia/requests/Abtesting.test.java index eb17b31d56c..2273951cb71 100644 --- a/tests/output/java/src/test/java/com/algolia/requests/Abtesting.test.java +++ b/tests/output/java/src/test/java/com/algolia/requests/Abtesting.test.java @@ -636,6 +636,35 @@ void listABTestsTest1() { } } + @Test + @DisplayName("scheduleABTest with minimal parameters") + void scheduleABTestTest() { + assertDoesNotThrow(() -> { + client.scheduleABTest( + new ScheduleABTestsRequest() + .setEndAt("2022-12-31T00:00:00.000Z") + .setScheduledAt("2022-11-31T00:00:00.000Z") + .setName("myABTest") + .setVariants( + List.of( + new AbTestsVariant().setIndex("AB_TEST_1").setTrafficPercentage(30), + new AbTestsVariant().setIndex("AB_TEST_2").setTrafficPercentage(50) + ) + ) + ); + }); + EchoResponse req = echo.getLastResponse(); + assertEquals("/2/abtests/schedule", req.path); + assertEquals("POST", req.method); + assertDoesNotThrow(() -> + JSONAssert.assertEquals( + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"scheduledAt\":\"2022-11-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}", + req.body, + JSONCompareMode.STRICT + ) + ); + } + @Test @DisplayName("stopABTest") void stopABTestTest() { diff --git a/tests/output/javascript/src/requests/abtesting.test.ts b/tests/output/javascript/src/requests/abtesting.test.ts index 93693ff70db..b04e862f2e1 100644 --- a/tests/output/javascript/src/requests/abtesting.test.ts +++ b/tests/output/javascript/src/requests/abtesting.test.ts @@ -403,6 +403,33 @@ describe('listABTests', () => { }); }); +describe('scheduleABTest', () => { + test('scheduleABTest with minimal parameters', async () => { + const req = (await client.scheduleABTest({ + endAt: '2022-12-31T00:00:00.000Z', + scheduledAt: '2022-11-31T00:00:00.000Z', + name: 'myABTest', + variants: [ + { index: 'AB_TEST_1', trafficPercentage: 30 }, + { index: 'AB_TEST_2', trafficPercentage: 50 }, + ], + })) as unknown as EchoResponse; + + expect(req.path).toEqual('/2/abtests/schedule'); + expect(req.method).toEqual('POST'); + expect(req.data).toEqual({ + endAt: '2022-12-31T00:00:00.000Z', + scheduledAt: '2022-11-31T00:00:00.000Z', + name: 'myABTest', + variants: [ + { index: 'AB_TEST_1', trafficPercentage: 30 }, + { index: 'AB_TEST_2', trafficPercentage: 50 }, + ], + }); + expect(req.searchParams).toStrictEqual(undefined); + }); +}); + describe('stopABTest', () => { test('stopABTest', async () => { const req = (await client.stopABTest({ diff --git a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/AbtestingTest.kt b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/AbtestingTest.kt index 51855fa8324..17fb42f6bf5 100644 --- a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/AbtestingTest.kt +++ b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/requests/AbtestingTest.kt @@ -569,6 +569,38 @@ class AbtestingTest { ) } + // scheduleABTest + + @Test + fun `scheduleABTest with minimal parameters`() = runTest { + client.runTest( + call = { + scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = listOf( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30, + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50, + ), + ), + ), + ) + }, + intercept = { + assertEquals("/2/abtests/schedule".toPathSegments(), it.url.pathSegments) + assertEquals(HttpMethod.parse("POST"), it.method) + assertJsonBody("""{"endAt":"2022-12-31T00:00:00.000Z","scheduledAt":"2022-11-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}""", it.body) + }, + ) + } + // stopABTest @Test diff --git a/tests/output/php/src/requests/AbtestingTest.php b/tests/output/php/src/requests/AbtestingTest.php index fc9b2a8b56f..940e8beb3ce 100644 --- a/tests/output/php/src/requests/AbtestingTest.php +++ b/tests/output/php/src/requests/AbtestingTest.php @@ -560,6 +560,35 @@ public function testListABTests1() ]); } + #[TestDox('scheduleABTest with minimal parameters')] + public function testScheduleABTest() + { + $client = $this->getClient(); + $client->scheduleABTest( + ['endAt' => '2022-12-31T00:00:00.000Z', + 'scheduledAt' => '2022-11-31T00:00:00.000Z', + 'name' => 'myABTest', + 'variants' => [ + ['index' => 'AB_TEST_1', + 'trafficPercentage' => 30, + ], + + ['index' => 'AB_TEST_2', + 'trafficPercentage' => 50, + ], + ], + ], + ); + + $this->assertRequests([ + [ + 'path' => '/2/abtests/schedule', + 'method' => 'POST', + 'body' => json_decode('{"endAt":"2022-12-31T00:00:00.000Z","scheduledAt":"2022-11-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}'), + ], + ]); + } + #[TestDox('stopABTest')] public function testStopABTest() { diff --git a/tests/output/python/tests/requests/abtesting_test.py b/tests/output/python/tests/requests/abtesting_test.py index 7ab670a851e..39f27de5ad3 100644 --- a/tests/output/python/tests/requests/abtesting_test.py +++ b/tests/output/python/tests/requests/abtesting_test.py @@ -492,6 +492,36 @@ async def test_list_ab_tests_1(self): assert _req.headers.items() >= {}.items() assert _req.data is None + async def test_schedule_ab_test_(self): + """ + scheduleABTest with minimal parameters + """ + _req = await self._client.schedule_ab_test_with_http_info( + schedule_ab_tests_request={ + "endAt": "2022-12-31T00:00:00.000Z", + "scheduledAt": "2022-11-31T00:00:00.000Z", + "name": "myABTest", + "variants": [ + { + "index": "AB_TEST_1", + "trafficPercentage": 30, + }, + { + "index": "AB_TEST_2", + "trafficPercentage": 50, + }, + ], + }, + ) + + assert _req.path == "/2/abtests/schedule" + assert _req.verb == "POST" + assert _req.query_parameters.items() == {}.items() + assert _req.headers.items() >= {}.items() + assert loads(_req.data) == loads( + """{"endAt":"2022-12-31T00:00:00.000Z","scheduledAt":"2022-11-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}""" + ) + async def test_stop_ab_test_(self): """ stopABTest diff --git a/tests/output/ruby/test/requests/abtesting_test.rb b/tests/output/ruby/test/requests/abtesting_test.rb index 5f0f7753d91..1106391dd44 100644 --- a/tests/output/ruby/test/requests/abtesting_test.rb +++ b/tests/output/ruby/test/requests/abtesting_test.rb @@ -359,6 +359,32 @@ def test_list_ab_tests1 assert(req.body.nil?, "body is not nil") end + # scheduleABTest with minimal parameters + def test_schedule_ab_test + req = @client.schedule_ab_test_with_http_info( + ScheduleABTestsRequest.new( + end_at: "2022-12-31T00:00:00.000Z", + scheduled_at: "2022-11-31T00:00:00.000Z", + name: "myABTest", + variants: [ + AbTestsVariant.new(index: "AB_TEST_1", traffic_percentage: 30), + AbTestsVariant.new(index: "AB_TEST_2", traffic_percentage: 50) + ] + ) + ) + + assert_equal(:post, req.method) + assert_equal("/2/abtests/schedule", req.path) + assert_equal({}.to_a, req.query_params.to_a) + assert(({}.to_a - req.headers.to_a).empty?, req.headers.to_s) + assert_equal( + JSON.parse( + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"scheduledAt\":\"2022-11-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}" + ), + JSON.parse(req.body) + ) + end + # stopABTest def test_stop_ab_test req = @client.stop_ab_test_with_http_info(42) diff --git a/tests/output/scala/src/test/scala/algoliasearch/requests/AbtestingTest.scala b/tests/output/scala/src/test/scala/algoliasearch/requests/AbtestingTest.scala index 8f9dc5daddb..8af937a3c53 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/requests/AbtestingTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/requests/AbtestingTest.scala @@ -616,6 +616,38 @@ class AbtestingTest extends AnyFunSuite { } } + test("scheduleABTest with minimal parameters") { + val (client, echo) = testClient() + val future = client.scheduleABTest( + scheduleABTestsRequest = ScheduleABTestsRequest( + endAt = "2022-12-31T00:00:00.000Z", + scheduledAt = "2022-11-31T00:00:00.000Z", + name = "myABTest", + variants = Seq( + AbTestsVariant( + index = "AB_TEST_1", + trafficPercentage = 30 + ), + AbTestsVariant( + index = "AB_TEST_2", + trafficPercentage = 50 + ) + ) + ) + ) + + Await.ready(future, Duration.Inf) + val res = echo.lastResponse.get + + assert(res.path == "/2/abtests/schedule") + assert(res.method == "POST") + val expectedBody = parse( + """{"endAt":"2022-12-31T00:00:00.000Z","scheduledAt":"2022-11-31T00:00:00.000Z","name":"myABTest","variants":[{"index":"AB_TEST_1","trafficPercentage":30},{"index":"AB_TEST_2","trafficPercentage":50}]}""" + ) + val actualBody = parse(res.body.get) + assert(actualBody == expectedBody) + } + test("stopABTest") { val (client, echo) = testClient() val future = client.stopABTest( diff --git a/tests/output/swift/Tests/requests/AbtestingTests.swift b/tests/output/swift/Tests/requests/AbtestingTests.swift index 9e90abd750e..6ec84ff45a8 100644 --- a/tests/output/swift/Tests/requests/AbtestingTests.swift +++ b/tests/output/swift/Tests/requests/AbtestingTests.swift @@ -840,6 +840,44 @@ final class AbtestingClientRequestsTests: XCTestCase { XCTAssertEqual(echoResponse.queryParameters, expectedQueryParametersMap) } + /// scheduleABTest with minimal parameters + func testScheduleABTestTest() async throws { + let configuration = try AbtestingClientConfiguration( + appID: AbtestingClientRequestsTests.APPLICATION_ID, + apiKey: AbtestingClientRequestsTests.API_KEY, + region: Region.us + ) + let transporter = Transporter(configuration: configuration, requestBuilder: EchoRequestBuilder()) + let client = AbtestingClient(configuration: configuration, transporter: transporter) + + let response = try await client.scheduleABTestWithHTTPInfo(scheduleABTestsRequest: ScheduleABTestsRequest( + name: "myABTest", + variants: [ + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_1", trafficPercentage: 30)), + AddABTestsVariant.abTestsVariant(AbTestsVariant(index: "AB_TEST_2", trafficPercentage: 50)), + ], + scheduledAt: "2022-11-31T00:00:00.000Z", + endAt: "2022-12-31T00:00:00.000Z" + )) + let responseBodyData = try XCTUnwrap(response.bodyData) + let echoResponse = try CodableHelper.jsonDecoder.decode(EchoResponse.self, from: responseBodyData) + + let echoResponseBodyData = try XCTUnwrap(echoResponse.originalBodyData) + let echoResponseBodyJSON = try XCTUnwrap(echoResponseBodyData.jsonString) + + let expectedBodyData = + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"scheduledAt\":\"2022-11-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variants\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}" + .data(using: .utf8) + let expectedBodyJSON = try XCTUnwrap(expectedBodyData?.jsonString) + + XCTAssertEqual(echoResponseBodyJSON, expectedBodyJSON) + + XCTAssertEqual(echoResponse.path, "/2/abtests/schedule") + XCTAssertEqual(echoResponse.method, HTTPMethod.post) + + XCTAssertNil(echoResponse.queryParameters) + } + /// stopABTest func testStopABTestTest() async throws { let configuration = try AbtestingClientConfiguration(