marketstack/api.rs
1#![warn(missing_docs)]
2
3//! API endpoint structures.
4//!
5//! The types in this module are meant to aid in constructing the appropriate calls using type-safe
6//! Rust idioms.
7//!
8//! All endpoints use the builder pattern and have their members as private so that there are no
9//! API implications of adding new members for additional query parameters in future Marketstack
10//! releases.
11//!
12//! # Example
13//!
14//! ```rust,no_run
15//! use serde::{Deserialize, Serialize};
16//! use marketstack::Marketstack;
17//! use marketstack::api::{self, Query};
18//! use marketstack::api::eod;
19//! use marketstack::{PaginationInfo, EodDataItem};
20//!
21//! // The return type of an `EodData`. Note that Marketstack may contain more information, but you can
22//! // define your structure to only fetch what is needed.
23//! #[derive(Serialize, Deserialize, Debug, Clone)]
24//! pub struct EodData {
25//! pub pagination: PaginationInfo,
26//! pub data: Vec<EodDataItem>,
27//! }
28//!
29//! // Create the client.
30//! let client = Marketstack::new("api.marketstack.com", "private-token").unwrap();
31//!
32//! // OR create an insecure client (if on the Free plan).
33//! let client = Marketstack::new_insecure("api.marketstack.com", "private-token").unwrap();
34//!
35//! // Create a simple endpoint. This one gets the "eod" for the AAPL symbol.
36//! let endpoint = eod::Eod::builder().symbol("AAPL").build().unwrap();
37//! // Call the endpoint. The return type decides how to represent the value.
38//! let eod_data: EodData = endpoint.query(&client).unwrap();
39//!
40//! // Some endpoints support pagination. Since Marketstack does pagination through query
41//! // params, we simply specify them in the endpoint builder.
42//! // Note that there are limits defined, and therefore, limit(5) is fallible and returns
43//! // a Result.
44//! let pageable_endpoint = eod::Eod::builder().symbol("AAPL").limit(5).unwrap().build().unwrap();
45//! ```
46//!
47//! # Using Marketstack API
48//!
49//! The above provides an example as to how to query `eod` data from marketstack. To use the other
50//! builders, please see the respective modules within `api` for more information. The modules are
51//! organized by the endpoints that are provided by marketstack.
52
53mod client;
54mod endpoint;
55mod error;
56mod ignore;
57mod params;
58mod query;
59mod raw;
60
61pub mod endpoint_prelude;
62
63pub mod common;
64pub mod currencies;
65pub mod dividends;
66pub mod eod;
67pub mod exchanges;
68pub mod intraday;
69pub mod paged;
70pub mod splits;
71pub mod tickers;
72pub mod timezones;
73
74pub use self::client::AsyncClient;
75pub use self::client::Client;
76pub use self::client::RestClient;
77
78pub use self::endpoint::Endpoint;
79
80pub use self::error::ApiError;
81pub use self::error::BodyError;
82
83pub use self::ignore::ignore;
84pub use self::ignore::Ignore;
85
86pub use self::params::FormParams;
87pub use self::params::ParamValue;
88pub use self::params::QueryParams;
89
90pub use self::query::AsyncQuery;
91pub use self::query::Query;
92
93pub use self::raw::raw;
94pub use self::raw::Raw;
95
96pub use self::paged::PageLimit;