inaturalist 0.4.0

iNaturalist API bindings
Documentation
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
 * iNaturalist API
 *
 * # https://api.inaturalist.org/v1/  [iNaturalist](https://www.inaturalist.org/) is a global community of naturalists, scientists, and members of the public sharing over a million wildlife sightings to teach one another about the natural world while creating high quality citizen science data for science and conservation. The iNaturalist technology infrastructure and open source software is administered by the [California Academy of Sciences](https://www.calacademy.org/) as part of their mission to explore, explain, and sustain life on Earth.  These API methods return data in JSON/JSONP and PNG response formats. They are meant to supplement the existing [iNaturalist API](https://www.inaturalist.org/pages/api+reference), implemented in Ruby on Rails, which has more functionality and supports more write operations, but tends to be slower and have less consistent response formats. Visit our [developers page](https://www.inaturalist.org/pages/developers) for more information. Write operations that expect and return JSON describe a single `body` parameter that represents the request body, which should be specified as JSON. See the \"Model\" of each body parameter for attributes that we accept in these JSON objects.  Multiple values for a single URL parameter should be separated by commas, e.g. `taxon_id=1,2,3`.  Map tiles are generated using the [node-mapnik](https://github.com/mapnik/node-mapnik) library, following the XYZ map tiling scheme. The \"Observation Tile\" methods accept nearly all the parameters of the observation search APIs, and will generate map tiles reflecting the same observations returned by searches. These \"Observation Tile\" methods have corresponding [UTFGrid](https://github.com/mapbox/utfgrid-spec) JSON responses which return information needed to make interactive maps.  Authentication in the Node API is handled via JSON Web Tokens (JWT). To obtain one, make an [OAuth-authenticated request](http://www.inaturalist.org/pages/api+reference#auth) to https://www.inaturalist.org/users/api_token. Each JWT will expire after 24 hours. Authentication required for all PUT and POST requests. Some GET requests will also include private information like hidden coordinates if the authenticated user has permission to view them.  iNaturalist Website: https://www.inaturalist.org/  Open Source Software: https://github.com/inaturalist/  ## Terms of Use  Use of this API is subject to the iNaturalist [Terms of Service](https://www.inaturalist.org/terms) and [Privacy Policy](https://www.inaturalist.org/privacy). We will block any use of our API that violates our Terms or Privacy Policy without notice. The API is intended to support application development, not data scraping. For pre- generated data exports, see https://www.inaturalist.org/pages/developers.  Please note that we throttle API usage to a max of 100 requests per minute, though we ask that you try to keep it to 60 requests per minute or lower, and to keep under 10,000 requests per day. If we notice usage that has serious impact on our performance we may institute blocks without notification.  Terms of Service: https://www.inaturalist.org/terms  Privacy Policy: https://www.inaturalist.org/privacy
 *
 * The version of the OpenAPI document: 1.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use reqwest;

use super::{configuration, Error};
use crate::apis::ResponseContent;

/// struct for passing parameters to the method [`taxa_autocomplete_get`]
#[derive(Clone, Debug, Default)]
pub struct TaxaAutocompleteGetParams {
    /// Name must begin with this value
    pub q: String,
    /// Taxon is `active`
    pub is_active: Option<bool>,
    /// Only show taxa with this ID, or its descendants
    pub taxon_id: Option<Vec<String>>,
    /// Taxon must have this rank
    pub rank: Option<Vec<String>>,
    /// Taxon must have this rank level. Some example values are 70 (kingdom), 60 (phylum), 50 (class), 40 (order), 30 (family), 20 (genus), 10 (species), 5 (subspecies)
    pub rank_level: Option<i32>,
    /// Number of results to return in a `page`. The maximum value is 30 for this endpoint
    pub per_page: Option<String>,
    /// Locale preference for taxon common names
    pub locale: Option<String>,
    /// Place preference for regional taxon common names
    pub preferred_place_id: Option<i32>,
    /// Include all taxon names in the response
    pub all_names: Option<bool>,
}

/// struct for passing parameters to the method [`taxa_get`]
#[derive(Clone, Debug, Default)]
pub struct TaxaGetParams {
    /// Name must begin with this value
    pub q: Option<String>,
    /// Taxon is `active`
    pub is_active: Option<bool>,
    /// Only show taxa with this ID, or its descendants
    pub taxon_id: Option<Vec<String>>,
    /// Taxon's parent must have this ID
    pub parent_id: Option<i32>,
    /// Taxon must have this rank
    pub rank: Option<Vec<String>>,
    /// Taxon must have this rank level. Some example values are 70 (kingdom), 60 (phylum), 50 (class), 40 (order), 30 (family), 20 (genus), 10 (species), 5 (subspecies)
    pub rank_level: Option<i32>,
    /// Must have an ID above this value
    pub id_above: Option<String>,
    /// Must have an ID below this value
    pub id_below: Option<String>,
    /// Number of results to return in a `page`. The maximum value is generally 200 unless otherwise noted
    pub per_page: Option<String>,
    /// Locale preference for taxon common names
    pub locale: Option<String>,
    /// Place preference for regional taxon common names
    pub preferred_place_id: Option<i32>,
    /// Return only the record IDs
    pub only_id: Option<bool>,
    /// Include all taxon names in the response
    pub all_names: Option<bool>,
    /// Sort order
    pub order: Option<String>,
    /// Sort field
    pub order_by: Option<String>,
}

/// struct for passing parameters to the method [`taxa_id_get`]
#[derive(Clone, Debug, Default)]
pub struct TaxaIdGetParams {
    /// Must have this ID
    pub id: Vec<i32>,
}

