Skip to content

Commit

Permalink
fixes #233
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Nov 26, 2020
1 parent 09d407b commit 34aed2d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions fastcore/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
"urlvalid": "03_xtras.ipynb",
"urlrequest": "03_xtras.ipynb",
"loads": "03_xtras.ipynb",
"Request.summary": "03_xtras.ipynb",
"urlsend": "03_xtras.ipynb",
"untar_dir": "03_xtras.ipynb",
"repo_details": "03_xtras.ipynb",
Expand Down
12 changes: 10 additions & 2 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,17 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=parse_int, parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)

# Cell
def urlsend(url, verb, headers=None, route=None, query=None, data=None, json_data=True, return_json=True):
@patch
def summary(self:Request)->dict:
"Summary containing full_url, headers, method, and data"
return L('full_url','method','headers','data').map_dict(partial(getattr,self))

# Cell
def urlsend(url, verb, headers=None, route=None, query=None, data=None, json_data=True, return_json=True, debug=None):
"Send request with `urlrequest`, converting result to json if `return_json`"
res = urlread(urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data))
req = urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data)
if debug: debug(req)
res = urlread(req)
return loads(res) if return_json else res

# Cell
Expand Down
44 changes: 41 additions & 3 deletions nbs/03_xtras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
{
"data": {
"text/plain": [
"['c', 'd', 'a', 'f', 'e', 'b', 'g', 'h']"
"['g', 'e', 'f', 'h', 'a', 'c', 'b', 'd']"
]
},
"execution_count": null,
Expand Down Expand Up @@ -1440,9 +1440,47 @@
"outputs": [],
"source": [
"#export\n",
"def urlsend(url, verb, headers=None, route=None, query=None, data=None, json_data=True, return_json=True):\n",
"@patch\n",
"def summary(self:Request)->dict:\n",
" \"Summary containing full_url, headers, method, and data\"\n",
" return L('full_url','method','headers','data').map_dict(partial(getattr,self))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'full_url': 'http://example.com/{foo}/1',\n",
" 'method': 'POST',\n",
" 'headers': {},\n",
" 'data': b'd=5&e=6'}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"req.summary()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#export\n",
"def urlsend(url, verb, headers=None, route=None, query=None, data=None, json_data=True, return_json=True, debug=None):\n",
" \"Send request with `urlrequest`, converting result to json if `return_json`\"\n",
" res = urlread(urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data))\n",
" req = urlrequest(url, verb, headers, route=route, query=query, data=data, json_data=json_data)\n",
" if debug: debug(req)\n",
" res = urlread(req)\n",
" return loads(res) if return_json else res"
]
},
Expand Down

0 comments on commit 34aed2d

Please sign in to comment.