@@ -8,18 +8,25 @@ class JsonBox:
88 def __init__ (self , service_host = "https://jsonbox.io" ):
99 self .service_host = service_host
1010
11- def _get_url (self , box_id , collection_or_record ):
11+ def _get_url (self , box_id , collection_or_record = None , sort_by = None ):
12+ url = "{0}/{1}" .format (self .service_host , box_id )
13+
1214 if collection_or_record :
13- url = "{0}/{1}/{2}" .format (self .service_host , box_id , collection_or_record )
14- else :
15- url = "{0}/{1}" .format (self .service_host , box_id )
15+ url = "{0}/{1}" .format (url , collection_or_record )
16+
17+ if sort_by :
18+ url = "{0}?sort={1}" .format (url , sort_by )
19+
1620 return url
1721
1822 def get_record_id (self , data ):
19- return data [self .RECORD_ID_KEY ]
23+ if isinstance (data , list ):
24+ return [item [self .RECORD_ID_KEY ] for item in data ]
25+ else :
26+ return data [self .RECORD_ID_KEY ]
2027
21- def read (self , box_id , collection_or_record = None ):
22- url = self ._get_url (box_id , collection_or_record )
28+ def read (self , box_id , collection_or_record = None , sort_by = None ):
29+ url = self ._get_url (box_id , collection_or_record , sort_by )
2330
2431 response = requests .get (url )
2532 if response .ok :
0 commit comments