{"action":"created","comment":{"url":"https://api.github.com/repos/Yelp/swagger-py/pulls/comments/22563922","id":22563922,"diff_hunk":"@@ -173,203 +195,207 @@ def _construct_request(self, **kwargs):\n     def __call__(self, **kwargs):\n         log.debug(u\"%s?%r\" % (\n             self._json[u'nickname'],\n-            urllib_utf8.urlencode(kwargs)\n-        ))\n+            urllib_utf8.urlencode(kwargs)))\n         request = self._construct_request(**kwargs)\n \n-        def py_model_convert_callback(response, **kwargs):\n-            value = None\n-            type_ = swagger_type.get_swagger_type(self._json)\n-            # Assume status is OK,\n-            # as exception would have been raised otherwise\n-            # Validate the response if it is not empty.\n-            if response.text:\n-                # Validate and convert API response to Python model instance\n-                value = SwaggerResponse(\n-                    response.json(), type_, self._models,\n-                    **kwargs).swagger_object\n-            return value\n-        return HTTPFuture(self._http_client,\n-                          request, py_model_convert_callback)\n+        def response_future(response, **kwargs):\n+            # Assume status is OK, an exception would have been raised already\n+            if not response.text:\n+                return None\n+\n+            return post_receive(\n+                response.json(),\n+                swagger_type.get_swagger_type(self._json),\n+                self._models,\n+                **kwargs)\n+        return HTTPFuture(self._http_client, request, response_future)\n+\n+\n+def build_models(model_dicts):\n+    return dict(\n+        (name, create_model_type(model_def))\n+        for name, model_def in model_dicts.iteritems())\n+\n+\n+def get_resource_url(base_path, url_base, resource_base_path):\n+    if base_path:\n+        return base_path\n+\n+    if url_base and resource_base_path.startswith('/'):\n+        if is_file_scheme_uri(url_base):\n+            raise AssertionError(\"Can't resolve relative resource urls with a \"\n+                                 \" file:// url, for %s.\" % resource_base_path)\n+        return url_base.rstrip('/') + resource_base_path\n+\n+    return resource_base_path\n \n \n class Resource(object):\n     \"\"\"Swagger resource, described in an API declaration.\n-\n-    :param resource: Resource model\n-    :param http_client: HTTP client API\n-    :param basePath: url path used for api-docs fetch\n     \"\"\"\n \n-    def __init__(self, resource, http_client, base_path):\n-        log.debug(u\"Building resource '%s'\" % resource[u'name'])\n-        self._json = resource\n-        decl = resource['api_declaration']\n-        self._http_client = http_client\n-        self._base_path = base_path\n-        self._set_models()\n-        self._operations = dict(\n-            (oper['nickname'], self._build_operation(decl, api, oper))\n-            for api in decl['apis']\n-            for oper in api['operations'])\n-        for key in self._operations:\n-            setattr(self, key, self._get_operation(key))\n+    def __init__(self, name, operations):\n+        log.debug(u\"Building resource '%s'\" % name)\n+        self._name = name\n+        self._operations = operations\n \n-    def _set_models(self):\n-        \"\"\"Create namedtuple of model types created from 'api_declaration'\n+    @classmethod\n+    def from_api_doc(cls, api_doc, http_client, base_path, url_base=None):\n+        \"\"\"\n+        :param api_doc: api doc which defines this resource","path":"swaggerpy/client.py","position":339,"original_position":339,"commit_id":"181a0b4374bbffd0116a4d3fd7a79e90474306e7","original_commit_id":"181a0b4374bbffd0116a4d3fd7a79e90474306e7","user":{"login":"analogue","id":26757,"avatar_url":"https://avatars.githubusercontent.com/u/26757?v=3","gravatar_id":"","url":"https://api.github.com/users/analogue","html_url":"https://github.com/analogue","followers_url":"https://api.github.com/users/analogue/followers","following_url":"https://api.github.com/users/analogue/following{/other_user}","gists_url":"https://api.github.com/users/analogue/gists{/gist_id}","starred_url":"https://api.github.com/users/analogue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/analogue/subscriptions","organizations_url":"https://api.github.com/users/analogue/orgs","repos_url":"https://api.github.com/users/analogue/repos","events_url":"https://api.github.com/users/analogue/events{/privacy}","received_events_url":"https://api.github.com/users/analogue/received_events","type":"User","site_admin":false},"body":"Expected type would be helpful","created_at":"2015-01-07T00:39:12Z","updated_at":"2015-01-07T00:39:12Z","html_url":"https://github.com/Yelp/swagger-py/pull/86#discussion_r22563922","pull_request_url":"https://api.github.com/repos/Yelp/swagger-py/pulls/86","_links":{"self":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/comments/22563922"},"html":{"href":"https://github.com/Yelp/swagger-py/pull/86#discussion_r22563922"},"pull_request":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/86"}}},"pull_request":{"url":"https://api.github.com/repos/Yelp/swagger-py/pulls/86","id":26618958,"html_url":"https://github.com/Yelp/swagger-py/pull/86","diff_url":"https://github.com/Yelp/swagger-py/pull/86.diff","patch_url":"https://github.com/Yelp/swagger-py/pull/86.patch","issue_url":"https://api.github.com/repos/Yelp/swagger-py/issues/86","number":86,"state":"open","locked":false,"title":"Cleanup swagger client","user":{"login":"dnephin","id":442180,"avatar_url":"https://avatars.githubusercontent.com/u/442180?v=3","gravatar_id":"","url":"https://api.github.com/users/dnephin","html_url":"https://github.com/dnephin","followers_url":"https://api.github.com/users/dnephin/followers","following_url":"https://api.github.com/users/dnephin/following{/other_user}","gists_url":"https://api.github.com/users/dnephin/gists{/gist_id}","starred_url":"https://api.github.com/users/dnephin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnephin/subscriptions","organizations_url":"https://api.github.com/users/dnephin/orgs","repos_url":"https://api.github.com/users/dnephin/repos","events_url":"https://api.github.com/users/dnephin/events{/privacy}","received_events_url":"https://api.github.com/users/dnephin/received_events","type":"User","site_admin":false},"body":"Previously the entire process of fetching the api docs, validating the api docs, and building `Resources`/`Operations` was done as part of the constructor of `SwaggerClient`.  Constructors should never do anything more than assignment to fields.  Complex constructors are difficult to test, and make re-use more difficult. \r\n\r\nThis branch splits the constructor into two factory methods `from_url()`, and `from_resource_listing()`.  This allows consumers to create a `SwaggerClient` from just a list of resources, which also removes the branch logic from the constructor. This is still backwards compatible because the only documented interface is the `get_client()` call. \r\n\r\nSome other things:\r\n* use `simplejson` if it's available (since it's much faster, and this is very slow)\r\n* completely removed the need for `ClientProcessor` (yay less inheritance!). This subclass was only being used for the single method that it implemented. All other operations are already done by default by the `Loader`. That method was extracted to `append_name_to_api()`.\r\n* change the kwarg for the client cache to be `ttl` instead of `timeout` (`timeout` is still supported for backwards compatibility), and some other renames around the cache\r\n* cache clients based on all args + kwargs, not just the first argument. All the arguments change the behaviour of the client, so they all need to be part of the key. Uses `repr()` instead of `json.dumps()`.\r\n* `SwaggerClient` and `Resource` now support `dir()` (and tab completion in ipython) without `setattr` (which was duplicating the `__getattr__`).\r\n\r\n\r\nResolves #80. Remove special case for `datetime` in `stringify_body`. This should be totally unnecessary. The `swagger_model` should already convert this datetime into the proper format.\r\n\r\nResolves #76. Previously `api_base_path` was being used for two different things: overriding the default url that was specified in the swagger api doc, and also as a base url for swagger api docs that use relative urls.  I've split this into two params. `api_base_path` is now only an override, `base_url` is now the base url to append to relatives `basePath` urls.\r\n\r\nResolves #83. `raise_with` is unnecessary, and makes the interface for `swagger-py` more verbose than it needs to be.\r\n\r\n\r\nSorry this is so big. Most of this had to be changed all at once, so I wasn't able to break it into smaller parts. I did pull out a couple isolated commits, and a lot of this is just simple replacement (json imports, and test changes to use the new factories).","created_at":"2014-12-27T22:59:09Z","updated_at":"2015-01-07T00:39:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"66c1c9fda18d041347b22e08aee306cfca4b6c80","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Yelp/swagger-py/pulls/86/commits","review_comments_url":"https://api.github.com/repos/Yelp/swagger-py/pulls/86/comments","review_comment_url":"https://api.github.com/repos/Yelp/swagger-py/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Yelp/swagger-py/issues/86/comments","statuses_url":"https://api.github.com/repos/Yelp/swagger-py/statuses/181a0b4374bbffd0116a4d3fd7a79e90474306e7","head":{"label":"dnephin:cleanup_swagger_client","ref":"cleanup_swagger_client","sha":"181a0b4374bbffd0116a4d3fd7a79e90474306e7","user":{"login":"dnephin","id":442180,"avatar_url":"https://avatars.githubusercontent.com/u/442180?v=3","gravatar_id":"","url":"https://api.github.com/users/dnephin","html_url":"https://github.com/dnephin","followers_url":"https://api.github.com/users/dnephin/followers","following_url":"https://api.github.com/users/dnephin/following{/other_user}","gists_url":"https://api.github.com/users/dnephin/gists{/gist_id}","starred_url":"https://api.github.com/users/dnephin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnephin/subscriptions","organizations_url":"https://api.github.com/users/dnephin/orgs","repos_url":"https://api.github.com/users/dnephin/repos","events_url":"https://api.github.com/users/dnephin/events{/privacy}","received_events_url":"https://api.github.com/users/dnephin/received_events","type":"User","site_admin":false},"repo":{"id":28411944,"name":"swagger-py","full_name":"dnephin/swagger-py","owner":{"login":"dnephin","id":442180,"avatar_url":"https://avatars.githubusercontent.com/u/442180?v=3","gravatar_id":"","url":"https://api.github.com/users/dnephin","html_url":"https://github.com/dnephin","followers_url":"https://api.github.com/users/dnephin/followers","following_url":"https://api.github.com/users/dnephin/following{/other_user}","gists_url":"https://api.github.com/users/dnephin/gists{/gist_id}","starred_url":"https://api.github.com/users/dnephin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dnephin/subscriptions","organizations_url":"https://api.github.com/users/dnephin/orgs","repos_url":"https://api.github.com/users/dnephin/repos","events_url":"https://api.github.com/users/dnephin/events{/privacy}","received_events_url":"https://api.github.com/users/dnephin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dnephin/swagger-py","description":"Generic client library for Python2.6 - adopts SwaggerVersion 1.2","fork":true,"url":"https://api.github.com/repos/dnephin/swagger-py","forks_url":"https://api.github.com/repos/dnephin/swagger-py/forks","keys_url":"https://api.github.com/repos/dnephin/swagger-py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dnephin/swagger-py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dnephin/swagger-py/teams","hooks_url":"https://api.github.com/repos/dnephin/swagger-py/hooks","issue_events_url":"https://api.github.com/repos/dnephin/swagger-py/issues/events{/number}","events_url":"https://api.github.com/repos/dnephin/swagger-py/events","assignees_url":"https://api.github.com/repos/dnephin/swagger-py/assignees{/user}","branches_url":"https://api.github.com/repos/dnephin/swagger-py/branches{/branch}","tags_url":"https://api.github.com/repos/dnephin/swagger-py/tags","blobs_url":"https://api.github.com/repos/dnephin/swagger-py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dnephin/swagger-py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dnephin/swagger-py/git/refs{/sha}","trees_url":"https://api.github.com/repos/dnephin/swagger-py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dnephin/swagger-py/statuses/{sha}","languages_url":"https://api.github.com/repos/dnephin/swagger-py/languages","stargazers_url":"https://api.github.com/repos/dnephin/swagger-py/stargazers","contributors_url":"https://api.github.com/repos/dnephin/swagger-py/contributors","subscribers_url":"https://api.github.com/repos/dnephin/swagger-py/subscribers","subscription_url":"https://api.github.com/repos/dnephin/swagger-py/subscription","commits_url":"https://api.github.com/repos/dnephin/swagger-py/commits{/sha}","git_commits_url":"https://api.github.com/repos/dnephin/swagger-py/git/commits{/sha}","comments_url":"https://api.github.com/repos/dnephin/swagger-py/comments{/number}","issue_comment_url":"https://api.github.com/repos/dnephin/swagger-py/issues/comments/{number}","contents_url":"https://api.github.com/repos/dnephin/swagger-py/contents/{+path}","compare_url":"https://api.github.com/repos/dnephin/swagger-py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dnephin/swagger-py/merges","archive_url":"https://api.github.com/repos/dnephin/swagger-py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dnephin/swagger-py/downloads","issues_url":"https://api.github.com/repos/dnephin/swagger-py/issues{/number}","pulls_url":"https://api.github.com/repos/dnephin/swagger-py/pulls{/number}","milestones_url":"https://api.github.com/repos/dnephin/swagger-py/milestones{/number}","notifications_url":"https://api.github.com/repos/dnephin/swagger-py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dnephin/swagger-py/labels{/name}","releases_url":"https://api.github.com/repos/dnephin/swagger-py/releases{/id}","created_at":"2014-12-23T18:00:38Z","updated_at":"2014-12-27T21:11:20Z","pushed_at":"2015-01-05T16:46:46Z","git_url":"git://github.com/dnephin/swagger-py.git","ssh_url":"git@github.com:dnephin/swagger-py.git","clone_url":"https://github.com/dnephin/swagger-py.git","svn_url":"https://github.com/dnephin/swagger-py","homepage":"","size":691,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Yelp:master","ref":"master","sha":"d92252259906a469ccaaa0eb68f4d771cd461a07","user":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"repo":{"id":20313056,"name":"swagger-py","full_name":"Yelp/swagger-py","owner":{"login":"Yelp","id":49071,"avatar_url":"https://avatars.githubusercontent.com/u/49071?v=3","gravatar_id":"","url":"https://api.github.com/users/Yelp","html_url":"https://github.com/Yelp","followers_url":"https://api.github.com/users/Yelp/followers","following_url":"https://api.github.com/users/Yelp/following{/other_user}","gists_url":"https://api.github.com/users/Yelp/gists{/gist_id}","starred_url":"https://api.github.com/users/Yelp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yelp/subscriptions","organizations_url":"https://api.github.com/users/Yelp/orgs","repos_url":"https://api.github.com/users/Yelp/repos","events_url":"https://api.github.com/users/Yelp/events{/privacy}","received_events_url":"https://api.github.com/users/Yelp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Yelp/swagger-py","description":"Generic client library for Python2.6 - adopts SwaggerVersion 1.2","fork":false,"url":"https://api.github.com/repos/Yelp/swagger-py","forks_url":"https://api.github.com/repos/Yelp/swagger-py/forks","keys_url":"https://api.github.com/repos/Yelp/swagger-py/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Yelp/swagger-py/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Yelp/swagger-py/teams","hooks_url":"https://api.github.com/repos/Yelp/swagger-py/hooks","issue_events_url":"https://api.github.com/repos/Yelp/swagger-py/issues/events{/number}","events_url":"https://api.github.com/repos/Yelp/swagger-py/events","assignees_url":"https://api.github.com/repos/Yelp/swagger-py/assignees{/user}","branches_url":"https://api.github.com/repos/Yelp/swagger-py/branches{/branch}","tags_url":"https://api.github.com/repos/Yelp/swagger-py/tags","blobs_url":"https://api.github.com/repos/Yelp/swagger-py/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Yelp/swagger-py/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Yelp/swagger-py/git/refs{/sha}","trees_url":"https://api.github.com/repos/Yelp/swagger-py/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Yelp/swagger-py/statuses/{sha}","languages_url":"https://api.github.com/repos/Yelp/swagger-py/languages","stargazers_url":"https://api.github.com/repos/Yelp/swagger-py/stargazers","contributors_url":"https://api.github.com/repos/Yelp/swagger-py/contributors","subscribers_url":"https://api.github.com/repos/Yelp/swagger-py/subscribers","subscription_url":"https://api.github.com/repos/Yelp/swagger-py/subscription","commits_url":"https://api.github.com/repos/Yelp/swagger-py/commits{/sha}","git_commits_url":"https://api.github.com/repos/Yelp/swagger-py/git/commits{/sha}","comments_url":"https://api.github.com/repos/Yelp/swagger-py/comments{/number}","issue_comment_url":"https://api.github.com/repos/Yelp/swagger-py/issues/comments/{number}","contents_url":"https://api.github.com/repos/Yelp/swagger-py/contents/{+path}","compare_url":"https://api.github.com/repos/Yelp/swagger-py/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Yelp/swagger-py/merges","archive_url":"https://api.github.com/repos/Yelp/swagger-py/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Yelp/swagger-py/downloads","issues_url":"https://api.github.com/repos/Yelp/swagger-py/issues{/number}","pulls_url":"https://api.github.com/repos/Yelp/swagger-py/pulls{/number}","milestones_url":"https://api.github.com/repos/Yelp/swagger-py/milestones{/number}","notifications_url":"https://api.github.com/repos/Yelp/swagger-py/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Yelp/swagger-py/labels{/name}","releases_url":"https://api.github.com/repos/Yelp/swagger-py/releases{/id}","created_at":"2014-05-30T01:03:02Z","updated_at":"2015-01-05T16:46:43Z","pushed_at":"2015-01-05T16:46:43Z","git_url":"git://github.com/Yelp/swagger-py.git","ssh_url":"git@github.com:Yelp/swagger-py.git","clone_url":"https://github.com/Yelp/swagger-py.git","svn_url":"https://github.com/Yelp/swagger-py","homepage":"","size":1228,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":16,"forks":10,"open_issues":16,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/86"},"html":{"href":"https://github.com/Yelp/swagger-py/pull/86"},"issue":{"href":"https://api.github.com/repos/Yelp/swagger-py/issues/86"},"comments":{"href":"https://api.github.com/repos/Yelp/swagger-py/issues/86/comments"},"review_comments":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/86/comments"},"review_comment":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Yelp/swagger-py/pulls/86/commits"},"statuses":{"href":"https://api.github.com/repos/Yelp/swagger-py/statuses/181a0b4374bbffd0116a4d3fd7a79e90474306e7"}}}}