/// struct for typed errors of method [`taxa_autocomplete_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TaxaAutocompleteGetError {
    DefaultResponse(crate::models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`taxa_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TaxaGetError {
    DefaultResponse(crate::models::Error),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`taxa_id_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TaxaIdGetError {
    DefaultResponse(crate::models::Error),
    UnknownValue(serde_json::Value),
}

/// Given an string, returns taxa with names starting with the search term
pub async fn taxa_autocomplete_get(
    configuration: &configuration::Configuration,
    params: TaxaAutocompleteGetParams,
) -> Result<crate::models::TaxaAutocompleteResponse, Error<TaxaAutocompleteGetError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let q = params.q;
    let is_active = params.is_active;
    let taxon_id = params.taxon_id;
    let rank = params.rank;
    let rank_level = params.rank_level;
    let per_page = params.per_page;
    let locale = params.locale;
    let preferred_place_id = params.preferred_place_id;
    let all_names = params.all_names;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/taxa/autocomplete", local_var_configuration.base_path);
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("q", &q.to_string())]);
    if let Some(ref local_var_str) = is_active {
        local_var_req_builder =
            local_var_req_builder.query(&[("is_active", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = taxon_id {
        local_var_req_builder = match "csv" {
            "multi" => local_var_req_builder.query(
                &local_var_str
                    .into_iter()
                    .map(|p| ("taxon_id".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => local_var_req_builder.query(&[(
                "taxon_id",
                &local_var_str
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref local_var_str) = rank {
        local_var_req_builder = match "csv" {
            "multi" => local_var_req_builder.query(
                &local_var_str
                    .into_iter()
                    .map(|p| ("rank".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => local_var_req_builder.query(&[(
                "rank",
                &local_var_str
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref local_var_str) = rank_level {
        local_var_req_builder =
            local_var_req_builder.query(&[("rank_level", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = per_page {
        local_var_req_builder =
            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = locale {
        local_var_req_builder =
            local_var_req_builder.query(&[("locale", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = preferred_place_id {
        local_var_req_builder =
            local_var_req_builder.query(&[("preferred_place_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = all_names {
        local_var_req_builder =
            local_var_req_builder.query(&[("all_names", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<TaxaAutocompleteGetError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Given zero to many of following parameters, returns taxa matching the search criteria
pub async fn taxa_get(
    configuration: &configuration::Configuration,
    params: TaxaGetParams,
) -> Result<crate::models::TaxaShowResponse, Error<TaxaGetError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let q = params.q;
    let is_active = params.is_active;
    let taxon_id = params.taxon_id;
    let parent_id = params.parent_id;
    let rank = params.rank;
    let rank_level = params.rank_level;
    let id_above = params.id_above;
    let id_below = params.id_below;
    let per_page = params.per_page;
    let locale = params.locale;
    let preferred_place_id = params.preferred_place_id;
    let only_id = params.only_id;
    let all_names = params.all_names;
    let order = params.order;
    let order_by = params.order_by;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/taxa", local_var_configuration.base_path);
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_str) = q {
        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = is_active {
        local_var_req_builder =
            local_var_req_builder.query(&[("is_active", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = taxon_id {
        local_var_req_builder = match "csv" {
            "multi" => local_var_req_builder.query(
                &local_var_str
                    .into_iter()
                    .map(|p| ("taxon_id".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => local_var_req_builder.query(&[(
                "taxon_id",
                &local_var_str
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref local_var_str) = parent_id {
        local_var_req_builder =
            local_var_req_builder.query(&[("parent_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = rank {
        local_var_req_builder = match "csv" {
            "multi" => local_var_req_builder.query(
                &local_var_str
                    .into_iter()
                    .map(|p| ("rank".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => local_var_req_builder.query(&[(
                "rank",
                &local_var_str
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref local_var_str) = rank_level {
        local_var_req_builder =
            local_var_req_builder.query(&[("rank_level", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = id_above {
        local_var_req_builder =
            local_var_req_builder.query(&[("id_above", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = id_below {
        local_var_req_builder =
            local_var_req_builder.query(&[("id_below", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = per_page {
        local_var_req_builder =
            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = locale {
        local_var_req_builder =
            local_var_req_builder.query(&[("locale", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = preferred_place_id {
        local_var_req_builder =
            local_var_req_builder.query(&[("preferred_place_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = only_id {
        local_var_req_builder =
            local_var_req_builder.query(&[("only_id", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = all_names {
        local_var_req_builder =
            local_var_req_builder.query(&[("all_names", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = order {
        local_var_req_builder =
            local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = order_by {
        local_var_req_builder =
            local_var_req_builder.query(&[("order_by", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<TaxaGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Given an ID, or an array of IDs in comma-delimited format, returns corresponding taxa. A maximum of 30 results will be returned
pub async fn taxa_id_get(
    configuration: &configuration::Configuration,
    params: TaxaIdGetParams,
) -> Result<crate::models::TaxaShowResponse, Error<TaxaIdGetError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let id = params.id;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/taxa/{id}",
        local_var_configuration.base_path,
        id = id
            .into_iter()
            .map(|n| n.to_string())
            .collect::<Vec<String>>()
            .join(",")
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder =
            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<TaxaIdGetError> =
            serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent {
            status: local_var_status,
            content: local_var_content,
            entity: local_var_entity,
        };
        Err(Error::ResponseError(local_var_error))
    }
}