qcs_api/apis/
reservations_api.rs

1/*
2 * Rigetti QCS API
3 *
4 * # Introduction  This is the documentation for the Rigetti QCS HTTP API.  You can find out more about Rigetti at [https://rigetti.com](https://rigetti.com), and also interact with QCS via the web at [https://qcs.rigetti.com](https://qcs.rigetti.com).  This API is documented in **OpenAPI format** and so is compatible with the dozens of language-specific client generators available [here](https://github.com/OpenAPITools/openapi-generator) and elsewhere on the web.  # Principles  This API follows REST design principles where appropriate, and otherwise an HTTP RPC paradigm. We adhere to the Google [API Improvement Proposals](https://google.aip.dev/general) where reasonable to provide a consistent, intuitive developer experience. HTTP response codes match their specifications, and error messages fit a common format.  # Authentication  All access to the QCS API requires OAuth2 authentication provided by Okta. You can request access [here](https://www.rigetti.com/get-quantum). Once you have a user account, you can download your access token from QCS [here](https://qcs.rigetti.com/auth/token).   That access token is valid for 24 hours after issuance. The value of `access_token` within the JSON file is the token used for authentication (don't use the entire JSON file).  Authenticate requests using the `Authorization` header and a `Bearer` prefix:  ``` curl --header \"Authorization: Bearer eyJraW...Iow\" ```  # Quantum Processor Access  Access to the quantum processors themselves is not yet provided directly by this HTTP API, but is instead performed over ZeroMQ/[rpcq](https://gitlab.com/rigetti/rpcq). Until that changes, we suggest using [pyquil](https://gitlab.com/rigetti/pyquil) to build and execute quantum programs via the Legacy API.  # Legacy API  Our legacy HTTP API remains accessible at https://forest-server.qcs.rigetti.com, and it shares a source of truth with this API's services. You can use either service with the same user account and means of authentication. We strongly recommend using the API documented here, as the legacy API is on the path to deprecation.
5 *
6 * The version of the OpenAPI document: 2020-07-31
7 * Contact: support@rigetti.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`create_reservation`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateReservationError {
20    Status401(crate::models::Error),
21    Status402(crate::models::Error),
22    Status403(crate::models::Error),
23    Status409(crate::models::Error),
24    Status422(crate::models::Error),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`delete_reservation`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteReservationError {
32    Status401(crate::models::Error),
33    Status403(crate::models::Error),
34    Status404(crate::models::Error),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`find_available_reservations`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum FindAvailableReservationsError {
42    Status401(crate::models::Error),
43    Status422(crate::models::Error),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`list_group_reservations`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ListGroupReservationsError {
51    Status401(crate::models::Error),
52    Status422(crate::models::Error),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`list_reservations`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum ListReservationsError {
60    Status401(crate::models::Error),
61    Status422(crate::models::Error),
62    UnknownValue(serde_json::Value),
63}
64
65/// Create a new reservation.  The following precedence applies when specifying the reservation subject account ID and type: * request body `accountId` field, or if unset then `X-QCS-ACCOUNT-ID` header, or if unset then requesting user's ID. * request body `accountType` field, or if unset then `X-QCS-ACCOUNT-TYPE` header, or if unset then \"user\" type.
66pub async fn create_reservation(
67    configuration: &configuration::Configuration,
68    create_reservation_request: crate::models::CreateReservationRequest,
69    x_qcs_account_id: Option<&str>,
70    x_qcs_account_type: Option<crate::models::AccountType>,
71) -> Result<crate::models::Reservation, Error<CreateReservationError>> {
72    let local_var_configuration = configuration;
73
74    let local_var_client = &local_var_configuration.client;
75
76    let local_var_uri_str = format!("{}/v1/reservations", local_var_configuration.base_path);
77    let mut local_var_req_builder =
78        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81        local_var_req_builder =
82            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    if let Some(local_var_param_value) = x_qcs_account_id {
85        local_var_req_builder =
86            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
87    }
88    if let Some(local_var_param_value) = x_qcs_account_type {
89        local_var_req_builder =
90            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
91    }
92    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
93        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
94    };
95    local_var_req_builder = local_var_req_builder.json(&create_reservation_request);
96
97    let local_var_req = local_var_req_builder.build()?;
98    let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100    let local_var_status = local_var_resp.status();
101    let local_var_content = local_var_resp.text().await?;
102
103    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
104        serde_json::from_str(&local_var_content).map_err(Error::from)
105    } else {
106        let local_var_entity: Option<CreateReservationError> =
107            serde_json::from_str(&local_var_content).ok();
108        let local_var_error = ResponseContent {
109            status: local_var_status,
110            content: local_var_content,
111            entity: local_var_entity,
112        };
113        Err(Error::ResponseError(local_var_error))
114    }
115}
116
117/// Cancel an existing reservation for the user.
118pub async fn delete_reservation(
119    configuration: &configuration::Configuration,
120    reservation_id: i32,
121) -> Result<crate::models::Reservation, Error<DeleteReservationError>> {
122    let local_var_configuration = configuration;
123
124    let local_var_client = &local_var_configuration.client;
125
126    let local_var_uri_str = format!(
127        "{}/v1/reservations/{reservationId}",
128        local_var_configuration.base_path,
129        reservationId = reservation_id
130    );
131    let mut local_var_req_builder =
132        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
133
134    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135        local_var_req_builder =
136            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
139        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
140    };
141
142    let local_var_req = local_var_req_builder.build()?;
143    let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145    let local_var_status = local_var_resp.status();
146    let local_var_content = local_var_resp.text().await?;
147
148    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149        serde_json::from_str(&local_var_content).map_err(Error::from)
150    } else {
151        let local_var_entity: Option<DeleteReservationError> =
152            serde_json::from_str(&local_var_content).ok();
153        let local_var_error = ResponseContent {
154            status: local_var_status,
155            content: local_var_content,
156            entity: local_var_entity,
157        };
158        Err(Error::ResponseError(local_var_error))
159    }
160}
161
162/// List currently available reservations on the requested Rigetti quantum computer.
163pub async fn find_available_reservations(
164    configuration: &configuration::Configuration,
165    quantum_processor_id: &str,
166    start_time_from: String,
167    duration: &str,
168    page_size: Option<i32>,
169    page_token: Option<&str>,
170) -> Result<crate::models::FindAvailableReservationsResponse, Error<FindAvailableReservationsError>>
171{
172    let local_var_configuration = configuration;
173
174    let local_var_client = &local_var_configuration.client;
175
176    let local_var_uri_str = format!(
177        "{}/v1/reservations:findAvailable",
178        local_var_configuration.base_path
179    );
180    let mut local_var_req_builder =
181        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_str) = page_size {
184        local_var_req_builder =
185            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
186    }
187    if let Some(ref local_var_str) = page_token {
188        local_var_req_builder =
189            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
190    }
191    local_var_req_builder =
192        local_var_req_builder.query(&[("quantumProcessorId", &quantum_processor_id.to_string())]);
193    local_var_req_builder =
194        local_var_req_builder.query(&[("startTimeFrom", &start_time_from.to_string())]);
195    local_var_req_builder = local_var_req_builder.query(&[("duration", &duration.to_string())]);
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder =
198            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
201        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
202    };
203
204    let local_var_req = local_var_req_builder.build()?;
205    let local_var_resp = local_var_client.execute(local_var_req).await?;
206
207    let local_var_status = local_var_resp.status();
208    let local_var_content = local_var_resp.text().await?;
209
210    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
211        serde_json::from_str(&local_var_content).map_err(Error::from)
212    } else {
213        let local_var_entity: Option<FindAvailableReservationsError> =
214            serde_json::from_str(&local_var_content).ok();
215        let local_var_error = ResponseContent {
216            status: local_var_status,
217            content: local_var_content,
218            entity: local_var_entity,
219        };
220        Err(Error::ResponseError(local_var_error))
221    }
222}
223
224/// List existing reservations for the requested group.  Available filter fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer * `quantumProcessorId` - string  Available order fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer
225pub async fn list_group_reservations(
226    configuration: &configuration::Configuration,
227    group_name: &str,
228    filter: Option<&str>,
229    order: Option<&str>,
230    page_size: Option<i32>,
231    page_token: Option<&str>,
232    show_deleted: Option<&str>,
233) -> Result<crate::models::ListReservationsResponse, Error<ListGroupReservationsError>> {
234    let local_var_configuration = configuration;
235
236    let local_var_client = &local_var_configuration.client;
237
238    let local_var_uri_str = format!(
239        "{}/v1/groups/{groupName}/reservations",
240        local_var_configuration.base_path,
241        groupName = crate::apis::urlencode(group_name)
242    );
243    let mut local_var_req_builder =
244        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
245
246    if let Some(ref local_var_str) = filter {
247        local_var_req_builder =
248            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
249    }
250    if let Some(ref local_var_str) = order {
251        local_var_req_builder =
252            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
253    }
254    if let Some(ref local_var_str) = page_size {
255        local_var_req_builder =
256            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
257    }
258    if let Some(ref local_var_str) = page_token {
259        local_var_req_builder =
260            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
261    }
262    if let Some(ref local_var_str) = show_deleted {
263        local_var_req_builder =
264            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
265    }
266    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
267        local_var_req_builder =
268            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
269    }
270    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
271        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
272    };
273
274    let local_var_req = local_var_req_builder.build()?;
275    let local_var_resp = local_var_client.execute(local_var_req).await?;
276
277    let local_var_status = local_var_resp.status();
278    let local_var_content = local_var_resp.text().await?;
279
280    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
281        serde_json::from_str(&local_var_content).map_err(Error::from)
282    } else {
283        let local_var_entity: Option<ListGroupReservationsError> =
284            serde_json::from_str(&local_var_content).ok();
285        let local_var_error = ResponseContent {
286            status: local_var_status,
287            content: local_var_content,
288            entity: local_var_entity,
289        };
290        Err(Error::ResponseError(local_var_error))
291    }
292}
293
294/// List existing reservations for the authenticated user, or a target user when specifying `X-QCS-ACCOUNT-ID` and `X-QCS-ACCOUNT-TYPE` headers.  Available filter fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer * `cancelled` - boolean (deprecated, use `showDeleted` parameter) * `quantumProcessorId` - string  Available order fields include:  * `startTime` - timestamp * `endTime` - timestamp * `createdTime` - timestamp * `price` - integer
295pub async fn list_reservations(
296    configuration: &configuration::Configuration,
297    filter: Option<&str>,
298    order: Option<&str>,
299    page_size: Option<i32>,
300    page_token: Option<&str>,
301    show_deleted: Option<&str>,
302    x_qcs_account_id: Option<&str>,
303    x_qcs_account_type: Option<crate::models::AccountType>,
304) -> Result<crate::models::ListReservationsResponse, Error<ListReservationsError>> {
305    let local_var_configuration = configuration;
306
307    let local_var_client = &local_var_configuration.client;
308
309    let local_var_uri_str = format!("{}/v1/reservations", local_var_configuration.base_path);
310    let mut local_var_req_builder =
311        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
312
313    if let Some(ref local_var_str) = filter {
314        local_var_req_builder =
315            local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
316    }
317    if let Some(ref local_var_str) = order {
318        local_var_req_builder =
319            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
320    }
321    if let Some(ref local_var_str) = page_size {
322        local_var_req_builder =
323            local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
324    }
325    if let Some(ref local_var_str) = page_token {
326        local_var_req_builder =
327            local_var_req_builder.query(&[("pageToken", &local_var_str.to_string())]);
328    }
329    if let Some(ref local_var_str) = show_deleted {
330        local_var_req_builder =
331            local_var_req_builder.query(&[("showDeleted", &local_var_str.to_string())]);
332    }
333    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
334        local_var_req_builder =
335            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
336    }
337    if let Some(local_var_param_value) = x_qcs_account_id {
338        local_var_req_builder =
339            local_var_req_builder.header("x-qcs-account-id", local_var_param_value.to_string());
340    }
341    if let Some(local_var_param_value) = x_qcs_account_type {
342        local_var_req_builder =
343            local_var_req_builder.header("x-qcs-account-type", local_var_param_value.to_string());
344    }
345    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
346        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
347    };
348
349    let local_var_req = local_var_req_builder.build()?;
350    let local_var_resp = local_var_client.execute(local_var_req).await?;
351
352    let local_var_status = local_var_resp.status();
353    let local_var_content = local_var_resp.text().await?;
354
355    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
356        serde_json::from_str(&local_var_content).map_err(Error::from)
357    } else {
358        let local_var_entity: Option<ListReservationsError> =
359            serde_json::from_str(&local_var_content).ok();
360        let local_var_error = ResponseContent {
361            status: local_var_status,
362            content: local_var_content,
363            entity: local_var_entity,
364        };
365        Err(Error::ResponseError(local_var_error))
366    }
367}