bozupy 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. bozupy-0.1.2/LICENSE +201 -0
  2. bozupy-0.1.2/PKG-INFO +11 -0
  3. bozupy-0.1.2/README.md +57 -0
  4. bozupy-0.1.2/bozupy/__init__.py +22 -0
  5. bozupy-0.1.2/bozupy/cybozu/__init__.py +0 -0
  6. bozupy-0.1.2/bozupy/cybozu/constant.py +32 -0
  7. bozupy-0.1.2/bozupy/cybozu/dto.py +118 -0
  8. bozupy-0.1.2/bozupy/cybozu/url.py +11 -0
  9. bozupy-0.1.2/bozupy/cybozu/util.py +85 -0
  10. bozupy-0.1.2/bozupy/exception.py +39 -0
  11. bozupy-0.1.2/bozupy/garoon/__init__.py +13 -0
  12. bozupy-0.1.2/bozupy/garoon/base/__init__.py +0 -0
  13. bozupy-0.1.2/bozupy/garoon/base/dto.py +11 -0
  14. bozupy-0.1.2/bozupy/garoon/constant.py +31 -0
  15. bozupy-0.1.2/bozupy/garoon/notification/__init__.py +7 -0
  16. bozupy-0.1.2/bozupy/garoon/notification/client.py +34 -0
  17. bozupy-0.1.2/bozupy/garoon/notification/dto.py +34 -0
  18. bozupy-0.1.2/bozupy/garoon/notification/dxo.py +22 -0
  19. bozupy-0.1.2/bozupy/garoon/schedule/__init__.py +24 -0
  20. bozupy-0.1.2/bozupy/garoon/schedule/client.py +193 -0
  21. bozupy-0.1.2/bozupy/garoon/schedule/dto.py +30 -0
  22. bozupy-0.1.2/bozupy/garoon/schedule/dxo.py +29 -0
  23. bozupy-0.1.2/bozupy/garoon/url/__init__.py +10 -0
  24. bozupy-0.1.2/bozupy/garoon/url/dto.py +52 -0
  25. bozupy-0.1.2/bozupy/garoon/url/logic.py +21 -0
  26. bozupy-0.1.2/bozupy/garoon/user/__init__.py +10 -0
  27. bozupy-0.1.2/bozupy/garoon/user/client.py +46 -0
  28. bozupy-0.1.2/bozupy/kintone/__init__.py +12 -0
  29. bozupy-0.1.2/bozupy/kintone/app/__init__.py +33 -0
  30. bozupy-0.1.2/bozupy/kintone/app/client.py +142 -0
  31. bozupy-0.1.2/bozupy/kintone/app/dto.py +69 -0
  32. bozupy-0.1.2/bozupy/kintone/app/dxo.py +66 -0
  33. bozupy-0.1.2/bozupy/kintone/app/graph/__init__.py +24 -0
  34. bozupy-0.1.2/bozupy/kintone/app/graph/logic.py +268 -0
  35. bozupy-0.1.2/bozupy/kintone/comment/__init__.py +10 -0
  36. bozupy-0.1.2/bozupy/kintone/comment/client.py +92 -0
  37. bozupy-0.1.2/bozupy/kintone/comment/dto.py +28 -0
  38. bozupy-0.1.2/bozupy/kintone/comment/dxo.py +36 -0
  39. bozupy-0.1.2/bozupy/kintone/constant.py +40 -0
  40. bozupy-0.1.2/bozupy/kintone/record/__init__.py +70 -0
  41. bozupy-0.1.2/bozupy/kintone/record/client.py +235 -0
  42. bozupy-0.1.2/bozupy/kintone/record/dto.py +538 -0
  43. bozupy-0.1.2/bozupy/kintone/record/dxo.py +84 -0
  44. bozupy-0.1.2/bozupy/kintone/record/query/__init__.py +24 -0
  45. bozupy-0.1.2/bozupy/kintone/record/query/dto.py +136 -0
  46. bozupy-0.1.2/bozupy/kintone/record/query/logic.py +247 -0
  47. bozupy-0.1.2/bozupy/kintone/space/__init__.py +12 -0
  48. bozupy-0.1.2/bozupy/kintone/space/client.py +119 -0
  49. bozupy-0.1.2/bozupy/kintone/space/dto.py +16 -0
  50. bozupy-0.1.2/bozupy/kintone/space/dxo.py +23 -0
  51. bozupy-0.1.2/bozupy/kintone/url/__init__.py +38 -0
  52. bozupy-0.1.2/bozupy/kintone/url/dto.py +134 -0
  53. bozupy-0.1.2/bozupy/kintone/url/logic.py +134 -0
  54. bozupy-0.1.2/bozupy/kintone/util.py +67 -0
  55. bozupy-0.1.2/bozupy/setting.py +39 -0
  56. bozupy-0.1.2/bozupy/slash/__init__.py +16 -0
  57. bozupy-0.1.2/bozupy/slash/client.py +123 -0
  58. bozupy-0.1.2/bozupy/slash/dto.py +42 -0
  59. bozupy-0.1.2/bozupy/slash/dxo.py +43 -0
  60. bozupy-0.1.2/bozupy/util.py +295 -0
  61. bozupy-0.1.2/bozupy.egg-info/PKG-INFO +11 -0
  62. bozupy-0.1.2/bozupy.egg-info/SOURCES.txt +69 -0
  63. bozupy-0.1.2/bozupy.egg-info/dependency_links.txt +1 -0
  64. bozupy-0.1.2/bozupy.egg-info/requires.txt +3 -0
  65. bozupy-0.1.2/bozupy.egg-info/top_level.txt +1 -0
  66. bozupy-0.1.2/pyproject.toml +16 -0
  67. bozupy-0.1.2/requirements.txt +3 -0
  68. bozupy-0.1.2/setup.cfg +18 -0
  69. bozupy-0.1.2/tests/test_util.py +189 -0
  70. bozupy-0.1.2/tests/testtool.py +192 -0
