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
155
156
157
158
// this file is @generated
#![allow(clippy::doc_markdown, clippy::default_trait_access)]
#[allow(unused_imports, clippy::wildcard_imports)]
use crate::{error::Result, models::*, Configuration};
/// Query and header parameters of [`CreditUnits::list`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct CreditUnitsListOptions {
/// Include archived units. Defaults to false.
pub include_archived: Option<bool>,
}
impl CreditUnitsListOptions {
/// Options with no parameter set.
#[must_use]
pub fn new() -> Self {
Self {
include_archived: None,
}
}
/// Sets the `include_archived` query parameter.
#[must_use]
pub fn include_archived(mut self, include_archived: impl Into<bool>) -> Self {
self.include_archived = Some(include_archived.into());
self
}
/// Sets the `include_archived` query parameter, or unsets it with `None`.
#[must_use]
pub fn maybe_include_archived(mut self, include_archived: Option<bool>) -> Self {
self.include_archived = include_archived;
self
}
}
/// The credit units API, from the client's
/// [`credit_units`](crate::api::Meteroid::credit_units).
#[derive(Clone)]
pub struct CreditUnits {
cfg: std::sync::Arc<Configuration>,
options: crate::api::RequestOptions,
}
impl std::fmt::Debug for CreditUnits {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CreditUnits")
.field("options", &self.options)
.finish_non_exhaustive()
}
}
impl CreditUnits {
pub(super) fn new(cfg: std::sync::Arc<Configuration>) -> Self {
Self {
cfg,
options: crate::api::RequestOptions::default(),
}
}
/// Applies `options` (headers, timeout, retries, idempotency key) to the calls made
/// through the returned value.
#[must_use]
pub fn with_options(mut self, options: crate::api::RequestOptions) -> Self {
self.options = options;
self
}
/// The prices API, with the options of this one.
#[must_use]
pub fn prices(&self) -> super::CreditUnitsPrices {
super::CreditUnitsPrices::new(self.cfg.clone()).with_options(self.options.clone())
}
/// List credit units
///
/// The tenant's credit units (e.g. "Halyard credits"): denominations usage can be priced and
/// credit granted in, instead of money, each with its selling prices.
///
/// `GET /api/v1/credit-units`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 429, 500).
pub fn list(
&self,
options: impl Into<Option<CreditUnitsListOptions>>,
) -> crate::api::Call<crate::models::CreditUnitListResponse> {
let CreditUnitsListOptions { include_archived } = options.into().unwrap_or_default();
crate::request::Request::new(http::Method::GET, "/api/v1/credit-units")
.with_optional_query_param("include_archived", include_archived)
.with_options(&self.options)
.json(&self.cfg)
}
/// Create a credit unit
///
/// `code` and `precision` are immutable once created. Price usage in the unit with a plan fee's
/// `credit_unit`, grant it with a credit pack or a credit grant, and sell it with a top-up once
/// it has a `product_id` and a selling price.
///
/// `POST /api/v1/credit-units`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 409, 429, 500).
pub fn create(
&self,
credit_unit_create_request: crate::models::CreditUnitCreateRequest,
) -> crate::api::Call<crate::models::CreditUnit> {
crate::request::Request::new(http::Method::POST, "/api/v1/credit-units")
.with_body_param(credit_unit_create_request)
.with_options(&self.options)
.json(&self.cfg)
}
/// Get a credit unit
///
/// The unit with its active selling prices.
///
/// `GET /api/v1/credit-units/{id}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (401, 404, 429, 500).
pub fn retrieve(&self, id: &str) -> crate::api::Call<crate::models::CreditUnit> {
crate::request::Request::new(http::Method::GET, "/api/v1/credit-units/{id}")
.with_path_param("id", id)
.with_options(&self.options)
.json(&self.cfg)
}
/// Update a credit unit
///
/// Partial update: an absent field is left unchanged. `code` and `precision` are immutable and
/// cannot be changed here. Setting `archived: true` blocks the unit from new prices, packs and
/// grants; existing ones keep working.
///
/// `PATCH /api/v1/credit-units/{id}`.
///
/// # Errors
///
/// An API error's body is [`RestErrorResponse`](crate::models::RestErrorResponse) (400, 401, 404, 409, 429, 500).
pub fn update(
&self,
id: &str,
credit_unit_update_request: crate::models::CreditUnitUpdateRequest,
) -> crate::api::Call<crate::models::CreditUnit> {
crate::request::Request::new(http::Method::PATCH, "/api/v1/credit-units/{id}")
.with_path_param("id", id)
.with_body_param(credit_unit_update_request)
.with_options(&self.options)
.json(&self.cfg)
}
}