Skip to content

Commit

Permalink
added option for proxies while initiliazing FacebookSession...
Browse files Browse the repository at this point in the history
- proxies can be added as an optional argument while calling FacebookAdsApi.init
  • Loading branch information
Prateek Sanyal committed Oct 11, 2016
1 parent 26255e8 commit 0d17a6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions facebookads/api.py
Expand Up @@ -189,9 +189,10 @@ def init(
app_secret=None,
access_token=None,
account_id=None,
api_version=None
api_version=None,
proxies=None
):
session = FacebookSession(app_id, app_secret, access_token)
session = FacebookSession(app_id, app_secret, access_token, proxies)
api = cls(session, api_version)
cls.set_default_api(api)

Expand Down
11 changes: 8 additions & 3 deletions facebookads/session.py
Expand Up @@ -39,20 +39,22 @@ class FacebookSession(object):
app_secret: The application secret.
access_token: The access token.
appsecret_proof: The application secret proof.
proxies: Object containing proxies for 'http' and 'https'
requests: The python requests object through which calls to the api can
be made.
"""
GRAPH = 'https://graph.facebook.com'

def __init__(self, app_id=None, app_secret=None, access_token=None):
def __init__(self, app_id=None, app_secret=None, access_token=None, proxies=None):
"""
Initializes and populates the instance attributes with app_id,
app_secret, access_token, appsecret_proof, and requests given arguments
app_id, app_secret, and access_token.
app_secret, access_token, appsecret_proof, proxies, and requests given arguments
app_id, app_secret, access_token and proxies.
"""
self.app_id = app_id
self.app_secret = app_secret
self.access_token = access_token
self.proxies = proxies

self.requests = requests.Session()
self.requests.verify = os.path.join(
Expand All @@ -66,6 +68,9 @@ def __init__(self, app_id=None, app_secret=None, access_token=None):
params['appsecret_proof'] = self._gen_appsecret_proof()
self.requests.params.update(params)

if self.proxies:
self.requests.proxies.update(self.proxies)

def _gen_appsecret_proof(self):
h = hmac.new(
self.app_secret.encode('utf-8'),
Expand Down

0 comments on commit 0d17a6c

Please sign in to comment.