Coverage for functions \ flipdare \ generated \ shared \ app_deep_link.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# 

3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

4# 

5# This file is part of Flipdare's proprietary software and contains 

6# confidential and copyrighted material. Unauthorised copying, 

7# modification, distribution, or use of this file is strictly 

8# prohibited without prior written permission from Flipdare Pty Ltd. 

9# 

10# This software includes third-party components licensed under MIT, 

11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

12# 

13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT. 

14# 

15# Generated by codegen_models.py 

16# 

17# Modify 'codegen_models.py' 

18# and re-run the script above to update. 

19# 

20 

21# pragma: no cover 

22 

23from enum import StrEnum 

24from typing import Any 

25from urllib.parse import quote_plus 

26from flipdare.wrapper.backend.user_summary_entry_wrapper import UserSummaryEntryWrapper 

27from flipdare.constants import DEEP_LINK_BASE 

28 

29 

30class AppDeepLink(StrEnum): 

31 """App Deep Link format.""" 

32 

33 # Declared here so type-checkers know these attributes exist. 

34 # They are populated per-member inside __new__. 

35 _category: str 

36 _is_resource: bool 

37 _params: str 

38 

39 def __new__( 

40 cls, 

41 code: str, 

42 category: str | None = None, 

43 is_resource: bool | None = None, 

44 params: str | None = None, 

45 ) -> "AppDeepLink": 

46 obj = str.__new__(cls, code) 

47 obj._value_ = code 

48 # Only set attributes if they are provided (during member definition) 

49 if category is not None: 

50 obj._category = category 

51 if is_resource is not None: 

52 obj._is_resource = is_resource 

53 if params is not None: 

54 obj._params = params 

55 return obj 

56 

57 # ---- Members -------------------------------------------------------- 

58 # fmt: off 

59 INVITE = ("invite", "invite", False, "invite_id") 

60 DARE = ("dare", "dare", True, "slug_code") 

61 USER = ("user", "user", True, "slug_code") 

62 GROUP = ("group", "group", True, "slug_code") 

63 FLAG = ("flag", "flag", True, "slug_code") 

64 RESTRICTION = ("restriction", "restriction", True, "slug_code") 

65 CHAT = ("chat", "chat", True, "slug_code") 

66 PLEDGE = ("pledge", "pledge", True, "slug_code") 

67 PAYMENT_ISSUE = ("pay_issue", "payment_issue", False, "slug_code") 

68 ISSUE = ("issue", "issue", False, "slug_code") 

69 PAYMENT_WEBHOOK = ("pay_webhook", "payment_webhook", False, "payment_intent_id,status") 

70 # fmt: on 

71 # ---- Properties ----------------------------------------------------- 

72 @property 

73 def category(self) -> str: 

74 return self._category 

75 

76 @property 

77 def is_resource(self) -> bool: 

78 return self._is_resource 

79 

80 @property 

81 def params(self) -> str: 

82 return self._params 

83 

84 # ---- Convenience predicates ----------------------------------------- 

85 

86 @staticmethod 

87 def for_summary(entry: UserSummaryEntryWrapper) -> str | None: 

88 """Get a deep link URL for the given email type, if applicable.""" 

89 if entry.obj_id is None: 

90 return None 

91 

92 obj_id = entry.obj_id 

93 email_type = entry.entry_type 

94 if email_type.is_friend_request: 

95 return AppDeepLink.USER.app_link(obj_id) 

96 if email_type.is_group: 

97 return AppDeepLink.DARE.app_link(obj_id) 

98 if email_type.is_pledge: 

99 return AppDeepLink.PLEDGE.app_link(obj_id) 

100 return None 

101 

102 def app_link(self, *args: Any, **kwargs: Any) -> str: 

103 base_url = f"{DEEP_LINK_BASE}/{quote_plus(self.value)}" 

104 path = self.path(*args, **kwargs) 

105 return f"{base_url}/{path}" 

106 

107 def path(self, *args: Any, **kwargs: Any) -> str: 

108 # we use args for ACTIONS and kwargs for RESOURCES. 

109 required = self.params.split(",") 

110 if self.is_resource: 

111 if len(args) != len(required): 

112 msg = f"Resource link {self} requires {len(required)} positional arguments" 

113 raise ValueError(msg) 

114 

115 return "/".join(quote_plus(str(a)) for a in args) 

116 

117 if len(kwargs) != len(required): 

118 raise ValueError(f"Action link {self} requires {len(required)} keyword arguments") 

119 

120 query_str = "&".join(f"{quote_plus(k)}={quote_plus(str(kwargs[k]))}" for k in required) 

121 return f"?{query_str}"