-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎉Source Hubspot: Add contacts associations to Deals stream. #5693
Changes from 2 commits
7ba2b69
9caab78
1d885c7
e0b483a
1cf0c2b
ebdef51
b57fb36
d51f1f5
e69541b
59f4eb5
b7a6fb1
a44003e
673dc4c
4f09a61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -620,6 +620,63 @@ def list(self, fields) -> Iterable: | |
yield record | ||
|
||
|
||
class CRMAssociationStream(Stream): | ||
""" see https://developers.hubspot.com/docs/api/crm/associations for more details | ||
""" | ||
|
||
entity: Optional[str] = None | ||
associations: List[str] = [] | ||
updated_at_field = None | ||
created_at_field = None | ||
|
||
@property | ||
def url(self): | ||
"""Entity URL""" | ||
return f"/crm/v3/associations/{self._relationship_from}/{self._relationship_to}/{self._endpoint}" | ||
|
||
def __init__(self, relationship_from: str = None, relationship_to: str = None, endpoint: str = None, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend the following ordering convention:
|
||
super().__init__(**kwargs) | ||
self._relationship_from = relationship_from | ||
self._relationship_to = relationship_to | ||
self._endpoint = endpoint | ||
|
||
def _transform(self, records: Iterable) -> Iterable: | ||
"""Preprocess record """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add more description in docstring, why we need this method just passing the records. |
||
for record in records: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yield from records in this case, no need for the loop. |
||
yield record | ||
|
||
def _filter_old_records(self, records: Iterable) -> Iterable: | ||
"""Skip """ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment above. |
||
for record in records: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can simply: |
||
yield record | ||
|
||
|
||
class DealToContactAssociationsStream(CRMAssociationStream): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is useful part of the connector, however I have a question around reusing the parts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello @bazarnov, thanks for the comment and the advices, you are right the
Now my question is, how to do a right json schema, since it's almost the same as the deals schema, is it good to duplicate it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can always go with
Inside of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sounds great, can wee proceed with reusing those parts, instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'm gonna update the pr with the new changes. |
||
def __init__(self, deal_stream, **kwargs): | ||
super().__init__(relationship_from="Deals", relationship_to="Contacts", endpoint="batch/read", **kwargs) | ||
self._deal_stream = deal_stream | ||
|
||
def prepare_payload(self, ids: Iterable) -> Mapping[str, Any]: | ||
payload = {"inputs": []} | ||
|
||
for deal_id in ids: | ||
payload['inputs'].append({"id": deal_id}) | ||
|
||
return payload | ||
|
||
def list(self, fields) -> Iterable: | ||
|
||
deals = self._deal_stream.list(fields) | ||
ids = [] | ||
|
||
for deal in deals: | ||
ids.append(deal.get('id')) | ||
if len(ids) == self.limit: | ||
payload = self.prepare_payload(ids=ids) | ||
yield from self.read(partial(self._api.post, url=self.url, data=payload)) | ||
ids = [] | ||
|
||
|
||
class DealPipelineStream(Stream): | ||
"""Deal pipelines, API v1, | ||
This endpoint requires the contacts scope the tickets scope. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||
{ | ||||||
"$schema": "http://json-schema.org/draft-07/schema#", | ||||||
"type": ["null", "object"], | ||||||
"properties": { | ||||||
"from": { | ||||||
"type": ["null", "Object"], | ||||||
"properties": { | ||||||
"id": { | ||||||
"type": ["null", "string"] | ||||||
} | ||||||
} | ||||||
}, | ||||||
"to": { | ||||||
"type": ["null", "array"], | ||||||
"items": { | ||||||
"type": ["null", "Object"], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"properties":{ | ||||||
"id": ["null", "string"], | ||||||
"type": ["null", "string"] | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to bump to
0.1.12
also get latest code from master because yesterday was merged a change to Hubspot connector.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladimir-remar please bump the versions in all required places, to the
0.1.12