Skip to content

Commit

Permalink
attempting to simplify setting headers on the BaseClient for #22
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetrucciani committed Mar 10, 2019
1 parent 12937eb commit 8d0b780
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions hubspot3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ def _get_path(self, subpath):
def _prepare_request_auth(self, subpath, params, data, opts):
if self.api_key:
params["hapikey"] = params.get("hapikey") or self.api_key
else:
# Be sure that we're consistent about what access_token is being used
# If one was provided at instantiation, that is always used. If it was not
# but one was provided as part of the method invocation, we persist it
headers = opts.get("headers") or {}
if headers.get("Authorization") and not self.access_token:
self.access_token = headers.get("Authorization").split(" ")[-1]
headers.update(
{"Authorization": "Bearer {}".format(self.access_token)}
)

def _prepare_request(
self, subpath, params, data, opts, doseq=False, query=""
Expand Down Expand Up @@ -125,6 +115,10 @@ def _prepare_request(
"Content-Type": opts.get("content_type") or "application/json",
}
)
if self.access_token:
headers.update(
{"Authorization": "Bearer {}".format(self.access_token)}
)

if data and headers["Content-Type"] == "application/json":
data = json.dumps(data)
Expand Down

1 comment on commit 8d0b780

@Nusnus
Copy link

@Nusnus Nusnus commented on 8d0b780 Mar 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works!!

Please sign in to comment.