2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 21:16:46 +00:00

add sample for api caller

This commit is contained in:
Matthias 2022-01-09 03:03:05 +01:00
parent 19f2c44c2a
commit 61b21d1ec1
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -0,0 +1,34 @@
"""
Sample plugin for calling an external API
"""
from django.utils.translation import ugettext_lazy as _
from plugin import IntegrationPluginBase
from plugin.mixins import APICallMixin, SettingsMixin
class SampleApiCallerPlugin(APICallMixin, SettingsMixin, IntegrationPluginBase):
"""
A small api call sample
"""
PLUGIN_NAME = "Sample API Caller"
SETTINGS = {
'API_TOKEN': {
'name': 'API Token',
'protected': True,
},
'API_URL': {
'name': 'External URL',
'description': 'Where is your API located?',
'default': 'https://reqres.in',
},
}
API_URL_SETTING = 'API_URL'
API_TOKEN_SETTING = 'API_TOKEN'
def get_external_url(self):
"""
returns data from the sample endpoint
"""
return self.api_call('api/users/2')