growsurf-python 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. growsurf/__init__.py +102 -0
  2. growsurf/_base_client.py +2153 -0
  3. growsurf/_client.py +484 -0
  4. growsurf/_compat.py +226 -0
  5. growsurf/_constants.py +14 -0
  6. growsurf/_exceptions.py +108 -0
  7. growsurf/_files.py +173 -0
  8. growsurf/_models.py +878 -0
  9. growsurf/_qs.py +149 -0
  10. growsurf/_resource.py +43 -0
  11. growsurf/_response.py +833 -0
  12. growsurf/_streaming.py +338 -0
  13. growsurf/_types.py +274 -0
  14. growsurf/_utils/__init__.py +64 -0
  15. growsurf/_utils/_compat.py +45 -0
  16. growsurf/_utils/_datetime_parse.py +136 -0
  17. growsurf/_utils/_json.py +35 -0
  18. growsurf/_utils/_logs.py +25 -0
  19. growsurf/_utils/_path.py +127 -0
  20. growsurf/_utils/_proxy.py +65 -0
  21. growsurf/_utils/_reflection.py +42 -0
  22. growsurf/_utils/_resources_proxy.py +24 -0
  23. growsurf/_utils/_streams.py +12 -0
  24. growsurf/_utils/_sync.py +58 -0
  25. growsurf/_utils/_transform.py +457 -0
  26. growsurf/_utils/_typing.py +156 -0
  27. growsurf/_utils/_utils.py +433 -0
  28. growsurf/_version.py +4 -0
  29. growsurf/lib/.keep +4 -0
  30. growsurf/py.typed +0 -0
  31. growsurf/resources/__init__.py +19 -0
  32. growsurf/resources/campaign/__init__.py +61 -0
  33. growsurf/resources/campaign/campaign.py +1126 -0
  34. growsurf/resources/campaign/commission.py +259 -0
  35. growsurf/resources/campaign/participant.py +1587 -0
  36. growsurf/resources/campaign/reward.py +355 -0
  37. growsurf/types/__init__.py +18 -0
  38. growsurf/types/campaign/__init__.py +35 -0
  39. growsurf/types/campaign/campaign.py +73 -0
  40. growsurf/types/campaign/commission_approve_response.py +9 -0
  41. growsurf/types/campaign/commission_delete_response.py +9 -0
  42. growsurf/types/campaign/fraud_risk_level.py +7 -0
  43. growsurf/types/campaign/participant.py +147 -0
  44. growsurf/types/campaign/participant_add_params.py +30 -0
  45. growsurf/types/campaign/participant_delete_response.py +9 -0
  46. growsurf/types/campaign/participant_list_commissions_params.py +22 -0
  47. growsurf/types/campaign/participant_list_payouts_params.py +22 -0
  48. growsurf/types/campaign/participant_list_referrals_params.py +43 -0
  49. growsurf/types/campaign/participant_list_rewards_params.py +19 -0
  50. growsurf/types/campaign/participant_list_rewards_response.py +18 -0
  51. growsurf/types/campaign/participant_record_transaction_params.py +60 -0
  52. growsurf/types/campaign/participant_record_transaction_response.py +37 -0
  53. growsurf/types/campaign/participant_reward.py +39 -0
  54. growsurf/types/campaign/participant_send_invites_params.py +20 -0
  55. growsurf/types/campaign/participant_send_invites_response.py +15 -0
  56. growsurf/types/campaign/participant_trigger_referral_response.py +13 -0
  57. growsurf/types/campaign/participant_update_params.py +34 -0
  58. growsurf/types/campaign/referral_source.py +7 -0
  59. growsurf/types/campaign/referral_status.py +7 -0
  60. growsurf/types/campaign/reward_approve_params.py +14 -0
  61. growsurf/types/campaign/reward_approve_response.py +9 -0
  62. growsurf/types/campaign/reward_delete_response.py +9 -0
  63. growsurf/types/campaign/reward_fulfill_response.py +9 -0
  64. growsurf/types/campaign_list_commissions_params.py +20 -0
  65. growsurf/types/campaign_list_leaderboard_params.py +36 -0
  66. growsurf/types/campaign_list_participants_params.py +17 -0
  67. growsurf/types/campaign_list_payouts_params.py +20 -0
  68. growsurf/types/campaign_list_referrals_params.py +41 -0
  69. growsurf/types/campaign_list_response.py +12 -0
  70. growsurf/types/campaign_retrieve_analytics_params.py +26 -0
  71. growsurf/types/campaign_retrieve_analytics_response.py +75 -0
  72. growsurf/types/commission_structure.py +62 -0
  73. growsurf/types/participant_commission_list.py +62 -0
  74. growsurf/types/participant_list.py +18 -0
  75. growsurf/types/participant_payout_list.py +50 -0
  76. growsurf/types/referral_list.py +40 -0
  77. growsurf_python-0.0.2.dist-info/METADATA +399 -0
  78. growsurf_python-0.0.2.dist-info/RECORD +80 -0
  79. growsurf_python-0.0.2.dist-info/WHEEL +4 -0
  80. growsurf_python-0.0.2.dist-info/licenses/LICENSE +201 -0
