Commits

Peter Rudenko committed 6955d97

API refactor

Comments (0)

Files changed (1)

templeton/src/templeton/api.py

 
 class Templeton(object):
 
-    def get(self, url, data):
+    def __init__(self, user="hdfs"):
+        self.user = user
+
+    def get(self, url, data=None):
         """
         Make GET query to templeton url.
         """
+        if data is not None:
+            data['user.name'] = self.user
+        else:
+            data = {"user.name": self.user}
         data = urllib.urlencode(data)
-        print TEMPLETON_URL + url + "?" + data
         response = urllib2.urlopen(TEMPLETON_URL + url + "?" + data)
         return json.loads(response.read())
 
-    def post(self, url, data):
+    def post(self, url, data=None):
         """
         Make POST query to templeton url.
         """
+        if data is not None:
+            data['user.name'] = self.user
+        else:
+            data = {"user.name": self.user}
         data = urllib.urlencode(data)
         req = urllib2.Request(TEMPLETON_URL + url, data)
         response = urllib2.urlopen(req)
-        return json.loads(response.read()) 
+        return json.loads(response.read())
 
 
-    def pig_query(self, user="hdfs", execute=None, pig_file=None, statusdir=None, callback=None):
+    def pig_query(self, execute=None, pig_file=None, statusdir=None, callback=None):
         """
         Create and queue a Pig job.
 
         """
         if not any([execute, pig_file]):
             raise Exception("""One of either "execcute" or "file" is required""")
-        data = {"user.name": user}
+        data = {}
         if execute:
             data['execute'] = execute
         if pig_file:
         """
         Check the status of a job and get related job information given its job ID.
         """
-        data = {'user.name': user}
-        return self.get("queue/%s" % job_id, data)
+        return self.get("queue/%s" % job_id)
 
     def show_hcat_tables(self, user="hdfs", db="default"):
         """
         List the tables in an HCatalog database.
         """
-        data = {'user.name': user}
-        return self.get("ddl/database/%s/table" % db, data)['tables']
+        return self.get("ddl/database/%s/table" % db)['tables']
         
             
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.