{ "info": { "author": "romeo1m", "author_email": "romeo.tudureanu@onem.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Build Tools" ], "description": "# ONEm Python SDK\n\n*ONEm Python SDK* is a library that helps in communication between your web app and the\nONEm platform. It guides the developer to build JSON responses which are compliant with\nthe [JSON schema](https://app.swaggerhub.com/apis/romeo1m/schemajson) ONEm platform works \nby.\n\n## Installation\n```bash\n$ pip install onemsdk\n```\n\n## Version history\nSee [HISTORY.md](HISTORY.md) file.\n\n## Usage example\n\nIn order to serve a selectable menu like the one below, the application has to respond to\nONEm platform with a JSON having a certain structure.\n\nThe menu:\n```\n#MY-FIRST-APP MENU\nA First item\nB Second item\nC Third item\n--Reply A-C\n```\n\nThe menu, as any other screen the user receives, has a simple structure, very similar with\nwith a web page:\n- the first line is called **header** (\"#MY-FIRST-APP MENU\")\n- it continues with a **body** (containing the selectable options)\n- the last line is called **footer** (\"--Reply A-C\").\n\n\nThe JSON that generates this menu:\n```json\n{\n \"content_type\": \"menu\",\n \"content\": {\n \"type\": \"menu\",\n \"body\": [\n {\n \"type\": \"option\",\n \"description\": \"First item\",\n \"method\": \"GET\",\n \"path\": \"/callback-url/item1\"\n },\n {\n \"type\": \"option\",\n \"description\": \"Second item\",\n \"method\": \"GET\",\n \"path\": \"/callback-url/item2\"\n },\n {\n \"type\": \"option\",\n \"description\": \"Third item\",\n \"method\": \"POST\",\n \"path\": \"/callback-url/item3\"\n }\n ],\n \"header\": \"my menu\",\n \"footer\": \"Reply A-C\"\n }\n}\n``` \n\nWorking with JSONs is not as fast and clear as using simple Python objects or HTML. Here\nis where the ONEm SDK comes into play.\n\nBefore starting to write code please make sure you have an account on the ONEm developer\nportal and registered an app. We will assume your app is called **my-first-app**.\n\n### Create a menu with Python objects\n```python\nfrom onemsdk.schema.v1 import Response, Menu, MenuItem\n\n\ndef handle_request_with_objects(request):\n\n menu_items = [\n MenuItem(description='First item',\n method='GET',\n path='/callback-url/item1'),\n MenuItem(description='Second item',\n method='GET',\n path='/callback-url/item2'),\n MenuItem(description='Third item',\n method='POST',\n path='/callback-url/item3')\n ]\n\n menu = Menu(header='menu', footer='Reply A-C', body=menu_items)\n\n # Wrap the Menu object into a Response object compatible with the JSON schema\n response = Response(content=menu)\n\n # Jsonify the response and send it the over the wire\n return response.json()\n```\n\n### Create a menu with HTML\n\n#### 1. Create `/static/menu.html` file:\n```html\n
\n
menu
\n \n
Reply A-C
\n
\n```\n\n#### 2. In your request handler:\n```python\nfrom onemsdk.parser import load_html\nfrom onemsdk.schema.v1 import Response\n\n\ndef handle_request_with_html(request):\n ...\n # Turn the HTML into a Python tag object\n root_tag = load_html(html_file=\"/static/menu.html\")\n\n # Turn the tag object into a Response object compatible with the JSON schema\n response = Response.from_tag(root_tag)\n\n # Jsonify the response and send it the over the wire\n return response.json()\n```\n\nONEm SDK supports Jinja2 and Django template engines, as HTML is not a good fit for dynamic content.\n\nSetting a directory with static files is recommended when using HTML or Jinja2 files.\nAfter doing that, all the files can be referred relative to the static directory. The\nplace to do that is the entry file of your web application:\n\n```python\nimport onemsdk\n\n...\nonemsdk.config.set_static_dir('./static')\n...\n```\n\n### Create a menu with Jinja2 template\n#### 1. Create `/static/menu.jinja2` file:\n```jinja2\n
\n
{{ header }}
\n \n
{{ footer }}
\n
\n```\n\n#### 2. In your request handler:\n```python\nfrom onemsdk.schema.v1 import Response\nfrom onemsdk.parser import load_template\n\n\ndef handle_request_with_template(request):\n ...\n data = {\n 'header': 'menu',\n 'footer': 'Reply A-C',\n 'items': [\n {\n 'method': 'GET', \n 'href': '/callback-url/item1', \n 'description': 'First item'\n },\n {\n 'method': 'GET', \n 'href': '/callback-url/item2', \n 'description': 'Second item'\n },\n {\n 'method': 'POST', \n 'href': '/callback-url/item3', \n 'description': 'Third item'\n },\n ]\n }\n \n # Turn the HTML template into Python object\n # Static directory is set, so write only the name of the Jinja2 file \n root_tag = load_template(template_file=\"menu.jinja2\", **data)\n\n # Turn the tag object into a Response object compatible with the JSON schema\n response = Response.from_tag(root_tag)\n\n # Jsonify the response and send it the over the wire\n return response.json()\n```\n\n\n### Using Django templates\n#### 1. Add the middleware, ideally last in your `settings.MIDDLEWARE` chain\n\n```python\n\nMIDDLEWARE = [\n ...,\n 'onemsdk.contrib.django.HtmlToOnemResponseMiddleware',\n]\n```\n\n\n#### 2. Use Django templates with the ONEm supported tags.\n\n```python\nfrom django.views.generic import TemplateView\n\nclass MyMenuView(TemplateView):\n template_name = 'my_menu.html'\n\n def get_context_data(self):\n items = Item.objects.all() # some items\n return {'items': items}\n```\n\n```html\n
\n
My Menu
\n \n \n
\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/romeo1m/onemsdk", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/romeo1m/onemsdk", "keywords": "sdk onem python", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "ONEmSDK", "package_url": "https://pypi.org/project/ONEmSDK/", "platform": "", "project_url": "https://pypi.org/project/ONEmSDK/", "project_urls": { "Download": "https://github.com/romeo1m/onemsdk", "Homepage": "https://github.com/romeo1m/onemsdk", "Source": "https://github.com/romeo1m/onemsdk" }, "release_url": "https://pypi.org/project/ONEmSDK/0.8.0/", "requires_dist": null, "requires_python": ">=3.6, <4", "summary": "Python ONEm SDK", "version": "0.8.0" }, "last_serial": 5906980, "releases": { "0.3.4": [ { "comment_text": "", "digests": { "md5": "9b33a1591e9422340a4c65d5d70960fb", "sha256": "c45b6841f13b2736385fbb84a10ef61cc8619d46ea66f267173c11dd556d2464" }, "downloads": -1, "filename": "ONEmSDK-0.3.4.tar.gz", "has_sig": false, "md5_digest": "9b33a1591e9422340a4c65d5d70960fb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9148, "upload_time": "2019-07-11T08:46:35", "url": "https://files.pythonhosted.org/packages/62/d8/efd0baded4af0feccbffbd2918b770dc62bccf086d969ae65c28de9d6fac/ONEmSDK-0.3.4.tar.gz" } ], "0.3.5": [ { "comment_text": "", "digests": { "md5": "bf5eb04d11cdab76774fe122ce4cbe69", "sha256": "bd125bf32e29eb8d637883ea82a9fc8c787721cdc40b8b821a20b699938d4c39" }, "downloads": -1, "filename": "ONEmSDK-0.3.5.tar.gz", "has_sig": false, "md5_digest": "bf5eb04d11cdab76774fe122ce4cbe69", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9163, "upload_time": "2019-07-17T10:21:53", "url": "https://files.pythonhosted.org/packages/f5/76/0e50f053f12897291ba7ea79c9b5d045d6902a87676d0f924ec9431ad2d5/ONEmSDK-0.3.5.tar.gz" } ], "0.3.6": [ { "comment_text": "", "digests": { "md5": "377348567fe45a02b715e30bbcebab31", "sha256": "4382e0c4007671b9f5986fd007ed1d98a9fcfc68bf3f550668a992e2d6b40b6c" }, "downloads": -1, "filename": "ONEmSDK-0.3.6.tar.gz", "has_sig": false, "md5_digest": "377348567fe45a02b715e30bbcebab31", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9160, "upload_time": "2019-07-18T09:50:54", "url": "https://files.pythonhosted.org/packages/eb/ef/46d11fb0512f05ad1411e20499ac41b02555e1e7b93cdcdfc506d72a7171/ONEmSDK-0.3.6.tar.gz" } ], "0.3.7": [ { "comment_text": "", "digests": { "md5": "16c9b4870df5055e5b3ba37101735764", "sha256": "58c55639b592c74cb6e33fc9c6aada46767fe8de271a07781386a6c24ddc1676" }, "downloads": -1, "filename": "ONEmSDK-0.3.7.tar.gz", "has_sig": false, "md5_digest": "16c9b4870df5055e5b3ba37101735764", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 10000, "upload_time": "2019-07-22T09:45:24", "url": "https://files.pythonhosted.org/packages/ab/93/316a0cea18ef5e592f060979e79f409b902c7780996b445de1ee3752dd4f/ONEmSDK-0.3.7.tar.gz" } ], "0.3.8": [ { "comment_text": "", "digests": { "md5": "7a16f1d193e36a2479c9642a5bafeb41", "sha256": "f708b0ad209a5cd6dab456e5d67a3e5318c74d19a3cffe92e84fe9bff6496d46" }, "downloads": -1, "filename": "ONEmSDK-0.3.8.tar.gz", "has_sig": false, "md5_digest": "7a16f1d193e36a2479c9642a5bafeb41", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9626, "upload_time": "2019-07-24T11:01:54", "url": "https://files.pythonhosted.org/packages/29/e5/6a6ba78e7389337578789bba92b0ead099841aa1d90ff25abcb37c40699e/ONEmSDK-0.3.8.tar.gz" } ], "0.3.9": [ { "comment_text": "", "digests": { "md5": "3cbf7236fdcdd950e254d8a7fa7f0eab", "sha256": "e2f6bee30190f5313313fcedb9bdc5b3030351a5a5cff970cf7219a2a184c624" }, "downloads": -1, "filename": "ONEmSDK-0.3.9.tar.gz", "has_sig": false, "md5_digest": "3cbf7236fdcdd950e254d8a7fa7f0eab", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9763, "upload_time": "2019-07-24T13:50:11", "url": "https://files.pythonhosted.org/packages/86/7b/c037f8242c87c4b7c91a411e55c8d6004fbeeba602e2bdeb65bd6c0bfc89/ONEmSDK-0.3.9.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "fcb68d19d5b464869668040cf80d756e", "sha256": "32f2a814cd8d31556910f2f334c583608ad1628171a8a8cd47da40c189857c86" }, "downloads": -1, "filename": "ONEmSDK-0.4.0.tar.gz", "has_sig": false, "md5_digest": "fcb68d19d5b464869668040cf80d756e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 9966, "upload_time": "2019-08-08T07:42:59", "url": "https://files.pythonhosted.org/packages/12/f0/4c92b49f8da1390987fd4558e4af0f85b57208d85a21d86eb911241983b5/ONEmSDK-0.4.0.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "32a018a860248fdd3f7e57e51f603f7b", "sha256": "5848eeffcf95b9587307193c75f5b2b79ca8cccdb524571a4d2c5ebe8e1e9a63" }, "downloads": -1, "filename": "ONEmSDK-0.5.0.tar.gz", "has_sig": false, "md5_digest": "32a018a860248fdd3f7e57e51f603f7b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 10351, "upload_time": "2019-08-26T10:58:01", "url": "https://files.pythonhosted.org/packages/d7/12/a40bb6ebff7f5065c4462e757bcef5a078923f584d744e784dbfed85deea/ONEmSDK-0.5.0.tar.gz" } ], "0.5.1": [ { "comment_text": "", "digests": { "md5": "b138ce530cd4ad0771cc673fff64d77e", "sha256": "1b7863044d2fe5acb15f47bfebc0cd64de7ed0a536d1b7a0bf724c325645e1f4" }, "downloads": -1, "filename": "ONEmSDK-0.5.1.tar.gz", "has_sig": false, "md5_digest": "b138ce530cd4ad0771cc673fff64d77e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7, <4", "size": 10644, "upload_time": "2019-08-26T11:03:44", "url": "https://files.pythonhosted.org/packages/ae/52/35290d55dcd7df545ef57c941044e4cdc0b0ec2d1f69383495996980154f/ONEmSDK-0.5.1.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "bdf0bd996ac71370a282df48fdca7bcb", "sha256": "1401a5d8b9ba7de5013821743d57e4b14ab99e3380585cd01d2cfe95670debcc" }, "downloads": -1, "filename": "ONEmSDK-0.6.0.tar.gz", "has_sig": false, "md5_digest": "bdf0bd996ac71370a282df48fdca7bcb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6, <4", "size": 14347, "upload_time": "2019-09-12T10:54:08", "url": "https://files.pythonhosted.org/packages/62/72/dc8acb1bc78e240fa1e2a6c9ec45b87c99aecd420997f077d2911963b984/ONEmSDK-0.6.0.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "7f8bf10e6a95b8d8f8b10699c5ac6c3e", "sha256": "3479718d1e2f11aa31b44f182fd07d360b664a97a5cca78c16f1b2df8634c953" }, "downloads": -1, "filename": "ONEmSDK-0.7.0.tar.gz", "has_sig": false, "md5_digest": "7f8bf10e6a95b8d8f8b10699c5ac6c3e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6, <4", "size": 14522, "upload_time": "2019-09-19T12:19:32", "url": "https://files.pythonhosted.org/packages/a8/16/c7420f77fd6e9d37193d8e672be8485fed0f979909d2d12baafd85bb9089/ONEmSDK-0.7.0.tar.gz" } ], "0.8.0": [ { "comment_text": "", "digests": { "md5": "d210ca8f27da8ff2dbda1bbceee80c58", "sha256": "ec56a6f78c6599c3d545322313b4f8242ee0ac35a2cfafe2faa5cfc6b8b43218" }, "downloads": -1, "filename": "ONEmSDK-0.8.0.tar.gz", "has_sig": false, "md5_digest": "d210ca8f27da8ff2dbda1bbceee80c58", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6, <4", "size": 16286, "upload_time": "2019-09-30T13:40:17", "url": "https://files.pythonhosted.org/packages/77/26/4124aa16d3fc8b56e613287b4adb03f5bd338377e04e74c2d5e21adbd482/ONEmSDK-0.8.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d210ca8f27da8ff2dbda1bbceee80c58", "sha256": "ec56a6f78c6599c3d545322313b4f8242ee0ac35a2cfafe2faa5cfc6b8b43218" }, "downloads": -1, "filename": "ONEmSDK-0.8.0.tar.gz", "has_sig": false, "md5_digest": "d210ca8f27da8ff2dbda1bbceee80c58", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6, <4", "size": 16286, "upload_time": "2019-09-30T13:40:17", "url": "https://files.pythonhosted.org/packages/77/26/4124aa16d3fc8b56e613287b4adb03f5bd338377e04e74c2d5e21adbd482/ONEmSDK-0.8.0.tar.gz" } ] }