growsurf/_constants.py ADDED
@@ -0,0 +1,14 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import httpx
4
+
5
+ RAW_RESPONSE_HEADER = "X-Stainless-Raw-Response"
6
+ OVERRIDE_CAST_TO_HEADER = "____stainless_override_cast_to"
7
+
8
+ # default timeout is 1 minute
9
+ DEFAULT_TIMEOUT = httpx.Timeout(timeout=60, connect=5.0)
10
+ DEFAULT_MAX_RETRIES = 2
11
+ DEFAULT_CONNECTION_LIMITS = httpx.Limits(max_connections=100, max_keepalive_connections=20)
12
+
13
+ INITIAL_RETRY_DELAY = 0.5
14
+ MAX_RETRY_DELAY = 8.0
@@ -0,0 +1,108 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Literal
6
+
7
+ import httpx
8
+
9
+ __all__ = [
10
+ "BadRequestError",
11
+ "AuthenticationError",
12
+ "PermissionDeniedError",
13
+ "NotFoundError",
14
+ "ConflictError",
15
+ "UnprocessableEntityError",
16
+ "RateLimitError",
17
+ "InternalServerError",
18
+ ]
19
+
20
+
21
+ class GrowsurfError(Exception):
22
+ pass
23
+
24
+
25
+ class APIError(GrowsurfError):
26
+ message: str
27
+ request: httpx.Request
28
+
29
+ body: object | None
30
+ """The API response body.
31
+
32
+ If the API responded with a valid JSON structure then this property will be the
33
+ decoded result.
34
+
35
+ If it isn't a valid JSON structure then this will be the raw response.
36
+
37
+ If there was no response associated with this error then it will be `None`.
38
+ """
39
+
40
+ def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None: # noqa: ARG002
41
+ super().__init__(message)
42
+ self.request = request
43
+ self.message = message
44
+ self.body = body
45
+
46
+
47
+ class APIResponseValidationError(APIError):
48
+ response: httpx.Response
49
+ status_code: int
50
+
51
+ def __init__(self, response: httpx.Response, body: object | None, *, message: str | None = None) -> None:
52
+ super().__init__(message or "Data returned by API invalid for expected schema.", response.request, body=body)
53
+ self.response = response
54
+ self.status_code = response.status_code
55
+
56
+
57
+ class APIStatusError(APIError):
58
+ """Raised when an API response has a status code of 4xx or 5xx."""
59
+
60
+ response: httpx.Response
61
+ status_code: int
62
+
63
+ def __init__(self, message: str, *, response: httpx.Response, body: object | None) -> None:
64
+ super().__init__(message, response.request, body=body)
65
+ self.response = response
66
+ self.status_code = response.status_code
67
+
68
+
69
+ class APIConnectionError(APIError):
70
+ def __init__(self, *, message: str = "Connection error.", request: httpx.Request) -> None:
71
+ super().__init__(message, request, body=None)
72
+
73
+
74
+ class APITimeoutError(APIConnectionError):
75
+ def __init__(self, request: httpx.Request) -> None:
76
+ super().__init__(message="Request timed out.", request=request)
77
+
78
+
79
+ class BadRequestError(APIStatusError):
80
+ status_code: Literal[400] = 400 # pyright: ignore[reportIncompatibleVariableOverride]
81
+
82
+
83
+ class AuthenticationError(APIStatusError):
84
+ status_code: Literal[401] = 401 # pyright: ignore[reportIncompatibleVariableOverride]
85
+
86
+
87
+ class PermissionDeniedError(APIStatusError):
88
+ status_code: Literal[403] = 403 # pyright: ignore[reportIncompatibleVariableOverride]
89
+
90
+
91
+ class NotFoundError(APIStatusError):
92
+ status_code: Literal[404] = 404 # pyright: ignore[reportIncompatibleVariableOverride]
93
+
94
+
95
+ class ConflictError(APIStatusError):
96
+ status_code: Literal[409] = 409 # pyright: ignore[reportIncompatibleVariableOverride]
97
+
98
+
99
+ class UnprocessableEntityError(APIStatusError):
100
+ status_code: Literal[422] = 422 # pyright: ignore[reportIncompatibleVariableOverride]
101
+
102
+
103
+ class RateLimitError(APIStatusError):
104
+ status_code: Literal[429] = 429 # pyright: ignore[reportIncompatibleVariableOverride]
105
+
106
+
107
+ class InternalServerError(APIStatusError):
108
+ pass
growsurf/_files.py ADDED
@@ -0,0 +1,173 @@
1
+ from __future__ import annotations
2
+
3
+ import io
4
+ import os
5
+ import pathlib
6
+ from typing import Sequence, cast, overload
7
+ from typing_extensions import TypeVar, TypeGuard
8
+
9
+ import anyio
10
+
11
+ from ._types import (
12
+ FileTypes,
13
+ FileContent,
14
+ RequestFiles,
15
+ HttpxFileTypes,
16
+ Base64FileInput,
17
+ HttpxFileContent,
18
+ HttpxRequestFiles,
19
+ )
20
+ from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t
21
+
22
+ _T = TypeVar("_T")
23
+
24
+
25
+ def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
26
+ return isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
27
+
28
+
29
+ def is_file_content(obj: object) -> TypeGuard[FileContent]:
30
+ return (
31
+ isinstance(obj, bytes) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
32
+ )
33
+
34
+
35
+ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
36
+ if not is_file_content(obj):
37
+ prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
38
+ raise RuntimeError(
39
+ f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
40
+ ) from None
41
+
42
+
43
+ @overload
44
+ def to_httpx_files(files: None) -> None: ...
45
+
46
+
47
+ @overload
48
+ def to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...
49
+
50
+
51
+ def to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
52
+ if files is None:
53
+ return None
54
+
55
+ if is_mapping_t(files):
56
+ files = {key: _transform_file(file) for key, file in files.items()}
57
+ elif is_sequence_t(files):
58
+ files = [(key, _transform_file(file)) for key, file in files]
59
+ else:
60
+ raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")
61
+
62
+ return files
63
+
64
+
65
+ def _transform_file(file: FileTypes) -> HttpxFileTypes:
66
+ if is_file_content(file):
67
+ if isinstance(file, os.PathLike):
68
+ path = pathlib.Path(file)
69
+ return (path.name, path.read_bytes())
70
+
71
+ return file
72
+
73
+ if is_tuple_t(file):
74
+ return (file[0], read_file_content(file[1]), *file[2:])
75
+
76
+ raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
77
+
78
+
79
+ def read_file_content(file: FileContent) -> HttpxFileContent:
80
+ if isinstance(file, os.PathLike):
81
+ return pathlib.Path(file).read_bytes()
82
+ return file
83
+
84
+
85
+ @overload
86
+ async def async_to_httpx_files(files: None) -> None: ...
87
+
88
+
89
+ @overload
90
+ async def async_to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...
91
+
92
+
93
+ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
94
+ if files is None:
95
+ return None
96
+
97
+ if is_mapping_t(files):
98
+ files = {key: await _async_transform_file(file) for key, file in files.items()}
99
+ elif is_sequence_t(files):
100
+ files = [(key, await _async_transform_file(file)) for key, file in files]
101
+ else:
102
+ raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence")
103
+
104
+ return files
105
+
106
+
107
+ async def _async_transform_file(file: FileTypes) -> HttpxFileTypes:
108
+ if is_file_content(file):
109
+ if isinstance(file, os.PathLike):
110
+ path = anyio.Path(file)
111
+ return (path.name, await path.read_bytes())
112
+
113
+ return file
114
+
115
+ if is_tuple_t(file):
116
+ return (file[0], await async_read_file_content(file[1]), *file[2:])
117
+
118
+ raise TypeError(f"Expected file types input to be a FileContent type or to be a tuple")
119
+
120
+
121
+ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
122
+ if isinstance(file, os.PathLike):
123
+ return await anyio.Path(file).read_bytes()
124
+
125
+ return file
126
+
127
+
128
+ def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
129
+ """Copy only the containers along the given paths.
130
+
131
+ Used to guard against mutation by extract_files without copying the entire structure.
132
+ Only dicts and lists that lie on a path are copied; everything else
133
+ is returned by reference.
134
+
135
+ For example, given paths=[["foo", "files", "file"]] and the structure:
136
+ {
137
+ "foo": {
138
+ "bar": {"baz": {}},
139
+ "files": {"file": <content>}
140
+ }
141
+ }
142
+ The root dict, "foo", and "files" are copied (they lie on the path).
143
+ "bar" and "baz" are returned by reference (off the path).
144
+ """
145
+ return _deepcopy_with_paths(item, paths, 0)
146
+
147
+
148
+ def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
149
+ if not paths:
150
+ return item
151
+ if is_mapping(item):
152
+ key_to_paths: dict[str, list[Sequence[str]]] = {}
153
+ for path in paths:
154
+ if index < len(path):
155
+ key_to_paths.setdefault(path[index], []).append(path)
156
+
157
+ # if no path continues through this mapping, it won't be mutated and copying it is redundant
158
+ if not key_to_paths:
159
+ return item
160
+
161
+ result = dict(item)
162
+ for key, subpaths in key_to_paths.items():
163
+ if key in result:
164
+ result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
165
+ return cast(_T, result)
166
+ if is_list(item):
167
+ array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]
168
+
169
+ # if no path expects a list here, nothing will be mutated inside it - return by reference
170
+ if not array_paths:
171
+ return cast(_T, item)
172
+ return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
173
+ return item