Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Falled back to httplib #1

Merged
merged 1 commit into from

2 participants

@xarg

As discussed on the #3 we should remove the httplib to avoid needless requirements.

@makaimc makaimc merged commit 6decb02 into makaimc:master
@makaimc
Owner

Sorry it took me so long to merge this request, thanks!

@xarg

No problem. Hope the peoples at UA will pull our changes this century.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 23 deletions.
  1. +0 −1  README.rst
  2. +0 −1  requirements.txt
  3. +10 −14 tests.py
  4. +14 −7 urbanairship.py
View
1  README.rst
@@ -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)
View
1  requirements.txt
@@ -1 +0,0 @@
-requests
View
24 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()
View
21 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:
@@ -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."""
@@ -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,
Something went wrong with that request. Please try again.