GetEverythingResponse

Struct GetEverythingResponse 

Source
pub struct GetEverythingResponse { /* private fields */ }

Implementations§

Source§

impl GetEverythingResponse

Source

pub fn get_status(&self) -> &String

Source

pub fn get_total_results(&self) -> &i32

Examples found in repository?
examples/everything_search.rs (line 70)
53async fn main() {
54    dotenvy::dotenv().ok();
55
56    // Provide your API key here or set it in the environment variable NEWS_API_KEY
57    // let client = NewsApiClient::new("api_key");
58    let client = NewsApiClient::from_env();
59
60    let everything_request = GetEverythingRequest::builder()
61        .search_term(String::from("Nvidia+NVDA+stock"))
62        .language(Language::EN)
63        .start_date(Utc::now() - chrono::Duration::days(30))
64        .end_date(Utc::now())
65        .page_size(1)
66        .build();
67
68    match client.get_everything(&everything_request).await {
69        Ok(response) => {
70            println!("Total Results: {}", response.get_total_results());
71            println!("Articles retrieved: {}", response.get_articles().len());
72
73            for (i, article) in response.get_articles().iter().enumerate() {
74                println!("Article #{}: {}", i + 1, article.get_title());
75                println!("  Source: {}", article.get_source().get_name());
76                println!("  Published: {}", article.get_published_at());
77                println!("  URL: {}", article.get_url());
78                println!();
79            }
80        }
81        Err(err) => {
82            eprintln!(
83                "Error: {}",
84                match err {
85                    ApiClientError::InvalidResponse(response) => response.message.clone(),
86                    _ => err.to_string(),
87                }
88            );
89        }
90    }
91}
More examples
Hide additional examples
examples/async_everything_search.rs (line 24)
6async fn main() {
7    dotenvy::dotenv().ok();
8
9    println!("Example 1: Using the builder pattern");
10    let builder_client = NewsApiClient::builder()
11        .build()
12        .expect("Failed to build NewsApiClient");
13
14    let request1 = GetEverythingRequest::builder()
15        .search_term(String::from("Nvidia+NVDA+stock"))
16        .language(Language::EN)
17        .page_size(1)
18        .build();
19
20    match builder_client.get_everything(&request1).await {
21        Ok(response) => {
22            println!(
23                "Builder client - Total Results: {}",
24                response.get_total_results()
25            );
26            println!("Articles retrieved: {}", response.get_articles().len());
27            if let Some(article) = response.get_articles().first() {
28                println!("First article: {}", article.get_title());
29            }
30        }
31        Err(err) => {
32            eprintln!("Builder client error: {}", err);
33        }
34    }
35
36    println!("\nExample 2: Using from_env");
37    let env_client = NewsApiClient::from_env();
38
39    let request2 = GetEverythingRequest::builder()
40        .search_term(String::from("Bitcoin+crypto"))
41        .language(Language::EN)
42        .page_size(1)
43        .build();
44
45    match env_client.get_everything(&request2).await {
46        Ok(response) => {
47            println!(
48                "Env client - Total Results: {}",
49                response.get_total_results()
50            );
51            println!("Articles retrieved: {}", response.get_articles().len());
52            if let Some(article) = response.get_articles().first() {
53                println!("First article: {}", article.get_title());
54            }
55        }
56        Err(err) => {
57            eprintln!("Env client error: {}", err);
58        }
59    }
60}
Source

pub fn get_articles(&self) -> &Vec<Article>

Examples found in repository?
examples/everything_search.rs (line 71)
53async fn main() {
54    dotenvy::dotenv().ok();
55
56    // Provide your API key here or set it in the environment variable NEWS_API_KEY
57    // let client = NewsApiClient::new("api_key");
58    let client = NewsApiClient::from_env();
59
60    let everything_request = GetEverythingRequest::builder()
61        .search_term(String::from("Nvidia+NVDA+stock"))
62        .language(Language::EN)
63        .start_date(Utc::now() - chrono::Duration::days(30))
64        .end_date(Utc::now())
65        .page_size(1)
66        .build();
67
68    match client.get_everything(&everything_request).await {
69        Ok(response) => {
70            println!("Total Results: {}", response.get_total_results());
71            println!("Articles retrieved: {}", response.get_articles().len());
72
73            for (i, article) in response.get_articles().iter().enumerate() {
74                println!("Article #{}: {}", i + 1, article.get_title());
75                println!("  Source: {}", article.get_source().get_name());
76                println!("  Published: {}", article.get_published_at());
77                println!("  URL: {}", article.get_url());
78                println!();
79            }
80        }
81        Err(err) => {
82            eprintln!(
83                "Error: {}",
84                match err {
85                    ApiClientError::InvalidResponse(response) => response.message.clone(),
86                    _ => err.to_string(),
87                }
88            );
89        }
90    }
91}
More examples
Hide additional examples
examples/async_everything_search.rs (line 26)
6async fn main() {
7    dotenvy::dotenv().ok();
8
9    println!("Example 1: Using the builder pattern");
10    let builder_client = NewsApiClient::builder()
11        .build()
12        .expect("Failed to build NewsApiClient");
13
14    let request1 = GetEverythingRequest::builder()
15        .search_term(String::from("Nvidia+NVDA+stock"))
16        .language(Language::EN)
17        .page_size(1)
18        .build();
19
20    match builder_client.get_everything(&request1).await {
21        Ok(response) => {
22            println!(
23                "Builder client - Total Results: {}",
24                response.get_total_results()
25            );
26            println!("Articles retrieved: {}", response.get_articles().len());
27            if let Some(article) = response.get_articles().first() {
28                println!("First article: {}", article.get_title());
29            }
30        }
31        Err(err) => {
32            eprintln!("Builder client error: {}", err);
33        }
34    }
35
36    println!("\nExample 2: Using from_env");
37    let env_client = NewsApiClient::from_env();
38
39    let request2 = GetEverythingRequest::builder()
40        .search_term(String::from("Bitcoin+crypto"))
41        .language(Language::EN)
42        .page_size(1)
43        .build();
44
45    match env_client.get_everything(&request2).await {
46        Ok(response) => {
47            println!(
48                "Env client - Total Results: {}",
49                response.get_total_results()
50            );
51            println!("Articles retrieved: {}", response.get_articles().len());
52            if let Some(article) = response.get_articles().first() {
53                println!("First article: {}", article.get_title());
54            }
55        }
56        Err(err) => {
57            eprintln!("Env client error: {}", err);
58        }
59    }
60}

Trait Implementations§

Source§

impl Debug for GetEverythingResponse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for GetEverythingResponse

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GetEverythingResponse

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,