crossref_client/response/journal.rs
1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// How many DOIs crossref holds for a journal.
7#[derive(Debug, Deserialize, Serialize, Clone)]
8#[serde(rename_all = "kebab-case")]
9pub struct Counts {
10 /// every DOI, current and backfile
11 pub total_dois: i32,
12 /// DOIs for material published within the last two years
13 pub current_dois: i32,
14 /// DOIs for material published more than two years ago
15 pub backfile_dois: i32,
16}
17
18/// The per-year DOI counts crossref reports for a journal.
19#[derive(Debug, Deserialize, Serialize, Clone, Default)]
20#[serde(rename_all = "kebab-case")]
21pub struct Breakdowns {
22 /// `(year, number of DOIs issued that year)` pairs, in the order crossref returned them
23 #[serde(default)]
24 pub dois_by_issued_year: Vec<(i64, i64)>,
25}
26
27/// response item for the `/journals/{issn}` route
28#[derive(Debug, Deserialize, Serialize, Clone)]
29#[serde(rename_all = "kebab-case")]
30pub struct Journal {
31 /// when crossref last checked the journal's status, if ever
32 #[serde(with = "chrono::serde::ts_milliseconds_option", default)]
33 pub last_status_check_time: Option<DateTime<Utc>>,
34 /// total/current/backfile DOI counts; crossref returns `null` for journals it has not tallied
35 pub counts: Option<Counts>,
36 /// DOI counts per issued year; crossref returns `null` for journals it has not tallied
37 pub breakdowns: Option<Breakdowns>,
38 /// the publisher that deposits the journal
39 pub publisher: String,
40 /// what share of the journal's deposits carry each optional field
41 ///
42 /// Left untyped: crossref keeps adding fields to it, and a struct listing
43 /// them would reject every journal deposited after the next one lands.
44 pub coverage: Option<serde_json::Value>,
45 /// the journal's title
46 pub title: String,
47 /// subject categories the journal is classified under
48 #[serde(default)]
49 pub subjects: Vec<String>,
50 /// [`Journal::coverage`], split into current, backfile and all
51 pub coverage_type: Option<serde_json::Value>,
52 /// the `deposits-*` flags crossref records for the journal, keyed by flag name
53 pub flags: Option<HashMap<String, bool>>,
54 /// the journal's ISSNs, print and electronic
55 #[serde(rename = "ISSN", default)]
56 pub issn: Vec<String>,
57 /// the same ISSNs, each labelled with which kind it is
58 #[serde(default)]
59 pub issn_type: Vec<IssnType>,
60}
61
62impl Journal {
63 /// `(year, DOI count)` pairs sorted ascending by year.
64 ///
65 /// Empty if crossref reported no breakdown for this journal.
66 pub fn dois_by_issued_year(&self) -> Vec<(i64, i64)> {
67 let mut years = self
68 .breakdowns
69 .as_ref()
70 .map(|b| b.dois_by_issued_year.clone())
71 .unwrap_or_default();
72 years.sort_by_key(|(year, _)| *year);
73 years
74 }
75}
76
77/// an ISSN together with the kind of ISSN it is
78#[derive(Debug, Deserialize, Serialize, Clone)]
79#[serde(rename_all = "kebab-case")]
80pub struct IssnType {
81 /// the identifier, in `xxxx-xxxx` form
82 pub value: String,
83 /// `print`, `electronic` or `link`; crossref leaves this `null` for some journals
84 #[serde(rename = "type")]
85 pub type_: Option<String>,
86}