|
10 | 10 | from blindpay import BlindPay, BlindPaySync |
11 | 11 |
|
12 | 12 |
|
13 | | -async def async_example(): |
| 13 | +async def async_example() -> None: |
14 | 14 | print("=== Async Example ===\n") |
15 | 15 |
|
16 | 16 | client = BlindPay( |
@@ -55,7 +55,7 @@ async def async_example(): |
55 | 55 | print(f" • {detail['label']} ({detail['key']}) - {required}") |
56 | 56 |
|
57 | 57 |
|
58 | | -def sync_example(): |
| 58 | +def sync_example() -> None: |
59 | 59 | print("\n\n=== Sync Example ===\n") |
60 | 60 |
|
61 | 61 | client = BlindPaySync( |
@@ -100,69 +100,7 @@ def sync_example(): |
100 | 100 | print(f" • {detail['label']} ({detail['key']}) - {required}") |
101 | 101 |
|
102 | 102 |
|
103 | | -def context_manager_example(): |
104 | | - """Example using context manager (auto-closes connection)""" |
105 | | - print("\n\n=== Context Manager Example ===\n") |
106 | | - |
107 | | - with BlindPaySync( |
108 | | - api_key="your_api_key_here", |
109 | | - instance_id="your_instance_id_here", |
110 | | - ) as client: |
111 | | - rails_response = client.available.get_rails() |
112 | | - |
113 | | - if rails_response["error"]: |
114 | | - print(f"Error: {rails_response['error']['message']}") |
115 | | - elif rails_response["data"]: |
116 | | - rails = rails_response["data"] |
117 | | - print(f"Available rails: {[r['value'] for r in rails]}") |
118 | | - else: |
119 | | - print("No data returned") |
120 | | - |
121 | | - # Connection is automatically closed when exiting the context |
122 | | - |
123 | | - |
124 | | -def error_handling_example(): |
125 | | - """Example with proper error handling""" |
126 | | - print("\n\n=== Error Handling Example ===\n") |
127 | | - |
128 | | - try: |
129 | | - client = BlindPaySync( |
130 | | - api_key="your_api_key_here", |
131 | | - instance_id="your_instance_id_here", |
132 | | - ) |
133 | | - |
134 | | - response = client.available.get_rails() |
135 | | - |
136 | | - # Check for errors |
137 | | - if response["error"]: |
138 | | - error_msg = response["error"]["message"] |
139 | | - print(f"❌ API Error: {error_msg}") |
140 | | - # Handle the error appropriately |
141 | | - return |
142 | | - |
143 | | - # Process the successful response |
144 | | - rails = response["data"] |
145 | | - if rails is None: |
146 | | - print("⚠️ No data returned") |
147 | | - return |
148 | | - |
149 | | - print(f"✅ Success! Retrieved {len(rails)} rails") |
150 | | - |
151 | | - # Do something with the data |
152 | | - for rail in rails: |
153 | | - print(f" - {rail['label']}: {rail['value']}") |
154 | | - |
155 | | - except Exception as e: |
156 | | - print(f"❌ Unexpected error: {e}") |
157 | | - # Handle unexpected errors |
158 | | - |
159 | | - |
160 | 103 | if __name__ == "__main__": |
161 | 104 | asyncio.run(async_example()) |
162 | 105 |
|
163 | 106 | sync_example() |
164 | | - |
165 | | - context_manager_example() |
166 | | - |
167 | | - error_handling_example() |
168 | | - |
0 commit comments