Skip to main content

AfasConnector is a Python package that simplifies interacting with AFAS Connectors via HTTP requests. It provides classes for making GET, POST, and PUT requests to AFAS Connectors and handling their responses.

Project description

AfasConnector

The AfasConnector class provides a convenient interface for interacting with AFAS Connectors via HTTP requests. It simplifies the process of sending GET, POST, and PUT requests to your AFAS Connectors and handling their responses.

Features

  • Easy configuration through environment variables.
  • Support for GET, POST, and PUT requests.
  • Integrated filtering, ordering, and pagination for GET requests.
  • Automatic handling of AFAS token authentication.

Usage

First, set the necessary environment variables:

AFAS_CONNECTORS_URL: The base URL for your AFAS Connectors. AFAS_TOKEN: Your AFAS token. Here's an example of how to use AfasConnector in your Python code:

from afas import AfasConnector

# Initialize the connector
connector = AfasConnector()

# GET request example
status_code, response = connector.get(endpoint='Profit_OData/SomeEndpoint', filters=[...])
if status_code == 200:
    print(response)

# PUT request example
payload = {...}
status_code, response = connector.put(endpoint='Profit_OData/SomeEndpoint', payload=payload)
if status_code == 200:
    print(response)

# POST request example
payload = {...}
status_code, response = connector.post(endpoint='Profit_OData/SomeEndpoint', payload=payload)
if status_code == 200:
    print(response)

Handling Responses and Errors

Each method returns a tuple containing the HTTP status code and the response from the AFAS Connector. A successful request will return a status code of 200. If the request is unsuccessful, the status code can be used to diagnose the issue. The second element of the tuple will be the JSON response for successful requests or None in case of an error.

AfasFilter

The AfasFilter class provides a way to define filters for the AFAS Connectors. It allows you to specify the field, value(s), and operator for the filter.

Usage

Here's an example of how to use the AfasFilter class:

# Create an example of using the AfasFilter class
filter = AfasFilter(field='Itemcode', value='1234', operator=AfasFilter.EQUAL_TO)
filter_OR = AfasFilter(field='Itemcode', value=['1234', '4321'], operator=[AfasFilter.EQUAL_TO, AfasFilter.EQUAL_TO])

# Convert the filters to a query string
query = afas_filters_to_query([filter, filter_OR])

# Print the query string
print(query)

AfasObject

The AfasObject is a wrapper for updating an item in Afas. The object has an update method that uses the AfasConnector class to update an item in a single line.

Usage

Here's an exampke of how to use the AfasObject class:

from afas.afas_object import AfasObject

# Create an instance of AfasObject
obj = AfasObject('FbItemArticle', {'Field1': 'Value1', 'Field2': 'Value2'})

# Update the object in AFAS Profit
status_code, response = obj.update()
if status_code == 200:
    print("Object updated successfully")
else:
    print("Failed to update object")

# Get a string representation of the object
print(str(obj))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

afas_connector-0.1.5.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

afas_connector-0.1.5-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file afas_connector-0.1.5.tar.gz.

File metadata

  • Download URL: afas_connector-0.1.5.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for afas_connector-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ec9921a99f54b661072782d488a1a677a4f64d2ba3ceab93687c3c889705f5fd
MD5 69894bafdc41e751ae6b888293f0d806
BLAKE2b-256 5598acaedc32076c2abd2d8025819388a3da4328b27c7ad5bb404c79556922d7

See more details on using hashes here.

File details

Details for the file afas_connector-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for afas_connector-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5a1bacfaf0c6b16b6dd1b6842d8dffc6c15e3ded6f8c7b76da30432887b5aa90
MD5 aaf43ffade66e0105e637914f7ac6d08
BLAKE2b-256 a8e802eeb9a6b06f0d4e6cb378b5a524903a1c252be233b9ee49063b61393f7b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page