Skip to content
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

Add fix for recently updated companies #76

Merged
merged 2 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions hubspot3/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def search_domain(
def get_all(
self,
prettify_output: bool = True,
extra_properties: Union[str, List] = None,
extra_properties: Union[str, List]=None,
**options
) -> Optional[List]:
"""get all companies, including extra properties if they are passed in"""
Expand Down Expand Up @@ -137,7 +137,13 @@ def get_all(

return output

def _get_recent(self, recency_type: str, **options) -> Optional[List]:
def _get_recent(
self,
recency_type: str,
limit: int = 250,
offset: int = 0,
since: int = None,
**options) -> Optional[List]:
"""
Returns either list of recently modified companies or recently created companies,
depending on recency_type passed in. Both API endpoints take identical parameters
Expand All @@ -148,15 +154,19 @@ def _get_recent(self, recency_type: str, **options) -> Optional[List]:
"""
finished = False
output = []
offset = 0
query_limit = 250 # Max value according to docs

while not finished:
params = {
"count": limit,
"offset": offset,
}
if since:
params["since"] = since
batch = self._call(
"companies/recent/{}".format(recency_type),
method="GET",
doseq=True,
params={"count": query_limit, "offset": offset},
params=params,
**options
)
output.extend(
Expand All @@ -171,11 +181,33 @@ def _get_recent(self, recency_type: str, **options) -> Optional[List]:

return output

def get_recently_modified(self, **options) -> Optional[List]:
return self._get_recent("modified", **options)

def get_recently_created(self, **options) -> Optional[List]:
return self._get_recent("created", **options)
def get_recently_modified(
self,
limit: int = 250,
offset: int = 0,
since: int = None,
**options
) -> Optional[List]:
return self._get_recent(
"modified",
limit=limit,
offset=offset,
since=since,
**options)

def get_recently_created(
self,
limit: int = 250,
offset: int = 0,
since: int = None,
**options
) -> Optional[List]:
return self._get_recent(
"created",
limit=limit,
offset=offset,
since=since,
**options)

def get_contacts_at_a_company(self, company_id: str, **options) -> Optional[List]:
"""
Expand Down
8 changes: 5 additions & 3 deletions hubspot3/deals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def delete(self, deal_id: str, **options) -> Dict:

def associate(self, deal_id, object_type, object_ids, **options):
# Encoding the query string here since HubSpot is expecting the "id" parameter to be
# repeated for each object ID, which is not a standard practice and won't work otherwise.
# repeated for each object ID, which is not a standard practice and
# won't work otherwise.
object_ids = [("id", object_id) for object_id in object_ids]
query = urllib.parse.urlencode(object_ids)

Expand All @@ -69,7 +70,7 @@ def associate(self, deal_id, object_type, object_ids, **options):
def get_all(
self,
offset: int = 0,
extra_properties: Union[list, str] = None,
extra_properties: Union[list, str]=None,
limit: int = -1,
**options
):
Expand Down Expand Up @@ -126,7 +127,8 @@ def get_all(
if not deal["isDeleted"]
]
)
finished = not batch["hasMore"] or (limited and len(output) >= limit)
finished = not batch["hasMore"] or (
limited and len(output) >= limit)
offset = batch["offset"]

return output if not limited else output[:limit]
Expand Down