Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return HelpdeskCommentRequest(self).post(self.endpoint.comments, article, comment)
@extract_id(Article)
def update(self, article, comment):
return HelpdeskCommentRequest(self).put(self.endpoint.comments_update, article, comment)
@extract_id(Article, Comment)
def delete(self, article, comment):
return HelpdeskCommentRequest(self).delete(self.endpoint.comments_delete, article, comment)
@extract_id(User)
def user_comments(self, user):
return self._query_zendesk(self.endpoint.user_comments, object_type='comment', id=user)
class CategoryApi(HelpCentreApiBase, CRUDApi, TranslationApi):
def articles(self, category_id):
return self._query_zendesk(self.endpoint.articles, 'article', id=category_id)
def sections(self, category_id):
return self._query_zendesk(self.endpoint.sections, 'section', id=category_id)
class AccessPolicyApi(Api):
@extract_id(Topic, Section)
def access_policies(self, help_centre_object):
return self._query_zendesk(self.endpoint.access_policies, 'access_policy', id=help_centre_object)
@extract_id(Topic, Section)
def update_access_policy(self, help_centre_object, access_policy):
return AccessPolicyRequest(self).put(self.endpoint.access_policies, help_centre_object, access_policy)
def sections(self, category_id):
return self._query_zendesk(self.endpoint.sections, 'section', id=category_id)
class AccessPolicyApi(Api):
@extract_id(Topic, Section)
def access_policies(self, help_centre_object):
return self._query_zendesk(self.endpoint.access_policies, 'access_policy', id=help_centre_object)
@extract_id(Topic, Section)
def update_access_policy(self, help_centre_object, access_policy):
return AccessPolicyRequest(self).put(self.endpoint.access_policies, help_centre_object, access_policy)
class SectionApi(HelpCentreApiBase, CRUDApi, TranslationApi, SubscriptionApi, AccessPolicyApi):
@extract_id(Section)
def articles(self, section):
return self._query_zendesk(self.endpoint.articles, 'article', id=section)
class ArticleAttachmentApi(HelpCentreApiBase, SubscriptionApi):
@extract_id(Article)
def __call__(self, article):
return self._query_zendesk(self.endpoint, 'article_attachment', id=article)
@extract_id(Article)
def inline(self, article):
return self._query_zendesk(self.endpoint.inline, 'article_attachment', id=article)
@extract_id(Article)
def block(self, article):
class UserSegmentApi(HelpCentreApiBase, CRUDApi):
def applicable(self):
return self._query_zendesk(self.endpoint.applicable, object_type='user_segment')
@extract_id(Section)
def sections(self, section):
return self._query_zendesk(self.endpoint.sections, object_type='section', id=section)
@extract_id(Topic)
def topics(self, topic):
return self._query_zendesk(self.endpoint.topics, object_type='topic', id=topic)
class HelpCentreApi(HelpCentreApiBase):
def __init__(self, config):
super(HelpCentreApi, self).__init__(config, endpoint=EndpointFactory('help_centre'), object_type='help_centre')
self.articles = ArticleApi(config, self.endpoint.articles, object_type='article')
self.comments = CommentApi(config, self.endpoint.articles, object_type='comment')
self.sections = SectionApi(config, self.endpoint.sections, object_type='section')
self.categories = CategoryApi(config, self.endpoint.categories, object_type='category')
self.attachments = ArticleAttachmentApi(config, self.endpoint.attachments, object_type='article_attachment')
self.labels = LabelApi(config, self.endpoint.labels, object_type='label')
self.topics = TopicApi(config, self.endpoint.topics, object_type='topic')
self.posts = PostApi(config, self.endpoint.posts, object_type='post')
self.user_segments = UserSegmentApi(config, self.endpoint.user_segments, object_type='user_segment')
def __call__(self, *args, **kwargs):
raise NotImplementedError("Cannot directly call the HelpCentreApi!")
@extract_id(Post)
def update(self, post, comment):
return PostCommentRequest(self).put(self.endpoint.update, post, comment)
@extract_id(Post, Comment)
def delete(self, post, comment):
return PostCommentRequest(self).delete(self.endpoint.delete, post, comment)
class PostApi(HelpCentreApiBase, CRUDApi, SubscriptionApi, VoteApi):
def __init__(self, config, endpoint, object_type):
super(PostApi, self).__init__(config, endpoint, object_type)
self.comments = PostCommentApi(config, endpoint.comments, 'post')
class UserSegmentApi(HelpCentreApiBase, CRUDApi):
def applicable(self):
return self._query_zendesk(self.endpoint.applicable, object_type='user_segment')
@extract_id(Section)
def sections(self, section):
return self._query_zendesk(self.endpoint.sections, object_type='section', id=section)
@extract_id(Topic)
def topics(self, topic):
return self._query_zendesk(self.endpoint.topics, object_type='topic', id=topic)
class HelpCentreApi(HelpCentreApiBase):
def __init__(self, config):
super(HelpCentreApi, self).__init__(config, endpoint=EndpointFactory('help_centre'), object_type='help_centre')
return HelpdeskAttachmentRequest(self).post(self.endpoint.create,
article=article,
attachment=attachment,
inline=inline)
def create_unassociated(self, attachment, inline=False):
return HelpdeskAttachmentRequest(self).post(self.endpoint.create_unassociated,
attachment=attachment,
inline=inline)
@extract_id(ArticleAttachment)
def delete(self, article_attachment):
return HelpdeskAttachmentRequest(self).delete(self.endpoint.delete, article_attachment)
class LabelApi(HelpCentreApiBase):
@extract_id(Article)
def create(self, article, label):
return HelpCentreRequest(self).post(self.endpoint.create, article, label)
@extract_id(Article, Label)
def delete(self, article, label):
return HelpCentreRequest(self).delete(self.endpoint.delete, article, label)
class TopicApi(HelpCentreApiBase, CRUDApi, SubscriptionApi):
@extract_id(Topic)
def posts(self, topic):
url = self._build_url(self.endpoint.posts(id=topic))
return self._get(url)
return super(PostCommentApi, self).__call__(id=post)
@extract_id(Post)
def create(self, post, comment):
return PostCommentRequest(self).post(self.endpoint, post, comment)
@extract_id(Post)
def update(self, post, comment):
return PostCommentRequest(self).put(self.endpoint.update, post, comment)
@extract_id(Post, Comment)
def delete(self, post, comment):
return PostCommentRequest(self).delete(self.endpoint.delete, post, comment)
class PostApi(HelpCentreApiBase, CRUDApi, SubscriptionApi, VoteApi):
def __init__(self, config, endpoint, object_type):
super(PostApi, self).__init__(config, endpoint, object_type)
self.comments = PostCommentApi(config, endpoint.comments, 'post')
class UserSegmentApi(HelpCentreApiBase, CRUDApi):
def applicable(self):
return self._query_zendesk(self.endpoint.applicable, object_type='user_segment')
@extract_id(Section)
def sections(self, section):
return self._query_zendesk(self.endpoint.sections, object_type='section', id=section)
@extract_id(Topic)
def topics(self, topic):
return self._query_zendesk(self.endpoint.topics, object_type='topic', id=topic)
def _process_response(self, response):
endpoint_path = get_endpoint_path(self, response)
if endpoint_path.startswith('/help_center') or endpoint_path.startswith('/community'):
object_mapping = self._object_mapping
else:
object_mapping = ZendeskObjectMapping(self)
return super(HelpCentreApiBase, self)._process_response(response, object_mapping)
def comment_votes(self, help_centre_object, comment):
url = self._build_url(self.endpoint.comment_votes(help_centre_object, comment))
return self._get(url)
@extract_id(Article, Post, Comment)
def vote_comment_up(self, help_centre_object, comment):
url = self._build_url(self.endpoint.comment_votes.up(help_centre_object, comment))
return self._post(url, payload={})
@extract_id(Article, Post, Comment)
def vote_comment_down(self, help_centre_object, comment):
url = self._build_url(self.endpoint.comment_votes.down(help_centre_object, comment))
return self._post(url, payload={})
class ArticleApi(HelpCentreApiBase, TranslationApi, SubscriptionApi, VoteApi, VoteCommentApi):
@extract_id(Section)
def create(self, section, article):
"""
Create (POST) an Article - https://developer.zendesk.com/rest_api/docs/help_center/articles#create-article
:param section: Section ID or object
:param article: Article to create
"""
return CRUDRequest(self).post(article, create=True, id=section)
def update(self, article):
"""
Update (PUT) and Article - https://developer.zendesk.com/rest_api/docs/help_center/articles#update-article
:param article: Article to update
"""
@extract_id(ArticleAttachment)
def delete(self, article_attachment):
return HelpdeskAttachmentRequest(self).delete(self.endpoint.delete, article_attachment)
class LabelApi(HelpCentreApiBase):
@extract_id(Article)
def create(self, article, label):
return HelpCentreRequest(self).post(self.endpoint.create, article, label)
@extract_id(Article, Label)
def delete(self, article, label):
return HelpCentreRequest(self).delete(self.endpoint.delete, article, label)
class TopicApi(HelpCentreApiBase, CRUDApi, SubscriptionApi):
@extract_id(Topic)
def posts(self, topic):
url = self._build_url(self.endpoint.posts(id=topic))
return self._get(url)
class PostCommentApi(HelpCentreApiBase, VoteCommentApi):
@extract_id(Post)
def __call__(self, post):
return super(PostCommentApi, self).__call__(id=post)
@extract_id(Post)
def create(self, post, comment):
return PostCommentRequest(self).post(self.endpoint, post, comment)
@extract_id(Post)
def create(self, article, label):
return HelpCentreRequest(self).post(self.endpoint.create, article, label)
@extract_id(Article, Label)
def delete(self, article, label):
return HelpCentreRequest(self).delete(self.endpoint.delete, article, label)
class TopicApi(HelpCentreApiBase, CRUDApi, SubscriptionApi):
@extract_id(Topic)
def posts(self, topic):
url = self._build_url(self.endpoint.posts(id=topic))
return self._get(url)
class PostCommentApi(HelpCentreApiBase, VoteCommentApi):
@extract_id(Post)
def __call__(self, post):
return super(PostCommentApi, self).__call__(id=post)
@extract_id(Post)
def create(self, post, comment):
return PostCommentRequest(self).post(self.endpoint, post, comment)
@extract_id(Post)
def update(self, post, comment):
return PostCommentRequest(self).put(self.endpoint.update, post, comment)
@extract_id(Post, Comment)
def delete(self, post, comment):
return PostCommentRequest(self).delete(self.endpoint.delete, post, comment)