当前位置: 首页>>代码示例>>Python>>正文


Python ContactClient.put方法代码示例

本文整理汇总了Python中newebe.lib.http_util.ContactClient.put方法的典型用法代码示例。如果您正苦于以下问题:Python ContactClient.put方法的具体用法?Python ContactClient.put怎么用?Python ContactClient.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在newebe.lib.http_util.ContactClient的用法示例。


在下文中一共展示了ContactClient.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: put

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import put [as 别名]
    def put(self, key):
        '''
        Resend deletion of micropost with *key* as key to the contact given in
        the posted JSON. Corresponding activity ID is given inside the posted
        json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''

        data = self.get_body_as_dict(
                expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:

                user = UserManager.getUser()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date)
                )

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact, CONTACT_PATH, body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                                "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                        "Micropost correctly redeleted.")

                except:
                    self.return_failure("Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:62,代码来源:handlers.py

示例2: forward_to_contact

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import put [as 别名]
    def forward_to_contact(self, common, contact, activity, method="POST"):
        '''
        *common is sent to *contact* via a request of which method is set
        as *method*. If request succeeds, error linked to this contact
        is removed. Else nothing is done and error code is returned.
        '''

        client = ContactClient()
        body = common.toJson()

        try:
            if method == "POST":
                client.post(contact, CONTACT_PATH, body,
                            callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")
            else:
                body = common.toJson(localized=False)
                response = client.put(contact, CONTACT_PATH, body,
                                      callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")

            if response.error:
                message = "Retry common request to a contact failed ({})."
                self.return_failure(message.format(method))

            else:
                for error in activity.errors:
                    if error["contactKey"] == contact.key:
                        activity.errors.remove(error)
                        activity.save()
                        self.return_success("Common request correctly resent.")

        except:
            self.return_failure("Common resend to a contact failed again.")
开发者ID:DopeChicCity,项目名称:newebe,代码行数:36,代码来源:handlers.py

示例3: forward_to_contact

# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import put [as 别名]
    def forward_to_contact(self, picture, contact, activity, method = "POST"):
        '''
        *picture is sent to *contact* via a request of which method is set 
        as *method*. If request succeeds, error linked to this contact
        is removed. Else nothing is done and error code is returned.
        '''

        client = ContactClient()            

        try:

            if method == "POST":
                
                client.post_files(contact, CONTACT_PATH, 
                              { "json": str(picture.toJson(localized=False)) },
                              [("picture", str(picture.path), 
                               picture.fetch_attachment("th_" + picture.path))],
                              callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")

            else:                
                body = picture.toJson(localized=False)
                response = client.put(contact, CONTACT_PATH, body, 
                                      callback=(yield gen.Callback("retry")))
                response = yield gen.Wait("retry")

            if response.error:
                self.return_failure(
                  "Retry picture request to a contact failed ({}).".format(method))

            else:
                for error in activity.errors:
                    if error["contactKey"] == contact.key:
                        activity.errors.remove(error)
                        activity.save()
                        self.return_success("Picture request correctly resent.")

        except:
            self.return_failure("Picture resend to a contact failed again.")
开发者ID:mike-perdide,项目名称:newebe,代码行数:41,代码来源:handlers.py


注:本文中的newebe.lib.http_util.ContactClient.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。