Skip to content

Commit

Permalink
feat(api): expose affiliate_utm to chat bot
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Feb 14, 2024
1 parent e4a0820 commit 6719739
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 6 additions & 3 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def test_get_active_channels(client, mocker, requests_mock):
assert response.json() == [
{
"channel_login": "foo_bar",
"deck_url": deck_url
"deck_url": deck_url,
"affiliate_utm": None,
}
]

Expand Down Expand Up @@ -440,7 +441,8 @@ def test_get_active_channels_with_cached_deck(client, mocker, requests_mock):
assert response.json() == [
{
"channel_login": "foo_bar",
"deck_url": deck_url
"deck_url": deck_url,
"affiliate_utm": None,
}
]
mock_get_shortid_from_deck_list.assert_not_called()
Expand Down Expand Up @@ -493,7 +495,8 @@ def test_get_active_channels_for_bgs_game(client, mocker, requests_mock):
assert response.json() == [
{
"channel_login": "foo_bar",
"deck_url": None
"deck_url": None,
"affiliate_utm": None,
}
]

Expand Down
1 change: 1 addition & 0 deletions twitch_hdt_ebs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ConfigSerializer(serializers.Serializer):
max_value=50,
)
promote_on_hsreplaynet = serializers.BooleanField(default=True)
affiliate_utm = serializers.CharField(required=False)

def validate_hidden(self, value):
if value == "":
Expand Down
12 changes: 7 additions & 5 deletions twitch_hdt_ebs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ def post(self, request, format=None) -> Response:
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)

config = ConfigSerializer(instance=request.user.settings.get("twitch_ebs", {}))

data = serializer.validated_data["data"]
if serializer.validated_data["type"] == "game_start":
self.cache_deck_data(data, serializer.validated_data["version"])
self.cache_deck_data(data, serializer.validated_data["version"], config)
else:
self.heartbeat_deck_data()

config = ConfigSerializer(instance=request.user.settings.get("twitch_ebs", {}))

pubsub_data = {
"type": serializer.validated_data["type"],
"data": serializer.validated_data["data"],
Expand All @@ -185,7 +185,7 @@ def post(self, request, format=None) -> Response:
}
)

def cache_deck_data(self, data, version: int) -> bool:
def cache_deck_data(self, data, version: int, config: dict) -> bool:
if version < 3:
# Discard old HDT versions
return False
Expand Down Expand Up @@ -213,6 +213,7 @@ def cache_deck_data(self, data, version: int) -> bool:
"legend_rank": data.get("legend_rank", 0),
"game_type": data.get("game_type", 0),
"twitch_user_id": self.request.twitch_user_id,
"affiliate_utm": config.get("affiliate_utm"),
}, timeout=120)

return True
Expand Down Expand Up @@ -443,7 +444,8 @@ def get(self, request):

data.append({
"channel_login": channel_login,
"deck_url": deck_url
"deck_url": deck_url,
"affiliate_utm": details.get("affiliate_utm")
})

return Response(status=200, data=data)
Expand Down

0 comments on commit 6719739

Please sign in to comment.