@@ -855,6 +855,77 @@ def receive_random_data(self, generator_id: int):
855
855
path = self ._compose_path ("integrations/words/{0}" .format (generator_id ))
856
856
return self ._get (path )
857
857
858
+ def get_user_info (self ):
859
+ """
860
+ Get detailed account information for the current user.
861
+
862
+ See https://io.adafruit.com/api/docs/#get-user-info
863
+ """
864
+ return self ._get ("https://io.adafruit.com/api/v2/user" )
865
+
866
+ def get_user_rate_info (self ):
867
+ """
868
+ Get rate limit and usage information for the current user.
869
+
870
+ See https://io.adafruit.com/api/docs/#get-detailed-user-info
871
+
872
+ Example output:
873
+ ```
874
+ {
875
+ "data_rate_limit": 30,
876
+ "active_data_rate": 0,
877
+ "authentication_rate": 0,
878
+ "subscribe_authorization_rate": 0,
879
+ "publish_authorization_rate": 0,
880
+ "hourly_ban_rate": 0,
881
+ "mqtt_ban_error_message": null,
882
+ "active_sms_rate": 0
883
+ }
884
+ ```
885
+ """
886
+ path = self ._compose_path ("throttle" )
887
+ return self ._get (path )
888
+
889
+ def get_remaining_throttle_limit (self ):
890
+ """
891
+ Get the remaining data points allowed before hitting the throttle limit.
892
+ This retrieves the user rate limit and deducts usage for the current user.
893
+
894
+ See https://io.adafruit.com/api/docs/#get-detailed-user-info
895
+ """
896
+ user_rates = self .get_user_rate_info ()
897
+ if user_rates is None :
898
+ raise ValueError (
899
+ "Could not get user info, get_user_rate_info returned None."
900
+ )
901
+ return user_rates ["data_rate_limit" ] - user_rates ["active_data_rate" ]
902
+
903
+ def get_throttle_limit (self ):
904
+ """
905
+ Get user throttle limit a.k.a "data_rate_limit" for the current user.
906
+
907
+ See https://io.adafruit.com/api/docs/#get-detailed-user-info
908
+ """
909
+ user_rates = self .get_user_rate_info ()
910
+ if user_rates is None :
911
+ raise ValueError (
912
+ "Could not get user info, get_user_rate_info returned None."
913
+ )
914
+ return user_rates ["data_rate_limit" ]
915
+
916
+ def get_current_usage (self ):
917
+ """
918
+ Get current rate usage a.k.a "active_data_rate" for the current user.
919
+
920
+ See https://io.adafruit.com/api/docs/#get-detailed-user-info
921
+ """
922
+ user_rates = self .get_user_rate_info ()
923
+ if user_rates is None :
924
+ raise ValueError (
925
+ "Could not get user info, get_user_rate_info returned None."
926
+ )
927
+ return user_rates ["active_data_rate" ]
928
+
858
929
def receive_time (self , timezone : str = None ):
859
930
"""
860
931
Returns a struct_time from the Adafruit IO Server based on the device's IP address.
0 commit comments