stakeapi-codestats 0.2.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.
- stakeapi/__init__.py +31 -0
- stakeapi/_version.py +1 -0
- stakeapi/auth.py +138 -0
- stakeapi/client.py +695 -0
- stakeapi/endpoints.py +916 -0
- stakeapi/exceptions.py +43 -0
- stakeapi/models.py +285 -0
- stakeapi/utils.py +141 -0
- stakeapi_codestats-0.2.0.dist-info/METADATA +230 -0
- stakeapi_codestats-0.2.0.dist-info/RECORD +13 -0
- stakeapi_codestats-0.2.0.dist-info/WHEEL +5 -0
- stakeapi_codestats-0.2.0.dist-info/licenses/LICENSE +21 -0
- stakeapi_codestats-0.2.0.dist-info/top_level.txt +1 -0
stakeapi/__init__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""
|
|
2
|
+
StakeAPI - Unofficial Python API wrapper for stake.com
|
|
3
|
+
|
|
4
|
+
This package provides a comprehensive interface to interact with stake.com's
|
|
5
|
+
GraphQL API programmatically.
|
|
6
|
+
|
|
7
|
+
Example usage:
|
|
8
|
+
import asyncio
|
|
9
|
+
from stakeapi import StakeAPI
|
|
10
|
+
|
|
11
|
+
async def main():
|
|
12
|
+
async with StakeAPI(access_token="your_token") as client:
|
|
13
|
+
balance = await client.get_user_balance()
|
|
14
|
+
print(balance)
|
|
15
|
+
|
|
16
|
+
asyncio.run(main())
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from ._version import __version__
|
|
20
|
+
from .auth import AuthManager
|
|
21
|
+
from .client import StakeAPI
|
|
22
|
+
from .exceptions import AuthenticationError, RateLimitError, StakeAPIError
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"StakeAPI",
|
|
26
|
+
"AuthManager",
|
|
27
|
+
"StakeAPIError",
|
|
28
|
+
"AuthenticationError",
|
|
29
|
+
"RateLimitError",
|
|
30
|
+
"__version__",
|
|
31
|
+
]
|
stakeapi/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
stakeapi/auth.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Authentication manager for StakeAPI."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
import json
|
|
7
|
+
import time
|
|
8
|
+
from typing import Dict, Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class AuthManager:
|
|
12
|
+
"""Handles authentication for StakeAPI."""
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self, access_token: Optional[str] = None, session_cookie: Optional[str] = None
|
|
16
|
+
):
|
|
17
|
+
"""
|
|
18
|
+
Initialize authentication manager.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
access_token: Access token from stake.com (x-access-token)
|
|
22
|
+
session_cookie: Session cookie for authentication
|
|
23
|
+
"""
|
|
24
|
+
self.access_token = access_token
|
|
25
|
+
self.session_cookie = session_cookie
|
|
26
|
+
self._token_expires_at: Optional[float] = None
|
|
27
|
+
|
|
28
|
+
async def get_auth_headers(self) -> Dict[str, str]:
|
|
29
|
+
"""
|
|
30
|
+
Get authentication headers for requests.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Dictionary of authentication headers
|
|
34
|
+
"""
|
|
35
|
+
headers = {}
|
|
36
|
+
|
|
37
|
+
if self.access_token:
|
|
38
|
+
headers["X-Access-Token"] = self.access_token
|
|
39
|
+
|
|
40
|
+
return headers
|
|
41
|
+
|
|
42
|
+
def get_cookies(self) -> Dict[str, str]:
|
|
43
|
+
"""
|
|
44
|
+
Get authentication cookies.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
Dictionary of cookies
|
|
48
|
+
"""
|
|
49
|
+
cookies = {}
|
|
50
|
+
|
|
51
|
+
if self.session_cookie:
|
|
52
|
+
cookies["session"] = self.session_cookie
|
|
53
|
+
|
|
54
|
+
return cookies
|
|
55
|
+
|
|
56
|
+
def set_access_token(self, access_token: str, expires_in: Optional[int] = None):
|
|
57
|
+
"""
|
|
58
|
+
Set access token.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
access_token: Access token
|
|
62
|
+
expires_in: Token expiration time in seconds
|
|
63
|
+
"""
|
|
64
|
+
self.access_token = access_token
|
|
65
|
+
if expires_in:
|
|
66
|
+
self._token_expires_at = time.time() + expires_in
|
|
67
|
+
|
|
68
|
+
def set_session_cookie(self, session_cookie: str):
|
|
69
|
+
"""
|
|
70
|
+
Set session cookie.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
session_cookie: Session cookie value
|
|
74
|
+
"""
|
|
75
|
+
self.session_cookie = session_cookie
|
|
76
|
+
|
|
77
|
+
def is_token_expired(self) -> bool:
|
|
78
|
+
"""
|
|
79
|
+
Check if the current token is expired.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
True if token is expired or about to expire
|
|
83
|
+
"""
|
|
84
|
+
if not self._token_expires_at:
|
|
85
|
+
return False # No expiration set, assume valid
|
|
86
|
+
|
|
87
|
+
# Consider token expired 5 minutes before actual expiration
|
|
88
|
+
return time.time() >= (self._token_expires_at - 300)
|
|
89
|
+
|
|
90
|
+
def clear_tokens(self):
|
|
91
|
+
"""Clear stored authentication tokens."""
|
|
92
|
+
self.access_token = None
|
|
93
|
+
self.session_cookie = None
|
|
94
|
+
self._token_expires_at = None
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def extract_access_token_from_curl(curl_command: str) -> Optional[str]:
|
|
98
|
+
"""
|
|
99
|
+
Extract access token from curl command.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
curl_command: Curl command string
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Extracted access token or None
|
|
106
|
+
"""
|
|
107
|
+
import re
|
|
108
|
+
|
|
109
|
+
# Look for x-access-token header
|
|
110
|
+
pattern = r'-H\s+["\']x-access-token:\s*([^"\']+)["\']'
|
|
111
|
+
match = re.search(pattern, curl_command, re.IGNORECASE)
|
|
112
|
+
|
|
113
|
+
if match:
|
|
114
|
+
return match.group(1).strip()
|
|
115
|
+
|
|
116
|
+
return None
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def extract_session_from_curl(curl_command: str) -> Optional[str]:
|
|
120
|
+
"""
|
|
121
|
+
Extract session cookie from curl command.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
curl_command: Curl command string
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Extracted session cookie or None
|
|
128
|
+
"""
|
|
129
|
+
import re
|
|
130
|
+
|
|
131
|
+
# Look for session cookie in -b parameter
|
|
132
|
+
pattern = r"session=([^;]+)"
|
|
133
|
+
match = re.search(pattern, curl_command)
|
|
134
|
+
|
|
135
|
+
if match:
|
|
136
|
+
return match.group(1).strip()
|
|
137
|
+
|
|
138
|
+
return None
|