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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//! # adsabs
//!
//! A Rust client for the SAO/NASA Astrophysics Data System API.
//!
//! ## Usage
//!
//! To use `adsabs` as a library, add it as a dependency in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! adsabs = "0.1"
//! ```
//!
//! For now, only the `/search` endpoint is supported, as described below. Other
//! endpoints could be manually accessed using [`Ads::get`] directly, and pull
//! requests would be welcome!
//!
//! ## Examples
//!
//! To search for highly cited supernova papers, something like the following
//! should do the trick:
//!
//! ```no_run
//! # fn doc() -> adsabs::Result<()> {
//! use adsabs::prelude::*;
//!
//! let client = Ads::new("ADS_API_TOKEN")?;
//! for doc in client.search("supernova")
//! .sort("citation_count")
//! .iter_docs()
//! .limit(5)
//! {
//! println!("{:?}", doc?.title);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! Don't forget to replace `ADS_API_TOKEN` with your [ADS settings page], or
//! using another method as described in the [API token](#api-token) section
//! below.
//!
//! The `query` parameter passed to [`Ads::search`] supports all the usual ADS
//! search syntax. So, for example, if you want to search for papers by a
//! particular first author, use something like the following:
//!
//! ```no_run
//! # fn doc() -> adsabs::Result<()> {
//! use adsabs::prelude::*;
//!
//! let client = Ads::new("ADS_API_TOKEN")?;
//! for doc in client.search("author:\"^Dalcanton, J\"").iter_docs().limit(5) {
//! println!("{:?}", doc?.title);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! You can find executable examples of these and other sample usage in [the
//! `examples` directory of the repository on
//! GitHub](https://github.com/dfm/adsabs-rs/tree/main/examples).
//!
//! ## API token
//!
//! All queries to the ADS API must be authenticated with your API token from
//! the [ADS settings page]. You can pass your token as a string directly to the
//! client:
//!
//! ```rust
//! # fn doc() -> adsabs::Result<()> {
//! # use adsabs::prelude::*;
//! let client = Ads::new("ADS_API_TOKEN")?;
//! # Ok(())
//! # }
//! ```
//!
//! Or you can load the token automatically from your environment using
//! [`AdsBuilder::from_env`]:
//!
//! ```no_run
//! # fn doc() -> adsabs::Result<()> {
//! # use adsabs::prelude::*;
//! let client = Ads::from_env()?;
//! # Ok(())
//! # }
//! ```
//!
//! In this case, the following locations are checked, in the listed order:
//!
//! 1. The `ADS_API_TOKEN` environment variable,
//! 2. The `ADS_DEV_KEY` environment variable,
//! 3. The contents of the `~/.ads/token` file, and
//! 4. The contents of the `~/.ads/dev_key` file.
//!
//! Where these were chosen to be compatible with the locations supported by the
//! Python client `ads`.
//!
//! [ADS settings page]: https://ui.adsabs.harvard.edu/user/settings/token
pub use ;
use ;
const API_BASE_URL: &str = "https://api.adsabs.harvard.edu/v1/";
/// An interface to the NASA ADS API.
///
/// This has various configuration values to tweak, but the most important one
/// is `token`, which you'll want to set to your ADS API token, which is
/// available on your [ADS settings page]. To configure your `Ads` interface,
/// use [`Ads::builder`].
///
/// [ADS settings page]: https://ui.adsabs.harvard.edu/user/settings/token
///
/// # Examples
///
/// ```rust
/// # fn doc() -> adsabs::Result<()> {
/// use adsabs::Ads;
/// let api_token = "ADS_API_TOKEN";
/// let client = Ads::new(api_token)?;
/// # Ok(())
/// # }
/// ```
/// A builder that can be used to create an [`Ads`] interface with custom
/// settings.
///
/// # Example
///
/// ```rust
/// # fn run() -> adsabs::Result<()> {
/// use adsabs::Ads;
/// let api_token = "ADS_API_TOKEN";
/// let client = Ads::builder(api_token)
/// .user_agent("my-user-agent")
/// .build()?;
/// # Ok(())
/// # }
/// ```