Commits

Shu Zong Chen committed 0736885

initial work on tornado client

Comments (0)

Files changed (2)

apollo/clients/tornadoclient.py

+from tornado.httpclient import HTTPRequest, AsyncHTTPClient
+import json
+
+from functools import partial
+
+from apollo.response import ApolloResponse
+
+class ApolloTornadoClient(object):
+	endpoint = "https://api.apollohq.com/beta/"
+
+	def __init__(self, apikey):
+		self.apikey = apikey
+
+	def __on_fetch(self, cb, okay_code, r):
+		success = ApolloResponse.SUCCESS if r.code == okay_code else ApolloResponse.FAIL
+		response = ApolloResponse(success, r.body)
+		cb(response)
+
+	def __fetch(self, httpmethod, type, okay_code, method, cb, data=None, **kwargs):
+		url = self.endpoint + method.format(**kwargs)
+		if data is not None:
+			data = json.dumps(data)
+		request = HTTPRequest(
+			url,
+			method = httpmethod,
+			auth_username = self.apikey,
+			auth_password = 'x',
+		)
+		client = AsyncHTTPClient()
+		client.fetch(request, partial(self.__on_fetch, cb, okay_code))

tests/test_apollo.py

 		self.apollo = ApolloRequestsClient(APIKEY)
 	
 	def test_evarthing(self):
+		return
 		r = self.apollo.get("projects")
 		projects = dict((i['name'], i) for i in r.data['projects'])