Skip to main content

boj_client/query/
options.rs

1use serde::{Deserialize, Serialize};
2
3/// Response format parameter used by BOJ API endpoints.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5pub enum Format {
6    /// JSON response (`format=json`).
7    Json,
8    /// CSV response (`format=csv`).
9    Csv,
10}
11
12impl Format {
13    /// Returns the BOJ query parameter value for this format.
14    ///
15    /// # Examples
16    ///
17    /// ```
18    /// use boj_client::query::Format;
19    ///
20    /// assert_eq!(Format::Json.as_query_value(), "json");
21    /// assert_eq!(Format::Csv.as_query_value(), "csv");
22    /// ```
23    pub fn as_query_value(self) -> &'static str {
24        match self {
25            Self::Json => "json",
26            Self::Csv => "csv",
27        }
28    }
29}
30
31/// Language option for localized labels in API responses.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
33pub enum Language {
34    /// Japanese labels (`lang=jp`).
35    #[default]
36    Jp,
37    /// English labels (`lang=en`).
38    En,
39}
40
41impl Language {
42    /// Returns the BOJ query parameter value for this language.
43    ///
44    /// # Examples
45    ///
46    /// ```
47    /// use boj_client::query::Language;
48    ///
49    /// assert_eq!(Language::Jp.as_query_value(), "jp");
50    /// assert_eq!(Language::En.as_query_value(), "en");
51    /// ```
52    pub fn as_query_value(self) -> &'static str {
53        match self {
54            Self::Jp => "jp",
55            Self::En => "en",
56        }
57    }
58}
59
60/// Frequency selector used by the `getDataLayer` endpoint.
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
62pub enum Frequency {
63    /// Calendar year frequency (`CY`).
64    Cy,
65    /// Fiscal year frequency (`FY`).
66    Fy,
67    /// Half-year frequency in calendar-year basis (`CH`).
68    Ch,
69    /// Half-year frequency in fiscal-year basis (`FH`).
70    Fh,
71    /// Quarterly frequency (`Q`).
72    Q,
73    /// Monthly frequency (`M`).
74    M,
75    /// Weekly frequency (`W`).
76    W,
77    /// Daily frequency (`D`).
78    D,
79}
80
81impl Frequency {
82    /// Returns the BOJ query parameter value for this frequency.
83    ///
84    /// # Examples
85    ///
86    /// ```
87    /// use boj_client::query::Frequency;
88    ///
89    /// assert_eq!(Frequency::Q.as_query_value(), "Q");
90    /// assert_eq!(Frequency::M.as_query_value(), "M");
91    /// ```
92    pub fn as_query_value(self) -> &'static str {
93        match self {
94            Self::Cy => "CY",
95            Self::Fy => "FY",
96            Self::Ch => "CH",
97            Self::Fh => "FH",
98            Self::Q => "Q",
99            Self::M => "M",
100            Self::W => "W",
101            Self::D => "D",
102        }
103    }
104}
105
106/// Expected CSV character encoding used by decoders.
107#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
108pub(crate) enum CsvEncoding {
109    /// Shift_JIS-encoded CSV.
110    ShiftJis,
111    /// UTF-8 encoded CSV.
112    Utf8,
113}