From 61b21d1ec14e0be683f8da2b92b3ca2aa9fdcf59 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 9 Jan 2022 03:03:05 +0100 Subject: [PATCH] add sample for api caller --- .../plugin/samples/integration/api_caller.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 InvenTree/plugin/samples/integration/api_caller.py diff --git a/InvenTree/plugin/samples/integration/api_caller.py b/InvenTree/plugin/samples/integration/api_caller.py new file mode 100644 index 0000000000..eaef93a4b6 --- /dev/null +++ b/InvenTree/plugin/samples/integration/api_caller.py @@ -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')