Esempio n. 1
0
 def award_points(self, user_id, points_awarded, reason=""):
     """
  Function: award_points
  Description: Award points to a user
  Required Arguments: user_id (unique user identifier)
                      points_awarded 
  Optional Arguments: reason (Why they got points)
  Return value: True on success, False otherwise
 """
     argsdict = {
         "apikey": self.api_key,
         "accountid": self.account,
         "userid": user_id,
         "pointsawarded": points_awarded,
         "reason": reason
     }
     ret = None
     try:
         if self.sync_all:
             ret = self.__url_post(self.award_points_path, argsdict)
         else:
             self.__url_async_post(self.award_points_path, argsdict)
             return True
         self.debug_log("Received: %s" % ret)
     except:
         self.debug_log("Connection Error")
         if self.raise_exceptions:
             raise ui_errors.ConnectionError()
     return self.__parse_return(ret)
Esempio n. 2
0
    def remove_badge(self, user_id, badge_id):
        """
     Function: remove_badge
     Description: Remove a badge from a user
     Required Arguments: user_id (unique user identifier)
                         badge_id (unique badge identifier from 
                                   UserInfuser website under badges tab of 
                                   control panel)
     Return value: True on success, False otherwise
    """

        argsdict = {
            "apikey": self.api_key,
            "accountid": self.account,
            "userid": user_id,
            "badgeid": badge_id
        }
        ret = None
        try:
            if self.sync_all:
                ret = self.__url_post(self.remove_badge_path, argsdict)
            else:
                self.__url_async_post(self.remove_badge_path, argsdict)
                return True
            self.debug_log("Received: %s" % ret)
        except:
            self.debug_log("Connection Error")
            if self.raise_exceptions:
                raise ui_errors.ConnectionError()
        return self.__parse_return(ret)
Esempio n. 3
0
 def award_badge(self, user_id, badge_id, reason="", resource=""):
     """
  Function: award_badge
  Description: Award a badge to a user
  Required Arguments: user_id (unique user identifier)
                      badge_id (unique badge identifier from 
                                UserInfuser website under badges tab of 
                                control panel)
  Optional Arguments: reason (A short string that shows up in the user's 
                              trophy case)
                      resource (A URL that the user goes to if the badge 
                              is clicked) 
  Return value: True on success, False otherwise
 """
     argsdict = {
         "apikey": self.api_key,
         "accountid": self.account,
         "userid": user_id,
         "badgeid": badge_id,
         "resource": resource,
         "reason": reason
     }
     ret = None
     try:
         if self.sync_all:
             ret = self.__url_post(self.award_badge_path, argsdict)
         else:
             self.__url_async_post(self.award_badge_path, argsdict)
             return True
         self.debug_log("Received: %s" % ret)
     except:
         self.debug_log("Connection Error")
         if self.raise_exceptions:
             raise ui_errors.ConnectionError()
     return self.__parse_return(ret)
Esempio n. 4
0
 def update_user(self, user_id, user_name="", link_to_profile="", link_to_profile_img=""):
   """
    Function: update_user
    Description: To either add a new user, or update a user's information
    Required Arguments: user_id (unique user identifier)
    Optional Arguments: 
               user_name (The name that will show up in widgets, otherwise it
                          will use the user_id)
               link_to_profile (a URL to the user's profile)
               link_to_profile (a URL to a user's profile picture)
    Return value: True on success, False otherwise
   """
   argsdict = {"apikey":self.api_key,
              "userid":user_id,
              "accountid":self.account,
              "profile_name":user_name,
              "profile_link": link_to_profile,
              "profile_img":link_to_profile_img}
   ret = None
   try:
     if self.sync_all:
       ret = self.__url_post(self.update_user_path, argsdict)
     else: 
       self.__url_async_post(self.update_user_path, argsdict)
       return True
     self.debug_log("Received: %s"%ret)
   except:
     self.debug_log("Connection Error")
     if self.raise_exceptions:
       raise ui_errors.ConnectionError()
   return self.__parse_return(ret)
Esempio n. 5
0
    def award_badge_points(self,
                           user_id,
                           badge_id,
                           points_awarded,
                           points_required,
                           reason="",
                           resource=""):
        """
     Function: award_badge_points
     Description: Award badge points to a user. Badges can also be achieved
                  after a certain number of points are given towards an 
                  action. When that number is reached the badge is awarded to
                  the user. 
     Required Arguments: user_id (unique user identifier)
                         points_awarded 
                         badge_id (unique badge identifier from 
                                   UserInfuser website under badges tab of 
                                   control panel)
                         points_required (The total number of points a user must
                                   collect to get the badge)
     Optional Arguments: reason (Why they got the badge points)
                         resource (URL link to assign to badge)
     Return value: True on success, False otherwise
    """
        argsdict = {
            "apikey": self.api_key,
            "accountid": self.account,
            "userid": user_id,
            "badgeid": badge_id,
            "pointsawarded": points_awarded,
            "pointsrequired": points_required,
            "reason": reason,
            "resource": resource
        }
        ret = None
        try:
            if self.sync_all:
                ret = self.__url_post(self.award_badge_points_path, argsdict)
            else:
                self.__url_async_post(self.award_badge_points_path, argsdict)
                return True
            self.debug_log("Received: %s" % ret)
        except:
            self.debug_log("Connection Error")
            if self.raise_exceptions:
                raise ui_errors.ConnectionError()
            return False

        return self.__parse_return(ret)
Esempio n. 6
0
 def create_badge(self, badge_name, badge_theme, description, link):
   """ Hidden Menu APIs """
   """ Badges should be created using the console """
   argsdict = {"apikey":self.api_key,
              "accountid":self.account,
              "name":badge_name,
              "theme":badge_theme,
              "description":description,
              "imagelink":link}
   ret = None
   try:
     ret = self.__url_post(self.create_badge_path, argsdict)
   except:
     self.debug_log("Connection Error")
     if self.raise_exceptions:
       raise ui_errors.ConnectionError()
   return self.__parse_return(ret)
Esempio n. 7
0
    def get_user_data(self, user_id):
        """
     Function: get_user_data
     Arguments: user_id
                The user id is a unique identifier. It could be an email or 
                unique name. 
     Return value: Returns a dictionary of information about the user
           example:
           {"status": "success", 
            "is_enabled": "yes", 
            "points": 200, 
            "user_id": "*****@*****.**", 
            "badges": ["muzaktheme-guitar-private", 
                       "muzaktheme-bass-private", 
                       "muzaktheme-drums-private"], 
            "profile_img": "http://test.com/images/raj.png",
            "profile_name": "Raj Chohan", 
            "profile_link": "http://test.com/nlake44", 
            "creation_date": "2011-02-26"} 
     Notes: This function is always synchronous. It will add latency into 
            your application/web site.
    """
        argsdict = {
            "apikey": self.api_key,
            "userid": user_id,
            "accountid": self.account
        }
        ret = '{"status":"failed"}'
        try:
            ret = self.__url_post(self.get_user_data_path, argsdict)
            self.debug_log("Received: %s" % ret)
        except:
            self.debug_log("Connection Error")
            if self.raise_exceptions:
                raise ui_errors.ConnectionError()

        try:
            ret = json.loads(ret)
        except:
            self.debug_log("Unable to parse return message")
        return ret