def init_in_fluid(self, name, description): pp("creating namespace...") namespace_info = { 'name': name, 'description': description } headers, response = fluidinfo.call('POST', self.parent_namespace(), namespace_info) # TODO check headers self.fluid_id = response['id'] self.fluid_url = response['URI'] pp(headers) pp(response) tag_info = { 'name' : 'element', 'description' : 'Tag indicating that object is part of a list', 'indexed' : False } headers, response = fluidinfo.call('POST', "/tags/%s/biar/collections/%s" % (self.connection.username, self.name), tag_info) # TODO check headers pp(headers) pp(response)
def set_canonical_tag(self, name, value=None): namespace = '/namespaces/biar' headers, response = fluidinfo.call('GET', namespace, returnTags=True) if not headers['status'] == '200': raise Exception("namespace %s does not exist" % namespace) if not name in response['tagNames']: raise Exception("tag %s not found in namespace" % (name, namespace)) tag_path = "/objects/%s/%s/%s" % (self.object_id, 'biar', name) headers, response = fluidinfo.call('PUT', tag_path, value)
def test_call_POST(self): fluidinfo.login(USERNAME, PASSWORD) new_namespace = str(uuid.uuid4()) ns_body = {'description': 'a test namespace', 'name': new_namespace} # Make sure that if the body is a dict it gets translated to json result = fluidinfo.post('/namespaces/test', ns_body) self.assertEqual('201', result[0]['status']) self.assertTrue(result[1].has_key('id')) # Housekeeping fluidinfo.call('DELETE', '/namespaces/test/'+new_namespace)
def list_all(klass, connection): # FIXME couldn't find a way of getting this to work. # We need to match all objects based on <username>/biar/collections # Tried to query on fluiddb path 'fluiddb/namespaces/path matches "ananelson/biar/collections"') headers, response = fluidinfo.call('GET', '/objects', query='fluiddb/namespaces/path matches "svanderwaal/biar/videos/title"') print headers print response for obj_id in response['ids']: object_tag_path = "/objects/%s/%s" % (obj_id, LIST_TAG) details_h, details_response = fluidinfo.call('GET', object_tag_path) pp(details_response) pass
def setPermOnTag(foo): permission_space = "/permissions/tags/biar/%s" % foo permission_info = { "policy": "closed", "exceptions": ["birukou", "ianmulvany", "axiomsofchoice", "svanderwaal", "ananelson", "biar"], } fluidinfo.call("PUT", permission_space, permission_info, action="create") print headers print response fluidinfo.call("PUT", permission_space, permission_info, action="delete") print headers print response
def get(self, page): user = users.get_current_user() if re.match("^[A-Za-z0-9_-]*$", page): # the page displayed if the root url is requested if not page: self.response.out.write('404') elif page == 'usernamefree': username = self.request.get("u") query = skillshelves.DBUsers.all() query.filter('username = '******'ne') else: self.response.out.write('jo') elif page == 'addbooktouser': objectid = self.request.get("o") if user and skillshelves.get_username(user) : # create users tag on fluidinfo skillshelves.connectToFluidinfo() headers, content = fluidinfo.call('PUT', '/objects/' + objectid + '/' + skillshelves.fluidinfoRootNamespace() + '/user/' + skillshelves.get_username(user), body='has') self.response.out.write('jo') self.response.out.write(headers) self.response.out.write(content) else: self.response.out.write('ne') elif page == 'deletebookfromuser': objectid = self.request.get("o") if user and skillshelves.get_username(user) : # delete users tag on fluidinfo skillshelves.connectToFluidinfo() headers, content = fluidinfo.call('DELETE', '/objects/' + objectid + '/' + skillshelves.fluidinfoRootNamespace() + '/user/' + skillshelves.get_username(user)) self.response.out.write('jo') else: self.response.out.write('ne') else: self.response.out.write('404')
def list_works(self): querystring = "has %s/biar/collections/%s/element" % ( self.connection.username, self.name) headers, response = fluidinfo.call('GET', '/objects', query=querystring) # TODO check headers return response['ids']
def setPermOnTag(foo): permission_space = '/permissions/tags/biar/%s' % foo permission_info = { 'policy': 'closed', 'exceptions': [ 'birukou', 'ianmulvany', 'axiomsofchoice', 'svanderwaal', 'ananelson', 'biar' ] } fluidinfo.call('PUT', permission_space, permission_info, action="create") print headers print response fluidinfo.call('PUT', permission_space, permission_info, action="delete") print headers print response
def exists_in_fluid(self): headers, response = fluidinfo.call('GET', self.collection_namespace()) if headers['status'] == '200': self.fluid_id = response['id'] return True elif headers['status'] == '404': return False else: raise Exception("unexpected status code %s" % headers['status'])
def list_all(klass, connection): # FIXME couldn't find a way of getting this to work. # We need to match all objects based on <username>/biar/collections # Tried to query on fluiddb path 'fluiddb/namespaces/path matches "ananelson/biar/collections"') headers, response = fluidinfo.call( 'GET', '/objects', query= 'fluiddb/namespaces/path matches "svanderwaal/biar/videos/title"') print headers print response for obj_id in response['ids']: object_tag_path = "/objects/%s/%s" % (obj_id, LIST_TAG) details_h, details_response = fluidinfo.call( 'GET', object_tag_path) pp(details_response) pass
def markAsRead(username, query): """ Attempts to mark the appropriate objects as read on the current date. Will log any failures but won't report them via the command line. """ payload = {'%s/has-read' % username: {'value': '%s' % date.today().isoformat()}} logger.info('Updating objects with query: %s' % query) logger.info('Updating objects with payload: %r' % payload) logger.info(fluidinfo.call('PUT', '/values', payload, query=query))
def init_in_fluid(self, name, description): pp("creating namespace...") namespace_info = {'name': name, 'description': description} headers, response = fluidinfo.call('POST', self.parent_namespace(), namespace_info) # TODO check headers self.fluid_id = response['id'] self.fluid_url = response['URI'] pp(headers) pp(response) tag_info = { 'name': 'element', 'description': 'Tag indicating that object is part of a list', 'indexed': False } headers, response = fluidinfo.call( 'POST', "/tags/%s/biar/collections/%s" % (self.connection.username, self.name), tag_info) # TODO check headers pp(headers) pp(response)
def markAsRead(username, query): """ Attempts to mark the appropriate objects as read on the current date. Will log any failures but won't report them via the command line. """ payload = { '%s/has-read' % username: { 'value': '%s' % date.today().isoformat() } } logger.info('Updating objects with query: %s' % query) logger.info('Updating objects with payload: %r' % payload) logger.info(fluidinfo.call('PUT', '/values', payload, query=query))
def getResultsFromFluidinfo(tags, query): """ Does exactly what it says on the tin... :-) """ logger.info('Fetching results from Fluidinfo') print "Fetching result from Fluidinfo..." headers, results = fluidinfo.call('GET', '/values', tags=tags, query=query) logger.info(headers) if headers['status'] == '200': print 'OK' return results else: print 'There was a problem getting your results. Check the log!' logger.warning('Problem getting results. Check the headers above.') return {}
def createHasRead(username): """ Asks for confirmation to create the 'has-read' tag under the user's root namespace. """ logger.info("Processing has-read tag") confirmation = raw_input("Create 'has-read' tag..? [y/n]").lower() if confirmation == 'y': path = '/tags/%s' % username payload = {'name': 'has-read', 'description': 'Indicates the referenced object has been read by the user on a'\ ' particular date (stored as a string representation of ISO date).', 'indexed': False} logger.info(fluidinfo.call('POST', path, payload)) else: logger.info("Has-read tag ignored/declined")
import os import urllib ### @export "fluid-login" USERNAME = "******" PASSWORD = "******" if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call("GET", "/users/%s" % USERNAME) print response ### @export "set-tag-permissions" taglist = [ "author", "keyword", "series" "is_video", "is_blog_post", "volume", "year", "name", "pmid", "short-name", "grant_id", "wonga",
def get(self, page): # this is the dictionary in which we keep all template values template_values = { 'skillshelves_logo' : '<span class="skillshelves"><span class="blue">S</span><span class="lightblue">K</span><span class="orange">I</span><span class="blue">L</span><span class="lightblue">L</span><span class="orange">S</span><span class="blue">H</span><span class="lightblue">E</span><span class="orange">L</span><span class="blue">V</span><span class="lightblue">E</span><span class="orange">S</span></span>', 'skillshelf_logo' : '<span class="skillshelves"><span class="blue">S</span><span class="lightblue">K</span><span class="orange">I</span><span class="blue">L</span><span class="lightblue">L</span><span class="orange">S</span><span class="blue">H</span><span class="lightblue">E</span><span class="orange">L</span><span class="blue">F</span></span>' } # determine the oauth username of the currently logged in user user = users.get_current_user() if user: # signed in already template_values["user_nickname"] = user.nickname() template_values["user_email"] = user.email() template_values["user_id"] = user.user_id() template_values["federated_identity"] = user.federated_identity() template_values["federated_provider"] = user.federated_provider() template_values['logout_url'] = users.create_logout_url('/_logout') if skillshelves.do_we_know_this_guy(user): template_values['username'] = skillshelves.get_username(user) else: template_values["google_login_url"] = users.create_login_url(federated_identity='google.com/accounts/o8/id', dest_url='/_login') template_values["yahoo_login_url"] = users.create_login_url(federated_identity='yahoo.com', dest_url='/_login') template_values["myspace_login_url"] = users.create_login_url(federated_identity='myspace.com', dest_url='/_login') template_values["aol_login_url"] = users.create_login_url(federated_identity='aol.com', dest_url='/_login') template_values["myopenid_login_url"] = users.create_login_url(federated_identity='myopenid.com', dest_url='/_login') # the list of tags is needed in various places, so we make it globally available to any page template_values["tag_list"] = [] template_values['taglistasurlparams'] = '' tag_list = skillshelves.get_tag_list() for tag in tag_list : template_values["tag_list"].append(tag) template_values['taglistasurlparams'] = template_values['taglistasurlparams'] + '&tag=skillshelves/skills/' + tag['tag'] if re.match("^[A-Za-z0-9_-]*$", page): # ROOT URL if not page or page == '_main': if not user or not skillshelves.do_we_know_this_guy(user): page = '_main' else: self.redirect('/_my_skillshelf') # USERPAGE elif page[0] != '_': # not in ['_404', '_main', '_login', '_loginform', '_register', '_logout', '_my_skillshelf', '_addbooks', '_managebooks']: template_values["whose_shelf"] = page page = 'userpage' # BOOK elif page == '_book': template_values['bookid'] = self.request.get('b') # TAG elif page == '_tag': requestedtag = self.request.get('t') template_values['requestedtagdisplay'] = 'Skill Information' for item in tag_list: if item['tag'] == requestedtag: template_values['requestedtag'] = item['tag'] template_values['requestedtagdisplay'] = item['display'] # TAG LIST # nothing to be said here # REGISTER if page == '_register': if user and len(self.request.get('username')) > 2 and len(self.request.get('email')) > 6: theusername = self.request.get('username') # store user in database newuser = skillshelves.DBUsers() newuser.federated_identity = user.federated_identity() newuser.federated_provider = user.federated_provider() newuser.user_id = user.user_id() newuser.username = theusername newuser.email = self.request.get('email') newuser.put() # create users tag on fluidinfo skillshelves.connectToFluidinfo() result = fluidinfo.call('POST', '/tags/' + skillshelves.fluidinfoRootNamespace() + '/user', {'indexed': True, 'description': 'www.skillshelv.es uses this tag to show that the user ' + theusername + ' has this book on her Skillshelf', 'name': theusername}) template_values["log_list"] = result page = '_addbooks' else: self.redirect('_login') # SELECT BOOKS if page == '_addbooks' or page == '_managebooks': if not user: self.redirect('_login') else: if page == '_addbooks': template_values["booklisttitle"] = 'fill your skillshelf' template_values["pagetitle"] = 'fill your skillshelf' else: template_values["booklisttitle"] = 'add/remove books' template_values["pagetitle"] = 'add/remove books' page = '_addbooks' # RANDOM SKILLSHELF if page == '_random': random.seed() userno = random.randint(0, skillshelves.get_user_count() - 1) query = skillshelves.DBUsers.all() dbresult = query.fetch(userno+1) # make sure it actually exists if len(dbresult)-1 < userno: userno = random.randint(0, len(dbresult)-1) self.redirect('/' + dbresult[userno].username) # LOGIN if page == '_login': if not user: page = '_loginform' # it's not really a loginform, just links for logging in elif skillshelves.do_we_know_this_guy(user): self.redirect('_my_skillshelf') else: # display the form that users see on first login suggestedusername = user.nickname() while not suggestedusername.isalnum() and not suggestedusername == '': suggestedusername = suggestedusername[0:len(suggestedusername)-2] template_values["suggestedusername"] = suggestedusername # MY SKILLSHELF if page == '_my_skillshelf' or page == '_my-skills': if not user: self.redirect('/_login') else: template_values["whose_shelf"] = skillshelves.get_username(user) # what if we figured out to show a page for which we don't actually have a template? # should never happen if not os.path.exists(page + '.html'): page = '_404' else: page = '_404' template_values["page"] = page template_values["page_filename"] = page + '.html' path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, template_values))
import json import os USERNAME = os.environ["FLUID_USERNAME"] PASSWORD = os.environ["FLUID_PASSWORD"] if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) # Create an object for an interesting book r,payload = fluidinfo.call('POST', "/about/I Can Has Cheezburger?: A Lolcat Colleckshun") cheezburgerId = payload['id'] """ # Create a namespace to put some tags into parent_namespace = '/namespaces/axiomsofchoice' namespace_info = { 'name': 'biar', 'description': 'Beyond Impact Attribution Registry' } print "%s\n%s" % fluidinfo.call('POST', parent_namespace, namespace_info) # Create a new tag for allowing me to like stuff namespace = '/tags/axiomsofchoice/biar' tag_info = {
def get_personal_tag(self, name): namespace = "/namespaces/%s/biar" % self.connection.username tag_path = "/objects/%s/%s/biar/%s" % (self.object_id, self.connection.username, name) headers, response = fluidinfo.call('GET', tag_path) return response
#!/usr/bin/env python import os import sys import fluidinfo from urllib import quote fluidinfo.login("twitter.com", os.environ["FLUIDINFO_TWITTER_PASSWORD"]) tags = sys.stdin.readlines() ntags = len(tags) for i, tag in enumerate(tags): tag = quote(tag[:-1]) hdrs, response = fluidinfo.call("DELETE", "/tags/%s" % tag) if hdrs["status"] == "204": print "%d/%d deleted %s", (i + 1, ntags, tag) else: print "%d/%d failed deleting %s: %s" % (i + 1, ntags, tag, hdrs)
def get_canonical_tag(self, name): namespace = "/namespaces/biar" tag_path = "/objects/%s/biar/%s" % (self.object_id,name) headers, response = fluidinfo.call('GET', tag_path) return response
def user_info(self): headers, response = fluidinfo.call('GET', "/users/%s" % self.username) return response
def list_works(self): querystring = "has %s/biar/collections/%s/element" % (self.connection.username, self.name) headers, response = fluidinfo.call('GET', '/objects', query=querystring) # TODO check headers return response['ids']
pp = pprint.PrettyPrinter(indent=4) ### @export "fluid-login" USERNAME = os.environ["FLUID_USERNAME"] PASSWORD = os.environ["FLUID_PASSWORD"] if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME) print response ### @export "create-named-object" headers, response = fluidinfo.call('POST', "/about/mybook") print "headers from creating named object:" pp.pprint(headers) print "response from creating named object:" pp.pprint(response) ### @export "create-anonymous-object" headers, response = fluidinfo.call('POST', '/objects/') print "headers from creating anonymous object:" pp.pprint(headers) print "response from creating anonymous object:"
def add_work(self, work): tag_path = "/objects/%s/%s/biar/collections/%s/%s" % ( work.object_id, self.connection.username, self.name, 'element') headers, response = fluidinfo.call('PUT', tag_path)
import json import os USERNAME = os.environ["FLUID_USERNAME"] PASSWORD = os.environ["FLUID_PASSWORD"] if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) # Create an object for an interesting book r, payload = fluidinfo.call( 'POST', "/about/I Can Has Cheezburger?: A Lolcat Colleckshun") cheezburgerId = payload['id'] """ # Create a namespace to put some tags into parent_namespace = '/namespaces/axiomsofchoice' namespace_info = { 'name': 'biar', 'description': 'Beyond Impact Attribution Registry' } print "%s\n%s" % fluidinfo.call('POST', parent_namespace, namespace_info) # Create a new tag for allowing me to like stuff namespace = '/tags/axiomsofchoice/biar' tag_info = { 'name': 'likes', 'description': 'Things I like.', 'indexed': False
def create(klass, connection): """Create a new, blank work.""" headers, response = fluidinfo.call('POST', '/objects/') work = klass(response['id']) work.connection = connection return work
import os import urllib ### @export "fluid-login" USERNAME = '******' PASSWORD = '******' if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME) print response ### @export "set-tag-permissions" taglist = [ 'author', 'keyword', 'series' 'is_video', 'is_blog_post', 'volume', 'year', 'name', 'pmid', 'short-name', 'grant_id', 'wonga' ] def setPermOnTag(foo): permission_space = '/permissions/tags/biar/%s' % foo permission_info = { 'policy':
import os import urllib ### @export "fluid-login" USERNAME = '******' PASSWORD = '******' if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME) print response ### @export "set-namespace-permissions" permission_space = '/permissions/namespaces/biar' permission_info = { 'policy': 'closed', 'exceptions': [ 'biar', 'birukou', 'ianmulvany', 'axiomsofchoice', 'svanderwaal', 'ananelson' ] } fluidinfo.call('PUT', permission_space, permission_info, action="create") fluidinfo.call('PUT', permission_space, permission_info, action="update") fluidinfo.call('PUT', permission_space, permission_info, action="delete")
def get_canonical_tag(self, name): namespace = "/namespaces/biar" tag_path = "/objects/%s/biar/%s" % (self.object_id, name) headers, response = fluidinfo.call('GET', tag_path) return response
import os import urllib ### @export "fluid-login" USERNAME = '******' PASSWORD = '******' if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME) print response ### @export "set-namespace-permissions" permission_space = '/permissions/namespaces/biar' permission_info = { 'policy': 'closed', 'exceptions': ['birukou', 'ianmulvany', 'axiomsofchoice', 'svanderwaal', 'ananelson', 'biar'] } fluidinfo.call('PUT', permission_space, permission_info, action="create") print headers print response fluidinfo.call('PUT', permission_space, permission_info, action="update") print headers print response fluidinfo.call('PUT', permission_space, permission_info, action="delete")
def add_work(self, work): tag_path = "/objects/%s/%s/biar/collections/%s/%s" % (work.object_id, self.connection.username, self.name, 'element') headers, response = fluidinfo.call('PUT', tag_path)
pp = pprint.PrettyPrinter(indent=4) ### @export "fluid-login" USERNAME = os.environ["FLUID_USERNAME"] PASSWORD = os.environ["FLUID_PASSWORD"] if not USERNAME: raise Exception("Please supply a fluid account username") if not PASSWORD: raise Exception("Please supply a fluid account password") fluidinfo.login(USERNAME, PASSWORD) headers, response = fluidinfo.call('GET', "/users/%s" % USERNAME) print response ### @export "create-named-object" headers, response = fluidinfo.call('POST', "/about/mybook") print "headers from creating named object:" pp.pprint(headers) print "response from creating named object:" pp.pprint(response) ### @export "create-anonymous-object" headers, response = fluidinfo.call('POST', '/objects/') print "headers from creating anonymous object:" pp.pprint(headers) print "response from creating anonymous object:" pp.pprint(response)