Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
obostjancic committed Jan 22, 2025
1 parent 5870f3b commit a4276ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/sentry/api/endpoints/email_capture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rest_framework import serializers
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import options
Expand All @@ -11,7 +12,7 @@
client = MarketoClient()


class EmailCaptureSerialier(CamelSnakeSerializer):
class EmailCaptureSerializer(CamelSnakeSerializer):
email = serializers.EmailField(required=True)


Expand All @@ -24,14 +25,13 @@ class EmailCaptureEndpoint(Endpoint):
# Disable authentication and permission requirements.
permission_classes = ()

def post(self, request):
def post(self, request: Request) -> Response:
if not options.get("demo-mode.enabled"):
return Response(status=404)

serializer = EmailCaptureSerialier(data=request.data)
serializer = EmailCaptureSerializer(data=request.data)

if not serializer.is_valid():
return Response(serializer.errors, status=400)
serializer.is_valid(raise_exception=True)

email = serializer.validated_data["email"]

Expand Down
16 changes: 12 additions & 4 deletions src/sentry/utils/marketo_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import TypedDict

from django.conf import settings

from sentry import http
Expand All @@ -7,8 +9,13 @@ def marketo_option(field):
return settings.MARKETO[field]


MarketoErrorResponse = TypedDict(
"DataDict", {"errors": list[TypedDict("ErrorDict", {"code": str, "message": str})]}
)


class MarketoError(Exception):
def __init__(self, data):
def __init__(self, data: MarketoErrorResponse):
# just use the first error
error = data["errors"][0]
self.code = error["code"]
Expand All @@ -22,7 +29,7 @@ class MarketoClient:
OAUTH_URL = "/identity/oauth/token"
SUBMIT_FORM_URL = "/rest/v1/leads/submitForm.json"

def make_request(self, url, *args, **kwargs):
def make_request(self, url: str, *args, method="GET", **kwargs):
base_url = marketo_option("base-url")
full_url = base_url + url
method = kwargs.pop("method", "GET")
Expand All @@ -31,8 +38,9 @@ def make_request(self, url, *args, **kwargs):
resp.raise_for_status()
return resp.json()

def make_rest_request(self, url, *args, **kwargs):
headers = kwargs.pop("headers", {})
def make_rest_request(self, url: str, *args, headers=None, **kwargs):
if headers is None:
headers = {}
headers["Authorization"] = f"Bearer {self.token}"
headers["Content-Type"] = "application/json"
data = self.make_request(url, *args, headers=headers, **kwargs)
Expand Down

0 comments on commit a4276ff

Please sign in to comment.