def login_member(self, name, pswd): print "Trying to login..." data = {} self.username = name self.password = pswd #api = rhapapi.Api() result = self.app.api.login_member(name, pswd) utils.prettyprint(result) #try: if result: if "access_token" in result: self.access_token = result["access_token"] self.catalog = result["catalog"] #self.expires_in = utils.eval_unicode(result["expires_in"]) #old self.expires_in = result["expires_in"] self.first_name = result["first_name"] self.guid = result["guid"] #self.issued_at = result["issued_at"] self.last_name = result["last_name"] self.refresh_token = result["refresh_token"] print "Successful! Grabbing account details now, too." self.app.api.token = self.access_token self.get_member_details() data['logged_in'] = True data['bad_creds'] = False self.save_user_info() return data else: print "Login failed. Try again." data['logged_in'] = False data['bad_creds'] = True return data
def add_album_to_library(self, alb_id): print "Rhapapi: Add album %s to library" % (alb_id) data = {"id": alb_id} data = json.dumps(data) url = "%sme/library/albums" % (self.S_BASEURL) req = self.__build_member_req(url) req.add_header('Content-Type', 'application/json') req.add_data(data) results = self.__get_data_from_rhapsody(req, 5) if results: print "results:" utils.prettyprint(results) return True else: return False
def add_album_to_library(self, alb_id): print "Rhapapi: Add album %s to library" % (alb_id) data = {"id": alb_id} data = json.dumps(data) url = "%sme/library/albums" % (self.S_BASEURL) req = self.__build_member_req(url) req.add_header("Content-Type", "application/json") req.add_data(data) results = self.__get_data_from_rhapsody(req, 5) if results: print "results:" utils.prettyprint(results) return True else: return False