Module intercom_python_sdk.apis.articles.api
Articles API
apis/articles/api.py
This module contains the ArticlesAPI class, which defines a client for the Articles API. It is used to interact with the Intercom Articles API [1] as defined in the Intercom API Reference [2].
[1] https://developers.intercom.com/intercom-api-reference/reference/articles [2] https://github.com/intercom/Intercom-OpenAPI
Expand source code
"""
# Articles API
`apis/articles/api.py`
This module contains the ArticlesAPI class, which defines a client for the Articles API.
It is used to interact with the Intercom Articles API [1] as defined in the Intercom API Reference [2].
---
[1] https://developers.intercom.com/intercom-api-reference/reference/articles
[2] https://github.com/intercom/Intercom-OpenAPI
"""
# Built-ins
from typing import Union
# External
from uplink import (
get, put, post,
delete, returns,
response_handler,
Body, json, Query
)
# From Current API
from .schemas import (
ArticleSchema,
ArticleListSchema
)
from .models import ArticleList
# From Current Package
from ...core.api_base import APIBase
from ...core.errors import catch_api_error
@response_handler(catch_api_error)
class ArticlesAPI(APIBase): # type: ignore
URI = "/articles/"
@returns(ArticleSchema) # type: ignore
@get("{article_id}")
def get_by_id(self, article_id: Union[str, int]):
""" Get an Article by ID.
Args:
article_id (Union[str, int]): The ID of the Article.
Returns:
Article: The Article with the given ID.
"""
@returns(ArticleSchema) # type: ignore
@json # type: ignore
@post("")
def create(self, data: Body(type=ArticleSchema)): # type: ignore
""" Create an Article.
Args:
data (ArticleSchema): The ArticleSchema to create the article with.
Returns:
Article: The created Article.
"""
@returns(ArticleSchema) # type: ignore
@delete("{article_id}")
def delete_by_id(self, article_id: Union[str, int]):
""" Delete an Article by ID.
Args:
article_id (Union[str, int]): The ID of the Article.
Returns:
DeletedArticle: The deleted Article.
"""
@returns(ArticleListSchema) # type: ignore
@get("")
def __list_all(self, page: Query('page'), per_page: Query('per_page') = 50) -> ArticleList: # noqa # type: ignore
""" List all Articles. """
def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList:
""" List all Articles. Automatically paginates through all Articles.
Args:
start (int): The page number to start at.
per_page (int): The number of Articles to return per page.
Returns:
ArticleList: A list of Articles.
"""
article_list: ArticleList = self.__list_all(page=page, per_page=per_page)
while page < article_list.pages['total_pages']:
page += 1
new_page = self.__list_all(page=page, per_page=per_page)
article_list.extend(new_page)
article_list.pages = new_page.pages
return article_list
@returns(ArticleSchema) # type: ignore
@json # type: ignore
@put("{article_id}")
def update_by_id(self, article_id: Union[str, int], data: Body(type=ArticleSchema)): # type: ignore
""" Update an Article by ID.
Args:
article_id (Union[str, int]): The ID of the Article.
data (ArticleSchema): An article schema object to update via.
"""
Classes
class ArticlesAPI (config: Configuration, **kwargs)
-
The base class for all API classes in the Intercom Python SDK.
Initializes a new instance of the APIBase class. Overrides the Consumer class from the Uplink library to configure the Consumer instance using a Configuration object.
Args
config
- The configuration settings for the API.
Expand source code
@response_handler(catch_api_error) class ArticlesAPI(APIBase): # type: ignore URI = "/articles/" @returns(ArticleSchema) # type: ignore @get("{article_id}") def get_by_id(self, article_id: Union[str, int]): """ Get an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. Returns: Article: The Article with the given ID. """ @returns(ArticleSchema) # type: ignore @json # type: ignore @post("") def create(self, data: Body(type=ArticleSchema)): # type: ignore """ Create an Article. Args: data (ArticleSchema): The ArticleSchema to create the article with. Returns: Article: The created Article. """ @returns(ArticleSchema) # type: ignore @delete("{article_id}") def delete_by_id(self, article_id: Union[str, int]): """ Delete an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. Returns: DeletedArticle: The deleted Article. """ @returns(ArticleListSchema) # type: ignore @get("") def __list_all(self, page: Query('page'), per_page: Query('per_page') = 50) -> ArticleList: # noqa # type: ignore """ List all Articles. """ def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList: """ List all Articles. Automatically paginates through all Articles. Args: start (int): The page number to start at. per_page (int): The number of Articles to return per page. Returns: ArticleList: A list of Articles. """ article_list: ArticleList = self.__list_all(page=page, per_page=per_page) while page < article_list.pages['total_pages']: page += 1 new_page = self.__list_all(page=page, per_page=per_page) article_list.extend(new_page) article_list.pages = new_page.pages return article_list @returns(ArticleSchema) # type: ignore @json # type: ignore @put("{article_id}") def update_by_id(self, article_id: Union[str, int], data: Body(type=ArticleSchema)): # type: ignore """ Update an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. data (ArticleSchema): An article schema object to update via. """
Ancestors
- APIBase
- uplink.builder.Consumer
- uplink.interfaces.Consumer
- uplink.builder._Consumer
Class variables
var URI
Methods
def create(self, data:
) -
Create an Article.
Args
data
:ArticleSchema
- The ArticleSchema to create the article with.
Returns
Article
- The created Article.
Expand source code
@returns(ArticleSchema) # type: ignore @json # type: ignore @post("") def create(self, data: Body(type=ArticleSchema)): # type: ignore """ Create an Article. Args: data (ArticleSchema): The ArticleSchema to create the article with. Returns: Article: The created Article. """
def delete_by_id(self, article_id: Union[str, int])
-
Delete an Article by ID.
Args
article_id
:Union[str, int]
- The ID of the Article.
Returns
DeletedArticle
- The deleted Article.
Expand source code
@returns(ArticleSchema) # type: ignore @delete("{article_id}") def delete_by_id(self, article_id: Union[str, int]): """ Delete an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. Returns: DeletedArticle: The deleted Article. """
def get_by_id(self, article_id: Union[str, int])
-
Get an Article by ID.
Args
article_id
:Union[str, int]
- The ID of the Article.
Returns
Article
- The Article with the given ID.
Expand source code
@returns(ArticleSchema) # type: ignore @get("{article_id}") def get_by_id(self, article_id: Union[str, int]): """ Get an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. Returns: Article: The Article with the given ID. """
def list_all(self, page: int = 1, per_page: int = 50) ‑> ArticleList
-
List all Articles. Automatically paginates through all Articles.
Args
start
:int
- The page number to start at.
per_page
:int
- The number of Articles to return per page.
Returns
ArticleList
- A list of Articles.
Expand source code
def list_all(self, page: int = 1, per_page: int = 50) -> ArticleList: """ List all Articles. Automatically paginates through all Articles. Args: start (int): The page number to start at. per_page (int): The number of Articles to return per page. Returns: ArticleList: A list of Articles. """ article_list: ArticleList = self.__list_all(page=page, per_page=per_page) while page < article_list.pages['total_pages']: page += 1 new_page = self.__list_all(page=page, per_page=per_page) article_list.extend(new_page) article_list.pages = new_page.pages return article_list
def update_by_id(self, article_id: Union[str, int], data:
) -
Update an Article by ID.
Args
article_id
:Union[str, int]
- The ID of the Article.
data
:ArticleSchema
- An article schema object to update via.
Expand source code
@returns(ArticleSchema) # type: ignore @json # type: ignore @put("{article_id}") def update_by_id(self, article_id: Union[str, int], data: Body(type=ArticleSchema)): # type: ignore """ Update an Article by ID. Args: article_id (Union[str, int]): The ID of the Article. data (ArticleSchema): An article schema object to update via. """