{"action":"created","comment":{"url":"https://api.github.com/repos/paze-me/mambu/pulls/comments/46297751","id":46297751,"diff_hunk":"@@ -1,21 +1,852 @@\n-from clients import ClientsAPI\n-from loans import LoansAPI\n-from savings import SavingsAPI\n-from loan_transaction import LoanTransactionsAPI\n-from savings_transaction import SavingsTransactionsAPI\n-from attachments import AttachmentsAPI\n-from custom_fields import CustomFieldsAPI\n-from loan_products import LoanProductsAPI\n+import threading\n+import logging\n+import requests\n+import json\n+import datetime\n+import base64\n+\n+\n+from tools import datelib, data\n+from exception import MambuAPIException\n+\n+metadata = data.load_yaml('data.yaml')\n+logger = logging.getLogger(__name__)\n+\n+\n+class AbstractDataObject(object):\n+    def __init__(self, **kw):\n+        for key, val in kw.items():\n+            self.__setattr__(key, val)\n+\n+    def __setattr__(self, key, val):\n+        if key not in type(self).fields:\n+            raise ValueError(key + \" is not an allowed field\")\n+        self.__dict__[key] = val\n+\n+    def __getattr__(self, key):\n+        return self.__dict__[key]\n+\n+\n+class RequestJSONEncoder(json.JSONEncoder):\n+    def default(self, o):\n+        if isinstance(o, AbstractDataObject):\n+            return o.__dict__\n+        if isinstance(o, (datetime.date, datetime.datetime)):\n+            return o.isoformat()\n+        return o\n \n \n class API(object):\n     def __init__(self, config_):\n         self.config = config_\n-        self.Clients = ClientsAPI(self)\n-        self.Loans = LoansAPI(self)\n-        self.Savings = SavingsAPI(self)\n-        self.LoanTransactions = LoanTransactionsAPI(self)\n-        self.SavingsTransactions = SavingsTransactionsAPI(self)\n-        self.Attachments = AttachmentsAPI(self)\n-        self.CustomFields = CustomFieldsAPI(self)\n-        self.LoanProducts = LoanProductsAPI(self)\n+        self.base_url = 'https://{}/api/'.format(self.config.domain)\n+        self.json_encoder = RequestJSONEncoder()\n+\n+    def _request(self, method, url, params=None, data=None):\n+        headers = {'Content-Type': 'application/json'} if data else {}\n+        data_str = self.json_encoder.encode(data)\n+        logging.debug(\"Body: \" + data_str)\n+        response = getattr(requests, method)(\n+            self.base_url + url, headers=headers, params=params, data=data_str,\n+            auth=(self.config.username, self.config.password))\n+        if response.status_code != 200 and response.status_code != 201:\n+            raise MambuAPIException(\"Error performing the request\",\n+                                    response.status_code, response.json())\n+        return response.json()\n+\n+    def _get(self, url, params=None, data=None):\n+        return self._request('get', url, params, data)\n+\n+    def _post(self, url, params=None, data=None):\n+        return self._request('post', url, params, data)\n+\n+    def _patch(self, url, params=None, data=None):\n+        return self._request('patch', url, params, data)\n+\n+    def _delete(self, url, params=None, data=None):\n+        return self._request('delete', url, params, data)\n+\n+    def _postfix_url(self, *args):\n+        return '/'.join([arg for arg in args if arg is not None])\n+\n+    def get_client(self, client_id=None, params=None):\n+        \"\"\"Get the details for the client fro mambu","path":"mambu/api.py","position":89,"original_position":89,"commit_id":"8972facc2649b128fdfd07492f3694913349fbe5","original_commit_id":"8972facc2649b128fdfd07492f3694913349fbe5","user":{"login":"hanselpaze","id":15737071,"avatar_url":"https://avatars.githubusercontent.com/u/15737071?v=3","gravatar_id":"","url":"https://api.github.com/users/hanselpaze","html_url":"https://github.com/hanselpaze","followers_url":"https://api.github.com/users/hanselpaze/followers","following_url":"https://api.github.com/users/hanselpaze/following{/other_user}","gists_url":"https://api.github.com/users/hanselpaze/gists{/gist_id}","starred_url":"https://api.github.com/users/hanselpaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanselpaze/subscriptions","organizations_url":"https://api.github.com/users/hanselpaze/orgs","repos_url":"https://api.github.com/users/hanselpaze/repos","events_url":"https://api.github.com/users/hanselpaze/events{/privacy}","received_events_url":"https://api.github.com/users/hanselpaze/received_events","type":"User","site_admin":false},"body":"just a typo","created_at":"2015-12-01T16:09:34Z","updated_at":"2015-12-01T16:09:34Z","html_url":"https://github.com/paze-me/mambu/pull/1#discussion_r46297751","pull_request_url":"https://api.github.com/repos/paze-me/mambu/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/comments/46297751"},"html":{"href":"https://github.com/paze-me/mambu/pull/1#discussion_r46297751"},"pull_request":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/paze-me/mambu/pulls/1","id":52275871,"html_url":"https://github.com/paze-me/mambu/pull/1","diff_url":"https://github.com/paze-me/mambu/pull/1.diff","patch_url":"https://github.com/paze-me/mambu/pull/1.patch","issue_url":"https://api.github.com/repos/paze-me/mambu/issues/1","number":1,"state":"open","locked":false,"title":"Independence ready","user":{"login":"davidsimpsonpaze","id":15737417,"avatar_url":"https://avatars.githubusercontent.com/u/15737417?v=3","gravatar_id":"","url":"https://api.github.com/users/davidsimpsonpaze","html_url":"https://github.com/davidsimpsonpaze","followers_url":"https://api.github.com/users/davidsimpsonpaze/followers","following_url":"https://api.github.com/users/davidsimpsonpaze/following{/other_user}","gists_url":"https://api.github.com/users/davidsimpsonpaze/gists{/gist_id}","starred_url":"https://api.github.com/users/davidsimpsonpaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidsimpsonpaze/subscriptions","organizations_url":"https://api.github.com/users/davidsimpsonpaze/orgs","repos_url":"https://api.github.com/users/davidsimpsonpaze/repos","events_url":"https://api.github.com/users/davidsimpsonpaze/events{/privacy}","received_events_url":"https://api.github.com/users/davidsimpsonpaze/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-12-01T15:57:13Z","updated_at":"2015-12-01T16:09:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b7c005e759d146625994484ee9495348668d9f91","assignee":{"login":"hanselpaze","id":15737071,"avatar_url":"https://avatars.githubusercontent.com/u/15737071?v=3","gravatar_id":"","url":"https://api.github.com/users/hanselpaze","html_url":"https://github.com/hanselpaze","followers_url":"https://api.github.com/users/hanselpaze/followers","following_url":"https://api.github.com/users/hanselpaze/following{/other_user}","gists_url":"https://api.github.com/users/hanselpaze/gists{/gist_id}","starred_url":"https://api.github.com/users/hanselpaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanselpaze/subscriptions","organizations_url":"https://api.github.com/users/hanselpaze/orgs","repos_url":"https://api.github.com/users/hanselpaze/repos","events_url":"https://api.github.com/users/hanselpaze/events{/privacy}","received_events_url":"https://api.github.com/users/hanselpaze/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/paze-me/mambu/pulls/1/commits","review_comments_url":"https://api.github.com/repos/paze-me/mambu/pulls/1/comments","review_comment_url":"https://api.github.com/repos/paze-me/mambu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paze-me/mambu/issues/1/comments","statuses_url":"https://api.github.com/repos/paze-me/mambu/statuses/8972facc2649b128fdfd07492f3694913349fbe5","head":{"label":"paze-me:independence-ready","ref":"independence-ready","sha":"8972facc2649b128fdfd07492f3694913349fbe5","user":{"login":"paze-me","id":15735644,"avatar_url":"https://avatars.githubusercontent.com/u/15735644?v=3","gravatar_id":"","url":"https://api.github.com/users/paze-me","html_url":"https://github.com/paze-me","followers_url":"https://api.github.com/users/paze-me/followers","following_url":"https://api.github.com/users/paze-me/following{/other_user}","gists_url":"https://api.github.com/users/paze-me/gists{/gist_id}","starred_url":"https://api.github.com/users/paze-me/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paze-me/subscriptions","organizations_url":"https://api.github.com/users/paze-me/orgs","repos_url":"https://api.github.com/users/paze-me/repos","events_url":"https://api.github.com/users/paze-me/events{/privacy}","received_events_url":"https://api.github.com/users/paze-me/received_events","type":"Organization","site_admin":false},"repo":{"id":46987222,"name":"mambu","full_name":"paze-me/mambu","owner":{"login":"paze-me","id":15735644,"avatar_url":"https://avatars.githubusercontent.com/u/15735644?v=3","gravatar_id":"","url":"https://api.github.com/users/paze-me","html_url":"https://github.com/paze-me","followers_url":"https://api.github.com/users/paze-me/followers","following_url":"https://api.github.com/users/paze-me/following{/other_user}","gists_url":"https://api.github.com/users/paze-me/gists{/gist_id}","starred_url":"https://api.github.com/users/paze-me/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paze-me/subscriptions","organizations_url":"https://api.github.com/users/paze-me/orgs","repos_url":"https://api.github.com/users/paze-me/repos","events_url":"https://api.github.com/users/paze-me/events{/privacy}","received_events_url":"https://api.github.com/users/paze-me/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paze-me/mambu","description":"Python module for the Mambu API","fork":false,"url":"https://api.github.com/repos/paze-me/mambu","forks_url":"https://api.github.com/repos/paze-me/mambu/forks","keys_url":"https://api.github.com/repos/paze-me/mambu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paze-me/mambu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paze-me/mambu/teams","hooks_url":"https://api.github.com/repos/paze-me/mambu/hooks","issue_events_url":"https://api.github.com/repos/paze-me/mambu/issues/events{/number}","events_url":"https://api.github.com/repos/paze-me/mambu/events","assignees_url":"https://api.github.com/repos/paze-me/mambu/assignees{/user}","branches_url":"https://api.github.com/repos/paze-me/mambu/branches{/branch}","tags_url":"https://api.github.com/repos/paze-me/mambu/tags","blobs_url":"https://api.github.com/repos/paze-me/mambu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paze-me/mambu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paze-me/mambu/git/refs{/sha}","trees_url":"https://api.github.com/repos/paze-me/mambu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paze-me/mambu/statuses/{sha}","languages_url":"https://api.github.com/repos/paze-me/mambu/languages","stargazers_url":"https://api.github.com/repos/paze-me/mambu/stargazers","contributors_url":"https://api.github.com/repos/paze-me/mambu/contributors","subscribers_url":"https://api.github.com/repos/paze-me/mambu/subscribers","subscription_url":"https://api.github.com/repos/paze-me/mambu/subscription","commits_url":"https://api.github.com/repos/paze-me/mambu/commits{/sha}","git_commits_url":"https://api.github.com/repos/paze-me/mambu/git/commits{/sha}","comments_url":"https://api.github.com/repos/paze-me/mambu/comments{/number}","issue_comment_url":"https://api.github.com/repos/paze-me/mambu/issues/comments{/number}","contents_url":"https://api.github.com/repos/paze-me/mambu/contents/{+path}","compare_url":"https://api.github.com/repos/paze-me/mambu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paze-me/mambu/merges","archive_url":"https://api.github.com/repos/paze-me/mambu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paze-me/mambu/downloads","issues_url":"https://api.github.com/repos/paze-me/mambu/issues{/number}","pulls_url":"https://api.github.com/repos/paze-me/mambu/pulls{/number}","milestones_url":"https://api.github.com/repos/paze-me/mambu/milestones{/number}","notifications_url":"https://api.github.com/repos/paze-me/mambu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paze-me/mambu/labels{/name}","releases_url":"https://api.github.com/repos/paze-me/mambu/releases{/id}","created_at":"2015-11-27T15:30:16Z","updated_at":"2015-11-27T15:34:14Z","pushed_at":"2015-12-01T15:57:13Z","git_url":"git://github.com/paze-me/mambu.git","ssh_url":"git@github.com:paze-me/mambu.git","clone_url":"https://github.com/paze-me/mambu.git","svn_url":"https://github.com/paze-me/mambu","homepage":null,"size":91,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"paze-me:master","ref":"master","sha":"ff46dc41692bf7a33de34af3c59108ca95489685","user":{"login":"paze-me","id":15735644,"avatar_url":"https://avatars.githubusercontent.com/u/15735644?v=3","gravatar_id":"","url":"https://api.github.com/users/paze-me","html_url":"https://github.com/paze-me","followers_url":"https://api.github.com/users/paze-me/followers","following_url":"https://api.github.com/users/paze-me/following{/other_user}","gists_url":"https://api.github.com/users/paze-me/gists{/gist_id}","starred_url":"https://api.github.com/users/paze-me/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paze-me/subscriptions","organizations_url":"https://api.github.com/users/paze-me/orgs","repos_url":"https://api.github.com/users/paze-me/repos","events_url":"https://api.github.com/users/paze-me/events{/privacy}","received_events_url":"https://api.github.com/users/paze-me/received_events","type":"Organization","site_admin":false},"repo":{"id":46987222,"name":"mambu","full_name":"paze-me/mambu","owner":{"login":"paze-me","id":15735644,"avatar_url":"https://avatars.githubusercontent.com/u/15735644?v=3","gravatar_id":"","url":"https://api.github.com/users/paze-me","html_url":"https://github.com/paze-me","followers_url":"https://api.github.com/users/paze-me/followers","following_url":"https://api.github.com/users/paze-me/following{/other_user}","gists_url":"https://api.github.com/users/paze-me/gists{/gist_id}","starred_url":"https://api.github.com/users/paze-me/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paze-me/subscriptions","organizations_url":"https://api.github.com/users/paze-me/orgs","repos_url":"https://api.github.com/users/paze-me/repos","events_url":"https://api.github.com/users/paze-me/events{/privacy}","received_events_url":"https://api.github.com/users/paze-me/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paze-me/mambu","description":"Python module for the Mambu API","fork":false,"url":"https://api.github.com/repos/paze-me/mambu","forks_url":"https://api.github.com/repos/paze-me/mambu/forks","keys_url":"https://api.github.com/repos/paze-me/mambu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paze-me/mambu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paze-me/mambu/teams","hooks_url":"https://api.github.com/repos/paze-me/mambu/hooks","issue_events_url":"https://api.github.com/repos/paze-me/mambu/issues/events{/number}","events_url":"https://api.github.com/repos/paze-me/mambu/events","assignees_url":"https://api.github.com/repos/paze-me/mambu/assignees{/user}","branches_url":"https://api.github.com/repos/paze-me/mambu/branches{/branch}","tags_url":"https://api.github.com/repos/paze-me/mambu/tags","blobs_url":"https://api.github.com/repos/paze-me/mambu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paze-me/mambu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paze-me/mambu/git/refs{/sha}","trees_url":"https://api.github.com/repos/paze-me/mambu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paze-me/mambu/statuses/{sha}","languages_url":"https://api.github.com/repos/paze-me/mambu/languages","stargazers_url":"https://api.github.com/repos/paze-me/mambu/stargazers","contributors_url":"https://api.github.com/repos/paze-me/mambu/contributors","subscribers_url":"https://api.github.com/repos/paze-me/mambu/subscribers","subscription_url":"https://api.github.com/repos/paze-me/mambu/subscription","commits_url":"https://api.github.com/repos/paze-me/mambu/commits{/sha}","git_commits_url":"https://api.github.com/repos/paze-me/mambu/git/commits{/sha}","comments_url":"https://api.github.com/repos/paze-me/mambu/comments{/number}","issue_comment_url":"https://api.github.com/repos/paze-me/mambu/issues/comments{/number}","contents_url":"https://api.github.com/repos/paze-me/mambu/contents/{+path}","compare_url":"https://api.github.com/repos/paze-me/mambu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paze-me/mambu/merges","archive_url":"https://api.github.com/repos/paze-me/mambu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paze-me/mambu/downloads","issues_url":"https://api.github.com/repos/paze-me/mambu/issues{/number}","pulls_url":"https://api.github.com/repos/paze-me/mambu/pulls{/number}","milestones_url":"https://api.github.com/repos/paze-me/mambu/milestones{/number}","notifications_url":"https://api.github.com/repos/paze-me/mambu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paze-me/mambu/labels{/name}","releases_url":"https://api.github.com/repos/paze-me/mambu/releases{/id}","created_at":"2015-11-27T15:30:16Z","updated_at":"2015-11-27T15:34:14Z","pushed_at":"2015-12-01T15:57:13Z","git_url":"git://github.com/paze-me/mambu.git","ssh_url":"git@github.com:paze-me/mambu.git","clone_url":"https://github.com/paze-me/mambu.git","svn_url":"https://github.com/paze-me/mambu","homepage":null,"size":91,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/1"},"html":{"href":"https://github.com/paze-me/mambu/pull/1"},"issue":{"href":"https://api.github.com/repos/paze-me/mambu/issues/1"},"comments":{"href":"https://api.github.com/repos/paze-me/mambu/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paze-me/mambu/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/paze-me/mambu/statuses/8972facc2649b128fdfd07492f3694913349fbe5"}}}}