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:
parent
19f2c44c2a
commit
61b21d1ec1
34
InvenTree/plugin/samples/integration/api_caller.py
Normal file
34
InvenTree/plugin/samples/integration/api_caller.py
Normal 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')
|
Loading…
x
Reference in New Issue
Block a user