Skip to content

Commit 60f0753

Browse files
committed
Updated articles api
1 parent 54584dc commit 60f0753

File tree

6 files changed

+97
-18
lines changed

6 files changed

+97
-18
lines changed

intercom_python_sdk/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@
5858
from .core.configuration import Configuration
5959
from .core.api_base import create_api_client
6060
from .apis.tags_to_api import tags_to_api_dict as API_TAGS
61+
from .core.errors import IntercomErrorList
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from enum import Enum
2+
class ArticleLanguages(Enum):
3+
ARABIC = "ar"
4+
BULGARIAN = "bg"
5+
BRAZILIAN_PORTUGUESE = "pt-BR"
6+
BOSNIAN = "bs"
7+
CATALAN = "ca"
8+
CZECH = "cs"
9+
DANISH = "da"
10+
GERMAN = "de"
11+
GREEK = "el"
12+
ENGLISH = "en"
13+
SPANISH = "es"
14+
ESTONIAN = "et"
15+
FINNISH = "fi"
16+
FRENCH = "fr"
17+
HEBREW = "he"
18+
HINDI = "hi"
19+
CROATIAN = "hr"
20+
HUNGARIAN = "hu"
21+
INDONESIAN = "id"
22+
ITALIAN = "it"
23+
JAPANESE = "ja"
24+
KOREAN = "ko"
25+
LITHUANIAN = "lt"
26+
LATVIAN = "lv"
27+
NORWEGIAN = "nb"
28+
DUTCH = "nl"
29+
POLISH = "pl"
30+
PORTUGUESE = "pt"
31+
ROMANIAN = "ro"
32+
RUSSIAN = "ru"
33+
SLOVAK = "sk"
34+
SLOVENIAN = "sl"
35+
SWEDISH = "sv"
36+
TURKISH = "tr"
37+
VIETNAMESE = "vi"
38+
CHINESE = "zh-CN"
39+
TAIWANESE = "zh-TW"

intercom_python_sdk/apis/articles/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@
2626
# From Current Package
2727
from ...core.model_base import ModelBase
2828

29+
from .languages import ArticleLanguages
30+
2931
# Type Check Imports - TYPE_CHECKING is assumed True by type-checkers but is False at runtime.
3032
# See: https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING
3133
if TYPE_CHECKING:
3234
from .api import ArticlesAPI
3335

3436

37+
class ArticleTranslation(ModelBase):
38+
type: str
39+
40+
def __init__(self, *args, **kwargs):
41+
self.type = kwargs.get('type', 'article_translated_content')
42+
43+
for language in ArticleLanguages:
44+
locale_code = language.value
45+
setattr(self, locale_code, kwargs.get(locale_code, None))
46+
47+
3548
class ArticleStatistics(ModelBase):
3649
"""
3750
This model represents the statistics of an Article on Intercom.
@@ -428,7 +441,7 @@ def translated_content(self, translated_content: dict):
428441

429442
# Methods
430443

431-
def update(self):
444+
def update(self) -> 'Article':
432445
"""
433446
Update the Article.
434447
"""

intercom_python_sdk/apis/articles/schemas.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
- [1] https://developers.intercom.com/intercom-api-reference/reference/the-article-model
1212
"""
1313

14+
# Built-in
15+
from enum import Enum
16+
1417
# External
1518
import marshmallow
1619
from marshmallow import fields
1720

1821
# From Current API
1922
from . import models as a_models
23+
from .languages import ArticleLanguages
2024

2125
# From Current Package
2226
from ...core.schema_base import SchemaBase
@@ -65,34 +69,52 @@ class ArticleSchema(SchemaBase):
6569
default_locale (str): The default locale of the Article.
6670
statistics (dict): The statistics of the Article.
6771
"""
68-
id = fields.Int(required=True)
69-
type = fields.Str(allow_none=True)
70-
workspace_id = fields.Str(allow_none=True)
72+
id = fields.Int(required=False)
73+
type = fields.Str(allow_none=True, required=False)
74+
workspace_id = fields.Str(allow_none=True, required=False)
7175
title = fields.Str(required=True)
72-
description = fields.Str(allow_none=True)
73-
body = fields.Str(required=True)
74-
author_id = fields.Int(required=True)
75-
state = fields.Str(allow_none=True)
76-
created_at = fields.Int(allow_none=True)
77-
updated_at = fields.Int(allow_none=True)
78-
url = fields.Str(allow_none=True)
79-
default_locale = fields.Str(allow_none=True)
80-
translated_content = fields.Dict(values=fields.Str(), default='', allow_none=True)
81-
statistics = fields.Nested(ArticleStatisticsSchema, allow_none=True)
82-
83-
parent_id = fields.Int(allow_none=True)
84-
parent_type = fields.Str(allow_none=True)
76+
description = fields.Str(allow_none=True, required=False)
77+
body = fields.Str(required=False)
78+
author_id = fields.Int(required=False)
79+
state = fields.Str(allow_none=True, required=False)
80+
created_at = fields.Int(allow_none=True, required=False)
81+
updated_at = fields.Int(allow_none=True, required=False)
82+
url = fields.Str(allow_none=True, required=False)
83+
default_locale = fields.Str(allow_none=True, required=False)
84+
translated_content = fields.Raw(allow_none=True, required=False)
85+
statistics = fields.Nested(ArticleStatisticsSchema, allow_none=True, required=False)
86+
87+
parent_id = fields.Int(allow_none=True, required=False)
88+
parent_type = fields.Str(allow_none=True, required=False)
8589

8690
@marshmallow.post_load
8791
def make_article(self, data, **kwargs):
8892
return a_models.Article(**data)
8993

9094

95+
class ArticleTranslationSchema(SchemaBase):
96+
"""
97+
This schema represents the translation of an Article on Intercom.
98+
"""
99+
type = fields.Str(default="article_translated_content")
100+
101+
def __init__(self, **kwargs):
102+
super().__init__(**kwargs)
103+
for language in ArticleLanguages:
104+
locale_code = language.value
105+
self.fields[locale_code] = fields.Str(allow_none=True, required=False)
106+
107+
@marshmallow.post_load
108+
def make_article_translation(self, data, **kwargs):
109+
return a_models.ArticleTranslation(**data)
110+
111+
112+
91113
class ArticlePagesSchema(SchemaBase):
92114
""" Paging information for a list of Articles on Intercom. """
93115
type = fields.Str(default='pages')
94116
page = fields.Int()
95-
next = fields.Url(allow_none=True)
117+
next = fields.Url(allow_none=True, required=False)
96118
per_page = fields.Int(default=50)
97119
total_pages = fields.Int()
98120

@@ -112,3 +134,5 @@ class ArticleListSchema(SchemaBase):
112134
@marshmallow.post_load
113135
def make_article_list(self, data, **kwargs):
114136
return a_models.ArticleList(**data)
137+
138+

intercom_python_sdk/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
from . import api_base # noqa
99
from . import configuration
1010
from . import model_base
11+
from . import errors

intercom_python_sdk/schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ArticleSchema,
2323
ArticleListSchema,
2424
ArticleStatisticsSchema,
25+
ArticleTranslationSchema
2526
)
2627

2728
from ..apis.data_attributes.schemas import (

0 commit comments

Comments
 (0)