Skip to content

Commit

Permalink
Automated commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
maxio-sdk committed Jan 10, 2024
1 parent c1ccb12 commit e822575
Show file tree
Hide file tree
Showing 131 changed files with 1,339 additions and 733 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ License:
The MIT License (MIT)
http://opensource.org/licenses/MIT

Copyright (c) 2014 - 2023 APIMATIC Limited
Copyright (c) 2014 - 2024 APIMATIC Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,16 @@ The following parameters are configurable for the API Client:
| `backoff_factor` | `float` | A backoff factor to apply between attempts after the second try. <br> **Default: 2** |
| `retry_statuses` | `Array of int` | The http statuses on which retry is to be done. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
| `retry_methods` | `Array of string` | The http methods on which retry is to be done. <br> **Default: ['GET', 'PUT']** |
| `basic_auth_user_name` | `str` | The username to use with basic authentication |
| `basic_auth_password` | `str` | The password to use with basic authentication |
| `basic_auth_credentials` | [`BasicAuthCredentials`](https://www.github.com/maxio-com/ab-python-sdk/tree/0.0.4/doc/$a/https://www.github.com/maxio-com/ab-python-sdk/tree/0.0.4/basic-authentication.md) | The credential object for Basic Authentication |

The API client can be initialized as follows:

```python
from advancedbilling.advanced_billing_client import AdvancedBillingClient
from advancedbilling.configuration import Environment

client = AdvancedBillingClient(
basic_auth_user_name='BasicAuthUserName',
basic_auth_password='BasicAuthPassword'
basic_auth_credentials=BasicAuthCredentials(
username='BasicAuthUserName',
password='BasicAuthPassword'
)
)
```

Expand All @@ -325,7 +323,9 @@ The SDK can be configured to use a different environment for making API calls. A

## Authorization

This API uses `Basic Authentication`.
This API uses the following authentication schemes.

* [`BasicAuth (Basic Authentication)`](https://www.github.com/maxio-com/ab-python-sdk/tree/0.0.4/doc/$a/https://www.github.com/maxio-com/ab-python-sdk/tree/0.0.4/basic-authentication.md)

## List of APIs

Expand Down
44 changes: 17 additions & 27 deletions advancedbilling/advanced_billing_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@


class AdvancedBillingClient(object):

@LazyProperty
def api_exports(self):
return APIExportsController(self.global_configuration)
Expand Down Expand Up @@ -198,38 +197,29 @@ def webhooks(self):
def __init__(self, http_client_instance=None,
override_http_client_configuration=False, http_call_back=None,
timeout=30, max_retries=0, backoff_factor=2,
retry_statuses=[408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
retry_methods=['GET', 'PUT'],
retry_statuses=None, retry_methods=None,
environment=Environment.PRODUCTION, subdomain='subdomain',
domain='chargify.com', basic_auth_user_name='TODO: Replace',
basic_auth_password='TODO: Replace', config=None):
if config is None:
self.config = Configuration(
http_client_instance=http_client_instance,
override_http_client_configuration=override_http_client_configuration,
http_call_back=http_call_back,
timeout=timeout,
max_retries=max_retries,
backoff_factor=backoff_factor,
retry_statuses=retry_statuses,
retry_methods=retry_methods,
environment=environment,
subdomain=subdomain, domain=domain,
basic_auth_user_name=basic_auth_user_name,
basic_auth_password=basic_auth_password)
else:
self.config = config
domain='chargify.com', basic_auth_user_name=None,
basic_auth_password=None, basic_auth_credentials=None,
config=None):
self.config = config or Configuration(
http_client_instance=http_client_instance,
override_http_client_configuration=override_http_client_configuration,
http_call_back=http_call_back, timeout=timeout,
max_retries=max_retries, backoff_factor=backoff_factor,
retry_statuses=retry_statuses, retry_methods=retry_methods,
environment=environment, subdomain=subdomain, domain=domain,
basic_auth_user_name=basic_auth_user_name,
basic_auth_password=basic_auth_password,
basic_auth_credentials=basic_auth_credentials)

self.global_configuration = GlobalConfiguration(self.config)\
.global_errors(BaseController.global_errors())\
.base_uri_executor(self.config.get_base_uri)\
.user_agent(BaseController.user_agent(), BaseController.user_agent_parameters())
self.initialize_auth_managers(self.global_configuration)

self.auth_managers = {key: None for key in ['BasicAuth']}
self.auth_managers['BasicAuth'] = BasicAuth(
self.config.basic_auth_credentials)
self.global_configuration = self.global_configuration.auth_managers(self.auth_managers)

def initialize_auth_managers(self, global_config):
http_client_config = global_config.get_http_client_configuration()
self.auth_managers = { key: None for key in ['global']}
self.auth_managers['global'] = BasicAuth(http_client_config.basic_auth_user_name, http_client_config.basic_auth_password)
return self.auth_managers
74 changes: 51 additions & 23 deletions advancedbilling/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
https://www.apimatic.io ).
"""

import warnings
from enum import Enum
from advancedbilling.api_helper import APIHelper
from apimatic_core.http.configurations.http_client_configuration import HttpClientConfiguration
Expand Down Expand Up @@ -44,24 +45,32 @@ def domain(self):

@property
def basic_auth_user_name(self):
return self._basic_auth_user_name
return self._basic_auth_credentials.username

@property
def basic_auth_password(self):
return self._basic_auth_password

def __init__(
self, http_client_instance=None,
override_http_client_configuration=False, http_call_back=None,
timeout=30, max_retries=0, backoff_factor=2,
retry_statuses=[408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
retry_methods=['GET', 'PUT'], environment=Environment.PRODUCTION,
subdomain='subdomain', domain='chargify.com',
basic_auth_user_name='TODO: Replace',
basic_auth_password='TODO: Replace'
):
return self._basic_auth_credentials.password

@property
def basic_auth_credentials(self):
return self._basic_auth_credentials

def __init__(self, http_client_instance=None,
override_http_client_configuration=False, http_call_back=None,
timeout=30, max_retries=0, backoff_factor=2,
retry_statuses=None, retry_methods=None,
environment=Environment.PRODUCTION, subdomain='subdomain',
domain='chargify.com', basic_auth_user_name=None,
basic_auth_password=None, basic_auth_credentials=None):
if retry_methods is None:
retry_methods = ['GET', 'PUT']

if retry_statuses is None:
retry_statuses = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]

super().__init__(http_client_instance, override_http_client_configuration, http_call_back, timeout, max_retries,
backoff_factor, retry_statuses, retry_methods)

# Current API environment
self._environment = environment

Expand All @@ -71,11 +80,8 @@ def __init__(
# The Chargify server domain.
self._domain = domain

# The username to use with basic authentication
self._basic_auth_user_name = basic_auth_user_name

# The password to use with basic authentication
self._basic_auth_password = basic_auth_password
self._basic_auth_credentials = self.create_auth_credentials_object(
basic_auth_user_name, basic_auth_password, basic_auth_credentials)

# The Http Client to use for making requests.
self.set_http_client(self.create_http_client())
Expand All @@ -85,7 +91,7 @@ def clone_with(self, http_client_instance=None,
timeout=None, max_retries=None, backoff_factor=None,
retry_statuses=None, retry_methods=None, environment=None,
subdomain=None, domain=None, basic_auth_user_name=None,
basic_auth_password=None):
basic_auth_password=None, basic_auth_credentials=None):
http_client_instance = http_client_instance or self.http_client_instance
override_http_client_configuration = override_http_client_configuration or self.override_http_client_configuration
http_call_back = http_call_back or self.http_callback
Expand All @@ -97,17 +103,18 @@ def clone_with(self, http_client_instance=None,
environment = environment or self.environment
subdomain = subdomain or self.subdomain
domain = domain or self.domain
basic_auth_user_name = basic_auth_user_name or self.basic_auth_user_name
basic_auth_password = basic_auth_password or self.basic_auth_password
basic_auth_credentials = self.create_auth_credentials_object(
basic_auth_user_name, basic_auth_password,
basic_auth_credentials or self.basic_auth_credentials,
stack_level=3)
return Configuration(
http_client_instance=http_client_instance,
override_http_client_configuration=override_http_client_configuration,
http_call_back=http_call_back, timeout=timeout,
max_retries=max_retries, backoff_factor=backoff_factor,
retry_statuses=retry_statuses, retry_methods=retry_methods,
environment=environment, subdomain=subdomain, domain=domain,
basic_auth_user_name=basic_auth_user_name,
basic_auth_password=basic_auth_password
basic_auth_credentials=basic_auth_credentials
)

def create_http_client(self):
Expand Down Expand Up @@ -150,3 +157,24 @@ def get_base_uri(self, server=Server.DEFAULT):
return APIHelper.append_url_with_template_parameters(
self.environments[self.environment][server], parameters
)

@staticmethod
def create_auth_credentials_object(basic_auth_user_name,
basic_auth_password,
basic_auth_credentials, stack_level=4):
if basic_auth_user_name is None \
and basic_auth_password is None:
return basic_auth_credentials

warnings.warn(message=('The \'basic_auth_user_name\', \'basic_auth_pass'
'word\' params are deprecated. Use \'basic_auth_'
'credentials\' param instead.'),
category=DeprecationWarning,
stacklevel=stack_level)

if basic_auth_credentials is not None:
return basic_auth_credentials.clone_with(basic_auth_user_name,
basic_auth_password)

from advancedbilling.http.auth.basic_auth import BasicAuthCredentials
return BasicAuthCredentials(basic_auth_user_name, basic_auth_password)
6 changes: 3 additions & 3 deletions advancedbilling/controllers/advance_invoice_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def issue_advance_invoice(self,
.key('accept')
.value('application/json'))
.body_serializer(APIHelper.json_serialize)
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -129,7 +129,7 @@ def read_advance_invoice(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -184,7 +184,7 @@ def void_advance_invoice(self,
.key('accept')
.value('application/json'))
.body_serializer(APIHelper.json_serialize)
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down
26 changes: 13 additions & 13 deletions advancedbilling/controllers/api_exports_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from advancedbilling.models.subscription import Subscription
from advancedbilling.models.batch_job_response import BatchJobResponse
from advancedbilling.exceptions.api_exception import APIException
from advancedbilling.exceptions.single_error_response_error_exception import SingleErrorResponseErrorException
from advancedbilling.exceptions.single_error_response_exception import SingleErrorResponseException


class APIExportsController(BaseController):
Expand Down Expand Up @@ -93,7 +93,7 @@ def list_exported_proforma_invoices(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -163,7 +163,7 @@ def list_exported_invoices(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -233,7 +233,7 @@ def list_exported_subscriptions(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -266,13 +266,13 @@ def export_proforma_invoices(self):
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
.deserialize_into(BatchJobResponse.from_dictionary)
.local_error('404', 'Not Found', APIException)
.local_error('409', 'Conflict', SingleErrorResponseErrorException)
.local_error('409', 'Conflict', SingleErrorResponseException)
).execute()

def export_invoices(self):
Expand All @@ -298,13 +298,13 @@ def export_invoices(self):
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
.deserialize_into(BatchJobResponse.from_dictionary)
.local_error('404', 'Not Found', APIException)
.local_error('409', 'Conflict', SingleErrorResponseErrorException)
.local_error('409', 'Conflict', SingleErrorResponseException)
).execute()

def export_subscriptions(self):
Expand All @@ -331,12 +331,12 @@ def export_subscriptions(self):
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
.deserialize_into(BatchJobResponse.from_dictionary)
.local_error('409', 'Conflict', SingleErrorResponseErrorException)
.local_error('409', 'Conflict', SingleErrorResponseException)
).execute()

def read_proforma_invoices_export(self,
Expand Down Expand Up @@ -371,7 +371,7 @@ def read_proforma_invoices_export(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -411,7 +411,7 @@ def read_invoices_export(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down Expand Up @@ -451,7 +451,7 @@ def read_subscriptions_export(self,
.header_param(Parameter()
.key('accept')
.value('application/json'))
.auth(Single('global'))
.auth(Single('BasicAuth'))
).response(
ResponseHandler()
.deserializer(APIHelper.json_deserialize)
Expand Down
8 changes: 1 addition & 7 deletions advancedbilling/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class BaseController(object):
http_call_back (HttpCallBack): An object which holds call back
methods to be called before and after the execution of an HttpRequest.
new_api_call_builder (APICall): Returns the API Call builder instance.
auth_managers (dict): A dictionary which holds the instances of authentication managers.
"""

Expand All @@ -46,8 +45,7 @@ def global_errors():
}

def __init__(self, config):
self._global_config = config
self._config = self._global_config.get_http_client_configuration()
self._config = config.get_http_client_configuration()
self._http_call_back = self.config.http_callback
self.api_call = ApiCall(config)

Expand All @@ -62,7 +60,3 @@ def http_call_back(self):
@property
def new_api_call_builder(self):
return self.api_call.new_builder

@property
def auth_managers(self):
return self._global_config.get_auth_managers()
Loading

0 comments on commit e822575

Please sign in to comment.