Skip to content

Commit

Permalink
add appid and user-agent to every request
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown authored and Unknown committed Mar 29, 2018
1 parent b27f3a8 commit 14589e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion rarbgapi/rarbgapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import logging
import platform

import requests

Expand Down Expand Up @@ -74,15 +75,31 @@ class _RarbgAPIv2(object):
https://torrentapi.org/apidocs_v2.txt
'''
ENDPOINT = 'http://torrentapi.org/pubapi_v2.php'
APP_ID = 'rarbgapi'

def __init__(self):
super(_RarbgAPIv2, self).__init__()
self._endpoint = self.ENDPOINT

def _get_user_agent(self):
return '{appid}/0.1.1 ({uname}) python {pyver}'.format(
appid=self.APP_ID,
uname='; '.join(platform.uname()),
pyver=platform.python_version())

# pylint: disable=no-self-use
def _requests(self, method, url, params=None):
if not params:
params = dict()
params.update({
'app_id': self.APP_ID
})

headers = {
'user-agent': self._get_user_agent()
}
sess = requests.Session()
req = requests.Request(method, url, params=params)
req = requests.Request(method, url, params=params, headers=headers)
preq = req.prepare()
resp = sess.send(preq)
resp.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="RarbgAPI",
version="0.1",
version="0.1.1",
author="verybada",
author_email="[email protected]",
description=("A simple interface of RARBG.to"),
Expand Down

0 comments on commit 14589e5

Please sign in to comment.