# # # 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 General Public License for # # more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging from openlp.core.api.endpoint.core import TRANSLATED_STRINGS from openlp.core.api.http.endpoint import Endpoint log = logging.getLogger(__name__) remote_endpoint = Endpoint('remote', template_dir='remotes') @remote_endpoint.route('{view}') def index(request, view): """ Handles requests for /remotes url :param request: The http request object. :param view: The view name to be servered. """ return remote_endpoint.render_template('{view}.mako'.format(view=view), **TRANSLATED_STRINGS)
import os from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.common.i18n import UiStrings, translate from openlp.core.common.registry import Registry from openlp.core.lib import PluginStatus, StringContent, image_to_byte template_dir = 'templates' static_dir = 'static' blank_dir = os.path.join(static_dir, 'index') log = logging.getLogger(__name__) chords_endpoint = Endpoint('chords', template_dir=template_dir, static_dir=static_dir) stage_endpoint = Endpoint('stage', template_dir=template_dir, static_dir=static_dir) main_endpoint = Endpoint('main', template_dir=template_dir, static_dir=static_dir) blank_endpoint = Endpoint('', template_dir=template_dir, static_dir=blank_dir) FILE_TYPES = { '.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript', '.jpg': 'image/jpeg', '.gif': 'image/gif',
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## import logging from openlp.core.api.endpoint.pluginhelpers import live, search, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) media_endpoint = Endpoint('media') api_media_endpoint = Endpoint('api') @media_endpoint.route('search') def media_search(request): """ Handles requests for searching the media plugin :param request: The http request object. """ return search(request, 'media', log) @media_endpoint.route('live') @requires_auth
import logging import os import urllib.error import urllib.request from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.common.applocation import AppLocation from openlp.core.common.path import Path from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings from openlp.core.lib import ItemCapabilities, create_thumb log = logging.getLogger(__name__) controller_endpoint = Endpoint('controller') api_controller_endpoint = Endpoint('api') @api_controller_endpoint.route('controller/live/text') @controller_endpoint.route('live/text') def controller_text(request): """ Perform an action on the slide controller. :param request: the http request - not used """ log.debug("controller_text ") live_controller = Registry().get('live_controller') current_item = live_controller.service_item data = []
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import json import logging import urllib from urllib.parse import urlparse from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.common.registry import Registry from openlp.core.lib import PluginStatus log = logging.getLogger(__name__) alerts_endpoint = Endpoint('alert') api_alerts_endpoint = Endpoint('api') @alerts_endpoint.route('') @api_alerts_endpoint.route('alert') @requires_auth def alert(request): """ Handles requests for setting service items in the service manager :param request: The http request object. """ plugin = Registry().get('plugin_manager').get_plugin_by_name("alerts") if plugin.status == PluginStatus.Active: try:
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## import logging from openlp.core.api.endpoint.pluginhelpers import live, search, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) custom_endpoint = Endpoint('custom') api_custom_endpoint = Endpoint('api') @custom_endpoint.route('search') def custom_search(request): """ Handles requests for searching the custom plugin :param request: The http request object. """ return search(request, 'custom', log) @custom_endpoint.route('live') @requires_auth
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## import logging from openlp.core.api.endpoint.pluginhelpers import display_thumbnails, live, search, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) images_endpoint = Endpoint('images') api_images_endpoint = Endpoint('api') # images/thumbnails/320x240/1.jpg @images_endpoint.route('thumbnails/{dimensions}/{file_name}') def images_thumbnails(request, dimensions, file_name): """ Return an image to a web page based on a URL :param request: Request object :param dimensions: the image size eg 88x88 :param file_name: the individual image name :return: """ return display_thumbnails(request, 'images', log, dimensions, file_name)
# more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging from openlp.core.api.endpoint.pluginhelpers import search, live, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) bibles_endpoint = Endpoint('bibles') api_bibles_endpoint = Endpoint('api') @bibles_endpoint.route('search') def bibles_search(request): """ Handles requests for searching the bibles plugin :param request: The http request object. """ return search(request, 'bibles', log) @bibles_endpoint.route('live') @requires_auth
# GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## import logging from openlp.core.api.endpoint.pluginhelpers import display_thumbnails, live, search, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) presentations_endpoint = Endpoint('presentations') api_presentations_endpoint = Endpoint('api') # /presentations/thumbnails88x88/PA%20Rota.pdf/slide5.png @presentations_endpoint.route('thumbnails/{dimensions}/{file_name}/{slide}') def presentations_thumbnails(request, dimensions, file_name, slide): """ Return a presentation to a web page based on a URL :param request: Request object :param dimensions: the image size eg 88x88 :param file_name: the file name of the image :param slide: the individual image name :return: """ return display_thumbnails(request, 'presentations', log, dimensions, file_name, slide)
# more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### import logging from openlp.core.api.endpoint.pluginhelpers import search, live, service from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.api.http.errors import NotFound log = logging.getLogger(__name__) songs_endpoint = Endpoint('songs') api_songs_endpoint = Endpoint('api') @songs_endpoint.route('search') def songs_search(request): """ Handles requests for searching the songs plugin :param request: The http request object. """ return search(request, 'songs', log) @songs_endpoint.route('live') @requires_auth
# GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## """ The :mod:`~openlp.core.api.endpoint` module contains various API endpoints """ import logging from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.common.registry import Registry log = logging.getLogger(__name__) media_endpoint = Endpoint('media') @media_endpoint.route('play') @requires_auth def media_play(request): """ Handles requests for playing media :param request: The http request object. """ media = Registry().get('media_controller') live = Registry().get('live_controller') status = media.media_play(live, False) return {'results': {'success': status}}
# with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ Functional test the routing code. """ import os from unittest import TestCase from unittest.mock import MagicMock from openlp.core.api.http import register_endpoint, application, NotFound from openlp.core.api.http.endpoint import Endpoint ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) test_endpoint = Endpoint('test', template_dir=ROOT_DIR, static_dir=ROOT_DIR) class TestRouting(TestCase): """ Test the HTTP routing """ def setUp(self): """ Convert the application to a test application :return: """ for route, views in application.route_map.items(): application.route_map[route]['GET'] = MagicMock() def test_routing(self):
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <https://www.gnu.org/licenses/>. # ########################################################################## import json import logging from openlp.core.api.http import requires_auth from openlp.core.api.http.endpoint import Endpoint from openlp.core.common.registry import Registry log = logging.getLogger(__name__) service_endpoint = Endpoint('service') api_service_endpoint = Endpoint('api/service') @api_service_endpoint.route('list') @service_endpoint.route('list') def list_service(request): """ Handles requests for service items in the service manager :param request: The http request object. """ return {'results': {'items': get_service_items()}} @api_service_endpoint.route('set')