Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement all eod endpoints #5

Merged
merged 10 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "marketstack"
version = "0.0.2"
version = "0.0.3"
edition = "2021"
license = "MIT"
description = "Rust bindings for Marketstack REST API"
Expand Down
49 changes: 45 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.
#![warn(missing_docs)]

//! API endpoint structures.
//!
//! The types in this module are meant to aid in constructing the appropriate calls using type-safe
//! Rust idioms.
//!
//! All endpoints use the builder pattern and have their members as private so that there are no
//! API implications of adding new members for additional query parameters in future GitLab
//! releases.
//!
//! # Example
//!
//! ```rust,no_run
//! use serde::{Deserialize, Serialize};
//! use marketstack::Marketstack;
//! use marketstack::api::{self, Query};
//! use marketstack::api::eod;
//! use marketstack::{PaginationInfo, EodDataItem};
//!
//! // The return type of an `EodData`. Note that Marketstack may contain more information, but you can
//! // define your structure to only fetch what is needed.
//! #[derive(Serialize, Deserialize, Debug, Clone)]
//! pub struct EodData {
//! pub pagination: PaginationInfo,
//! pub data: Vec<EodDataItem>,
//! }
//!
//! // Create the client.
//! let client = Marketstack::new("api.marketstack.com", "private-token").unwrap();
//!
//! // OR create an insecure token (if on the Free plan).
//! let client = Marketstack::new_insecure("api.marketstack.com", "private-token").unwrap();
//!
//! // Create a simple endpoint. This one gets the "eod" for the AAPL symbol.
//! let endpoint = eod::Eod::builder().symbol("AAPL").build().unwrap();
//! // Call the endpoint. The return type decides how to represent the value.
//! let eod_date: EodData = endpoint.query(&client).unwrap();
//!
//! // Some endpoints support pagination. Since Marketstack does pagination through query
//! // params, we simply specify them in the endpoint builder.
//! // Note that there are limits defined, and therefore, limit(5) is fallible and returns
//! // a Result.
//! let pageable_endpoint = eod::Eod::builder().symbol("AAPL").limit(5).unwrap().build().unwrap();
//! ```

mod basic;
mod client;
Expand Down
5 changes: 0 additions & 5 deletions src/api/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.

use std::error::Error;

use async_trait::async_trait;
Expand Down
6 changes: 1 addition & 5 deletions src/api/common.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.

//! API types common to many endpoints.
//!
//! Usually these are enumerations or other simple wrappers around structures
Expand All @@ -29,6 +24,7 @@ impl Default for SortOrder {
}
}
impl SortOrder {
/// The string representation of the sort order.
pub fn as_str(self) -> &'static str {
match self {
SortOrder::Ascending => "ASC",
Expand Down
1 change: 1 addition & 0 deletions src/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::de::DeserializeOwned;

use crate::api::{query, ApiError, AsyncClient, AsyncQuery, BodyError, Client, Query, QueryParams};

/// A trait for providing the necessary information for a single REST API endpoint.
pub trait Endpoint {
/// The HTTP method to use for the endpoint.
fn method(&self) -> Method;
Expand Down
5 changes: 0 additions & 5 deletions src/api/endpoint_prelude.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>.
// This file may not be copied, modified, or distributed
// except according to those terms.

//! Endpoint prelude
//!
//! This module re-exports all of the types needed for endpoints to implement the
Expand Down
Loading