{ "info": { "author": "Emmanuel Okeke", "author_email": "emmanix2002@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Dorcas Python3 SDK\n=======\nA Python library for interacting with the Dorcas API. It makes it easy to access the API services directly \nfrom your Python project.\n\n#### Example Usage\n```python\nfrom dorcas_sdk_python import Sdk\n\nclient_id = 'jAGOn0aygL'\nclient_secret = '7CDouHd526pbPubv4fFLRnw5uWjKeaIh0ymsjJ39'\nsdk = Sdk(client_id, client_secret, environment='local')\nplans = sdk('resource', 'Plan')\nplans.add_query_param('search', 'Pre')\nresponse = plans.send('get')\nresponse = response.send(method='post')\nif response.is_successful():\n print(response.data())\nelse:\n print('Something went wrong')\n```\n\n### Overview\n- [Getting Started](#getting-started)\n- [Using the Package](#using-the-package)\n- [The `Sdk` object](#the-sdk-object)\n- [Authentication](#authentication)\n- [Making Requests](#making-requests)\n- [The `DorcasResponse` object](#the-dorcas-response-object)\n\n\n\n### Getting Started\nTo get started, the first thing you need to do is create a developer account on the \n[Dorcas developer site](http://developers.dorcas.io/docs/). \nYou should follow the instructions inside the documentation.\n\n\n\n### Using the Package\nThe package was built to simplify the process of communicating with the API, and using it can be \nsummed up into 5 steps (excluding `import` statements):\n\n1. Instantiate the SDK\n2. Create the `Resource`, or `Service` instance\n3. Set your payload (`body`, or `query`)\n4. Send the request, and receive a `DorcasResponse` instance as the return value\n5. Use the `DorcasResponse` object\n\nBelow is an example:\n\n```python\nfrom dorcas_sdk_python import Sdk\n\n\nsdk = Sdk('jAGOn0aygL', '7CDouHd526pbPubv4fFLRnw5uWjKeaIh0ymsjJ39', environment='local') # step 1\n\npassword_login = sdk('service', 'PasswordLogin') # step 2\n\npassword_login.add_body_param('username', 'fakeid@gmail.com') # step 3\npassword_login.add_body_param('password', 'awesome secure uncrackable password') # step 3\n\nresponse = password_login.send(method='post') # step 4\n\nif response.is_successful(): # step 5\n print('Access Token: {}'.format(response.access_token))\nelse:\n print('Login failed')\n print(response.errors()[0])\n\n```\n\n\n### The `Sdk` object\nThe `Sdk` class allows you to set your API authentication details:\n\n- `client_id`\n- `client_secret`\n\nIt also allows you to choose an environment, you should either set it to:\n\n- production : for the live Dorcas API\n- staging: for the Dorcas testing API\n\nThe environment you choose decides which endpoint your requests are sent to. \n\n#### Model Types\nThere are 2 kinds of models represented on this library, they are:\n\n- `Resource`(s): these kind of models almost always require the call to be authenticated. They usually point to \ndatabase records. This means `Resource` models are always mapped to database records. \nE.g. `Product` maps to `Product` records on the API\n\n- `Service`(s): these kind of models usually refer to things that aren;t actually records in the database as you'd \nexpect. For instance, the `PasswordLogin` service is strictly used for authenticating a user.\n\nThe `Sdk` object makes it easy to instantiate these models; it can be done manually as well. To instantiate a model, \nyou do like so:\n\n```python\nfrom dorcas_sdk_python import Sdk\n\n\nsdk = Sdk('jAGOn0aygL', '7CDouHd526pbPubv4fFLRnw5uWjKeaIh0ymsjJ39', environment='local')\n\nresource = sdk('resource', 'ResourceModelClassName') # we use the Sdk instance object\nservice = sdk('service', 'ServiceModelClassName')\n```\n\nAll `Resource` models extend the base `Resource` class, while `Service` models extend the base `Service` class.\n\n**NOTE**: When instantiating the models, you can also pass in additional `keyword parameters` to the call, and they'll \nalso be passed to the constructor of the model class, and are collected in an `option` property on the instance. \n You can make the call like so:\n\n```python\nfrom dorcas_sdk_python import Sdk\n\n\nsdk = Sdk('jAGOn0aygL', '7CDouHd526pbPubv4fFLRnw5uWjKeaIh0ymsjJ39', environment='local')\n\nresource = sdk('resource', 'ResourceModelClassName', length=5, tag='general') # we use the Sdk instance object\nservice = sdk('service', 'ServiceModelClassName', name='growth hacking')\n\nprint(resource.option.tag) # general\nprint(service.option.name) # growth hacking\n\n```\n\nThis is useful for situations where you create your own custom `Service`, or `Resource` classes.\n\n\n\n### Authentication\nMost of the calls to the API require the caller to be authenticated; this mean, it must contain a \nvalid `access_token` for the user you're making the call on behalf of.\n\nThere are 2 ways to get a token:\n\n1. Via the login (`PasswordLogin` service) activity (public - available to all API clients)\n2. Via direct authentication (private - only available to select clients)\n\nBecause these activities always follow the same process, 3 utility methods were provided to simplify these \ncalls (see the `helpers.py` module):\n\n- `authorize_via_email_only` : direct authorization\n- `login_via_password` : username + password combination authentication\n- `create_account` : although not part of this, but this function was provided to make user registration as simple as \na function call\n\nAuthentication calls always provide a response similar to this:\n```json\n{\n \"token_type\": \"Bearer\",\n \"expires_in\": 31536000,\n \"access_token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjE1YTI3ZmY1ZWI0ZWNhZTczMjNhZWI2MjYwNjhkYzYyYTcxNzIwOTY2NzAwNzYxNDlhMzI1NTFjZjdlZDBkNjY4NWVkODVmYjA5NDMwNzExIn0.eyJhdWQiOiIyIiwianRpIjoiMTVhMjdmZjVlYjRlY2FlNzMyM2FlYjYyNjA2OGRjNjJhNzE3MjA5NjY3MDA3NjE0OWEzMjU1MWNmN2VkMGQ2Njg1ZWQ4NWZiMDk0MzA3MTEiLCJpYXQiOjE1MTUyNzc2MDksIm5iZiI6MTUxNTI3NzYwOSwiZXhwIjoxNTQ2ODEzNjA5LCJzdWIiOiIxIiwic2NvcGVzIjpbIioiXX0.GIBH8fuEg7bnSjm0Z3NtxuYshJ4RJVEcH-bNJPAMokLVvNSsMr4DBnYIsmJFk14pdMfiGRLqKQEZN2REgxTPj8q5a1btJwFoHqu5-nLcNGlrIKav8W8D5RtO8PZ1MHEBp-eyvu3U3-qIWe-vYan7csNdhnA0vcoZCXMU7JbAnATtahv0VjCqLo2n-VmICtYBvKfQjX3rVtp6sg4LqiChvGLDC5XoA0AYUfZdj2RvCj4oj0eC3W0y4ndcMpWkSSI1BIhZ9LyE6YloE0NNs4FB0upDoBVK_vxmwahdYsYaRgYGwu1RJf4v7hkLBvrSgwewqwTytCtfVU18EW71Pera9e9OMh1-ldZ3PiQMpBesos_bR9U2roEqfHUwJEY_1834hqiPQj_vq7E5ppMAVoWT2A9JMQIDzgZrxP7E0mynEoVohSBEvsF5VJxuUii8STcmGTo33x2dcMUYLtVNyRXHLzKjyYns_SrDtyIhyPrpYCtVNUWok_stLps6KrJFm7kJ0JB3u5-7tTP645DhPKaoMUrrodghZpkeCc_gabXtvughYgJkhlK3wixLCB1tdqR8IeuCdhWmqc31TfpfUob1Deka_jzmfxsyuu1VvIPiqdtw_Mm3RR6qQWhqfXQlpdf46SRa_lRveiOp7IXwPUFm_XSgSt8zBL5oQOm3k6r5lJo\",\n \"refresh_token\": \"def50200ffed0e36ba02030192de5ecf0fa7b098e774ee3854c0a1d2a9b5e376d410aa435bf101fadbfd54a169a1c17a68ed27d242339c13dc318a7cb258d4ae2bcc487d0e7e9597794240bd51b24fce8ed274c55f368c0bdf8a739ceaa4e0656575de854152ba6c98126dd6b8435145d9e9d79df5bbe5114ca3da1c157447dc062be9c0cea747edfa9202f3ae036d65a532588ce91975db489c9721e53017b5b9069c5a13f51b682f5938a838dec60fb28f8ef19f62657f5f25082a376e14808f1963c1d2abd0af04a3d3a45c4e7abad8aba5b71f0245365530445a1a089604e727bce80be03ff2a24a094dc9acc22146108f3ee1e1f7efc11573c7b58e2ecc9c81241da90a0a477aeb784147c62e991b1630d07d8d9fb4ba1fc6d843408d268454c242153b04648ed9a1d8d9cf06aeeee59e33de8db4d06a569e5a9b155999f0e68226fae133dc06a88064b25032605e2be0921b069596333b108e9d124fa1b4fd0105\"\n}\n```\n\nThe response contains an `access_token` key which you set on the `Sdk` instance for future use like \nso: `sdk.auth_token = response.access_token`\n\nAll calls after this using this `Sdk` instance will send the appropriate `Authorization` header in the request.\n\n\n#### Things to take note of\nYou will likely have to save this `access_token` in your _cache / session_ so you don't have to authenticate the \nuser on each page reload.\n\nThe `auth_token` can also be provided when instantiating the `Sdk` like so: \n\n```python\nsdk = Sdk('jAGOn0aygL', '7CDouHd526pbPubv4fFLRnw5uWjKeaIh0ymsjJ39', auth_token='...', environment='local')\n```\n\n\n\n### Making Requests\nMaking requests is the final step after setting your payload. It only requires you to know 2 things:\n\n- The request method: One of 'get', 'delete', 'post', or 'put'\n- The requests path: Every model has a base path, but certain sub-resources might require you appending something to \nthe path\n\nAn example of the second point is like so:\n\n- `Customer` resource has a base path of `/customers`\n- To get a single `Customer` model from the API, we need a path in the form: `/customers/{id}`\n\nIn the above case, our call to `send()` will look like: `resource.send('get', customer.id)` \n\n\n\n### The `DorcasResponse` object\nThe `DorcasResponse` object provides some simple methods:\n\n- `is_successful()` : returns `True`, or `False` if the request came back successfully. i.e. The API call worked fine\n- `code()` : only useful when a `code` key exists in the returned response\n- `message()`: useful when a `message` key exists in the returned response\n- `errors()` : will usually be a list of errors, when `is_successful()` is `False`\n- `data()`: for successful responses with a `data` key.\n\nFrom above, you can see that all the methods excluding `is_successful()` simply provide access to the keys in the \nresponse. For `keys` that don't have a defined method, you can access them like properties on the response object.\nsee [Authentication](#authentication) for the example of accessing the `access_token` key.\n\n\n### To-DO\n- Add file upload support\n\n\n### Questions?\nJust drop me a line at _emmanix2002 [at] gmail dot com_\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/dorcasng/dorcas-sdk-python", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "dorcas-sdk-python", "package_url": "https://pypi.org/project/dorcas-sdk-python/", "platform": "", "project_url": "https://pypi.org/project/dorcas-sdk-python/", "project_urls": { "Homepage": "https://gitlab.com/dorcasng/dorcas-sdk-python" }, "release_url": "https://pypi.org/project/dorcas-sdk-python/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "A Python wrapper for communicating with the Dorcas API", "version": "0.0.1" }, "last_serial": 4372433, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "f3cfc2f40430c3163313b185610f91d5", "sha256": "2030f544596bb455c680f8ce7cf15223ce3d0e491763425b3a11bddcaf65d3ad" }, "downloads": -1, "filename": "dorcas_sdk_python-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f3cfc2f40430c3163313b185610f91d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18042, "upload_time": "2018-10-13T18:21:26", "url": "https://files.pythonhosted.org/packages/85/36/84a2b78581bb63d2c043acda2219bcab96808950f1dad7449b961818f757/dorcas_sdk_python-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3ecd18f502d8682c75178e139dc68b69", "sha256": "ac56c0e02e6ff21c57ae18b78db71e07b09c39fe3c5d735d4bb838f9be2c0e25" }, "downloads": -1, "filename": "dorcas_sdk_python-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3ecd18f502d8682c75178e139dc68b69", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18634, "upload_time": "2018-10-13T18:21:28", "url": "https://files.pythonhosted.org/packages/ff/3c/8c0bdbb50745a1a19d1fe79438c82b32121ee467dfe3a0ebdd17cd57233a/dorcas_sdk_python-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f3cfc2f40430c3163313b185610f91d5", "sha256": "2030f544596bb455c680f8ce7cf15223ce3d0e491763425b3a11bddcaf65d3ad" }, "downloads": -1, "filename": "dorcas_sdk_python-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f3cfc2f40430c3163313b185610f91d5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18042, "upload_time": "2018-10-13T18:21:26", "url": "https://files.pythonhosted.org/packages/85/36/84a2b78581bb63d2c043acda2219bcab96808950f1dad7449b961818f757/dorcas_sdk_python-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3ecd18f502d8682c75178e139dc68b69", "sha256": "ac56c0e02e6ff21c57ae18b78db71e07b09c39fe3c5d735d4bb838f9be2c0e25" }, "downloads": -1, "filename": "dorcas_sdk_python-0.0.1.tar.gz", "has_sig": false, "md5_digest": "3ecd18f502d8682c75178e139dc68b69", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18634, "upload_time": "2018-10-13T18:21:28", "url": "https://files.pythonhosted.org/packages/ff/3c/8c0bdbb50745a1a19d1fe79438c82b32121ee467dfe3a0ebdd17cd57233a/dorcas_sdk_python-0.0.1.tar.gz" } ] }