Skip to content

Commit

Permalink
Update to support SendEvent API
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkoke committed Sep 9, 2021
1 parent 09803ec commit 4565049
Show file tree
Hide file tree
Showing 17 changed files with 544 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ target/

#Ipython Notebook
.ipynb_checkpoints
/.openapi-generator-ignore
6 changes: 6 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ docs/Collection.md
docs/CollectionsApi.md
docs/DeleteRecordRequest.md
docs/Error.md
docs/EventsApi.md
docs/GeneratePipelinesRequest.md
docs/GeneratePipelinesResponse.md
docs/GetDefaultPipelineResponse.md
Expand Down Expand Up @@ -55,6 +56,7 @@ docs/SchemaApi.md
docs/SchemaField.md
docs/SchemaFieldMode.md
docs/SchemaFieldType.md
docs/SendEventRequest.md
docs/SetDefaultPipelineRequest.md
docs/SetDefaultVersionRequest.md
docs/Status.md
Expand All @@ -67,6 +69,7 @@ sajari_client/api_client.py
sajari_client/apis/__init__.py
sajari_client/com.sajari.client.api/__init__.py
sajari_client/com/sajari/client/api/collections_api.py
sajari_client/com/sajari/client/api/events_api.py
sajari_client/com/sajari/client/api/pipelines_api.py
sajari_client/com/sajari/client/api/records_api.py
sajari_client/com/sajari/client/api/schema_api.py
Expand Down Expand Up @@ -124,6 +127,7 @@ sajari_client/model/record_key.py
sajari_client/model/schema_field.py
sajari_client/model/schema_field_mode.py
sajari_client/model/schema_field_type.py
sajari_client/model/send_event_request.py
sajari_client/model/set_default_pipeline_request.py
sajari_client/model/set_default_version_request.py
sajari_client/model/status.py
Expand All @@ -137,4 +141,6 @@ setup.cfg
setup.py
test-requirements.txt
test/__init__.py
test/test_events_api.py
test/test_send_event_request.py
tox.ini
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ configuration = sajari_client.Configuration(

# Configure HTTP basic authorization: BasicAuth
configuration = sajari_client.Configuration(
username = 'YOUR_USERNAME',
password = 'YOUR_PASSWORD'
username = 'KEY_ID',
password = 'KEY_SECRET'
)


Expand Down Expand Up @@ -106,6 +106,7 @@ Class | Method | HTTP request | Description
*CollectionsApi* | [**list_collections**](docs/CollectionsApi.md#list_collections) | **GET** /v4/collections | List collections
*CollectionsApi* | [**query_collection**](docs/CollectionsApi.md#query_collection) | **POST** /v4/collections/{collection_id}:queryCollection | Query collection
*CollectionsApi* | [**update_collection**](docs/CollectionsApi.md#update_collection) | **PATCH** /v4/collections/{collection_id} | Update collection
*EventsApi* | [**send_event**](docs/EventsApi.md#send_event) | **POST** /v4/events:sendEvent | Send event
*PipelinesApi* | [**create_pipeline**](docs/PipelinesApi.md#create_pipeline) | **POST** /v4/collections/{collection_id}/pipelines | Create pipeline
*PipelinesApi* | [**generate_pipelines**](docs/PipelinesApi.md#generate_pipelines) | **POST** /v4/collections/{collection_id}:generatePipelines | Generate pipelines
*PipelinesApi* | [**get_default_pipeline**](docs/PipelinesApi.md#get_default_pipeline) | **GET** /v4/collections/{collection_id}:getDefaultPipeline | Get default pipeline
Expand Down Expand Up @@ -176,6 +177,7 @@ Class | Method | HTTP request | Description
- [SchemaField](docs/SchemaField.md)
- [SchemaFieldMode](docs/SchemaFieldMode.md)
- [SchemaFieldType](docs/SchemaFieldType.md)
- [SendEventRequest](docs/SendEventRequest.md)
- [SetDefaultPipelineRequest](docs/SetDefaultPipelineRequest.md)
- [SetDefaultVersionRequest](docs/SetDefaultVersionRequest.md)
- [Status](docs/Status.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/CollectionsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Name | Type | Description | Notes
Delete collection

Delete a collection and all of its associated data. > Note: this operation cannot be reversed.
Delete a collection and all of its associated data. > Note: This operation cannot be reversed.

### Example

Expand Down
99 changes: 99 additions & 0 deletions docs/EventsApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# sajari_client.EventsApi

All URIs are relative to *https://api-gateway.sajari.com*

Method | HTTP request | Description
------------- | ------------- | -------------
[**send_event**](EventsApi.md#send_event) | **POST** /v4/events:sendEvent | Send event


# **send_event**
> {str: (bool, date, datetime, dict, float, int, list, str, none_type)} send_event(send_event_request)
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

* Basic Authentication (BasicAuth):
```python
import time
import sajari_client
from com.sajari.client.api import events_api
from sajari_client.model.send_event_request import SendEventRequest
from sajari_client.model.error import Error
from pprint import pprint
# Defining the host is optional and defaults to https://api-gateway.sajari.com
# See configuration.py for a list of all supported configuration parameters.
configuration = sajari_client.Configuration(
host = "https://api-gateway.sajari.com"
)

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure HTTP basic authorization: BasicAuth
configuration = sajari_client.Configuration(
username = 'YOUR_USERNAME',
password = 'YOUR_PASSWORD'
)

# Enter a context with an instance of the API client
with sajari_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = events_api.EventsApi(api_client)
send_event_request = SendEventRequest(
name="name_example",
token="token_example",
weight=1,
metadata={
"key": {},
},
) # SendEventRequest |

# example passing only required values which don't have defaults set
try:
# Send event
api_response = api_instance.send_event(send_event_request)
pprint(api_response)
except sajari_client.ApiException as e:
print("Exception when calling EventsApi->send_event: %s\n" % e)
```


### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**send_event_request** | [**SendEventRequest**](SendEventRequest.md)| |

### Return type

**{str: (bool, date, datetime, dict, float, int, list, str, none_type)}**

### 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)

2 changes: 1 addition & 1 deletion docs/QueryCollectionRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A request to perform a search using a pipeline.
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**variables** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | The initial values for the variables the pipeline operates on and transforms throughout its steps. A typical variable is `q` which is the query the user entered, for example: ```json { \"q\": \"search terms\" } ``` |
**variables** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | The initial values for the variables the pipeline operates on and transforms throughout its steps. The most important variable is `q` which is the query the user entered, for example: ```json { \"q\": \"search terms\" } ``` To paginate through results, set the variables `page` and `resultsPerPage`, for example: ```json { \"q\": \"search terms\", \"page\": 5, \"resultsPerPage\": 20 } ``` To sort results, set the variable `sort` to the name of one of your collection's schema fields, for example: ```json { \"q\": \"search terms\", \"sort\": \"name\" } ``` To sort in reverse, prefix the schema field with a minus sign `-`, for example: ```json { \"q\": \"search terms\", \"sort\": \"-name\" } ``` |
**pipeline** | [**QueryCollectionRequestPipeline**](QueryCollectionRequestPipeline.md) | | [optional]
**tracking** | [**QueryCollectionRequestTracking**](QueryCollectionRequestTracking.md) | | [optional]

Expand Down
15 changes: 15 additions & 0 deletions docs/SendEventRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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** | **str** | The name of event, e.g. `click`, `purchase`. |
**token** | **str** | 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** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)}** | 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)


2 changes: 1 addition & 1 deletion generate/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if [ -z "$TEMPLATES_PATH" ]; then
die "TEMPLATES_PATH must be set, e.g. /path/to/sajari/sdk-python/generate/templates"
fi

VERSION=4.0.0
VERSION=4.1.0

docker-entrypoint.sh generate \
-i /openapi.json \
Expand Down
2 changes: 1 addition & 1 deletion sajari_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'sajari-sdk-python-4.0.0'
self.user_agent = 'sajari-sdk-python-4.1.0'

def __enter__(self):
return self
Expand Down
1 change: 1 addition & 0 deletions sajari_client/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# Import APIs into API package:
from com.sajari.client.api.collections_api import CollectionsApi
from com.sajari.client.api.events_api import EventsApi
from com.sajari.client.api.pipelines_api import PipelinesApi
from com.sajari.client.api.records_api import RecordsApi
from com.sajari.client.api.schema_api import SchemaApi
2 changes: 1 addition & 1 deletion sajari_client/com/sajari/client/api/collections_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __delete_collection(
):
"""Delete collection # noqa: E501
Delete a collection and all of its associated data. > Note: this operation cannot be reversed. # noqa: E501
Delete a collection and all of its associated data. > Note: This operation cannot be reversed. # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
Expand Down
159 changes: 159 additions & 0 deletions sajari_client/com/sajari/client/api/events_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
"""
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. # noqa: E501
The version of the OpenAPI document: v4
Contact: [email protected]
Generated by: https://openapi-generator.tech
"""


import re # noqa: F401
import sys # noqa: F401

from sajari_client.api_client import ApiClient, Endpoint as _Endpoint
from sajari_client.model_utils import ( # noqa: F401
check_allowed_values,
check_validations,
date,
datetime,
file_type,
none_type,
validate_and_convert_types
)
from sajari_client.model.error import Error
from sajari_client.model.send_event_request import SendEventRequest


class EventsApi(object):
"""NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""

def __init__(self, api_client=None):
if api_client is None:
api_client = ApiClient()
self.api_client = api_client

def __send_event(
self,
send_event_request,
**kwargs
):
"""Send event # noqa: E501
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\" } } ``` # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.send_event(send_event_request, async_req=True)
>>> result = thread.get()
Args:
send_event_request (SendEventRequest):
Keyword Args:
_return_http_data_only (bool): response data without head status
code and headers. Default is True.
_preload_content (bool): if False, the urllib3.HTTPResponse object
will be returned without reading/decoding response data.
Default is True.
_request_timeout (float/tuple): timeout setting for this request. If one
number provided, it will be total request timeout. It can also
be a pair (tuple) of (connection, read) timeouts.
Default is None.
_check_input_type (bool): specifies if type checking
should be done one the data sent to the server.
Default is True.
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
async_req (bool): execute request asynchronously
Returns:
{str: (bool, date, datetime, dict, float, int, list, str, none_type)}
If the method is called asynchronously, returns the request
thread.
"""
kwargs['async_req'] = kwargs.get(
'async_req', False
)
kwargs['_return_http_data_only'] = kwargs.get(
'_return_http_data_only', True
)
kwargs['_preload_content'] = kwargs.get(
'_preload_content', True
)
kwargs['_request_timeout'] = kwargs.get(
'_request_timeout', None
)
kwargs['_check_input_type'] = kwargs.get(
'_check_input_type', True
)
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['send_event_request'] = \
send_event_request
return self.call_with_http_info(**kwargs)

self.send_event = _Endpoint(
settings={
'response_type': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},),
'auth': [
'BasicAuth'
],
'endpoint_path': '/v4/events:sendEvent',
'operation_id': 'send_event',
'http_method': 'POST',
'servers': None,
},
params_map={
'all': [
'send_event_request',
],
'required': [
'send_event_request',
],
'nullable': [
],
'enum': [
],
'validation': [
]
},
root_map={
'validations': {
},
'allowed_values': {
},
'openapi_types': {
'send_event_request':
(SendEventRequest,),
},
'attribute_map': {
},
'location_map': {
'send_event_request': 'body',
},
'collection_format_map': {
}
},
headers_map={
'accept': [
'application/json'
],
'content_type': [
'application/json'
]
},
api_client=api_client,
callable=__send_event
)
Loading

0 comments on commit 4565049

Please sign in to comment.