44import requests
55
66from datetime import datetime , timedelta , timezone
7+ from enum import Enum
78from nypl_py_utils .functions .log_helper import create_log
89from requests .adapters import HTTPAdapter , Retry
910
@@ -19,10 +20,8 @@ def __init__(self, library_id, account_id, account_key):
1920 self .library_id = library_id
2021 self .account_id = account_id
2122 self .account_key = account_key
22- self .setup_session ()
2323
24- def setup_session (self ):
25- """Authenticate and set up HTTP session"""
24+ # authenticate & set up HTTP session
2625 retry_policy = Retry (total = 3 , backoff_factor = 45 ,
2726 status_forcelist = [500 , 502 , 503 , 504 ],
2827 allowed_methods = frozenset (["GET" ]))
@@ -74,7 +73,7 @@ def create_request_body(self, request_type,
7473 "patron_id" : patron_id ,
7574 }
7675
77- def request (self , path , method_type = "POST " ,
76+ def request (self , path , method_type = "GET " ,
7877 body = None ) -> requests .Response :
7978 """
8079 Use this method to call specific paths in the cloudLibrary API.
@@ -87,21 +86,21 @@ def request(self, path, method_type="POST",
8786 method_type = method_type .upper ()
8887
8988 try :
90- if method_type == "GET" :
91- response = self .session .get (url = url ,
92- data = body ,
93- headers = headers ,
94- timeout = 60 )
95- elif method_type == "PUT" :
89+ if method_type == "PUT" :
9690 response = self .session .put (url = url ,
9791 data = body ,
9892 headers = headers ,
9993 timeout = 60 )
100- else :
94+ elif method_type == "POST" :
10195 response = self .session .post (url = url ,
10296 data = body ,
10397 headers = headers ,
10498 timeout = 60 )
99+ else :
100+ response = self .session .get (url = url ,
101+ data = body ,
102+ headers = headers ,
103+ timeout = 60 )
105104 response .raise_for_status ()
106105 except Exception as e :
107106 error_message = f"Failed to retrieve response from { url } : { e } "
@@ -144,3 +143,11 @@ def _build_authorization(self, method_type,
144143class CloudLibraryClientError (Exception ):
145144 def __init__ (self , message = None ):
146145 self .message = message
146+
147+ class CloudLibraryEventType (Enum ):
148+ CHECKIN = "Patron checked in or returned an item"
149+ CHECKOUT = "Patron checked out or borrowed an item"
150+ HOLD = "Patron placed a hold request on a book"
151+ PURCHASE = "Library purchased an item (this could be another copy of a currently owned item)"
152+ RESERVED = "The title which is currently on hold for the patron is now available for checkout"
153+ REMOVED = "A copy of a item has expired or was deliberately removed from library stock"
0 commit comments