1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Generated by basecamp-sdk-generator from openapi.json and behavior-model.json. DO NOT EDIT.
//! Projects operations.
#![allow(
clippy::too_many_arguments,
clippy::wildcard_imports,
clippy::doc_markdown
)]
use crate::client::AccountClient;
use crate::error::Error;
use crate::generated::routes;
#[allow(unused_imports)]
use crate::generated::types::*;
use crate::pagination::Page;
/// Optional query parameters for `ListProjects`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct ListProjectsParams {
/// active|archived|trashed
pub status: Option<String>,
/// Page number for paginating through results. Defaults to 1. A positive value selects exactly that page, not a starting offset; see SPEC section 8.
pub page: Option<i32>,
}
/// `Projects` operations, sent through one [`AccountClient`].
#[derive(Debug, Clone, Copy)]
pub struct ProjectsService<'a> {
client: &'a AccountClient,
}
impl<'a> ProjectsService<'a> {
pub(crate) fn new(client: &'a AccountClient) -> Self {
Self { client }
}
/// The client this service sends through.
pub fn client(&self) -> &'a AccountClient {
self.client
}
/// Archive a project, removing it from the active project list (returns 204 No Content).
/// Accounts on the admin pro pack may restrict archiving to admins and the project's
/// creator, which answers 403.
///
/// `PUT /projects/{projectId}/status/archived.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn archive(&self, project_id: i64) -> Result<(), Error> {
let operation = self
.client
.operation(&routes::ARCHIVE_PROJECT, &[&project_id]);
self.client.send_unit(operation).await
}
/// Create a new project
///
/// `POST /projects.json` — not idempotent, sent exactly once.
pub async fn create(
&self,
body: &CreateProjectRequestContent,
) -> Result<CreateProjectResponseContent, Error> {
let mut operation = self.client.operation(&routes::CREATE_PROJECT, &[]);
operation.json(body)?;
self.client.send(operation).await
}
/// Get a single project by id
///
/// `GET /projects/{projectId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn get(&self, project_id: i64) -> Result<GetProjectResponseContent, Error> {
let operation = self.client.operation(&routes::GET_PROJECT, &[&project_id]);
self.client.send(operation).await
}
/// List projects (active by default; optionally archived/trashed)
///
/// **Pagination**: Uses Link header (RFC5988). Follow the `next` rel URL
/// to fetch additional pages. X-Total-Count header provides total count.
///
/// `GET /projects.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn list(
&self,
params: &ListProjectsParams,
) -> Result<Page<ListProjectsResponseContent>, Error> {
let mut operation = self.client.operation(&routes::LIST_PROJECTS, &[]);
operation.query_optional("status", params.status.as_ref());
operation.query_optional("page", params.page.as_ref());
self.client.send_page(operation).await
}
/// List the projects the current user has most recently visited, most recent visit first.
/// Reads the per-user visit log — capped at the 50 most recent visits, keeping
/// only active projects the user can still access — not the home grid's
/// pinned-exclusion and padding. This endpoint is not paginated. Each entry is
/// the standard project projection plus the current user's bookmarked flag. A
/// visit is recorded when the user opens a project in Basecamp, when they
/// create one, and by RecordProjectVisit.
///
/// `GET /my/recent_projects.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn list_recent_projects(&self) -> Result<ListRecentProjectsResponseContent, Error> {
let operation = self.client.operation(&routes::LIST_RECENT_PROJECTS, &[]);
self.client.send(operation).await
}
/// Record that the current user visited a project, moving it to the front of ListRecentProjects (returns 204 No Content).
/// Idempotent: re-recording a visit refreshes the same entry. Visits to
/// archived or trashed projects are accepted but not recorded, and an
/// inaccessible project answers 404.
///
/// `POST /projects/{projectId}/recent_visit.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn record_project_visit(&self, project_id: i64) -> Result<(), Error> {
let operation = self
.client
.operation(&routes::RECORD_PROJECT_VISIT, &[&project_id]);
self.client.send_unit(operation).await
}
/// Trash a project (returns 204 No Content)
///
/// `DELETE /projects/{projectId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn trash(&self, project_id: i64) -> Result<(), Error> {
let operation = self
.client
.operation(&routes::TRASH_PROJECT, &[&project_id]);
self.client.send_unit(operation).await
}
/// Restore a project to active status from trash as well as from the archive (returns 204 No Content).
/// This is the inverse of both ArchiveProject and TrashProject. Restoring counts against
/// the account's project limit, so it answers 507 when that limit is already reached.
///
/// `PUT /projects/{projectId}/status/active.json` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn unarchive(&self, project_id: i64) -> Result<(), Error> {
let operation = self
.client
.operation(&routes::UNARCHIVE_PROJECT, &[&project_id]);
self.client.send_unit(operation).await
}
/// Update an existing project
///
/// `PUT /projects/{projectId}` — idempotent; retries up to 3 attempt(s) on 429, 503.
pub async fn update(
&self,
project_id: i64,
body: &UpdateProjectRequestContent,
) -> Result<UpdateProjectResponseContent, Error> {
let mut operation = self
.client
.operation(&routes::UPDATE_PROJECT, &[&project_id]);
operation.json(body)?;
self.client.send(operation).await
}
}