Skip to content

Commit e5ef272

Browse files
allow passing cookie at startup
1 parent cc3dbde commit e5ef272

File tree

16 files changed

+780
-392
lines changed

16 files changed

+780
-392
lines changed

Cargo.lock

Lines changed: 707 additions & 341 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::process::Command;
66

77
fn main() {
88
let output = Command::new("git")
9-
.args(&["rev-parse", "HEAD"])
9+
.args(["rev-parse", "HEAD"])
1010
.output()
1111
.unwrap();
1212
let git_hash = String::from_utf8(output.stdout).unwrap();

src/api/article.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use crate::api::{common::Article, error::ApiResult, fetch::fetch};
1+
use crate::{
2+
api::{common::Article, error::ApiResult, fetch::fetch},
3+
client::Client,
4+
};
25

36
const API_URL: &str = "https://www.reuters.com/pf/api/v3/content/fetch/article-by-id-or-url-v1";
47

5-
pub fn fetch_article_by_url(client: &ureq::Agent, path: &str) -> ApiResult<Article> {
8+
pub fn fetch_article_by_url(client: &Client, path: &str) -> ApiResult<Article> {
69
let query = format!(r#"{{"website_url":"{path}","website":"reuters"}}"#);
710

811
fetch(client, API_URL, &query)

src/api/common.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ pub struct Articles {
1010

1111
#[derive(Deserialize)]
1212
pub struct Pagination {
13-
pub size: Option<u32>,
1413
pub total_size: Option<u32>,
15-
pub orderby: String,
1614
}
1715

1816
#[derive(Deserialize)]
@@ -25,12 +23,6 @@ pub struct Article {
2523
pub published_time: String,
2624
}
2725

28-
#[derive(Deserialize)]
29-
pub struct Section {
30-
pub path: String,
31-
pub name: String,
32-
}
33-
3426
#[derive(Deserialize)]
3527
pub struct ApiResponse<T> {
3628
#[serde(rename = "statusCode")]

src/api/fetch.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use crate::api::{
2-
common::ApiResponse,
3-
error::{ApiError, ApiResult},
1+
use crate::{
2+
api::{
3+
common::ApiResponse,
4+
error::{ApiError, ApiResult},
5+
},
6+
client::Client,
47
};
58
use serde::Deserialize;
69

7-
pub(crate) fn fetch<T>(client: &ureq::Agent, url: &str, query: &str) -> ApiResult<T>
10+
pub(crate) fn fetch<T>(client: &Client, url: &str, query: &str) -> ApiResult<T>
811
where
912
T: for<'a> Deserialize<'a>,
1013
{

src/api/legacy_article.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::Deserialize;
22

3-
use crate::api::error::ApiError;
3+
use crate::{api::error::ApiError, client::Client};
44

55
use super::error::ApiResult;
66

@@ -27,7 +27,6 @@ pub struct LegacyArticleArticle {
2727

2828
#[derive(Deserialize)]
2929
pub struct LegacyArticleStream {
30-
pub id: String,
3130
pub headline: String,
3231
pub description: String,
3332
pub date: LegacyArticleDate,
@@ -52,10 +51,7 @@ pub struct LegacyArticleBodyItem {
5251
pub content: String,
5352
}
5453

55-
pub fn fetch_legacy_article(
56-
client: &ureq::Agent,
57-
path: &str,
58-
) -> Result<ureq::Response, ureq::Error> {
54+
pub fn fetch_legacy_article(client: &Client, path: &str) -> Result<ureq::Response, ureq::Error> {
5955
let link = format!("https://www.reuters.com{path}");
6056

6157
client.get(&link).call()

src/api/markit.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
use super::{
2-
common::{Article, Pagination},
3-
error::ApiResult,
4-
fetch::fetch,
5-
};
1+
use crate::client::Client;
2+
3+
use super::{common::Article, error::ApiResult, fetch::fetch};
64

75
#[derive(serde::Deserialize)]
86
#[serde(rename_all = "camelCase")]
97
pub struct StockSearchResult {
10-
pub pagination: Pagination,
11-
pub market_info: MarketInfo,
128
pub articles: Box<[Article]>,
139
}
1410

15-
#[derive(serde::Deserialize)]
16-
pub struct MarketInfo {
17-
pub website: String,
18-
pub about: String,
19-
}
20-
21-
pub fn fetch_by_stock_symbol(client: &ureq::Agent, symbol: &str) -> ApiResult<StockSearchResult> {
11+
pub fn fetch_by_stock_symbol(client: &Client, symbol: &str) -> ApiResult<StockSearchResult> {
2212
const API_URL: &str =
2313
"https://www.reuters.com/pf/api/v3/content/fetch/articles-by-stock-symbol-v1";
2414

src/api/search.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use crate::client::Client;
2+
13
use super::{common::Articles, error::ApiResult, fetch::fetch};
24

35
const API_URL: &str = "https://www.reuters.com/pf/api/v3/content/fetch/articles-by-search-v2";
46

57
pub fn fetch_articles_by_search(
6-
client: &ureq::Agent,
8+
client: &Client,
79
keyword: &str,
810
offset: u32,
911
size: u32,

src/api/section.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use crate::client::Client;
2+
13
use super::{common::Articles, error::ApiResult, fetch::fetch};
24

35
const API_URL: &str =
46
"https://www.reuters.com/pf/api/v3/content/fetch/recent-stories-by-sections-v1";
57

68
pub fn fetch_articles_by_section(
7-
client: &ureq::Agent,
9+
client: &Client,
810
path: &str,
911
offset: u32,
1012
size: u32,

src/api/topic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use crate::client::Client;
2+
13
use super::{common::Articles, error::ApiResult, fetch::fetch};
24

35
const API_URL: &str = "https://www.reuters.com/pf/api/v3/content/fetch/articles-by-topic-v1";
46

57
pub fn fetch_articles_by_topic(
6-
client: &ureq::Agent,
8+
client: &Client,
79
path: &str,
810
offset: u32,
911
size: u32,

0 commit comments

Comments
 (0)