From 5b6964a776b6e4f0adf789bacdd7ef603ae3cddd Mon Sep 17 00:00:00 2001 From: Justin Koke Date: Thu, 9 Sep 2021 22:34:23 +1000 Subject: [PATCH] Update to support the SendEvent API + security version bump for RestSharp --- docs/EventsApi.md | 89 +++++ docs/SendEventRequest.md | 13 + src/Com.Sajari.Sdk.Test/Api/EventsApiTests.cs | 70 ++++ .../Model/SendEventRequestTests.cs | 95 +++++ src/Com.Sajari.Sdk/Api/EventsApi.cs | 333 ++++++++++++++++++ src/Com.Sajari.Sdk/Model/SendEventRequest.cs | 184 ++++++++++ 6 files changed, 784 insertions(+) create mode 100644 docs/EventsApi.md create mode 100644 docs/SendEventRequest.md create mode 100644 src/Com.Sajari.Sdk.Test/Api/EventsApiTests.cs create mode 100644 src/Com.Sajari.Sdk.Test/Model/SendEventRequestTests.cs create mode 100644 src/Com.Sajari.Sdk/Api/EventsApi.cs create mode 100644 src/Com.Sajari.Sdk/Model/SendEventRequest.cs diff --git a/docs/EventsApi.md b/docs/EventsApi.md new file mode 100644 index 0000000..63d8edd --- /dev/null +++ b/docs/EventsApi.md @@ -0,0 +1,89 @@ +# Com.Sajari.Sdk.Api.EventsApi + +All URIs are relative to *https://api-gateway.sajari.com* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**SendEvent**](EventsApi.md#sendevent) | **POST** /v4/events:sendEvent | Send event + + + +# **SendEvent** +> Object SendEvent (SendEventRequest sendEventRequest) + +Send event + +Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + +### Example +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using Com.Sajari.Sdk.Api; +using Com.Sajari.Sdk.Client; +using Com.Sajari.Sdk.Model; + +namespace Example +{ + public class SendEventExample + { + public static void Main() + { + Configuration config = new Configuration(); + config.BasePath = "https://api-gateway.sajari.com"; + // Configure HTTP basic authorization: BasicAuth + config.Username = "YOUR_USERNAME"; + config.Password = "YOUR_PASSWORD"; + + var apiInstance = new EventsApi(config); + var sendEventRequest = new SendEventRequest(); // SendEventRequest | + + try + { + // Send event + Object result = apiInstance.SendEvent(sendEventRequest); + Debug.WriteLine(result); + } + catch (ApiException e) + { + Debug.Print("Exception when calling EventsApi.SendEvent: " + e.Message ); + Debug.Print("Status Code: "+ e.ErrorCode); + Debug.Print(e.StackTrace); + } + } + } +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **sendEventRequest** | [**SendEventRequest**](SendEventRequest.md)| | + +### Return type + +**Object** + +### Authorization + +[BasicAuth](../README.md#BasicAuth) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | A successful response. | - | +| **400** | Returned when the request contains violations for one or more fields. | - | +| **401** | Returned when the request does not have valid authentication credentials. | - | +| **403** | Returned when the user does not have permission to access the resource. | - | +| **404** | Returned when the resource does not exist. | - | +| **500** | Returned when the API encounters an internal error. | - | +| **0** | An unexpected error response | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/docs/SendEventRequest.md b/docs/SendEventRequest.md new file mode 100644 index 0000000..f2e20e8 --- /dev/null +++ b/docs/SendEventRequest.md @@ -0,0 +1,13 @@ +# Com.Sajari.Sdk.Model.SendEventRequest +A request to send an event to the ranking system after a user interacts with a search result. +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Name** | **string** | The name of event, e.g. `click`, `purchase`. | +**Token** | **string** | The token corresponding to the search result that was interacted with, e.g. `eyJ...`. | +**Weight** | **int** | The weight assigned to the event. Generally a sensible weight is 1. If you want to weight an event in a certain way you can use a value other than 1. For example, if you want to capture profit in an event, you could set the weight to a value that represents the profit. | [optional] +**Metadata** | **Dictionary<string, Object>** | An object made up of field-value pairs that contains additional metadata to record with the event. Every value in the object must be one of the following primitive types: - boolean - number - string | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + diff --git a/src/Com.Sajari.Sdk.Test/Api/EventsApiTests.cs b/src/Com.Sajari.Sdk.Test/Api/EventsApiTests.cs new file mode 100644 index 0000000..bb2a69c --- /dev/null +++ b/src/Com.Sajari.Sdk.Test/Api/EventsApiTests.cs @@ -0,0 +1,70 @@ +/* + * Sajari API + * + * Sajari is a smart, highly-configurable, real-time search service that enables thousands of businesses worldwide to provide amazing search experiences on their websites, stores, and applications. + * + * The version of the OpenAPI document: v4 + * Contact: support@sajari.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Com.Sajari.Sdk.Client; +using Com.Sajari.Sdk.Api; +// uncomment below to import models +//using Com.Sajari.Sdk.Model; + +namespace Com.Sajari.Sdk.Test.Api +{ + /// + /// Class for testing EventsApi + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the API endpoint. + /// + public class EventsApiTests : IDisposable + { + private EventsApi instance; + + public EventsApiTests() + { + instance = new EventsApi(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of EventsApi + /// + [Fact] + public void InstanceTest() + { + // TODO uncomment below to test 'IsType' EventsApi + //Assert.IsType(instance); + } + + /// + /// Test SendEvent + /// + [Fact] + public void SendEventTest() + { + // TODO uncomment below to test the method and replace null with proper value + //SendEventRequest sendEventRequest = null; + //var response = instance.SendEvent(sendEventRequest); + //Assert.IsType(response); + } + } +} diff --git a/src/Com.Sajari.Sdk.Test/Model/SendEventRequestTests.cs b/src/Com.Sajari.Sdk.Test/Model/SendEventRequestTests.cs new file mode 100644 index 0000000..e97dade --- /dev/null +++ b/src/Com.Sajari.Sdk.Test/Model/SendEventRequestTests.cs @@ -0,0 +1,95 @@ +/* + * Sajari API + * + * Sajari is a smart, highly-configurable, real-time search service that enables thousands of businesses worldwide to provide amazing search experiences on their websites, stores, and applications. + * + * The version of the OpenAPI document: v4 + * Contact: support@sajari.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + + +using Xunit; + +using System; +using System.Linq; +using System.IO; +using System.Collections.Generic; +using Com.Sajari.Sdk.Api; +using Com.Sajari.Sdk.Model; +using Com.Sajari.Sdk.Client; +using System.Reflection; +using Newtonsoft.Json; + +namespace Com.Sajari.Sdk.Test.Model +{ + /// + /// Class for testing SendEventRequest + /// + /// + /// This file is automatically generated by OpenAPI Generator (https://openapi-generator.tech). + /// Please update the test case below to test the model. + /// + public class SendEventRequestTests : IDisposable + { + // TODO uncomment below to declare an instance variable for SendEventRequest + //private SendEventRequest instance; + + public SendEventRequestTests() + { + // TODO uncomment below to create an instance of SendEventRequest + //instance = new SendEventRequest(); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of SendEventRequest + /// + [Fact] + public void SendEventRequestInstanceTest() + { + // TODO uncomment below to test "IsType" SendEventRequest + //Assert.IsType(instance); + } + + + /// + /// Test the property 'Name' + /// + [Fact] + public void NameTest() + { + // TODO unit test for the property 'Name' + } + /// + /// Test the property 'Token' + /// + [Fact] + public void TokenTest() + { + // TODO unit test for the property 'Token' + } + /// + /// Test the property 'Weight' + /// + [Fact] + public void WeightTest() + { + // TODO unit test for the property 'Weight' + } + /// + /// Test the property 'Metadata' + /// + [Fact] + public void MetadataTest() + { + // TODO unit test for the property 'Metadata' + } + + } + +} diff --git a/src/Com.Sajari.Sdk/Api/EventsApi.cs b/src/Com.Sajari.Sdk/Api/EventsApi.cs new file mode 100644 index 0000000..802337c --- /dev/null +++ b/src/Com.Sajari.Sdk/Api/EventsApi.cs @@ -0,0 +1,333 @@ +/* + * Sajari API + * + * Sajari is a smart, highly-configurable, real-time search service that enables thousands of businesses worldwide to provide amazing search experiences on their websites, stores, and applications. + * + * The version of the OpenAPI document: v4 + * Contact: support@sajari.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Net; +using System.Net.Mime; +using Com.Sajari.Sdk.Client; +using Com.Sajari.Sdk.Model; + +namespace Com.Sajari.Sdk.Api +{ + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IEventsApiSync : IApiAccessor + { + #region Synchronous Operations + /// + /// Send event + /// + /// + /// Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Object + Object SendEvent(SendEventRequest sendEventRequest); + + /// + /// Send event + /// + /// + /// Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// ApiResponse of Object + ApiResponse SendEventWithHttpInfo(SendEventRequest sendEventRequest); + #endregion Synchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IEventsApiAsync : IApiAccessor + { + #region Asynchronous Operations + /// + /// Send event + /// + /// + /// Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Cancellation Token to cancel the request. + /// Task of Object + System.Threading.Tasks.Task SendEventAsync(SendEventRequest sendEventRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + + /// + /// Send event + /// + /// + /// Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (Object) + System.Threading.Tasks.Task> SendEventWithHttpInfoAsync(SendEventRequest sendEventRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + #endregion Asynchronous Operations + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public interface IEventsApi : IEventsApiSync, IEventsApiAsync + { + + } + + /// + /// Represents a collection of functions to interact with the API endpoints + /// + public partial class EventsApi : IEventsApi + { + private Com.Sajari.Sdk.Client.ExceptionFactory _exceptionFactory = (name, response) => null; + + /// + /// Initializes a new instance of the class. + /// + /// + public EventsApi() : this((string)null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + public EventsApi(String basePath) + { + this.Configuration = Com.Sajari.Sdk.Client.Configuration.MergeConfigurations( + Com.Sajari.Sdk.Client.GlobalConfiguration.Instance, + new Com.Sajari.Sdk.Client.Configuration { BasePath = basePath } + ); + this.Client = new Com.Sajari.Sdk.Client.ApiClient(this.Configuration.BasePath); + this.AsynchronousClient = new Com.Sajari.Sdk.Client.ApiClient(this.Configuration.BasePath); + this.ExceptionFactory = Com.Sajari.Sdk.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using Configuration object + /// + /// An instance of Configuration + /// + public EventsApi(Com.Sajari.Sdk.Client.Configuration configuration) + { + if (configuration == null) throw new ArgumentNullException("configuration"); + + this.Configuration = Com.Sajari.Sdk.Client.Configuration.MergeConfigurations( + Com.Sajari.Sdk.Client.GlobalConfiguration.Instance, + configuration + ); + this.Client = new Com.Sajari.Sdk.Client.ApiClient(this.Configuration.BasePath); + this.AsynchronousClient = new Com.Sajari.Sdk.Client.ApiClient(this.Configuration.BasePath); + ExceptionFactory = Com.Sajari.Sdk.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// Initializes a new instance of the class + /// using a Configuration object and client instance. + /// + /// The client interface for synchronous API access. + /// The client interface for asynchronous API access. + /// The configuration object. + public EventsApi(Com.Sajari.Sdk.Client.ISynchronousClient client, Com.Sajari.Sdk.Client.IAsynchronousClient asyncClient, Com.Sajari.Sdk.Client.IReadableConfiguration configuration) + { + if (client == null) throw new ArgumentNullException("client"); + if (asyncClient == null) throw new ArgumentNullException("asyncClient"); + if (configuration == null) throw new ArgumentNullException("configuration"); + + this.Client = client; + this.AsynchronousClient = asyncClient; + this.Configuration = configuration; + this.ExceptionFactory = Com.Sajari.Sdk.Client.Configuration.DefaultExceptionFactory; + } + + /// + /// The client for accessing this underlying API asynchronously. + /// + public Com.Sajari.Sdk.Client.IAsynchronousClient AsynchronousClient { get; set; } + + /// + /// The client for accessing this underlying API synchronously. + /// + public Com.Sajari.Sdk.Client.ISynchronousClient Client { get; set; } + + /// + /// Gets the base path of the API client. + /// + /// The base path + public String GetBasePath() + { + return this.Configuration.BasePath; + } + + /// + /// Gets or sets the configuration object + /// + /// An instance of the Configuration + public Com.Sajari.Sdk.Client.IReadableConfiguration Configuration { get; set; } + + /// + /// Provides a factory method hook for the creation of exceptions. + /// + public Com.Sajari.Sdk.Client.ExceptionFactory ExceptionFactory + { + get + { + if (_exceptionFactory != null && _exceptionFactory.GetInvocationList().Length > 1) + { + throw new InvalidOperationException("Multicast delegate for ExceptionFactory is unsupported."); + } + return _exceptionFactory; + } + set { _exceptionFactory = value; } + } + + /// + /// Send event Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Object + public Object SendEvent(SendEventRequest sendEventRequest) + { + Com.Sajari.Sdk.Client.ApiResponse localVarResponse = SendEventWithHttpInfo(sendEventRequest); + return localVarResponse.Data; + } + + /// + /// Send event Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// ApiResponse of Object + public Com.Sajari.Sdk.Client.ApiResponse SendEventWithHttpInfo(SendEventRequest sendEventRequest) + { + // verify the required parameter 'sendEventRequest' is set + if (sendEventRequest == null) + throw new Com.Sajari.Sdk.Client.ApiException(400, "Missing required parameter 'sendEventRequest' when calling EventsApi->SendEvent"); + + Com.Sajari.Sdk.Client.RequestOptions localVarRequestOptions = new Com.Sajari.Sdk.Client.RequestOptions(); + + String[] _contentTypes = new String[] { + "application/json" + }; + + // to determine the Accept header + String[] _accepts = new String[] { + "application/json" + }; + + var localVarContentType = Com.Sajari.Sdk.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Com.Sajari.Sdk.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.Data = sendEventRequest; + + // authentication (BasicAuth) required + // http basic authentication required + if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Com.Sajari.Sdk.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password)); + } + + // make the HTTP request + var localVarResponse = this.Client.Post("/v4/events:sendEvent", localVarRequestOptions, this.Configuration); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("SendEvent", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + /// + /// Send event Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Cancellation Token to cancel the request. + /// Task of Object + public async System.Threading.Tasks.Task SendEventAsync(SendEventRequest sendEventRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + { + Com.Sajari.Sdk.Client.ApiResponse localVarResponse = await SendEventWithHttpInfoAsync(sendEventRequest, cancellationToken).ConfigureAwait(false); + return localVarResponse.Data; + } + + /// + /// Send event Send an event to the ranking system after a user interacts with a search result. When querying a collection, you can set the tracking type of the query request. When it is `CLICK` or `POS_NEG`, a token is generated for each result in the query response. You can use this token to provide feedback to the ranking system. Each time you want to record an event on a particular search result, use the send event call and provide: - The `name` of the event, e.g. `click`, `purchase`. - The `token` from the search result. - The `weight` to assign to the event, e.g. `1`. - An object containing any additional `metadata`. For example, to send an event where a customer purchased a product, use the following call: ```json { \"name\": \"purchase\", \"token\": \"eyJ...\", \"weight\": 1, \"metadata\": { \"discount\": 0.2, \"margin\": 30.0, \"customer_id\": \"12345\", \"ui_test_segment\": \"A\" } } ``` + /// + /// Thrown when fails to make API call + /// + /// Cancellation Token to cancel the request. + /// Task of ApiResponse (Object) + public async System.Threading.Tasks.Task> SendEventWithHttpInfoAsync(SendEventRequest sendEventRequest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + { + // verify the required parameter 'sendEventRequest' is set + if (sendEventRequest == null) + throw new Com.Sajari.Sdk.Client.ApiException(400, "Missing required parameter 'sendEventRequest' when calling EventsApi->SendEvent"); + + + Com.Sajari.Sdk.Client.RequestOptions localVarRequestOptions = new Com.Sajari.Sdk.Client.RequestOptions(); + + String[] _contentTypes = new String[] { + "application/json" + }; + + // to determine the Accept header + String[] _accepts = new String[] { + "application/json" + }; + + + var localVarContentType = Com.Sajari.Sdk.Client.ClientUtils.SelectHeaderContentType(_contentTypes); + if (localVarContentType != null) localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType); + + var localVarAccept = Com.Sajari.Sdk.Client.ClientUtils.SelectHeaderAccept(_accepts); + if (localVarAccept != null) localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept); + + localVarRequestOptions.Data = sendEventRequest; + + // authentication (BasicAuth) required + // http basic authentication required + if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password)) + { + localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Com.Sajari.Sdk.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password)); + } + + // make the HTTP request + + var localVarResponse = await this.AsynchronousClient.PostAsync("/v4/events:sendEvent", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false); + + if (this.ExceptionFactory != null) + { + Exception _exception = this.ExceptionFactory("SendEvent", localVarResponse); + if (_exception != null) throw _exception; + } + + return localVarResponse; + } + + } +} diff --git a/src/Com.Sajari.Sdk/Model/SendEventRequest.cs b/src/Com.Sajari.Sdk/Model/SendEventRequest.cs new file mode 100644 index 0000000..0368d8a --- /dev/null +++ b/src/Com.Sajari.Sdk/Model/SendEventRequest.cs @@ -0,0 +1,184 @@ +/* + * Sajari API + * + * Sajari is a smart, highly-configurable, real-time search service that enables thousands of businesses worldwide to provide amazing search experiences on their websites, stores, and applications. + * + * The version of the OpenAPI document: v4 + * Contact: support@sajari.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.IO; +using System.Runtime.Serialization; +using System.Text; +using System.Text.RegularExpressions; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using System.ComponentModel.DataAnnotations; +using OpenAPIDateConverter = Com.Sajari.Sdk.Client.OpenAPIDateConverter; + +namespace Com.Sajari.Sdk.Model +{ + /// + /// A request to send an event to the ranking system after a user interacts with a search result. + /// + [DataContract(Name = "SendEventRequest")] + public partial class SendEventRequest : IEquatable, IValidatableObject + { + /// + /// Initializes a new instance of the class. + /// + [JsonConstructorAttribute] + protected SendEventRequest() { } + /// + /// Initializes a new instance of the class. + /// + /// The name of event, e.g. `click`, `purchase`. (required). + /// The token corresponding to the search result that was interacted with, e.g. `eyJ...`. (required). + /// The weight assigned to the event. Generally a sensible weight is 1. If you want to weight an event in a certain way you can use a value other than 1. For example, if you want to capture profit in an event, you could set the weight to a value that represents the profit.. + /// An object made up of field-value pairs that contains additional metadata to record with the event. Every value in the object must be one of the following primitive types: - boolean - number - string. + public SendEventRequest(string name = default(string), string token = default(string), int weight = default(int), Dictionary metadata = default(Dictionary)) + { + // to ensure "name" is required (not null) + this.Name = name ?? throw new ArgumentNullException("name is a required property for SendEventRequest and cannot be null"); + // to ensure "token" is required (not null) + this.Token = token ?? throw new ArgumentNullException("token is a required property for SendEventRequest and cannot be null"); + this.Weight = weight; + this.Metadata = metadata; + } + + /// + /// The name of event, e.g. `click`, `purchase`. + /// + /// The name of event, e.g. `click`, `purchase`. + [DataMember(Name = "name", IsRequired = true, EmitDefaultValue = false)] + public string Name { get; set; } + + /// + /// The token corresponding to the search result that was interacted with, e.g. `eyJ...`. + /// + /// The token corresponding to the search result that was interacted with, e.g. `eyJ...`. + [DataMember(Name = "token", IsRequired = true, EmitDefaultValue = false)] + public string Token { get; set; } + + /// + /// The weight assigned to the event. Generally a sensible weight is 1. If you want to weight an event in a certain way you can use a value other than 1. For example, if you want to capture profit in an event, you could set the weight to a value that represents the profit. + /// + /// The weight assigned to the event. Generally a sensible weight is 1. If you want to weight an event in a certain way you can use a value other than 1. For example, if you want to capture profit in an event, you could set the weight to a value that represents the profit. + [DataMember(Name = "weight", EmitDefaultValue = false)] + public int Weight { get; set; } + + /// + /// An object made up of field-value pairs that contains additional metadata to record with the event. Every value in the object must be one of the following primitive types: - boolean - number - string + /// + /// An object made up of field-value pairs that contains additional metadata to record with the event. Every value in the object must be one of the following primitive types: - boolean - number - string + [DataMember(Name = "metadata", EmitDefaultValue = false)] + public Dictionary Metadata { get; set; } + + /// + /// Returns the string presentation of the object + /// + /// String presentation of the object + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class SendEventRequest {\n"); + sb.Append(" Name: ").Append(Name).Append("\n"); + sb.Append(" Token: ").Append(Token).Append("\n"); + sb.Append(" Weight: ").Append(Weight).Append("\n"); + sb.Append(" Metadata: ").Append(Metadata).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 JsonConvert.SerializeObject(this, Formatting.Indented); + } + + /// + /// Returns true if objects are equal + /// + /// Object to be compared + /// Boolean + public override bool Equals(object input) + { + return this.Equals(input as SendEventRequest); + } + + /// + /// Returns true if SendEventRequest instances are equal + /// + /// Instance of SendEventRequest to be compared + /// Boolean + public bool Equals(SendEventRequest input) + { + if (input == null) + return false; + + return + ( + this.Name == input.Name || + (this.Name != null && + this.Name.Equals(input.Name)) + ) && + ( + this.Token == input.Token || + (this.Token != null && + this.Token.Equals(input.Token)) + ) && + ( + this.Weight == input.Weight || + this.Weight.Equals(input.Weight) + ) && + ( + this.Metadata == input.Metadata || + this.Metadata != null && + input.Metadata != null && + this.Metadata.SequenceEqual(input.Metadata) + ); + } + + /// + /// Gets the hash code + /// + /// Hash code + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.Name != null) + hashCode = hashCode * 59 + this.Name.GetHashCode(); + if (this.Token != null) + hashCode = hashCode * 59 + this.Token.GetHashCode(); + hashCode = hashCode * 59 + this.Weight.GetHashCode(); + if (this.Metadata != null) + hashCode = hashCode * 59 + this.Metadata.GetHashCode(); + return hashCode; + } + } + + /// + /// To validate all properties of the instance + /// + /// Validation context + /// Validation Result + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + yield break; + } + } + +}