Skip to content

Commit

Permalink
Add header for internal use (#252)
Browse files Browse the repository at this point in the history
* add internal header
  • Loading branch information
jlricon authored May 4, 2020
1 parent 2820327 commit 0c445a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ python-dateutil
responses
mock
setuptools_scm
MarkupSafe
setuptools>=40.0
configparser>=3.5
6 changes: 6 additions & 0 deletions twitter_ads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self,
self._access_token = access_token
self._access_token_secret = access_token_secret
self._options = kwargs.get('options', {})
self._headers = kwargs.get('headers', {})

def __repr__(self):
return '<{name} object at {mem} consumer_key={key}>'.format(
Expand All @@ -42,6 +43,11 @@ def options(self):
"""Returns the options value."""
return self._options

@property
def headers(self):
"""Returns the headers value."""
return self._headers

@property
def consumer_key(self):
"""Returns the consumer_key value."""
Expand Down
6 changes: 4 additions & 2 deletions twitter_ads/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ def __oauth_request(self):
if 'headers' in self.options:
headers.update(self.options['headers'].copy())

# internal-only
# DEPRECATED: internal-only (Should pass a header to the client)
if 'x-as-user' in self._client.options:
headers['x-as-user'] = self._client.options.get('x-as-user')

# Add headers from the client to the request (Client headers take priority)
for key, val in self._client.headers.items():
headers[key] = val
params = self.options.get('params', None)
data = self.options.get('body', None)
files = self.options.get('files', None)
Expand Down

0 comments on commit 0c445a0

Please sign in to comment.