mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Add api module for android app
- Add api end-point to get enabled-services in plinth - Add api end-point to get acess info for plinth
This commit is contained in:
parent
7822c02fb6
commit
c0fb2abf46
@ -42,6 +42,8 @@ def add_shortcut(shortcut_id, name, short_description="", login_required=False,
|
|||||||
|
|
||||||
shortcuts[shortcut_id] = {
|
shortcuts[shortcut_id] = {
|
||||||
'id': shortcut_id,
|
'id': shortcut_id,
|
||||||
|
'name': name,
|
||||||
|
'short_description': short_description,
|
||||||
'label': label,
|
'label': label,
|
||||||
'url': url,
|
'url': url,
|
||||||
'icon': icon,
|
'icon': icon,
|
||||||
|
|||||||
22
plinth/modules/api/__init__.py
Normal file
22
plinth/modules/api/__init__.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Plinth module for api for android app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
version = 1
|
||||||
0
plinth/modules/api/test/__init__.py
Normal file
0
plinth/modules/api/test/__init__.py
Normal file
43
plinth/modules/api/test/test_get_apps.py
Normal file
43
plinth/modules/api/test/test_get_apps.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Test get apps for api module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from plinth.modules.api.views import get_app_payload
|
||||||
|
|
||||||
|
|
||||||
|
class TestApi(unittest.TestCase):
|
||||||
|
apps = [{
|
||||||
|
'name': 'someName',
|
||||||
|
'short_description': 'someDescription',
|
||||||
|
'icon': 'someIconURl',
|
||||||
|
'label': 'someLabel'
|
||||||
|
}]
|
||||||
|
|
||||||
|
expected = [{
|
||||||
|
'name': 'someName',
|
||||||
|
'short_description': 'someDescription',
|
||||||
|
'icon_url': 'static/theme/icons/someIconURl.svg'
|
||||||
|
}]
|
||||||
|
|
||||||
|
def test_get_app_payload(self):
|
||||||
|
apps = get_app_payload(self.apps)
|
||||||
|
self.assertEquals(apps, self.expected)
|
||||||
30
plinth/modules/api/urls.py
Normal file
30
plinth/modules/api/urls.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
URLs for the plinth api for android app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
from stronghold.decorators import public
|
||||||
|
|
||||||
|
from plinth.modules.api.views import get_apps, get_access_info
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^api/(?P<version>[0-9]+)/services/?$', public(get_apps)),
|
||||||
|
url(r'^api/(?P<version>[0-9]+)/accessInfo/?$', public(get_access_info))
|
||||||
|
]
|
||||||
52
plinth/modules/api/views.py
Normal file
52
plinth/modules/api/views.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#
|
||||||
|
# This file is part of Plinth.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Plinth module for api for android app.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
|
from plinth.modules.names import get_domain, get_domain_types
|
||||||
|
from plinth import frontpage
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def get_apps(request, **kwargs):
|
||||||
|
shortcuts = frontpage.get_shortcuts()
|
||||||
|
|
||||||
|
response = {'services': get_app_payload(shortcuts)}
|
||||||
|
return HttpResponse(json.dumps(response), content_type="application/json")
|
||||||
|
|
||||||
|
|
||||||
|
def get_app_payload(enabled_apps):
|
||||||
|
service_apps = []
|
||||||
|
for app in enabled_apps:
|
||||||
|
app['icon_url'] = 'static/theme/icons/' + app['icon'] + '.svg'
|
||||||
|
app_required_fields = dict((key, app[key]) for key in ('name', 'short_description', 'icon_url'))
|
||||||
|
apps = {key: str(value) for key, value in app_required_fields.items()}
|
||||||
|
service_apps.append(apps)
|
||||||
|
|
||||||
|
return service_apps
|
||||||
|
|
||||||
|
|
||||||
|
def get_access_info(request, **kwargs):
|
||||||
|
domain_types = get_domain_types()
|
||||||
|
response = {}
|
||||||
|
for domain_type in domain_types:
|
||||||
|
response[domain_type] = get_domain(domain_type)
|
||||||
|
return HttpResponse(json.dumps(response), content_type="application/json")
|
||||||
Loading…
x
Reference in New Issue
Block a user