Skip to content

Commit

Permalink
fix #5 Pretty awesome
Browse files Browse the repository at this point in the history
  • Loading branch information
josuebrunel committed Aug 16, 2014
1 parent b29597f commit c69ad06
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lokingyql/lokingyql.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, table=None, url=default_url, format='json'):
self.table = table
self.format = format
self._query = None # used to build query when using methods such as <select>, <insert>, ...
self.diagnostics = True # Who knows, someone would like to turn it off

def __repr__(self):
'''Returns information on the current instance
Expand All @@ -24,7 +25,7 @@ def payloadBuilder(self, query, format='json'):
payload = {
'q' : query,
'callback' : '', #This is not javascript
'diagnostics' : 'true', # always true
'diagnostics' : self.diagnostics, # always true
'format' : format
}

Expand Down Expand Up @@ -89,7 +90,8 @@ def use(self, url):

def select(self, table=None, items=[]):
'''This method simulate a select on a table
>>> yql.select('table')
>>> yql.select('table')
>>> yql.select('social.profile', ['guuid', 'givenName', 'gender'])
'''
try:
self.table = table
Expand All @@ -114,9 +116,28 @@ def where(self, *args):
x = self.clauseFormatter(x)
clause.append(x)

self._query += ' and '.join(clause)
return self._query
self._query += ' and '.join(clause)

payload = self.payloadBuilder(self._query)
response = self.executeQuery(payload)

return response

######################################################
#
# HELPERS
#
#####################################################

def getGUID(self, username):
'''Returns the guid of the username provided
>>> guid = self.getGUID('josue_brunel')
>>> guid
'''
response = self.select('yahoo.identity').where(['yid', '=', username])

return response

def showTables(self, format='json'):
'''Return list of all avaible tables'''

Expand Down

0 comments on commit c69ad06

Please sign in to comment.