2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

readd spaces

This commit is contained in:
Matthias 2022-01-11 00:32:56 +01:00
parent c3d7a26f5d
commit dd2547e117
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -328,6 +328,7 @@ class AppMixin:
class APICallMixin: class APICallMixin:
""" """
Mixin that enables easier API calls for a plugin Mixin that enables easier API calls for a plugin
Steps to set up: Steps to set up:
1. Add this mixin before (left of) SettingsMixin and PluginBase 1. Add this mixin before (left of) SettingsMixin and PluginBase
2. Add two settings for the required url and token/passowrd (use `SettingsMixin`) 2. Add two settings for the required url and token/passowrd (use `SettingsMixin`)
@ -336,15 +337,19 @@ class APICallMixin:
5. (Optional) Override the `api_url` property method if the setting needs to be extended 5. (Optional) Override the `api_url` property method if the setting needs to be extended
6. (Optional) Override `api_headers` to add extra headers (by default the token and Content-Type are contained) 6. (Optional) Override `api_headers` to add extra headers (by default the token and Content-Type are contained)
7. Access the API in you plugin code via `api_call` 7. Access the API in you plugin code via `api_call`
Example: Example:
``` ```
from plugin import IntegrationPluginBase from plugin import IntegrationPluginBase
from plugin.mixins import APICallMixin, SettingsMixin from plugin.mixins import APICallMixin, SettingsMixin
class SampleApiCallerPlugin(APICallMixin, SettingsMixin, IntegrationPluginBase): class SampleApiCallerPlugin(APICallMixin, SettingsMixin, IntegrationPluginBase):
''' '''
A small api call sample A small api call sample
''' '''
PLUGIN_NAME = "Sample API Caller" PLUGIN_NAME = "Sample API Caller"
SETTINGS = { SETTINGS = {
'API_TOKEN': { 'API_TOKEN': {
'name': 'API Token', 'name': 'API Token',
@ -358,6 +363,7 @@ class APICallMixin:
} }
API_URL_SETTING = 'API_URL' API_URL_SETTING = 'API_URL'
API_TOKEN_SETTING = 'API_TOKEN' API_TOKEN_SETTING = 'API_TOKEN'
def get_external_url(self): def get_external_url(self):
''' '''
returns data from the sample endpoint returns data from the sample endpoint