bozupy-0.1.2/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
bozupy-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: bozupy
3
+ Version: 0.1.2
4
+ Summary: **Unofficial**: cybozu.com(kintone,Garoon,common) Python SDK
5
+ Author-email: SirTeaBear <sirteabear@gmail.com>
6
+ Requires-Python: >=3.13.0
7
+ License-File: LICENSE
8
+ Requires-Dist: lxml
9
+ Requires-Dist: python-dotenv
10
+ Requires-Dist: requests
11
+ Dynamic: license-file
bozupy-0.1.2/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # bozupy
2
+
3
+ > [!WARNING]
4
+ > This is not an officially supported Cybozu/Kintone product. Please do not send requests for additional features or bug fixes to account manager or customer support.
5
+
6
+ > [!WARNING]
7
+ > このリポジトリは cybozu.com の一利用者として業務で kintone を利用しているサイボウズ社員によって作られたものを現状のまま ("AS IS") で公開しているものです。kintone のサービスの一部として提供しているものではありません。機能の追加や不具合の修正のリクエストをカスタマーサポートや担当営業に送ることはお控えください。公式の SDK の提供要望は [kintone 開発チームへのフィードバックとしてお送りください](https://jp.cybozu.help/k/ja/trouble_shooting/general/send_feedback.html) 😉
8
+
9
+
10
+ [![test](https://github.com/cybozu/bozupy/actions/workflows/test.yaml/badge.svg)](https://github.com/cybozu/bozupy/actions/workflows/test.yaml)
11
+ ![PyPI - Version](https://img.shields.io/pypi/v/bozupy)
12
+
13
+ cybozu.com Python library
14
+
15
+ ## 設定
16
+ ### 環境変数
17
+
18
+ 以下の環境変数を設定すると自動で使用してくれます。
19
+
20
+ ```env
21
+ CYBOZU_SUBDOMAIN=
22
+ CYBOZU_USERNAME=
23
+ CYBOZU_PASSWORD=
24
+
25
+ KINTONE_APP_TOKEN_<アプリID>=
26
+ ```
27
+
28
+ ## 使い方
29
+
30
+ ```python
31
+ # kintone
32
+ from bozupy import kintone
33
+ from bozupy.kintone.record import KintoneRecord, KintoneRecordSingleLineTextField
34
+
35
+ # env: KINTONE_APP_TOKEN_1=xxxxx を設定しておくとアクセストークンを使ってアクセスする
36
+ # それがなければユーザー名とパスワードを使ってアクセスする
37
+ record: KintoneRecord = kintone.record.get_record(app_id=1, record_id=1)
38
+ print(record.get_field("code", KintoneRecordSingleLineTextField).value)
39
+
40
+ ## 環境変数以外の認証情報を使うことも可能
41
+ from bozupy import AccessData
42
+ access_data: AccessData = AccessData('<subdomain>', 'username', 'password')
43
+ record = kintone.record.get_record(app_id=1, record_id=1, access_data=access_data)
44
+
45
+
46
+ # garoon
47
+ from bozupy import garoon
48
+ from bozupy.garoon.schedule import GaroonEvent
49
+
50
+ event: GaroonEvent = garoon.schedule.get_event(event_id=1)
51
+
52
+ # slash
53
+ from bozupy import slash
54
+ from bozupy.slash import User
55
+
56
+ users: list[User] = [u for u in slash.get_users(access_data=access_data)]
57
+ ```
@@ -0,0 +1,22 @@
1
+ from . import slash, garoon, kintone, exception
2
+ from .cybozu.dto import AccessData, Comment, CybozuDotComUrl, Notification
3
+ from .cybozu.constant import Locales, Regions
4
+ from .cybozu.url import parse_url
5
+ from .setting import BOZUPY_VERSION
6
+
7
+ __VERSION__: str = BOZUPY_VERSION
8
+
9
+
10
+ __all__: list[str] = [
11
+ Locales.__name__,
12
+ Regions.__name__,
13
+ AccessData.__name__,
14
+ Comment.__name__,
15
+ CybozuDotComUrl.__name__,
16
+ Notification.__name__,
17
+ slash.__name__,
18
+ garoon.__name__,
19
+ kintone.__name__,
20
+ exception.__name__,
21
+ parse_url.__name__
22
+ ]
File without changes
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+ from enum import Enum
3
+
4
+
5
+ class Locales(Enum):
6
+ JA = "ja"
7
+ EN = "en"
8
+ ZH = "zh"
9
+ OTHER = "other"
10
+
11
+ @classmethod
12
+ def from_str(cls, value: str | None) -> Locales:
13
+ if value is None:
14
+ return Locales.OTHER
15
+ try:
16
+ return cls(value.lower())
17
+ except ValueError:
18
+ return Locales.OTHER
19
+
20
+
21
+ class Regions(Enum):
22
+ JP = "jp"
23
+ CN = "cn"
24
+
25
+ @classmethod
26
+ def from_str(cls, value: str | None) -> Regions:
27
+ if value is None:
28
+ return Regions.JP
29
+ try:
30
+ return cls(value.lower())
31
+ except ValueError:
32
+ return Regions.JP
@@ -0,0 +1,118 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABCMeta, abstractmethod
4
+ from dataclasses import dataclass, field
5
+ from datetime import datetime
6
+
7
+ from .constant import Regions
8
+ from ..setting import DEFAULT_CYBOZU_SUBDOMAIN, DEFAULT_CYBOZU_USERNAME, DEFAULT_CYBOZU_PASSWORD, \
9
+ DEFAULT_OTP_SECRET, DEFAULT_CYBOZU_REGION, DEFAULT_APP_TOKENS
10
+
11
+
12
+ @dataclass
13
+ class AccessData:
14
+ subdomain: str = DEFAULT_CYBOZU_SUBDOMAIN
15
+ username: str = DEFAULT_CYBOZU_USERNAME
16
+ password: str = DEFAULT_CYBOZU_PASSWORD
17
+ is_dev: bool = False
18
+ otp_secret: str = DEFAULT_OTP_SECRET
19
+ region: Regions = Regions.from_str(DEFAULT_CYBOZU_REGION)
20
+ app_tokens: dict[int, str] = field(default_factory=lambda: DEFAULT_APP_TOKENS.copy())
21
+
22
+ @property
23
+ def has_auth(self) -> bool:
24
+ return len(self.username) > 0 and len(self.password) > 0
25
+
26
+ @property
27
+ def host(self) -> str:
28
+ host: str = f"{self.subdomain}.cybozu"
29
+ if self.is_dev:
30
+ host = host + "-dev"
31
+ if self.region == Regions.JP:
32
+ host = host + ".com"
33
+ elif self.region == Regions.CN:
34
+ host = host + ".cn"
35
+ else:
36
+ raise NotImplementedError(f"Region {self.region} is not implemented.")
37
+ return host
38
+
39
+
40
+ @dataclass
41
+ class CybozuDotComUrl(metaclass=ABCMeta):
42
+ subdomain: str
43
+ is_dev: bool
44
+
45
+ @property
46
+ def path(self) -> str:
47
+ return ""
48
+
49
+ @property
50
+ @abstractmethod
51
+ def _product(self) -> str:
52
+ raise NotImplementedError()
53
+
54
+ @property
55
+ def fragment(self) -> str:
56
+ return ""
57
+
58
+ @property
59
+ def params(self) -> dict[str, str]:
60
+ return {}
61
+
62
+ def fqdn(self, is_secure: bool = False) -> str:
63
+ fqdn: str = f"{self.subdomain}"
64
+ if is_secure:
65
+ fqdn = fqdn + ".s"
66
+ fqdn = fqdn + ".cybozu"
67
+ if self.is_dev:
68
+ fqdn = fqdn + "-dev"
69
+ fqdn = fqdn + ".com"
70
+ return fqdn
71
+
72
+ def url(self, is_secure: bool = False, params: dict[str, str] | None = None) -> str:
73
+ url_: str = f"https://{self.fqdn(is_secure)}/{self._product}/{self.path}"
74
+ if self.fragment:
75
+ url_ += "#" + self.fragment
76
+ params_: dict[str, str] = params if params else {}
77
+ params_.update(self.params)
78
+ if params_:
79
+ url_ += "?" + "&".join([f"{k}={v}" for k, v in params_.items()])
80
+ return url_
81
+
82
+ def __str__(self) -> str:
83
+ return self.url()
84
+
85
+
86
+ @dataclass
87
+ class Notification:
88
+ notify_at: datetime
89
+ user_code: str
90
+ text: str
91
+ has_mention: bool
92
+ subdomain: str
93
+ is_dev: bool
94
+
95
+ @property
96
+ @abstractmethod
97
+ def url(self) -> CybozuDotComUrl:
98
+ raise NotImplementedError()
99
+
100
+
101
+ @dataclass(order=True)
102
+ class Comment(metaclass=ABCMeta):
103
+ id: int = field(compare=False)
104
+ text: str = field(compare=False)
105
+ commented_at: datetime = field(compare=True)
106
+ like_count: int = field(compare=False)
107
+ like_codes: set[str] = field(compare=False)
108
+ creator_code: str = field(compare=False)
109
+ mention_codes: set[str] = field(compare=False)
110
+ mention_org_codes: set[str] = field(compare=False)
111
+ mention_group_codes: set[str] = field(compare=False)
112
+ subdomain: str = field(compare=False)
113
+ is_dev: bool = field(compare=False)
114
+
115
+ @property
116
+ @abstractmethod
117
+ def url(self) -> CybozuDotComUrl:
118
+ raise NotImplementedError()
@@ -0,0 +1,11 @@
1
+ from .dto import CybozuDotComUrl
2
+ from ..kintone.url import logic as kintone_logic
3
+ from ..garoon.url import logic as garoon_logic
4
+
5
+
6
+ def parse_url(url_str: str) -> CybozuDotComUrl | None:
7
+ if "/k/" in url_str:
8
+ return kintone_logic.parse_kintone_url(url_str)
9
+ elif "/g/" in url_str:
10
+ return garoon_logic.parse_garoon_url(url_str)
11
+ return None
@@ -0,0 +1,85 @@
1
+ import base64
2
+ import logging
3
+ from typing import Iterator
4
+
5
+ import requests
6
+
7
+ from .dto import AccessData
8
+ from ..exception import LoginRequired, AccessForbidden, RateLimitExceeded, RequestNotSuccess, APIError, NoJsonResponse
9
+ from ..setting import USER_AGENT
10
+ from ..util import debug_response_print
11
+
12
+
13
+ def get_headers(access_data: AccessData | None, has_body: bool = False, app_ids: set[int] | int | None = None) -> dict[str, str]:
14
+ if access_data is None:
15
+ access_data = AccessData()
16
+ headers: dict[str, str] = {
17
+ "Host": f"{access_data.host}:443",
18
+ "User-Agent": USER_AGENT
19
+ }
20
+ if has_body:
21
+ headers["Content-Type"] = "application/json"
22
+ tokens: set[str] = set([])
23
+ if app_ids is None:
24
+ app_ids = set([])
25
+ elif isinstance(app_ids, int):
26
+ app_ids = {app_ids}
27
+ for app_id in app_ids:
28
+ if app_id in access_data.app_tokens:
29
+ tokens.add(access_data.app_tokens[app_id])
30
+ if tokens and app_ids and len(tokens) == len(app_ids):
31
+ headers["X-Cybozu-API-Token"] = ",".join(sorted(tokens))
32
+ logging.info("Use API Token")
33
+ elif access_data.has_auth:
34
+ headers["X-Cybozu-Authorization"] = base64.b64encode(
35
+ f"{access_data.username}:{access_data.password}".encode()).decode()
36
+ logging.info("Use Password")
37
+ else:
38
+ raise ValueError("No Auth Data")
39
+ return headers
40
+
41
+
42
+ def check_response(res: requests.Response, is_plain: bool = False):
43
+ debug_response_print(res)
44
+ # エラーを出し分けたいのでres.raise_for_status()は使わない
45
+ if res.status_code <= 299:
46
+ if is_plain:
47
+ return
48
+ elif "application/json" not in res.headers.get("Content-Type", ""):
49
+ raise NoJsonResponse(res)
50
+ try:
51
+ res_json: dict | list = res.json()
52
+ except ValueError:
53
+ raise NoJsonResponse(res)
54
+ if not isinstance(res_json, dict) or "success" not in res_json or res_json["success"]:
55
+ return
56
+ else:
57
+ raise RequestNotSuccess(res)
58
+ elif res.status_code == 401:
59
+ raise LoginRequired(res)
60
+ elif res.status_code == 302 and "/login" in res.headers.get("Location", ""):
61
+ raise LoginRequired(res)
62
+ elif res.status_code == 403:
63
+ raise AccessForbidden(res)
64
+ elif res.status_code == 429:
65
+ raise RateLimitExceeded(res)
66
+ elif res.status_code == 502 and "一時的な過負荷かメンテナンス" in res.text:
67
+ raise RateLimitExceeded(res)
68
+ elif res.status_code == 520:
69
+ raise APIError(res)
70
+ raise requests.HTTPError(response=res)
71
+
72
+
73
+ def get_offset_request(url: str, headers: dict, params: dict, key: str, limit: int) -> Iterator[dict]:
74
+ offset: int = 0
75
+ params["size"] = limit
76
+ while True:
77
+ ps: dict = params.copy()
78
+ ps["offset"] = offset
79
+ res: requests.Response = requests.get(url, headers=headers, params=ps)
80
+ check_response(res)
81
+ result: list[dict] = res.json()[key]
82
+ yield from result
83
+ if len(result) < limit:
84
+ break
85
+ offset += len(result)
@@ -0,0 +1,39 @@
1
+ from dataclasses import dataclass
2
+
3
+ import requests
4
+
5
+
6
+ @dataclass
7
+ class LoginRequired(requests.HTTPError):
8
+ # 401
9
+ response: requests.Response
10
+
11
+
12
+ @dataclass
13
+ class AccessForbidden(requests.HTTPError):
14
+ # 403
15
+ response: requests.Response
16
+
17
+
18
+ @dataclass
19
+ class RateLimitExceeded(requests.HTTPError):
20
+ # 429
21
+ response: requests.Response
22
+
23
+
24
+ @dataclass
25
+ class RequestNotSuccess(requests.HTTPError):
26
+ # 520
27
+ response: requests.Response | None
28
+ json_: dict | None = None
29
+
30
+
31
+ @dataclass
32
+ class APIError(requests.HTTPError):
33
+ # 520
34
+ response: requests.Response
35
+
36
+
37
+ @dataclass
38
+ class NoJsonResponse(requests.HTTPError):
39
+ response: requests.Response
@@ -0,0 +1,13 @@
1
+ from .base.dto import GaroonComment
2
+ from .constant import EventTypes, OperationTypes
3
+ from . import notification, schedule, url, user
4
+
5
+ __all__: list[str] = [
6
+ EventTypes.__name__,
7
+ GaroonComment.__name__,
8
+ OperationTypes.__name__,
9
+ notification.__name__,
10
+ schedule.__name__,
11
+ url.__name__,
12
+ user.__name__
13
+ ]
File without changes
@@ -0,0 +1,11 @@
1
+ from __future__ import annotations
2
+
3
+ from abc import ABCMeta
4
+ from dataclasses import dataclass
5
+
6
+ from ...cybozu.dto import Comment
7
+
8
+
9
+ @dataclass(order=True)
10
+ class GaroonComment(Comment, metaclass=ABCMeta):
11
+ pass
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+ from enum import Enum
3
+
4
+
5
+ class EventTypes(Enum):
6
+ REGULAR = "REGULAR"
7
+ REPEATING = "REPEATING"
8
+ ALL_DAY = "ALL_DAY"
9
+ TEMPORARY = "TEMPORARY"
10
+ OTHER = "OTHER"
11
+
12
+ @classmethod
13
+ def from_str(cls, s: str) -> EventTypes:
14
+ try:
15
+ return cls(s)
16
+ except ValueError:
17
+ return cls.OTHER
18
+
19
+
20
+ class OperationTypes(Enum):
21
+ ADD = "add"
22
+ MODIFY = "modify"
23
+ REMOVE = "remove"
24
+ OTHER = "other"
25
+
26
+ @classmethod
27
+ def from_str(cls, s: str) -> OperationTypes:
28
+ try:
29
+ return cls(s)
30
+ except ValueError:
31
+ return cls.OTHER
@@ -0,0 +1,7 @@
1
+ from .client import get_notifications
2
+ from .dto import GaroonNotification
3
+
4
+ __all__: list[str] = [
5
+ get_notifications.__name__,
6
+ GaroonNotification.__name__
7
+ ]