Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76fae7a

Browse files
committed
add shorthand version for collections.create_reference
1 parent 1d7f635 commit 76fae7a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

stream/collections.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@ def __init__(self, client, token):
99
self.client = client
1010
self.token = token
1111

12-
def create_reference(self, collection_name, id):
13-
_id = id
14-
if isinstance(id, (dict,)) and id.get("id") is not None:
15-
_id = id.get("id")
16-
return "SO:%s:%s" % (collection_name, _id)
12+
def create_reference(self, collection_name=None, id=None, entry=None):
13+
if isinstance(entry, (dict,)):
14+
_collection = entry["collection"]
15+
_id = entry["id"]
16+
elif collection_name is not None and id is not None:
17+
_collection = collection_name
18+
_id = id
19+
else:
20+
raise ValueError(
21+
"must call with collection_name and id or with entry arguments"
22+
)
23+
return "SO:%s:%s" % (_collection, _id)
1724

1825
def upsert(self, collection_name, data):
1926
"""

stream/tests/test_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ def test_feed_enrichment_collection(self):
13291329
activity_data = {
13301330
"actor": "mike",
13311331
"verb": "buy",
1332-
"object": self.c.collections.create_reference("items", entry),
1332+
"object": self.c.collections.create_reference(entry=entry),
13331333
}
13341334
f.add_activity(activity_data)
13351335
response = f.get()

0 commit comments

Comments
 (0)