Skip to content

Commit

Permalink
fixing formatting, adding some docstrings, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetrucciani committed Nov 21, 2019
1 parent 2c4791f commit 3833b4b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
61 changes: 28 additions & 33 deletions hubspot3/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ 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"""
"""
get all companies, including extra properties if they are passed in
:see: https://developers.hubspot.com/docs/methods/deals/get-all-deals
"""
finished = False
output = []
offset = 0
Expand Down Expand Up @@ -138,12 +141,13 @@ def get_all(
return output

def _get_recent(
self,
recency_type: str,
limit: int = 250,
offset: int = 0,
since: int = None,
**options) -> Optional[List]:
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 @@ -156,10 +160,7 @@ def _get_recent(
output = []

while not finished:
params = {
"count": limit,
"offset": offset,
}
params = {"count": limit, "offset": offset}
if since:
params["since"] = since
batch = self._call(
Expand All @@ -182,36 +183,30 @@ def _get_recent(
return output

def get_recently_modified(
self,
limit: int = 250,
offset: int = 0,
since: int = None,
**options
self, limit: int = 250, offset: int = 0, since: int = None, **options
) -> Optional[List]:
"""
returns all of the recently modified deals
:see: https://developers.hubspot.com/docs/methods/deals/get_deals_modified
"""
return self._get_recent(
"modified",
limit=limit,
offset=offset,
since=since,
**options)
"modified", limit=limit, offset=offset, since=since, **options
)

def get_recently_created(
self,
limit: int = 250,
offset: int = 0,
since: int = None,
**options
self, limit: int = 250, offset: int = 0, since: int = None, **options
) -> Optional[List]:
"""
returns all of the recently created deals
:see: https://developers.hubspot.com/docs/methods/deals/get_deals_created
"""
return self._get_recent(
"created",
limit=limit,
offset=offset,
since=since,
**options)
"created", limit=limit, offset=offset, since=since, **options
)

def get_contacts_at_a_company(self, company_id: str, **options) -> Optional[List]:
"""
Returns all of the contacts who have an associatedcompanyid contact property of
returns all of the contacts who have an associatedcompanyid contact property of
`company_id`.
:see: https://developers.hubspot.com/docs/methods/companies/get_company_contacts
Expand Down
14 changes: 11 additions & 3 deletions hubspot3/deals.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ def __init__(self, *args, **kwargs):
self.log = get_log("hubspot3.deals")

def _get_path(self, subpath):
"""get the full api url for the given subpath on this client"""
return "deals/v{}/{}".format(
self.options.get("version") or DEALS_API_VERSION, subpath
)

def get(self, deal_id: str, **options):
"""
get a single deal by id
:see: https://developers.hubspot.com/docs/methods/deals/get_deal
"""
return self._call("deal/{}".format(deal_id), method="GET", **options)

def create(self, data: dict = None, **options):
Expand All @@ -43,6 +48,10 @@ def create(self, data: dict = None, **options):
return self._call("deal/", data=data, method="POST", **options)

def update(self, deal_id: str, data: dict = None, **options):
"""
update a deal by id
:see: https://developers.hubspot.com/docs/methods/deals/update_deal
"""
data = data or {}
return self._call("deal/{}".format(deal_id), data=data, method="PUT", **options)

Expand Down Expand Up @@ -70,7 +79,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 @@ -127,8 +136,7 @@ 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
2 changes: 1 addition & 1 deletion hubspot3/globals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
globals file for hubspot3
"""
__version__ = "3.2.38"
__version__ = "3.2.39"


BASE_URL = "https://api.hubapi.com"
Expand Down

0 comments on commit 3833b4b

Please sign in to comment.