1
1
import httpx
2
2
from openproject .exceptions import APIError , AuthenticationError
3
- from openproject .types import WorkPackage
3
+ from openproject .types import WorkPackage , Project
4
4
5
5
6
6
class Client :
@@ -10,6 +10,7 @@ def __init__(self, base_url: str, api_token: str):
10
10
self .api_token = api_token
11
11
12
12
self .work_packages = WorkPackages (self )
13
+ self .projects = Projects (self )
13
14
14
15
def _handle_response (self , response : httpx .Response ):
15
16
if response .status_code == 401 :
@@ -99,3 +100,34 @@ def update(self, id: int, **kwargs):
99
100
100
101
def delete (self , id : int ):
101
102
return self .client ._send_request ("DELETE" , f"/work_packages/{ id } " )
103
+
104
+
105
+ class Projects (SubClient ):
106
+ _args_api_mapping = {
107
+ "_links" : "_links" ,
108
+ "name" : "name" ,
109
+ "status_explanation" : "statusExplanation" ,
110
+ "description" : "description" ,
111
+ }
112
+
113
+ def _api_payload_from_kwargs (self , ** kwargs : Project ):
114
+ items = self ._args_api_mapping .items ()
115
+ data = {api_args : kwargs [args ] for args , api_args in items if args in kwargs }
116
+ return data
117
+
118
+ def list (self ):
119
+ return self .client ._send_request ("GET" , "/projects" )
120
+
121
+ def view (self , id : int ):
122
+ return self .client ._send_request ("GET" , f"/projects/{ id } " )
123
+
124
+ def create (self , ** kwargs ):
125
+ data = self ._api_payload_from_kwargs (** kwargs )
126
+ return self .client ._send_request ("POST" , "/projects" , data = data )
127
+
128
+ def update (self , id : int , ** kwargs ):
129
+ data = self ._api_payload_from_kwargs (** kwargs )
130
+ return self .client ._send_request ("PATCH" , f"/projects/{ id } " , data = data )
131
+
132
+ def delete (self , id : int ):
133
+ return self .client ._send_request ("DELETE" , f"/projects/{ id } " )
0 commit comments