{ "info": { "author": "LaunchKey", "author_email": "support@launchkey.com", "bugtrack_url": null, "classifiers": [ "Framework :: Twisted", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "LaunchKey Twisted SDK\n=====================\n\n.. image:: https://travis-ci.org/LaunchKey/launchkey-python-twisted.svg?branch=master\n :target: https://travis-ci.org/LaunchKey/launchkey-python-twisted\n\nOverview\n--------\n\nThe LaunchKey Twisted library allows for asynchronous communication with the LaunchKey Engine API\nvia a Python library and Twisted. The public interface is the same as the\n`synchronous SDK `_ with the two exceptions:\n\n1. The first argument of the init script for launchkey_twisted.TwistedAPI is a\n `Twisted Web Client Agent `_.\n\n2. All public methods return\n `Twisted Deferred `_\n objects.\n\nInstallation\n------------\n\n.. code-block:: bash\n\n $ easy_install launchkey-twisted\n\n\nor\n\n.. code-block:: bash\n\n $ pip install launchkey-twisted\n\n\nThe following example is a functional representation of a simple session based launch request and subsequent\nde-orbit if applicable. *The use of polling is not suggested for production server based implementations.*\n\n.. code-block:: python\n\n import sys\n from twisted.python import log\n from twisted.internet import task, reactor, defer\n from twisted.web.client import Agent\n from launchkey_twisted import TwistedAPI, PendingResponse\n\n # agent is needed to link the SDK to the reactor as an HTTP client\n agent = Agent(reactor)\n\n # app_key will be provided in the dashboard\n app_key = 1234567890\n\n # app_secret will be provided in the dashboard once, or a new one may be generated\n app_secret = \"abcdefghijklmnopqrstuvwxyz123456\"\n\n\n # private key location will will be the path to the private key file you received from the dashboard or the\n # private key file you used to generate the public key you uploaded to the dashboard\n private_key_location = \"/path/to/private.key\"\n\n # Your LaunchKey username\n username = \"myusername\"\n\n # Poll interval determines the delay in seconds between poll requests\n poll_interval = 1.0\n\n # Log out delay determines the delay in seconds between an accepted authentication and logout\n log_out_delay = 3.0\n\n # If you are having issues, set this to true for verbose logging onthe reactor\n debug = False\n\n\n def handle_auth_response(auth_request):\n \"\"\"\n Receives the auth_request identifier and begin the polling process\n :param auth_request: Identifier for this authentication request returned by the LaunchKey Engine API\n :return: Deferred\n \"\"\"\n print(\"Authentication request successfully initiated with identifier: {0}\".format(auth_request))\n return poll_for_user_repsonse(auth_request)\n\n\n def poll_for_user_repsonse(auth_request):\n \"\"\"\n Schedule the next poll operation. Adds callback for success and error situations\n :param auth_request: Identifier for this authentication request returned by the LaunchKey Engine API\n :return: Deferred\n \"\"\"\n print(\"Poll for user response in {0} seconds\".format(poll_interval))\n d = task.deferLater(reactor, poll_interval, api.poll_request, auth_request)\n d.addCallback(handle_poll_response, auth_request)\n d.addErrback(handle_poll_error)\n return d\n\n\n def handle_poll_error(failure):\n \"\"\"\n Trap PendingResponse errors and schedule another poll\n :param failure:\n :return: Deferred\n \"\"\"\n failure.trap(PendingResponse)\n return poll_for_user_repsonse(failure.value.auth_request)\n\n\n def handle_poll_response(response, auth_request):\n \"\"\"\n Receive the poll response and the original auth_request to validate the poll response package and detyermine the\n outcome.\n :param response: Poll response object\n :param auth_request: Identifier for this authentication request returned by the LaunchKey Engine API\n :return: Deferred\n \"\"\"\n print(\"User response received, checking the response package\")\n deferred = api.is_authorized(auth_request, response['auth'])\n deferred.addCallback(handle_is_authorized_response, auth_request)\n return deferred\n\n\n def handle_is_authorized_response(authorized, auth_request):\n \"\"\"\n Receive the is_authorized response and schedule the logout if authorized\n :param authorized: Boolean value depicting the users response to the auth_request.\n (True: accepted | False: declined)\n :param auth_request: Identifier for this authentication request returned by the LaunchKey Engine API\n :return: Deferred\n \"\"\"\n if authorized:\n print(\"User accepted, scheduling logout for {0} seconds from now\".format(log_out_delay))\n deferred = task.deferLater(reactor, log_out_delay, log_user_out, auth_request)\n else:\n print(\"User declined\")\n deferred = defer.succeed(True)\n\n return deferred\n\n\n def log_user_out(auth_request):\n \"\"\"\n End the user session for the provided authentication request\n :param auth_request: Identifier for this authentication request returned by the LaunchKey Engine API\n :return: Deferred\n \"\"\"\n print(\"Logging user out\")\n deferred = api.logout(auth_request)\n deferred.addCallback(done)\n return deferred\n\n\n def handle_error(failure):\n \"\"\"\n Print an error\n :param failure:\n :return:\n \"\"\"\n print(\"Completed with error: \", failure)\n return failure\n\n\n def done(*args):\n \"\"\"\n Stop the reactor\n :param args:\n :return:\n \"\"\"\n reactor.stop()\n print(\"Reactor stopped\")\n\n\n agent = Agent(reactor)\n\n api = TwistedAPI(\n agent,\n app_key,\n app_secret,\n open(private_key_location, \"r\").read()\n )\n\n print(\"Starting authentication request for user: {0}\".format(username))\n auth = api.authorize(username, True)\n auth.addCallback(handle_auth_response)\n auth.addErrback(handle_error)\n auth.addBoth(done)\n\n if debug:\n log.startLogging(sys.stderr)\n\n print(\"Starting reactor\")\n reactor.run()\n\nTests\n-----\n\n.. code-block:: bash\n\n $ python setup.py nosetests\n\nContributing\n------------\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://launchkey.com", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "launchkey-twisted", "package_url": "https://pypi.org/project/launchkey-twisted/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/launchkey-twisted/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://launchkey.com" }, "release_url": "https://pypi.org/project/launchkey-twisted/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "LaunchKey Asynchronous SDK for Twisted", "version": "1.0.0" }, "last_serial": 1693333, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "f1f7eb2b8f94d4dcf3bf955383a1fed2", "sha256": "634e11fda06a5f53717973628de828a9b36214bde524dddbb7653642794479cc" }, "downloads": -1, "filename": "launchkey-twisted-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f1f7eb2b8f94d4dcf3bf955383a1fed2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5943, "upload_time": "2015-08-25T18:24:14", "url": "https://files.pythonhosted.org/packages/b6/94/a9298f169ed0cf67dea67ebfaf65c8bb56d1900095f760eb85bb625d07ae/launchkey-twisted-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f1f7eb2b8f94d4dcf3bf955383a1fed2", "sha256": "634e11fda06a5f53717973628de828a9b36214bde524dddbb7653642794479cc" }, "downloads": -1, "filename": "launchkey-twisted-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f1f7eb2b8f94d4dcf3bf955383a1fed2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5943, "upload_time": "2015-08-25T18:24:14", "url": "https://files.pythonhosted.org/packages/b6/94/a9298f169ed0cf67dea67ebfaf65c8bb56d1900095f760eb85bb625d07ae/launchkey-twisted-1.0.0.tar.gz" } ] }