Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port code to requests library, fix an import error for python3, bump version #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions prowlpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,5 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from prowlpy import VERSION
# This version will get tossed in 0.6
__version__ = 0.52

from prowlpy import Prowl
from .prowlpy import VERSION
from .prowlpy import Prowl
60 changes: 23 additions & 37 deletions prowlpy/prowlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@
- retrieve_apikey, to get an API key from a registration token retrieved in
retrieve/token.
"""
from httplib import HTTPSConnection as Https
from urllib import urlencode
import requests
from xml.dom import minidom

API_DOMAIN = 'api.prowlapp.com'
VERSION = '0.52'
API_DOMAIN = 'https://api.prowlapp.com'
VERSION = '0.6'

class Prowl(object):
def __init__(self, apikey, providerkey=None):
Expand All @@ -64,8 +63,7 @@ def __init__(self, apikey, providerkey=None):
"""
self.apikey = apikey
# Set User-Agent
self.headers = {'User-Agent': "Prowlpy/%s" % VERSION,
'Content-type': "application/x-www-form-urlencoded"}
self.headers = {'User-Agent': "Prowlpy/%s" % VERSION}

# Aliasing
self.add = self.post
Expand Down Expand Up @@ -125,9 +123,6 @@ def post(self, application=None, event=None,
notification.
"""

# Create the http object
h = Https(API_DOMAIN)

# Perform the request and get the response headers and content
data = {'apikey': self.apikey,
'application': application,
Expand All @@ -141,17 +136,15 @@ def post(self, application=None, event=None,
if url is not None:
data['url'] = url[0:512] # API limits to 512 characters

h.request("POST",
"/publicapi/add",
headers=self.headers,
body=urlencode(data))
response = h.getresponse()
request_status = response.status
response = requests.post(API_DOMAIN + "/publicapi/add",
data=data,
headers=self.headers)
request_status = response.status_code

if request_status == 200:
return True
else:
self._relay_error(request_status, response.reason)
self._relay_error(request_status, response.text)

def verify_key(self, providerkey=None):
"""
Expand All @@ -161,18 +154,17 @@ def verify_key(self, providerkey=None):
- providerkey (optional) : your provider API key.
Only necessary if you have been whitelisted.
"""
h = Https(API_DOMAIN)

data = {'apikey': self.apikey}

if providerkey is not None:
data['providerkey'] = providerkey

h.request("GET",
"/publicapi/verify?" + urlencode(data),
headers=self.headers)
response = requests.get(API_DOMAIN + "/publicapi/verify",
params=data,
headers=self.headers)

request_status = h.getresponse().status
request_status = response.status_code

if request_status != 200:
self._relay_error(request_status)
Expand All @@ -193,22 +185,19 @@ def retrieve_token(self, providerkey=None):
'url': u'https://www.prowlapp.com/retrieve.php?token=60fd5684'}
"""

h = Https(API_DOMAIN)

data = {'apikey': self.apikey}

if providerkey is not None:
data['providerkey'] = providerkey

h.request("GET",
"/publicapi/retrieve/token?" + urlencode(data),
headers=self.headers)
response = requests.get(API_DOMAIN + "/publicapi/retrieve/token",
params=data,
headers=self.headers)

request = h.getresponse()
request_status = request.status
request_status = request.status_code

if request_status == 200:
dom = minidom.parseString(request.read())
dom = minidom.parseString(request.text)
code = dom.getElementsByTagName('prowl')[0].\
getElementsByTagName('success')[0].\
getAttribute('code')
Expand Down Expand Up @@ -246,8 +235,6 @@ def retrieve_apikey(self, providerkey=None, token=None):
'resetdate': u'1299535575'}
"""

h = Https(API_DOMAIN)

data = {'apikey': self.apikey}

if providerkey is not None:
Expand All @@ -261,15 +248,14 @@ def retrieve_apikey(self, providerkey=None, token=None):
raise Exception("Token is required for retrieving API key.\
Call retrieve_token to request it.")

h.request("GET",
"/publicapi/retrieve/apikey?" + urlencode(data),
headers=self.headers)
response = requests.get(API_DOMAIN + "/publicapi/retrieve/apikey",
params=data,
headers=self.headers)

request = h.getresponse()
request_status = request.status
request_status = request.status_code

if request_status == 200:
dom = minidom.parseString(request.read())
dom = minidom.parseString(request.text)
code = dom.getElementsByTagName('prowl')[0].\
getElementsByTagName('success')[0].\
getAttribute('code')
Expand Down
34 changes: 0 additions & 34 deletions python/__init__.py

This file was deleted.

Loading