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

Falled back to httplib #1

Merged
merged 1 commit into from Mar 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion README.rst
Expand Up @@ -64,5 +64,4 @@ History
* 0.2 Added tags, broadcast, feedback
* 0.3 Added deregister, device token list, other minor improvements
* 0.4 Added Android C2DM APID support
* 0.41 Changed httplib to requests library (merged from Benjamin Smith's fork)
* 0.42 Merged schedule_for fork into this branch (from hkukreja)
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

24 changes: 10 additions & 14 deletions tests.py
@@ -1,19 +1,15 @@
from ConfigParser import RawConfigParser
import unittest


class iOSTest(unittest.TestCase):
def setUp(self):
conf = RawConfigParser()
conf.read('keys.ini')
self.UA_MASTER_SECRET = conf.get('keys', 'UA_MASTER_SECRET')
self.UA_APPLICATION_SECRET = conf.get('keys', 'UA_APPLICATION_SECRET')

def testKeys(self):
print self.UA_MASTER_SECRET
print self.UA_APPLICATION_SECRET


def setUp(self):
conf = RawConfigParser()
conf.read('keys.ini')
self.UA_MASTER_SECRET = conf.get('keys', 'UA_MASTER_SECRET')
self.UA_APPLICATION_SECRET = conf.get('keys', 'UA_APPLICATION_SECRET')

def testKeys(self):
print self.UA_MASTER_SECRET
print self.UA_APPLICATION_SECRET
if __name__ == '__main__':
unittest.main()

unittest.main()
21 changes: 14 additions & 7 deletions urbanairship.py
@@ -1,7 +1,7 @@
"""Python module for using the Urban Airship API"""

import httplib
import urllib
import requests
try:
import simplejson as json
except ImportError:
Expand Down Expand Up @@ -83,12 +83,19 @@ def __init__(self, key, secret):
self.auth_string = ('%s:%s' % (key, secret)).encode('base64')[:-1]

def _request(self, method, body, url, content_type=None):
headers = {'content-type': content_type}
auth = (self.key, self.secret)
r = requests.request(method, url, data=body, auth=auth, headers=headers)
if r.status_code == 401:
h = httplib.HTTPSConnection(SERVER)
headers = {
'authorization': 'Basic %s' % self.auth_string,
}
if content_type:
headers['content-type'] = content_type
h.request(method, url, body=body, headers=headers)
resp = h.getresponse()

if resp.status == 401:
import pdb; pdb.set_trace()
raise Unauthorized
return r.status_code, r.content
return resp.status, resp.read()

def register(self, device_token, alias=None, tags=None, badge=None):
"""Register the device token with UA."""
Expand Down Expand Up @@ -183,7 +190,7 @@ def push(self, payload, device_tokens=None, aliases=None, tags=None, schedule_fo
payload['aliases'] = aliases
if tags:
payload['tags'] = tags
if scheduled_for:
if schedule_for:
payload['schedule_for'] = schedule_for
body = json.dumps(payload)
status, response = self._request('POST', body, PUSH_URL,
Expand Down