{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from zapy.requests import ZapyRequest, KeyValueItem\n",
    "from zapy.utils import module\n",
    "if __name__ == '__main__':\n",
    "    setup_store = module.load_module('./setup')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GET: https://echo.hoppscotch.io/ None get: test_1\n",
      "GET: https://echo.hoppscotch.io/ None set: test_2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'method': 'GET',\n",
       " 'args': {'param1': 'setup_store'},\n",
       " 'data': '',\n",
       " 'headers': {'cdn-loop': 'netlify',\n",
       "  'host': 'echo.hoppscotch.io',\n",
       "  'x-country': 'PE',\n",
       "  'x-forwarded-for': '181.67.74.241',\n",
       "  'x-forwarded-proto': 'https',\n",
       "  'x-nf-account-id': '5e2b91527eb7a24fb0054390',\n",
       "  'x-nf-client-connection-ip': '181.67.74.241',\n",
       "  'x-nf-deploy-id': '626b1bc6a7f6c1000902602e',\n",
       "  'x-nf-geo': 'eyJjaXR5IjoiTGltYSIsImNvdW50cnkiOnsiY29kZSI6IlBFIiwibmFtZSI6IlBlcnUifSwic3ViZGl2aXNpb24iOnsiY29kZSI6IkxNQSIsIm5hbWUiOiJMaW1hIn0sInRpbWV6b25lIjoiQW1lcmljYS9MaW1hIiwibGF0aXR1ZGUiOi0xMi4wNDMyLCJsb25naXR1ZGUiOi03Ny4wMjgyfQ==',\n",
       "  'x-nf-request-id': '01H9BAK287N1QXRXTX6RQVPBEB',\n",
       "  'x-nf-site-id': '5d797a9d-fe11-4582-8837-9986a4673158'},\n",
       " 'path': '/',\n",
       " 'isBase64Encoded': True}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "request = ZapyRequest(\n",
    "    endpoint=\"https://echo.hoppscotch.io/\",\n",
    "    method=\"GET\",\n",
    "    params=[\n",
    "        KeyValueItem(key='param1', value='{{ ctx.store.test_1 }}', active=True),\n",
    "    ],\n",
    "    script=[\n",
    "        '@ctx.hooks.post_request',\n",
    "        'async def on_post_script(response):',\n",
    "        '   ctx.store.test_2 = \"request 1 completed\"'\n",
    "    ],\n",
    ")\n",
    "response = await request.send()\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GET: https://echo.hoppscotch.io/ None get: test_2\n"
     ]
    },
    {
     "ename": "AssertionError",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 10\u001b[0m\n\u001b[1;32m      8\u001b[0m response \u001b[39m=\u001b[39m \u001b[39mawait\u001b[39;00m request\u001b[39m.\u001b[39msend()\n\u001b[1;32m      9\u001b[0m response\u001b[39m.\u001b[39mjson()\n\u001b[0;32m---> 10\u001b[0m \u001b[39massert\u001b[39;00m \u001b[39m1\u001b[39m \u001b[39m==\u001b[39m \u001b[39m2\u001b[39m\n",
      "\u001b[0;31mAssertionError\u001b[0m: "
     ]
    }
   ],
   "source": [
    "request = ZapyRequest(\n",
    "    endpoint=\"https://echo.hoppscotch.io/\",\n",
    "    method=\"GET\",\n",
    "    params=[\n",
    "        KeyValueItem(key='param1', value='{{ ctx.store.test_2 }}', active=True),\n",
    "    ],\n",
    ")\n",
    "response = await request.send()\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "out_response = response.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_kernel",
   "language": "python",
   "name": "my_kernel"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
