From 0c445a06f36ca4a2ffb4dd50bb349b25b06b6e7d Mon Sep 17 00:00:00 2001 From: Jose Luis Ricon Date: Mon, 4 May 2020 20:31:40 +0100 Subject: [PATCH] Add header for internal use (#252) * add internal header --- requirements.txt | 3 +++ twitter_ads/client.py | 6 ++++++ twitter_ads/http.py | 6 ++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3e9aab1..111c2e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,6 @@ python-dateutil responses mock setuptools_scm +MarkupSafe +setuptools>=40.0 +configparser>=3.5 \ No newline at end of file diff --git a/twitter_ads/client.py b/twitter_ads/client.py index 6b91a5c..47b625d 100644 --- a/twitter_ads/client.py +++ b/twitter_ads/client.py @@ -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( @@ -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.""" diff --git a/twitter_ads/http.py b/twitter_ads/http.py index 1931f12..c7e15b8 100644 --- a/twitter_ads/http.py +++ b/twitter_ads/http.py @@ -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)