if not self.username or not self.password: raise LoginError('password or username not specified')
self._login()
+ def logout(self):
+ """Logs out from a pod.
+ When logged out you can't do anything.
+ """
+ self.get('users/sign_out')
+
def podswitch(self, pod):
"""Switches pod from current to another one.
"""
def __str__(self):
"""Returns text of a post.
"""
- return self.get_data['text']
+ return self.get_data()['text']
def get_data(self):
"""This function retrieves data of the post.
_location = 'aspects.json'
_id_regexp = re.compile(r'<a href="/aspects/[0-9]+/edit" rel="facebox"')
+ def getID(self, aspect):
+ """Returns id of an aspect of given name.
+ Returns -1 if aspect is not found.
+
+ :param aspect: aspect name (must be spelled exactly as when created)
+ :type aspect: str
+ :returns: int
+ """
+ id = -1
+ regexp = re.compile("a_id=[0-9]+'>\s+{0}".format(aspect))
+ result = regexp.search(self._connection.get('aspects').text)
+ if result is not None:
+ id = int(re.compile('[0-9]+').search(result.group(0)).group(0))
+ return id
+
def filterByIDs(self, ids):
self._location += '?{0}'.format(','.join(ids))
self.fill()
"""
data = {'authenticity_token': self._connection.get_token()}
request = self._connection.delete('aspects/{}'.format(aspect_id),
- data=data)
+ data=data)
if request.status_code not in [404, 500]:
raise Exception('wrong status code: {0}'.format(request.status_code))
aspects = diaspy.streams.Aspects(test_connection)
test_aspect_id = aspects.add('diaspy-test')
+ def testAspectsGettingID(self):
+ aspects = diaspy.streams.Aspects(test_connection)
+ id = aspects.getID('Coding')
+ self.assertEqual(int, type(id))
+ self.assertNotEqual(-1, id)
+
def testAspectsRemove(self):
aspects = diaspy.streams.Aspects(test_connection)
aspects.remove(test_aspect_id)