Skip to content

Commit

Permalink
[230601] Automatic update of SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
bubianchi-criteo committed Jun 1, 2023
1 parent 88a3ea3 commit 5dc5619
Show file tree
Hide file tree
Showing 159 changed files with 1,481 additions and 305 deletions.
5 changes: 4 additions & 1 deletion sdks/marketingsolutions_2022-07/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ criteo_api_marketingsolutions_v2022_07/criteo_api_client.py
criteo_api_marketingsolutions_v2022_07/criteo_auth.py
criteo_api_marketingsolutions_v2022_07/criteo_rest.py
criteo_api_marketingsolutions_v2022_07/exceptions.py
criteo_api_marketingsolutions_v2022_07/flow_constants.py
criteo_api_marketingsolutions_v2022_07/model/__init__.py
criteo_api_marketingsolutions_v2022_07/model/ad_set_category_bid.py
criteo_api_marketingsolutions_v2022_07/model/ad_set_category_bid_list_response.py
Expand Down Expand Up @@ -240,6 +241,8 @@ requirements.txt
setup.cfg
setup.py
test-requirements.txt
test/example_application.py
test/example_application_with_auth_code.py
test/example_application_with_client_credentials.py
test/example_application_with_refresh_token.py
test/test_gateway_api.py
tox.ini
12 changes: 8 additions & 4 deletions sdks/marketingsolutions_2022-07/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ More information: [https://developers.criteo.com/](https://developers.criteo.com

This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:

- Package version: 2022.07.0.230427
- Package version: 2022.07.0.230601

## Requirements

Expand All @@ -18,9 +18,9 @@ Python 2.7 and 3.5+
### pip install

```sh
pip install criteo-api-marketingsolutions-sdk==2022.07.0.230427
pip install criteo-api-marketingsolutions-sdk==2022.07.0.230601
```
(you may need to run `pip` with root permission: `sudo pip install criteo-api-marketingsolutions-sdk==2022.07.0.230427`)
(you may need to run `pip` with root permission: `sudo pip install criteo-api-marketingsolutions-sdk==2022.07.0.230601`)

Then import the package:
```python
Expand All @@ -42,7 +42,11 @@ import criteo_api_marketingsolutions_v2022_07
```

## Example
Please see [test/example_application.py](test/example_application.py) for an example.
There are multiple examples for the different OAuth flows that the SDK supports.
- See [test/example_application_with_client_credentials.py](test/example_application_with_client_credentials.py) for an example with Client Credentials.
- See [test/example_application_with_auth_code.py](test/example_application_with_auth_code.py) for an example with Authorization Code.
Once you follow the authorization code flow, you will have a refresh token that has to be used to regenerate access token for future usage.
- See [test/example_application_with_refresh_token.py](test/example_application_with_refresh_token.py) for an example with Refresh Token .

## Documentation for API Endpoints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"""


__version__ = "2022.07.0.230427"
__version__ = "2022.07.0.230601"

# import ApiClient
from criteo_api_marketingsolutions_v2022_07.api_client import ApiClient
from criteo_api_marketingsolutions_v2022_07.criteo_api_client import CriteoApiClient
from criteo_api_marketingsolutions_v2022_07.api_client_builder import ApiClientBuilder
from criteo_api_marketingsolutions_v2022_07 import flow_constants

# import Configuration
from criteo_api_marketingsolutions_v2022_07.configuration import Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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 = 'OpenAPI-Generator/2022.07.0.230427/python'
self.user_agent = 'OpenAPI-Generator/2022.07.0.230601/python'

def __enter__(self):
return self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
from criteo_api_marketingsolutions_v2022_07.configuration import Configuration
from criteo_api_marketingsolutions_v2022_07.criteo_api_client import CriteoApiClient
from criteo_api_marketingsolutions_v2022_07 import flow_constants

class ApiClientBuilder :

@staticmethod
def WithClientCredentials(clientId, clientSecret):
configuration = Configuration(username=clientId, password=clientSecret)
def WithClientCredentials(clientId, clientSecret, host=None):
configuration = Configuration(username=clientId, password=clientSecret, host=host)

return CriteoApiClient(configuration)

@staticmethod
def WithNoAuthorization():

return CriteoApiClient()

@staticmethod
def WithAuthorizationCode(clientId, clientSecret, authorization_code, redirect_uri, host=None):
configuration = Configuration(username=clientId, password=clientSecret, host=host)
additional_parameters = {
'flow' : flow_constants.AUTHORIZATION_CODE_FLOW,
'authorization_code': authorization_code,
'redirect_uri': redirect_uri
}

return CriteoApiClient(configuration = configuration, additional_parameters = additional_parameters)

@staticmethod
def WithRefreshToken(clientId, clientSecret, refreshToken, host=None):
configuration = Configuration(username=clientId, password=clientSecret, host=host)
additional_parameters = {
'flow' : flow_constants.REFRESH_TOKEN_FLOW,
'refresh_token': refreshToken
}

return CriteoApiClient(configuration = configuration, additional_parameters = additional_parameters)
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def to_debug_report(self):
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 2022-07\n"\
"SDK Package Version: 2022.07.0.230427".\
"SDK Package Version: 2022.07.0.230601".\
format(env=sys.platform, pyversion=sys.version)

def get_host_settings(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ class CriteoApiClient(ApiClient):
def __init__(self, configuration=None, header_name=None, header_value=None,
cookie=None, pool_threads=1, additional_parameters= {}):
super().__init__(configuration=configuration,header_name=header_name, header_value=header_value, cookie=cookie, pool_threads=pool_threads)
self.rest_client = CriteoRESTClientObject(self.configuration, additional_parameters)
self.rest_client = CriteoRESTClientObject(self.configuration, additional_parameters)

def get_refresh_token(self):
return self.rest_client.get_refresh_token()
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime, timedelta
from criteo_api_marketingsolutions_v2022_07.exceptions import ApiException
from criteo_api_marketingsolutions_v2022_07.api_client import ApiClient
from criteo_api_marketingsolutions_v2022_07 import flow_constants

class Token(object):

Expand Down Expand Up @@ -29,10 +30,13 @@ def __init__(self, grant_type, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret
self.token = None
self.refreshToken = None

def get_token(self, client : ApiClient, headers) -> str:
if self.token and not self.token.has_expired():
self.token = None
if self.grant_type == flow_constants.AUTHORIZATION_CODE_FLOW:
self.grant_type = flow_constants.REFRESH_TOKEN_FLOW

if self.token is None:
self.refresh_token(client, headers)
Expand All @@ -50,6 +54,9 @@ def refresh_token(self, client : ApiClient, headers, parameters_dict= {}):
'grant_type' : self.grant_type
})
try:
if self.grant_type == flow_constants.REFRESH_TOKEN_FLOW:
params['refresh_token'] = self.refreshToken

response = client.request('POST', oauth_url,
headers=new_headers,
query_params=[],
Expand All @@ -61,11 +68,15 @@ def refresh_token(self, client : ApiClient, headers, parameters_dict= {}):
data = json.loads(response.data)
self.token = Token('Bearer '+ (data['access_token'] or ''),
RetryingOAuth.compute_expiration_date(data['expires_in']))

self.refreshToken = data['refresh_token']

return self.token
except ApiException as e:
raise self._enrich_exception_message(e, oauth_url)

def get_refresh_token(self):
return self.refreshToken

def _enrich_exception_message(self, e, url):
try:
data = json.loads(e.body or {})
Expand All @@ -82,18 +93,29 @@ def compute_expiration_date(expires_in):
class RetryingClientCredentials(RetryingOAuth):

def __init__(self, client_id, client_secret):
super().__init__('client_credentials', client_id, client_secret)
super().__init__(flow_constants.CLIENT_CREDENTIALS_FLOW, client_id, client_secret)

class RetryingAuthorizationCode(RetryingOAuth):

def __init__(self, client_id, client_secret, code, redirect_uri):
super().__init__('authorization_code', client_id, client_secret)
super().__init__(flow_constants.AUTHORIZATION_CODE_FLOW, client_id, client_secret)
self.authorization_code = code
self.redirect_uri = redirect_uri

def refresh_token(self, client : ApiClient, headers, parameters_dict= {}):
params = dict(parameters_dict, **{
'authorization_code' : self.authorization_code,
'code' : self.authorization_code,
'redirect_uri' : self.redirect_uri
})
return super().refresh_token(client, headers, params)

class RetryingRefreshToken(RetryingOAuth):

def __init__(self, client_id, client_secret, refresh_token):
super().__init__(flow_constants.REFRESH_TOKEN_FLOW, client_id, client_secret)
self.refreshToken = refresh_token

def refresh_token(self, client: ApiClient, headers, parameters_dict = {}):
params = dict(parameters_dict, **{
'refresh_token' : self.refreshToken
})
return super().refresh_token(client, headers,params)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from criteo_api_marketingsolutions_v2022_07.rest import RESTClientObject
from criteo_api_marketingsolutions_v2022_07.criteo_auth import *
from criteo_api_marketingsolutions_v2022_07 import flow_constants


class CriteoRESTClientObject(RESTClientObject):
Expand All @@ -12,13 +13,19 @@ def __init__(self, configuration, additional_parameters = {}, pools_size=4, maxs
client_secret = configuration.password

grant_type = additional_parameters.get('flow', 'client_credentials')
if grant_type == 'authorization_code' :
if grant_type == flow_constants.AUTHORIZATION_CODE_FLOW :
self.authorization = RetryingAuthorizationCode(
client_id,
client_secret,
additional_parameters.get('autorization_code',''),
additional_parameters.get('authorization_code',''),
additional_parameters.get('redirect_uri','')
)
elif grant_type == flow_constants.REFRESH_TOKEN_FLOW :
self.authorization = RetryingRefreshToken(
client_id,
client_secret,
additional_parameters.get('refresh_token', '')
)
else:
self.authorization = RetryingClientCredentials(
client_id,
Expand Down Expand Up @@ -64,3 +71,5 @@ def request(self, method, url, query_params=None, headers=None,

return super().request(method, url, query_params, headers, body, post_params, _preload_content, _request_timeout)

def get_refresh_token(self):
return self.authorization.get_refresh_token()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""This file defines authentication flows constants."""

CLIENT_CREDENTIALS_FLOW = 'client_credentials'
AUTHORIZATION_CODE_FLOW = 'authorization_code'
REFRESH_TOKEN_FLOW = 'refresh_token'
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,9 @@ def discriminator():

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, value, *args, **kwargs): # noqa: E501
def _from_openapi_data(cls, *args, **kwargs): # noqa: E501
"""NillableAdSetTargetingRule - a model defined in OpenAPI
Args:
value (NillableAdSetTargetingRuleValue):
Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
Expand Down Expand Up @@ -143,6 +140,7 @@ def _from_openapi_data(cls, value, *args, **kwargs): # noqa: E501
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
value (NillableAdSetTargetingRuleValue): [optional] # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down Expand Up @@ -174,7 +172,6 @@ def _from_openapi_data(cls, value, *args, **kwargs): # noqa: E501
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)

self.value = value
for var_name, var_value in kwargs.items():
if var_name not in self.attribute_map and \
self._configuration is not None and \
Expand All @@ -195,12 +192,9 @@ def _from_openapi_data(cls, value, *args, **kwargs): # noqa: E501
])

@convert_js_args_to_python_args
def __init__(self, value, *args, **kwargs): # noqa: E501
def __init__(self, *args, **kwargs): # noqa: E501
"""NillableAdSetTargetingRule - a model defined in OpenAPI
Args:
value (NillableAdSetTargetingRuleValue):
Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
Expand Down Expand Up @@ -232,6 +226,7 @@ def __init__(self, value, *args, **kwargs): # noqa: E501
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
value (NillableAdSetTargetingRuleValue): [optional] # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down Expand Up @@ -261,7 +256,6 @@ def __init__(self, value, *args, **kwargs): # noqa: E501
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)

self.value = value
for var_name, var_value in kwargs.items():
if var_name not in self.attribute_map and \
self._configuration is not None and \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ structure that encapsulates an object that have valid business null values. If t
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**value** | [**NillableAdSetTargetingRuleValue**](NillableAdSetTargetingRuleValue.md) | |
**value** | [**NillableAdSetTargetingRuleValue**](NillableAdSetTargetingRuleValue.md) | | [optional]
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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)
Expand Down
6 changes: 3 additions & 3 deletions sdks/marketingsolutions_2022-07/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages # noqa: H301

NAME = "criteo-api-marketingsolutions-sdk"
VERSION = "2022.07.0.230427"
VERSION = "2022.07.0.230601"
# To install the library, run the following
#
# python setup.py install
Expand All @@ -24,9 +24,9 @@
```sh
pip install criteo-api-marketingsolutions-sdk==2022.07.0.230427
pip install criteo-api-marketingsolutions-sdk==2022.07.0.230601
```
(you may need to run `pip` with root permission: `sudo pip install criteo-api-marketingsolutions-sdk==2022.07.0.230427`)
(you may need to run `pip` with root permission: `sudo pip install criteo-api-marketingsolutions-sdk==2022.07.0.230601`)
Then import the package:
```python
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from criteo_api_marketingsolutions_v2022_07.api.gateway_api import GatewayApi
from criteo_api_marketingsolutions_v2022_07 import ApiClientBuilder

class ExampleApplication:

def call_then_application_endpoint(self, clientId, clientSecret, authorization_code, redirect_uri):
# Create a client using your choosen OAuth flow, Authorization Code in this case. The client will handle the token generation/renewal for you
client = ApiClientBuilder.WithAuthorizationCode(clientId, clientSecret, authorization_code, redirect_uri)

# The Gateway API regroups common technical endpoints that exists for all versions
# You can find the other endpoints in the other *Api
# You can reuse the same client with several Apis, but be careful, as they will then use the same token and credentials
api = GatewayApi(client)

# Perform the call to the application introspection endpoint
response = api.get_current_application()

# Most of Criteo's API response follow the same structure:
# The response consists of a Data, Errors and Warnings fields
# The Data fields contains an Id (if applicable), a Type, and an Attributes field that contains the business object
myApplication = response.data.attributes
print(f'Hello, I\'m using Criteo API and I\'m connected as {myApplication.name}')

# You will need to save the refresh_token to use it in the refresh_token flow
# You can fetch the refresh token like this:
refreshToken = client.get_refresh_token()
print('The refresh token to be saved is ', refreshToken)
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import logging
import sys

from criteo_api_marketingsolutions_v2022_07.api.gateway_api import GatewayApi
from criteo_api_marketingsolutions_v2022_07 import ApiClientBuilder

class ExampleApplication:

def call_then_application_endpoint(self, clientId, clientSecret):
# Create a client using your choosen OAuth flow. The client will handle the token generation/renewal for you
# Create a client using your choosen OAuth flow, Client Credentials in this case. The client will handle the token generation/renewal for you
client = ApiClientBuilder.WithClientCredentials(clientId=clientId, clientSecret=clientSecret)

# The Gateway API regroups common technical endpoints that exists for all versions
Expand Down
Loading

0 comments on commit 5dc5619

Please sign in to comment.