Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Issue #1:
Browse files Browse the repository at this point in the history
- turn API function into class
- raise error
- requests are did by internal method
  • Loading branch information
RickBarretto committed May 21, 2022
1 parent 9238079 commit bccf491
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/core/fetch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@
from src.core.utils.exceptions import PackageNotFound


def fetch_api(osv_model: OsvModel) -> dict:
"""Fetch the OSV API and return a Json"""
import requests


class OsvApi:
"""Deal with OsvApi to get package Vulnerabilities
usage:
>>> django_pkg = OsvModel("Django", "3.0")
>>> response = OsvApi(django_pkg).fetch()
{...}
"""

def __init__(self, osv_parameters: OsvModel):

# Attributes
self.api_parameters = osv_parameters.get_data()

def fetch(self):
json: dict = self.__request()
if json:
return json
else:
raise PackageNotFound

def __request(self) -> dict:
"""Fetch the OSV API and return a Json"""

osv_link = "https://api.osv.dev/v1/query"

Expand Down

0 comments on commit bccf491

Please sign in to comment.