Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions pyperi/pyperi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class Peri(object):
PERISCOPE_API_BASE_URL = 'https://api.periscope.tv/api/v2'
PERISCOPE_WEB_BASE_URL = 'https://www.periscope.tv'

def __init__(self, session=None):
"""
Constructor. If a `session` is passed, it will be used to retrieve
URLs. This should be a `requests.Session` object, or something like it.
If no `session` is passed, one will be created for you.
"""
self.session = session if session else requests.Session()

def request_api(self, endpoint, **params):
"""
Make a request against the Periscope API and return the result.
Expand All @@ -27,7 +35,7 @@ def request_api(self, endpoint, **params):
url = self._create_api_request_url(endpoint, **params)

try:
r = requests.get(url)
r = self.session.get(url)
except requests.exceptions.ConnectionError as e:
raise PyPeriConnectionError(e)

Expand Down Expand Up @@ -121,7 +129,7 @@ def get_web_public_user_session_tokens(self, user_id=None, username=None):
'broadcastHistory', 'serviceToken', 'thumbnailPlaylist'
]

out = {'user_id': data_store['Tracking']['userId']}
out = {'user_id': data_store['UserCache']['usernames'][username.lower()]}
for token_name in token_names:
out[token_name] = public_tokens[token_name]['token']['session_id']

Expand Down Expand Up @@ -186,7 +194,7 @@ def _get_web_data_store(self, url):
return None.
"""
try:
r = requests.get(url)
r = self.session.get(url)
except requests.exceptions.ConnectionError as e:
raise PyPeriConnectionError(e)

Expand Down