add the NASA Sentry api call to the backend

This commit is contained in:
Jordan Yamada
2024-05-19 05:05:55 +00:00
parent 0de0b25fab
commit 94e3f37f70
21 changed files with 92 additions and 13 deletions

View File

@@ -1,8 +1,7 @@
from django.urls import path
from .views import (
Sentry,
OpenAI,
)
from .views import Sentry, OpenAI
urlpatterns = [
path('sentry/', Sentry.as_view(), name='sentry'),

View File

@@ -0,0 +1,23 @@
from django.core.exceptions import ValidationError
import os
import requests
from rest_framework.response import Response
from rest_framework.status import (
HTTP_200_OK,
HTTP_204_NO_CONTENT,
HTTP_201_CREATED,
HTTP_400_BAD_REQUEST
)
sentry_api_key = os.environ.get("SENTRY_API_KEY")
def get_sentry():
try:
response = requests.get(f'https://api.nasa.gov/neo/rest/v1/neo/browse?api_key={sentry_api_key}')
response.raise_for_status()
data = response.json()
return Response(data, status=HTTP_200_OK)
except ValidationError as e:
print(e)
return Response(e, status=HTTP_400_BAD_REQUEST)

View File

@@ -1,8 +1,26 @@
from django.shortcuts import render
from django.core.exceptions import ValidationError
import os
import requests
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.status import (
HTTP_200_OK,
HTTP_204_NO_CONTENT,
HTTP_201_CREATED,
HTTP_400_BAD_REQUEST
)
from .utils import get_sentry
sentry_api_key = os.environ.get("SENTRY_API_KEY")
# Create your views here.
class Sentry:
pass
class Sentry(APIView):
def get(self, request):
return get_sentry()
class OpenAI:
class OpenAI(APIView):
pass