payjp_core/term/
requests.rs

1use payjp_client_core::{PayjpClient, BlockingClient, PayjpRequest, RequestBuilder, PayjpMethod};
2
3#[derive(Copy,Clone,Debug,)]#[derive(serde::Serialize)]
4 struct ListTermBuilder {
5#[serde(skip_serializing_if = "Option::is_none")]
6 limit: Option<i64>,
7#[serde(skip_serializing_if = "Option::is_none")]
8 offset: Option<i64>,
9#[serde(skip_serializing_if = "Option::is_none")]
10 since: Option<i64>,
11#[serde(skip_serializing_if = "Option::is_none")]
12 until: Option<i64>,
13#[serde(skip_serializing_if = "Option::is_none")]
14 since_start_at: Option<i64>,
15#[serde(skip_serializing_if = "Option::is_none")]
16 until_start_at: Option<i64>,
17
18}
19impl ListTermBuilder {
20     fn new() -> Self {
21    Self {
22        limit: None,offset: None,since: None,until: None,since_start_at: None,until_start_at: None,
23    }
24}
25
26}
27        /// 集計区間(Termオブジェクト)のリストを取得します。
28#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
29pub struct ListTerm {
30 inner: ListTermBuilder,
31
32}
33impl ListTerm {
34    /// Construct a new `ListTerm`.
35pub fn new() -> Self {
36    Self {
37        inner: ListTermBuilder::new()
38    }
39}
40    /// 取得するデータ数の最大値(1~100まで)。指定がない場合は 10 となる。
41pub fn limit(mut self, limit: impl Into<i64>) -> Self {
42    self.inner.limit = Some(limit.into());
43    self
44}
45    /// 基準点からのデータ取得を行う開始位置。指定がない場合は 0 となる。
46pub fn offset(mut self, offset: impl Into<i64>) -> Self {
47    self.inner.offset = Some(offset.into());
48    self
49}
50    /// ここに指定したタイムスタンプ以降に作成されたデータを取得
51pub fn since(mut self, since: impl Into<i64>) -> Self {
52    self.inner.since = Some(since.into());
53    self
54}
55    /// ここに指定したタイムスタンプ以前に作成されたデータを取得
56pub fn until(mut self, until: impl Into<i64>) -> Self {
57    self.inner.until = Some(until.into());
58    self
59}
60    /// start_atが指定したタイムスタンプ以降のオブジェクトを取得
61pub fn since_start_at(mut self, since_start_at: impl Into<i64>) -> Self {
62    self.inner.since_start_at = Some(since_start_at.into());
63    self
64}
65    /// start_atが指定したタイムスタンプ以前のオブジェクトを取得
66pub fn until_start_at(mut self, until_start_at: impl Into<i64>) -> Self {
67    self.inner.until_start_at = Some(until_start_at.into());
68    self
69}
70
71}
72    impl Default for ListTerm {
73    fn default() -> Self {
74        Self::new()
75    }
76}impl ListTerm {
77    /// Send the request and return the deserialized response.
78    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
79        self.customize().send(client).await
80    }
81
82    /// Send the request and return the deserialized response, blocking until completion.
83    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
84        self.customize().send_blocking(client)
85    }
86
87    pub fn paginate(&self) -> payjp_client_core::ListPaginator<payjp_types::List<payjp_core::Term>> {
88    
89    payjp_client_core::ListPaginator::new_list("/terms", &self.inner)
90}
91
92}
93
94impl PayjpRequest for ListTerm {
95    type Output = payjp_types::List<payjp_core::Term>;
96
97    fn build(&self) -> RequestBuilder {
98    RequestBuilder::new(PayjpMethod::Get, "/terms").query(&self.inner)
99}
100
101}
102    /// 指定されたIDの集計区間(Termオブジェクト)を取得します。
103#[derive(Clone,Debug,)]#[derive(serde::Serialize)]
104pub struct RetrieveTerm {
105 term: payjp_core::TermId,
106
107}
108impl RetrieveTerm {
109    /// Construct a new `RetrieveTerm`.
110pub fn new(term:impl Into<payjp_core::TermId>) -> Self {
111    Self {
112        term: term.into(),
113    }
114}
115
116}
117    impl RetrieveTerm {
118    /// Send the request and return the deserialized response.
119    pub async fn send<C: PayjpClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
120        self.customize().send(client).await
121    }
122
123    /// Send the request and return the deserialized response, blocking until completion.
124    pub fn send_blocking<C: BlockingClient>(&self, client: &C) -> Result<<Self as PayjpRequest>::Output, C::Err> {
125        self.customize().send_blocking(client)
126    }
127
128    
129}
130
131impl PayjpRequest for RetrieveTerm {
132    type Output = payjp_core::Term;
133
134    fn build(&self) -> RequestBuilder {
135    let term = &self.term;
136RequestBuilder::new(PayjpMethod::Get, format!("/terms/{term}"))
137}
138
139}
140