{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "# Define the API endpoint URL\n",
    "url = \"https://jsonplaceholder.typicode.com/todos/1\"\n",
    "\n",
    "# Define the request parameters (if any)\n",
    "params = {\n",
    "    \"param1\": \"value1\",\n",
    "    \"param2\": \"value2\"\n",
    "}\n",
    "\n",
    "# Define the request headers (if any)\n",
    "headers = {\n",
    "    \"Authorization\": \"Bearer <your_token>\",\n",
    "    \"Content-Type\": \"application/json\"\n",
    "}\n",
    "\n",
    "# Make the API request\n",
    "response = requests.get(url, params=params, headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from requests import Response\n",
    "\n",
    "\n",
    "class InstagramApiResponse:\n",
    "    def __init__(self, response: Response):\n",
    "        self._response = response\n",
    "        self.headers = response.headers\n",
    "        self.url = response.url\n",
    "        self.status_code = response.status_code \n",
    "        self.json = response.json\n",
    "\n",
    "    def __str__(self):\n",
    "        return f\"InstagramApiResponse({self.status_code})\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "r = InstagramApiResponse(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "l = [r.headers, r.url, r.status_code, r.json]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'list' object has no attribute 'first'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m/Users/matthieuthibaut/Documents/InstagramAPI/main.ipynb Cellule 5\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/matthieuthibaut/Documents/InstagramAPI/main.ipynb#W6sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m l\u001b[39m.\u001b[39;49mfirst\n",
      "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'first'"
     ]
    }
   ],
   "source": [
    "l.first"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Date': 'Sun, 11 Feb 2024 11:51:59 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Report-To': '{\"group\":\"heroku-nel\",\"max_age\":3600,\"endpoints\":[{\"url\":\"https://nel.heroku.com/reports?ts=1707652319&sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d&s=k3TH%2BwWy5p%2FwAhWJQoXkdimjWRakblZjiE2zpEoaxwA%3D\"}]}', 'Reporting-Endpoints': 'heroku-nel=https://nel.heroku.com/reports?ts=1707652319&sid=e11707d5-02a7-43ef-b45e-2cf4d2036f7d&s=k3TH%2BwWy5p%2FwAhWJQoXkdimjWRakblZjiE2zpEoaxwA%3D', 'Nel': '{\"report_to\":\"heroku-nel\",\"max_age\":3600,\"success_fraction\":0.005,\"failure_fraction\":0.05,\"response_headers\":[\"Via\"]}', 'X-Powered-By': 'Express', 'X-Ratelimit-Limit': '1000', 'X-Ratelimit-Remaining': '999', 'X-Ratelimit-Reset': '1707652364', 'Vary': 'Origin, Accept-Encoding', 'Access-Control-Allow-Credentials': 'true', 'Cache-Control': 'no-cache', 'Pragma': 'no-cache', 'Expires': '-1', 'X-Content-Type-Options': 'nosniff', 'Etag': 'W/\"53-hfEnumeNh6YirfjyjaujcOPPT+s\"', 'Via': '1.1 vegur', 'CF-Cache-Status': 'BYPASS', 'Server': 'cloudflare', 'CF-RAY': '853c621399eaf164-CDG', 'Content-Encoding': 'gzip', 'alt-svc': 'h3=\":443\"; ma=86400'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.headers"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "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.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
