agentref 1.0.0__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.
- agentref/__init__.py +24 -0
- agentref/_http.py +252 -0
- agentref/client.py +83 -0
- agentref/errors.py +62 -0
- agentref/resources/__init__.py +24 -0
- agentref/resources/affiliates.py +122 -0
- agentref/resources/billing.py +66 -0
- agentref/resources/conversions.py +124 -0
- agentref/resources/flags.py +132 -0
- agentref/resources/merchant.py +34 -0
- agentref/resources/payouts.py +150 -0
- agentref/resources/programs.py +320 -0
- agentref/types/__init__.py +39 -0
- agentref/types/models.py +210 -0
- agentref-1.0.0.dist-info/METADATA +101 -0
- agentref-1.0.0.dist-info/RECORD +17 -0
- agentref-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, AsyncGenerator, Dict, Generator, List, Literal, Optional
|
|
4
|
+
|
|
5
|
+
from .._http import AsyncHttpClient, SyncHttpClient
|
|
6
|
+
from ..types.models import Affiliate, Coupon, Invite, PaginatedResponse, Program
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ProgramsResource:
|
|
10
|
+
def __init__(self, http: SyncHttpClient) -> None:
|
|
11
|
+
self._http = http
|
|
12
|
+
|
|
13
|
+
def list(
|
|
14
|
+
self,
|
|
15
|
+
*,
|
|
16
|
+
cursor: Optional[str] = None,
|
|
17
|
+
limit: Optional[int] = None,
|
|
18
|
+
page: Optional[int] = None,
|
|
19
|
+
page_size: Optional[int] = None,
|
|
20
|
+
offset: Optional[int] = None,
|
|
21
|
+
) -> PaginatedResponse[Program]:
|
|
22
|
+
envelope = self._http.request(
|
|
23
|
+
"GET",
|
|
24
|
+
"/programs",
|
|
25
|
+
params={"cursor": cursor, "limit": limit, "page": page, "pageSize": page_size, "offset": offset},
|
|
26
|
+
)
|
|
27
|
+
return PaginatedResponse[Program].model_validate(envelope)
|
|
28
|
+
|
|
29
|
+
def list_all(self, *, page_size: int = 100) -> Generator[Program, None, None]:
|
|
30
|
+
page = 1
|
|
31
|
+
while True:
|
|
32
|
+
result = self.list(limit=page_size, page=page)
|
|
33
|
+
for item in result.data:
|
|
34
|
+
yield item
|
|
35
|
+
if not result.meta.has_more:
|
|
36
|
+
break
|
|
37
|
+
page += 1
|
|
38
|
+
|
|
39
|
+
def get(self, id: str) -> Program:
|
|
40
|
+
envelope = self._http.request("GET", f"/programs/{id}")
|
|
41
|
+
return Program.model_validate(envelope["data"])
|
|
42
|
+
|
|
43
|
+
def create(
|
|
44
|
+
self,
|
|
45
|
+
*,
|
|
46
|
+
name: str,
|
|
47
|
+
commission_type: Literal["one_time", "recurring", "recurring_limited"],
|
|
48
|
+
commission_percent: float,
|
|
49
|
+
cookie_duration: Optional[int] = None,
|
|
50
|
+
payout_threshold: Optional[int] = None,
|
|
51
|
+
auto_approve_affiliates: Optional[bool] = None,
|
|
52
|
+
description: Optional[str] = None,
|
|
53
|
+
landing_page_url: Optional[str] = None,
|
|
54
|
+
commission_limit_months: Optional[int] = None,
|
|
55
|
+
idempotency_key: Optional[str] = None,
|
|
56
|
+
) -> Program:
|
|
57
|
+
body: Dict[str, Any] = {
|
|
58
|
+
"name": name,
|
|
59
|
+
"commissionType": commission_type,
|
|
60
|
+
"commissionPercent": commission_percent,
|
|
61
|
+
"cookieDuration": cookie_duration,
|
|
62
|
+
"payoutThreshold": payout_threshold,
|
|
63
|
+
"autoApproveAffiliates": auto_approve_affiliates,
|
|
64
|
+
"description": description,
|
|
65
|
+
"landingPageUrl": landing_page_url,
|
|
66
|
+
"commissionLimitMonths": commission_limit_months,
|
|
67
|
+
}
|
|
68
|
+
envelope = self._http.request(
|
|
69
|
+
"POST",
|
|
70
|
+
"/programs",
|
|
71
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
72
|
+
idempotency_key=idempotency_key,
|
|
73
|
+
)
|
|
74
|
+
return Program.model_validate(envelope["data"])
|
|
75
|
+
|
|
76
|
+
def update(self, id: str, **data: Any) -> Program:
|
|
77
|
+
envelope = self._http.request("PATCH", f"/programs/{id}", json=data)
|
|
78
|
+
return Program.model_validate(envelope["data"])
|
|
79
|
+
|
|
80
|
+
def delete(self, id: str) -> Program:
|
|
81
|
+
envelope = self._http.request("DELETE", f"/programs/{id}")
|
|
82
|
+
return Program.model_validate(envelope["data"])
|
|
83
|
+
|
|
84
|
+
def stats(self, id: str, *, period: Optional[str] = None) -> Dict[str, Any]:
|
|
85
|
+
envelope = self._http.request("GET", f"/programs/{id}/stats", params={"period": period})
|
|
86
|
+
data = envelope.get("data", {})
|
|
87
|
+
return data if isinstance(data, dict) else {}
|
|
88
|
+
|
|
89
|
+
def list_affiliates(
|
|
90
|
+
self,
|
|
91
|
+
id: str,
|
|
92
|
+
*,
|
|
93
|
+
include_blocked: Optional[bool] = None,
|
|
94
|
+
cursor: Optional[str] = None,
|
|
95
|
+
limit: Optional[int] = None,
|
|
96
|
+
page: Optional[int] = None,
|
|
97
|
+
page_size: Optional[int] = None,
|
|
98
|
+
offset: Optional[int] = None,
|
|
99
|
+
) -> PaginatedResponse[Affiliate]:
|
|
100
|
+
envelope = self._http.request(
|
|
101
|
+
"GET",
|
|
102
|
+
f"/programs/{id}/affiliates",
|
|
103
|
+
params={
|
|
104
|
+
"includeBlocked": include_blocked,
|
|
105
|
+
"cursor": cursor,
|
|
106
|
+
"limit": limit,
|
|
107
|
+
"page": page,
|
|
108
|
+
"pageSize": page_size,
|
|
109
|
+
"offset": offset,
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
return PaginatedResponse[Affiliate].model_validate(envelope)
|
|
113
|
+
|
|
114
|
+
def list_coupons(self, id: str) -> List[Coupon]:
|
|
115
|
+
envelope = self._http.request("GET", f"/programs/{id}/coupons")
|
|
116
|
+
raw = envelope.get("data", [])
|
|
117
|
+
if not isinstance(raw, list):
|
|
118
|
+
return []
|
|
119
|
+
return [Coupon.model_validate(item) for item in raw]
|
|
120
|
+
|
|
121
|
+
def create_coupon(
|
|
122
|
+
self,
|
|
123
|
+
id: str,
|
|
124
|
+
*,
|
|
125
|
+
affiliate_id: str,
|
|
126
|
+
code: str,
|
|
127
|
+
expires_at: Optional[str] = None,
|
|
128
|
+
idempotency_key: Optional[str] = None,
|
|
129
|
+
) -> Coupon:
|
|
130
|
+
body = {"affiliateId": affiliate_id, "code": code, "expiresAt": expires_at}
|
|
131
|
+
envelope = self._http.request(
|
|
132
|
+
"POST",
|
|
133
|
+
f"/programs/{id}/coupons",
|
|
134
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
135
|
+
idempotency_key=idempotency_key,
|
|
136
|
+
)
|
|
137
|
+
return Coupon.model_validate(envelope["data"])
|
|
138
|
+
|
|
139
|
+
def create_invite(
|
|
140
|
+
self,
|
|
141
|
+
id: str,
|
|
142
|
+
*,
|
|
143
|
+
email: Optional[str] = None,
|
|
144
|
+
name: Optional[str] = None,
|
|
145
|
+
is_public: Optional[bool] = None,
|
|
146
|
+
usage_limit: Optional[int] = None,
|
|
147
|
+
expires_in_days: Optional[int] = None,
|
|
148
|
+
idempotency_key: Optional[str] = None,
|
|
149
|
+
) -> Invite:
|
|
150
|
+
body = {
|
|
151
|
+
"email": email,
|
|
152
|
+
"name": name,
|
|
153
|
+
"isPublic": is_public,
|
|
154
|
+
"usageLimit": usage_limit,
|
|
155
|
+
"expiresInDays": expires_in_days,
|
|
156
|
+
}
|
|
157
|
+
envelope = self._http.request(
|
|
158
|
+
"POST",
|
|
159
|
+
f"/programs/{id}/invites",
|
|
160
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
161
|
+
idempotency_key=idempotency_key,
|
|
162
|
+
)
|
|
163
|
+
return Invite.model_validate(envelope["data"])
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class AsyncProgramsResource:
|
|
167
|
+
def __init__(self, http: AsyncHttpClient) -> None:
|
|
168
|
+
self._http = http
|
|
169
|
+
|
|
170
|
+
async def list(
|
|
171
|
+
self,
|
|
172
|
+
*,
|
|
173
|
+
cursor: Optional[str] = None,
|
|
174
|
+
limit: Optional[int] = None,
|
|
175
|
+
page: Optional[int] = None,
|
|
176
|
+
page_size: Optional[int] = None,
|
|
177
|
+
offset: Optional[int] = None,
|
|
178
|
+
) -> PaginatedResponse[Program]:
|
|
179
|
+
envelope = await self._http.request(
|
|
180
|
+
"GET",
|
|
181
|
+
"/programs",
|
|
182
|
+
params={"cursor": cursor, "limit": limit, "page": page, "pageSize": page_size, "offset": offset},
|
|
183
|
+
)
|
|
184
|
+
return PaginatedResponse[Program].model_validate(envelope)
|
|
185
|
+
|
|
186
|
+
async def list_all(self, *, page_size: int = 100) -> AsyncGenerator[Program, None]:
|
|
187
|
+
page = 1
|
|
188
|
+
while True:
|
|
189
|
+
result = await self.list(limit=page_size, page=page)
|
|
190
|
+
for item in result.data:
|
|
191
|
+
yield item
|
|
192
|
+
if not result.meta.has_more:
|
|
193
|
+
break
|
|
194
|
+
page += 1
|
|
195
|
+
|
|
196
|
+
async def get(self, id: str) -> Program:
|
|
197
|
+
envelope = await self._http.request("GET", f"/programs/{id}")
|
|
198
|
+
return Program.model_validate(envelope["data"])
|
|
199
|
+
|
|
200
|
+
async def create(
|
|
201
|
+
self,
|
|
202
|
+
*,
|
|
203
|
+
name: str,
|
|
204
|
+
commission_type: Literal["one_time", "recurring", "recurring_limited"],
|
|
205
|
+
commission_percent: float,
|
|
206
|
+
cookie_duration: Optional[int] = None,
|
|
207
|
+
payout_threshold: Optional[int] = None,
|
|
208
|
+
auto_approve_affiliates: Optional[bool] = None,
|
|
209
|
+
description: Optional[str] = None,
|
|
210
|
+
landing_page_url: Optional[str] = None,
|
|
211
|
+
commission_limit_months: Optional[int] = None,
|
|
212
|
+
idempotency_key: Optional[str] = None,
|
|
213
|
+
) -> Program:
|
|
214
|
+
body: Dict[str, Any] = {
|
|
215
|
+
"name": name,
|
|
216
|
+
"commissionType": commission_type,
|
|
217
|
+
"commissionPercent": commission_percent,
|
|
218
|
+
"cookieDuration": cookie_duration,
|
|
219
|
+
"payoutThreshold": payout_threshold,
|
|
220
|
+
"autoApproveAffiliates": auto_approve_affiliates,
|
|
221
|
+
"description": description,
|
|
222
|
+
"landingPageUrl": landing_page_url,
|
|
223
|
+
"commissionLimitMonths": commission_limit_months,
|
|
224
|
+
}
|
|
225
|
+
envelope = await self._http.request(
|
|
226
|
+
"POST",
|
|
227
|
+
"/programs",
|
|
228
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
229
|
+
idempotency_key=idempotency_key,
|
|
230
|
+
)
|
|
231
|
+
return Program.model_validate(envelope["data"])
|
|
232
|
+
|
|
233
|
+
async def update(self, id: str, **data: Any) -> Program:
|
|
234
|
+
envelope = await self._http.request("PATCH", f"/programs/{id}", json=data)
|
|
235
|
+
return Program.model_validate(envelope["data"])
|
|
236
|
+
|
|
237
|
+
async def delete(self, id: str) -> Program:
|
|
238
|
+
envelope = await self._http.request("DELETE", f"/programs/{id}")
|
|
239
|
+
return Program.model_validate(envelope["data"])
|
|
240
|
+
|
|
241
|
+
async def stats(self, id: str, *, period: Optional[str] = None) -> Dict[str, Any]:
|
|
242
|
+
envelope = await self._http.request("GET", f"/programs/{id}/stats", params={"period": period})
|
|
243
|
+
data = envelope.get("data", {})
|
|
244
|
+
return data if isinstance(data, dict) else {}
|
|
245
|
+
|
|
246
|
+
async def list_affiliates(
|
|
247
|
+
self,
|
|
248
|
+
id: str,
|
|
249
|
+
*,
|
|
250
|
+
include_blocked: Optional[bool] = None,
|
|
251
|
+
cursor: Optional[str] = None,
|
|
252
|
+
limit: Optional[int] = None,
|
|
253
|
+
page: Optional[int] = None,
|
|
254
|
+
page_size: Optional[int] = None,
|
|
255
|
+
offset: Optional[int] = None,
|
|
256
|
+
) -> PaginatedResponse[Affiliate]:
|
|
257
|
+
envelope = await self._http.request(
|
|
258
|
+
"GET",
|
|
259
|
+
f"/programs/{id}/affiliates",
|
|
260
|
+
params={
|
|
261
|
+
"includeBlocked": include_blocked,
|
|
262
|
+
"cursor": cursor,
|
|
263
|
+
"limit": limit,
|
|
264
|
+
"page": page,
|
|
265
|
+
"pageSize": page_size,
|
|
266
|
+
"offset": offset,
|
|
267
|
+
},
|
|
268
|
+
)
|
|
269
|
+
return PaginatedResponse[Affiliate].model_validate(envelope)
|
|
270
|
+
|
|
271
|
+
async def list_coupons(self, id: str) -> List[Coupon]:
|
|
272
|
+
envelope = await self._http.request("GET", f"/programs/{id}/coupons")
|
|
273
|
+
raw = envelope.get("data", [])
|
|
274
|
+
if not isinstance(raw, list):
|
|
275
|
+
return []
|
|
276
|
+
return [Coupon.model_validate(item) for item in raw]
|
|
277
|
+
|
|
278
|
+
async def create_coupon(
|
|
279
|
+
self,
|
|
280
|
+
id: str,
|
|
281
|
+
*,
|
|
282
|
+
affiliate_id: str,
|
|
283
|
+
code: str,
|
|
284
|
+
expires_at: Optional[str] = None,
|
|
285
|
+
idempotency_key: Optional[str] = None,
|
|
286
|
+
) -> Coupon:
|
|
287
|
+
body = {"affiliateId": affiliate_id, "code": code, "expiresAt": expires_at}
|
|
288
|
+
envelope = await self._http.request(
|
|
289
|
+
"POST",
|
|
290
|
+
f"/programs/{id}/coupons",
|
|
291
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
292
|
+
idempotency_key=idempotency_key,
|
|
293
|
+
)
|
|
294
|
+
return Coupon.model_validate(envelope["data"])
|
|
295
|
+
|
|
296
|
+
async def create_invite(
|
|
297
|
+
self,
|
|
298
|
+
id: str,
|
|
299
|
+
*,
|
|
300
|
+
email: Optional[str] = None,
|
|
301
|
+
name: Optional[str] = None,
|
|
302
|
+
is_public: Optional[bool] = None,
|
|
303
|
+
usage_limit: Optional[int] = None,
|
|
304
|
+
expires_in_days: Optional[int] = None,
|
|
305
|
+
idempotency_key: Optional[str] = None,
|
|
306
|
+
) -> Invite:
|
|
307
|
+
body = {
|
|
308
|
+
"email": email,
|
|
309
|
+
"name": name,
|
|
310
|
+
"isPublic": is_public,
|
|
311
|
+
"usageLimit": usage_limit,
|
|
312
|
+
"expiresInDays": expires_in_days,
|
|
313
|
+
}
|
|
314
|
+
envelope = await self._http.request(
|
|
315
|
+
"POST",
|
|
316
|
+
f"/programs/{id}/invites",
|
|
317
|
+
json={k: v for k, v in body.items() if v is not None},
|
|
318
|
+
idempotency_key=idempotency_key,
|
|
319
|
+
)
|
|
320
|
+
return Invite.model_validate(envelope["data"])
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from .models import (
|
|
2
|
+
Affiliate,
|
|
3
|
+
BillingStatus,
|
|
4
|
+
BillingTier,
|
|
5
|
+
Conversion,
|
|
6
|
+
ConversionStats,
|
|
7
|
+
Coupon,
|
|
8
|
+
Flag,
|
|
9
|
+
FlagStats,
|
|
10
|
+
Invite,
|
|
11
|
+
Merchant,
|
|
12
|
+
PaginatedResponse,
|
|
13
|
+
PaginationMeta,
|
|
14
|
+
PendingAffiliate,
|
|
15
|
+
Payout,
|
|
16
|
+
PayoutStats,
|
|
17
|
+
Program,
|
|
18
|
+
ResolveFlagParams,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"PaginationMeta",
|
|
23
|
+
"PaginatedResponse",
|
|
24
|
+
"Program",
|
|
25
|
+
"Affiliate",
|
|
26
|
+
"Conversion",
|
|
27
|
+
"ConversionStats",
|
|
28
|
+
"Payout",
|
|
29
|
+
"PendingAffiliate",
|
|
30
|
+
"PayoutStats",
|
|
31
|
+
"Flag",
|
|
32
|
+
"FlagStats",
|
|
33
|
+
"ResolveFlagParams",
|
|
34
|
+
"BillingTier",
|
|
35
|
+
"BillingStatus",
|
|
36
|
+
"Merchant",
|
|
37
|
+
"Coupon",
|
|
38
|
+
"Invite",
|
|
39
|
+
]
|
agentref/types/models.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Generic, List, Literal, Optional, TypeVar
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict
|
|
6
|
+
from pydantic.alias_generators import to_camel
|
|
7
|
+
|
|
8
|
+
T = TypeVar("T")
|
|
9
|
+
|
|
10
|
+
_API_CONFIG = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PaginationMeta(BaseModel):
|
|
14
|
+
model_config = _API_CONFIG
|
|
15
|
+
|
|
16
|
+
total: int
|
|
17
|
+
page: int
|
|
18
|
+
page_size: int
|
|
19
|
+
has_more: bool
|
|
20
|
+
next_cursor: Optional[str] = None
|
|
21
|
+
request_id: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class PaginatedResponse(BaseModel, Generic[T]):
|
|
25
|
+
model_config = _API_CONFIG
|
|
26
|
+
|
|
27
|
+
data: List[T]
|
|
28
|
+
meta: PaginationMeta
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class Program(BaseModel):
|
|
32
|
+
model_config = _API_CONFIG
|
|
33
|
+
|
|
34
|
+
id: str
|
|
35
|
+
name: str
|
|
36
|
+
commission_type: str
|
|
37
|
+
commission_percent: float
|
|
38
|
+
commission_limit_months: Optional[int] = None
|
|
39
|
+
cookie_duration: int
|
|
40
|
+
payout_threshold: int
|
|
41
|
+
auto_approve_affiliates: bool
|
|
42
|
+
description: Optional[str] = None
|
|
43
|
+
landing_page_url: Optional[str] = None
|
|
44
|
+
status: str
|
|
45
|
+
is_public: Optional[bool] = None
|
|
46
|
+
merchant_id: Optional[str] = None
|
|
47
|
+
created_at: Optional[str] = None
|
|
48
|
+
updated_at: Optional[str] = None
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class Affiliate(BaseModel):
|
|
52
|
+
model_config = _API_CONFIG
|
|
53
|
+
|
|
54
|
+
id: str
|
|
55
|
+
user_id: Optional[str] = None
|
|
56
|
+
program_id: Optional[str] = None
|
|
57
|
+
code: Optional[str] = None
|
|
58
|
+
status: Optional[str] = None
|
|
59
|
+
total_clicks: Optional[int] = None
|
|
60
|
+
total_conversions: Optional[int] = None
|
|
61
|
+
total_earnings: Optional[float] = None
|
|
62
|
+
created_at: Optional[str] = None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Conversion(BaseModel):
|
|
66
|
+
model_config = _API_CONFIG
|
|
67
|
+
|
|
68
|
+
id: str
|
|
69
|
+
affiliate_id: Optional[str] = None
|
|
70
|
+
program_id: Optional[str] = None
|
|
71
|
+
amount: Optional[float] = None
|
|
72
|
+
commission: Optional[float] = None
|
|
73
|
+
status: Optional[str] = None
|
|
74
|
+
method: Optional[str] = None
|
|
75
|
+
stripe_session_id: Optional[str] = None
|
|
76
|
+
created_at: Optional[str] = None
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class ConversionStats(BaseModel):
|
|
80
|
+
model_config = _API_CONFIG
|
|
81
|
+
|
|
82
|
+
total: int = 0
|
|
83
|
+
pending: int = 0
|
|
84
|
+
approved: int = 0
|
|
85
|
+
total_revenue: float = 0
|
|
86
|
+
total_commissions: float = 0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Payout(BaseModel):
|
|
90
|
+
model_config = _API_CONFIG
|
|
91
|
+
|
|
92
|
+
id: str
|
|
93
|
+
affiliate_id: Optional[str] = None
|
|
94
|
+
amount: Optional[float] = None
|
|
95
|
+
status: Optional[str] = None
|
|
96
|
+
method: Optional[str] = None
|
|
97
|
+
created_at: Optional[str] = None
|
|
98
|
+
completed_at: Optional[str] = None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class PendingAffiliate(BaseModel):
|
|
102
|
+
model_config = _API_CONFIG
|
|
103
|
+
|
|
104
|
+
affiliate_id: Optional[str] = None
|
|
105
|
+
email: Optional[str] = None
|
|
106
|
+
name: Optional[str] = None
|
|
107
|
+
code: Optional[str] = None
|
|
108
|
+
program_id: Optional[str] = None
|
|
109
|
+
program_name: Optional[str] = None
|
|
110
|
+
payout_method: Optional[str] = None
|
|
111
|
+
paypal_email: Optional[str] = None
|
|
112
|
+
bank_iban: Optional[str] = None
|
|
113
|
+
pending_amount: Optional[float] = None
|
|
114
|
+
currency: Optional[str] = None
|
|
115
|
+
threshold: Optional[float] = None
|
|
116
|
+
meets_threshold: Optional[bool] = None
|
|
117
|
+
commission_count: Optional[int] = None
|
|
118
|
+
has_payout_method: Optional[bool] = None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class PayoutStats(BaseModel):
|
|
122
|
+
model_config = _API_CONFIG
|
|
123
|
+
|
|
124
|
+
total_paid: float = 0
|
|
125
|
+
total_pending: float = 0
|
|
126
|
+
count: int = 0
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class Flag(BaseModel):
|
|
130
|
+
model_config = _API_CONFIG
|
|
131
|
+
|
|
132
|
+
id: str
|
|
133
|
+
affiliate_id: Optional[str] = None
|
|
134
|
+
type: Optional[str] = None
|
|
135
|
+
status: Optional[str] = None
|
|
136
|
+
details: Optional[Dict[str, Any]] = None
|
|
137
|
+
note: Optional[str] = None
|
|
138
|
+
created_at: Optional[str] = None
|
|
139
|
+
resolved_at: Optional[str] = None
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class FlagStats(BaseModel):
|
|
143
|
+
model_config = _API_CONFIG
|
|
144
|
+
|
|
145
|
+
open: int = 0
|
|
146
|
+
reviewed: int = 0
|
|
147
|
+
dismissed: int = 0
|
|
148
|
+
confirmed: int = 0
|
|
149
|
+
total: int = 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class ResolveFlagParams(BaseModel):
|
|
153
|
+
model_config = _API_CONFIG
|
|
154
|
+
|
|
155
|
+
status: Literal["reviewed", "dismissed", "confirmed"]
|
|
156
|
+
note: Optional[str] = None
|
|
157
|
+
block_affiliate: bool = False
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class BillingTier(BaseModel):
|
|
161
|
+
model_config = _API_CONFIG
|
|
162
|
+
|
|
163
|
+
id: str
|
|
164
|
+
name: str
|
|
165
|
+
price: float
|
|
166
|
+
max_revenue: Optional[float] = None
|
|
167
|
+
features: Optional[List[str]] = None
|
|
168
|
+
bookable: Optional[bool] = None
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class BillingStatus(BaseModel):
|
|
172
|
+
model_config = _API_CONFIG
|
|
173
|
+
|
|
174
|
+
tier: Optional[str] = None
|
|
175
|
+
monthly_revenue: Optional[float] = None
|
|
176
|
+
next_tier: Optional[str] = None
|
|
177
|
+
stripe_subscription_id: Optional[str] = None
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class Merchant(BaseModel):
|
|
181
|
+
model_config = _API_CONFIG
|
|
182
|
+
|
|
183
|
+
id: str
|
|
184
|
+
email: str
|
|
185
|
+
company_name: Optional[str] = None
|
|
186
|
+
domain: Optional[str] = None
|
|
187
|
+
domain_verified: Optional[bool] = None
|
|
188
|
+
trust_level: Optional[str] = None
|
|
189
|
+
stripe_connected: Optional[bool] = None
|
|
190
|
+
created_at: Optional[str] = None
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class Coupon(BaseModel):
|
|
194
|
+
model_config = _API_CONFIG
|
|
195
|
+
|
|
196
|
+
id: str
|
|
197
|
+
code: str
|
|
198
|
+
affiliate_id: Optional[str] = None
|
|
199
|
+
program_id: Optional[str] = None
|
|
200
|
+
created_at: Optional[str] = None
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class Invite(BaseModel):
|
|
204
|
+
model_config = _API_CONFIG
|
|
205
|
+
|
|
206
|
+
token: Optional[str] = None
|
|
207
|
+
email: Optional[str] = None
|
|
208
|
+
program_id: Optional[str] = None
|
|
209
|
+
expires_at: Optional[str] = None
|
|
210
|
+
created_at: Optional[str] = None
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentref
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the AgentRef Affiliate API
|
|
5
|
+
Author-email: AgentRef <hi@agentref.dev>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Requires-Dist: httpx>=0.27.0
|
|
9
|
+
Requires-Dist: pydantic>=2.0.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: build>=1.2.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: mypy>=1.9.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
15
|
+
Requires-Dist: respx>=0.21.0; extra == 'dev'
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# AgentRef Python SDK
|
|
19
|
+
|
|
20
|
+
Official Python SDK for the AgentRef REST API v1.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install agentref
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quickstart
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from agentref import AgentRef
|
|
32
|
+
|
|
33
|
+
client = AgentRef(api_key="ak_live_...")
|
|
34
|
+
programs = client.programs.list()
|
|
35
|
+
print(programs.meta.request_id)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Async quickstart
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from agentref import AsyncAgentRef
|
|
42
|
+
|
|
43
|
+
async with AsyncAgentRef(api_key="ak_live_...") as client:
|
|
44
|
+
programs = await client.programs.list()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Authentication
|
|
48
|
+
|
|
49
|
+
- Uses `Authorization: Bearer <key>`.
|
|
50
|
+
- Supports `ak_live_*`, `ak_aff_*`, `ak_onb_*`.
|
|
51
|
+
- Provide `api_key` directly or set `AGENTREF_API_KEY`.
|
|
52
|
+
|
|
53
|
+
## Resources
|
|
54
|
+
|
|
55
|
+
- `client.programs`: `list`, `list_all`, `get`, `create`, `update`, `delete`, `stats`, `list_affiliates`, `list_coupons`, `create_coupon`, `create_invite`
|
|
56
|
+
- `client.affiliates`: `list`, `get`, `approve`, `block`, `unblock`
|
|
57
|
+
- `client.conversions`: `list`, `stats`, `recent`
|
|
58
|
+
- `client.payouts`: `list`, `list_pending`, `stats`
|
|
59
|
+
- `client.flags`: `list`, `stats`, `resolve`
|
|
60
|
+
- `client.billing`: `current`, `tiers`, `subscribe`
|
|
61
|
+
- `client.merchant`: `get`, `domain_status`
|
|
62
|
+
|
|
63
|
+
## Pagination
|
|
64
|
+
|
|
65
|
+
List endpoints return `PaginatedResponse[T]` with:
|
|
66
|
+
|
|
67
|
+
- `meta.total`
|
|
68
|
+
- `meta.page`
|
|
69
|
+
- `meta.page_size`
|
|
70
|
+
- `meta.has_more`
|
|
71
|
+
- `meta.next_cursor`
|
|
72
|
+
- `meta.request_id`
|
|
73
|
+
|
|
74
|
+
Auto-pagination (`list_all`) stops on `has_more is False`.
|
|
75
|
+
|
|
76
|
+
## Idempotency and retry behavior
|
|
77
|
+
|
|
78
|
+
- GET/HEAD: auto-retry on 429/5xx.
|
|
79
|
+
- POST: auto-retry only when `idempotency_key` is provided.
|
|
80
|
+
- PATCH/DELETE: never auto-retry.
|
|
81
|
+
- `Idempotency-Key` header is sent only for POST requests.
|
|
82
|
+
|
|
83
|
+
## Error handling
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from agentref import AgentRef
|
|
87
|
+
from agentref.errors import ForbiddenError, NotFoundError, RateLimitError, AgentRefError
|
|
88
|
+
|
|
89
|
+
client = AgentRef(api_key="ak_live_...")
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
client.programs.get("missing-id")
|
|
93
|
+
except ForbiddenError as e:
|
|
94
|
+
print(e.code, e.request_id)
|
|
95
|
+
except NotFoundError as e:
|
|
96
|
+
print(e.request_id)
|
|
97
|
+
except RateLimitError as e:
|
|
98
|
+
print(e.retry_after)
|
|
99
|
+
except AgentRefError as e:
|
|
100
|
+
print(e.status)
|
|
101
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
agentref/__init__.py,sha256=SWifBKdppFmIhFX8yZx7Bwk5whf4cRJgPi4L-asBFr4,436
|
|
2
|
+
agentref/_http.py,sha256=gesorbeLTSuWGbBJCjwD9BZjROmnY9JiUgGasHPn09s,8445
|
|
3
|
+
agentref/client.py,sha256=-XNvaDIpJPN1vFtf1jSMOcRy3wICQsHefgfb4a3zkZs,2435
|
|
4
|
+
agentref/errors.py,sha256=VCRxtZqnk8GpQ1e3BO3nUiPJjA7PFgS_5OEjvKuL__Y,1837
|
|
5
|
+
agentref/resources/__init__.py,sha256=tJy_JLhJZLksHo7WG4utl24CrgI3-lJ2O0QtOKOMpbg,820
|
|
6
|
+
agentref/resources/affiliates.py,sha256=aXuWCPRJJR58xWZxZDxxzYNMCdrAnvvPngHC5oKaMvs,4329
|
|
7
|
+
agentref/resources/billing.py,sha256=Wq3CBVeD_gzZ80Kvdln_6z_kn2igvngC6DALLXkRKWo,2138
|
|
8
|
+
agentref/resources/conversions.py,sha256=_rnzLDoXwJqwb49GN2AgOnXXJt9pNGhnyomWyHr3NoY,4332
|
|
9
|
+
agentref/resources/flags.py,sha256=1jbJTsm00X-SDeslhkId-7SDdUhagpj8qxsoghv_0P8,3995
|
|
10
|
+
agentref/resources/merchant.py,sha256=G1dM1_sexka3WAPcCrB3IM6lrCizGQHpjLxRF2mgZwA,1118
|
|
11
|
+
agentref/resources/payouts.py,sha256=aVZUc3O_tUWMDREKW-0Jp76_1hMljKWqzY4O3Is4d7c,5013
|
|
12
|
+
agentref/resources/programs.py,sha256=XPrF_07yws33YKPYPbv812o_1s76Zfr66SvnT_85eO4,11370
|
|
13
|
+
agentref/types/__init__.py,sha256=hsnay8Dmow13hk5XPmZS-tRX7EFhgg03rotxAN6vwTI,635
|
|
14
|
+
agentref/types/models.py,sha256=_mLZgiCSU5kNmlIfp9KfCvo62O-88G_G6zZ1iMKwJkA,5019
|
|
15
|
+
agentref-1.0.0.dist-info/METADATA,sha256=0Ci0b_7Fvxz25Tx9vIhIchfaz8zH_RBZTEL1A8X7NSk,2555
|
|
16
|
+
agentref-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
agentref-1.0.0.dist-info/RECORD,,
|