Repository: SnarkAttack/pybgg-json

Issue:
Collections Requests

Discussion:

Patch:
diff --git a/pybgg_json/pybgg_json.py b/pybgg_json/pybgg_json.py
index 3f23f4b..bd105bc 100755
--- a/pybgg_json/pybgg_json.py
+++ b/pybgg_json/pybgg_json.py
@@ -111,4 +111,25 @@ class PyBggInterface(object):
 
         root = pybgg_utils._make_request(plays_url)
         
+        return json.dumps(pybgg_utils._generate_dict_from_element_tree(root))
+    
+    def collection_request(self, username, subtype='boardgame', exclude_subtype=None, id=None,
+                           brief=None, stats=None, own=None, rated=None, playerd=None, comment=None,
+                           trade=None, want=None, wishlist=None, wishlist_priority=None, preordered=None,
+                           wanttoplay=None, wanttobuy=None, prevowned=None, hasparts=None, wantparts=None,
+                           minrating=None, rating=None, minbggrating=None, bggrating=None, minplays=None,
+                           maxplays=None, showprivate=None, collid=None, modifiedsince=MIN_DATE):
+        
+        collection_url = (
+                    f"collection?username={username}&subtype={subtype}"
+        )
+        
+        for arg, arg_val in locals().items():
+            if arg_val is not None:
+                collection_url += f"{arg}={arg_val}&"
+        collection_url += f"modifiedsince={modifiedsince}"
+            
+        
+        root = pybgg_utils._make_request(collection_url)
+        
         return json.dumps(pybgg_utils._generate_dict_from_element_tree(root))
\ No newline at end of file


Test patch:
diff --git a/tests/test_pybgg_json.py b/tests/test_pybgg_json.py
index 92687e4..b9d66aa 100644
--- a/tests/test_pybgg_json.py
+++ b/tests/test_pybgg_json.py
@@ -3,13 +3,13 @@ import json
 import unittest
 
 expected_keys = {
-    'items': ['termsofuse', 'item'],
+    'items': ['termsofuse', 'item', 'totalitems', 'pubdate'],
     # There are actually multiple fields that use item as a keyword, so this combines all seen
     'item': ['type', 'id', 'thumbnail', 'image', 'name', 'description', 'yearpublished',
              'minplayers', 'maxplayers', 'poll', 'playingtime', 'productcode', 'minplaytime', 'maxplaytime',
              'minage', 'link', 'width', 'length', 'depth', 'weight', 'versions', 'videos',
              'comments', 'ratingcomments', 'statistics', 'marketplacelistings', 'rank', 'objecttype',
-             'objectid', 'subtypes'],
+             'objectid', 'subtypes', 'subtype', 'collid', 'status', 'numplays'],
     'name': ['primary', 'alternate'],
     'primary': ['sortindex', 'value'],
     'alternate': ['sortindex', 'value'],
@@ -71,6 +71,7 @@ expected_keys = {
     'subtypes': ['subtype'],
     'players': ['player'],
     'player': ['username', 'userid', 'name', 'startposition', 'color', 'score', 'new', 'rating', 'win'],
+    'status': ['own', 'prevowned', 'fortrade', 'want', 'wanttoplay', 'wanttobuy', 'wishlist', 'preordered', 'lastmodified'],
 }
 
 
@@ -81,9 +82,9 @@ def check_all_element_data(elem, parent_key):
     if type(elem) != dict:
         return True
 
-    # print(parent_key)
-    # print(elem.keys())
-    # print(expected_keys.get(parent_key, {}))
+    print(parent_key)
+    print(elem.keys())
+    print(expected_keys.get(parent_key, {}))
 
     return all(item in expected_keys.get(parent_key, {}) for item in elem.keys())
 
@@ -213,3 +214,7 @@ def test_guild_request_members():
 def test_plays_basic_request():
     bgg_int = PyBggInterface()
     assert check_json(bgg_int.plays_request(username='mcpat0226')) == True
+    
+def test_collection_request_basic():
+    bgg_int = PyBggInterface()
+    assert check_json(bgg_int.collection_request(username='mcpat0226')) == True