Skip to content

Repository files navigation

Ding Python SDK

The Ding Python library provides convenient access to the Ding API from applications written in the Python language.

Summary

Ding: The OTP API allows you to send authentication codes to your users using their phone numbers.

Table of Contents

SDK Installation

The SDK can be installed using the pip package manager, with dependencies and metadata stored in the setup.py file.

pip install ding_api_client

SDK Example Usage

SDK Example Usage

Send a code

Send an OTP code to a user's phone number.

importdingfromding.modelsimportcomponentss=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.create_authentication(request=components.CreateAuthenticationRequest(
customer_uuid='cf2edc1c-7fc6-48fb-86da-b7508c6b7b71',
phone_number='+1234567890',
locale='fr-FR',
))
ifres.create_authentication_responseisnotNone:
# handle responsepass

Check a code

Check that a code entered by a user is valid.

importdingfromding.modelsimportcomponentss=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.check(request=components.CreateCheckRequest(
customer_uuid='eebe792b-2fcc-44a0-87f1-650e79259e02',
authentication_uuid='64f66a7c-4b2c-4131-a8ff-d5b954cca05f',
check_code='123456',
))
ifres.create_check_responseisnotNone:
# handle responsepass

Perform a retry

Perform a retry if a user has not received the code.

importdings=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.retry()
ifres.retry_authentication_responseisnotNone:
# handle responsepass

Send feedback

Send feedback about the authentication process.

importdingfromding.modelsimportcomponentss=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.feedback(request=components.FeedbackRequest(
customer_uuid='cc0f6c04-40de-448f-8301-3cb0e6565dff',
phone_number='+1234567890',
status=components.FeedbackRequestStatus.ONBOARDED,
))
ifres.feedback_responseisnotNone:
# handle responsepass

Get authentication status

Get the status of an authentication.

importdings=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.get_authentication_status(auth_uuid='d8446450-f2fa-4dd9-806b-df5b8c661f23')
ifres.authentication_status_responseisnotNone:
# handle responsepass

Look up for phone number

Perform a phone number lookup.

importdings=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.lookup.lookup(phone_number='<value>', customer_uuid='69a197d9-356c-45d1-a807-41874e16b555')
ifres.lookup_responseisnotNone:
# handle responsepass

Available Resources and Operations

Available methods
  • lookup - Look up for phone number

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will raise a errors.SDKError exception, which has the following properties:

PropertyTypeDescription
.status_codeintThe HTTP status code
.messagestrThe error message
.raw_responsehttpx.ResponseThe raw HTTP response
.bodystrThe response content

When custom error responses are specified for an operation, the SDK may also raise their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the create_authentication method may raise the following exceptions:

Error TypeStatus CodeContent Type
errors.ErrorResponse400application/json
errors.SDKError4XX, 5XX*/*

Example

importdingfromding.modelsimportcomponents, errorss=ding.Ding(
api_key='YOUR_API_KEY',
)
res=Nonetry:
res=s.otp.create_authentication(request=components.CreateAuthenticationRequest(
customer_uuid='cf2edc1c-7fc6-48fb-86da-b7508c6b7b71',
phone_number='+1234567890',
locale='fr-FR',
))
excepterrors.ErrorResponsease:
# handle exceptionraise(e)
excepterrors.SDKErrorase:
# handle exceptionraise(e)
ifres.create_authentication_responseisnotNone:
# handle responsepass

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

importdingfromding.modelsimportcomponentss=ding.Ding(
server_url='https://api.ding.live/v1',
api_key='YOUR_API_KEY',
)
res=s.otp.create_authentication(request=components.CreateAuthenticationRequest(
customer_uuid='cf2edc1c-7fc6-48fb-86da-b7508c6b7b71',
phone_number='+1234567890',
locale='fr-FR',
))
ifres.create_authentication_responseisnotNone:
# handle responsepass

Custom HTTP Client

The Python SDK makes API calls using the requests HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom requests.Session object.

For example, you could specify a header for every request that this sdk makes as follows:

importdingimportrequestshttp_client=requests.Session()
http_client.headers.update({'x-custom-header': 'someValue'})
s=ding.Ding(client=http_client)

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

NameTypeScheme
api_keyapiKeyAPI key

To authenticate with the API the api_key parameter must be set when initializing the SDK client instance. For example:

importdingfromding.modelsimportcomponentss=ding.Ding(
api_key='YOUR_API_KEY',
)
res=s.otp.create_authentication(request=components.CreateAuthenticationRequest(
customer_uuid='cf2edc1c-7fc6-48fb-86da-b7508c6b7b71',
phone_number='+1234567890',
locale='fr-FR',
))
ifres.create_authentication_responseisnotNone:
# handle responsepass

Development

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

About

Ding's Python SDK

Topics

Resources

Contributing

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages