本文整理汇总了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)
示例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.")
示例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.")