25
25
26
26
A CircuitPython/Python library for communicating with Adafruit IO
27
27
28
-
29
28
* Author(s): Brent Rubell for Adafruit Industries
30
29
31
30
Implementation Notes
40
39
https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI
41
40
"""
42
41
43
- # imports
44
-
45
42
__version__ = "0.0.0-auto.0"
46
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Adafruit_IO.git"
47
44
48
45
class AdafruitIO_ThrottleError (Exception ):
49
- """Adafruit IO request error class for Throttle Errors """
46
+ """Adafruit IO request error class for rate-limiting """
50
47
def __init__ (self ):
51
48
super (AdafruitIO_ThrottleError , self ).__init__ ("Number of Adafruit IO Requests exceeded! \
52
49
Please try again in 30 seconds.." )
53
50
54
51
class AdafruitIO_RequestError (Exception ):
55
- """Base Adafruit IO request error class"""
52
+ """Adafruit IO request error class"""
56
53
def __init__ (self , response ):
57
54
response_content = response .json ()
58
55
error = response_content ['error' ]
@@ -63,18 +60,15 @@ class RESTClient():
63
60
"""
64
61
REST Client for interacting with the Adafruit IO API.
65
62
"""
66
- def __init__ (self , username , key , wifi_manager , api_version = 'v2' ):
67
- """
68
- Creates an instance of the Adafruit IO REST Client
69
- :param str username: Adafruit IO Username
70
- :param str key: Adafruit IO Key
71
- :param wifi_manager: WiFiManager Object
72
- :param str api_version: Adafruit IO REST API Version
73
- """
74
- self .api_version = api_version
75
- self .url = 'https://io.adafruit.com/api'
76
- self .username = username
77
- self .key = key
63
+ def __init__ (self , adafruit_io_username , adafruit_io_key , wifi_manager ):
64
+ """
65
+ Creates an instance of the Adafruit IO REST Client.
66
+ :param str adafruit_io_username: Adafruit IO Username
67
+ :param str adafruit_io_key: Adafruit IO Key
68
+ :param wifi_manager: WiFiManager object from adafruit_esp32spi_wifimanager
69
+ """
70
+ self .username = adafruit_io_username
71
+ self .key = adafruit_io_key
78
72
if wifi_manager :
79
73
self .wifi = wifi_manager
80
74
else :
@@ -96,10 +90,9 @@ def _handle_error(response):
96
90
raise AdafruitIO_RequestError (response )
97
91
elif response .status_code >= 400 :
98
92
raise AdafruitIO_RequestError (response )
99
- # no error? do nothing
100
93
101
94
def _compose_path (self , path ):
102
- return "{0}/{1}/{2}/{3}" .format (self . url , self . api_version , self .username , path )
95
+ return "{0}/{1}/{2}/{3}" .format ('https://io.adafruit.com/api' , 'v2' , self .username , path )
103
96
104
97
# HTTP Requests
105
98
def _post (self , path , payload ):
@@ -184,7 +177,8 @@ def create_new_group(self, group_key, group_description):
184
177
:param str group_description: Brief summary about the group
185
178
"""
186
179
path = self ._compose_path ("groups" )
187
- payload = {'name' :group_key , 'description' :group_description }
180
+ payload = {'name' :group_key ,
181
+ 'description' :group_description }
188
182
return self ._post (path , payload )
189
183
190
184
def delete_group (self , group_key ):
0 commit comments