Skip to content

Commit ac2ec8d

Browse files
authored
Release/0.8.0 (#9)
* v0.8.0 - see CHANGELOG for details
1 parent c80c03e commit ac2ec8d

File tree

9 files changed

+48
-39
lines changed

9 files changed

+48
-39
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [0.8.0] - 2025-03-31
2+
3+
### Changed
4+
5+
- `get_profile_info()` argument changed
6+
- `get_conversations()` argument changed
7+
18
## [0.7.0] - 2025-03-28
29

310
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rusty_meta_threads"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
edition = "2024"
55
description = "Community Rust SDK for integrating with Meta Threads API"
66
repository = "https://github.com/Thesephi/rusty_meta_threads.git"

src/create_reply.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ pub async fn create_reply(
1111
) -> Result<SimpleMediaObject, reqwest::Error> {
1212
let mut url = format!(
1313
"https://graph.threads.net/v1.0/me/threads\
14-
?reply_to_id={reply_to_id}\
15-
&access_token={token}"
14+
?reply_to_id={reply_to_id}"
1615
);
1716

1817
let mut publish_wait_time_ms = 300;
@@ -34,6 +33,7 @@ pub async fn create_reply(
3433

3534
let media_container = reqwest::Client::new()
3635
.post(&url)
36+
.bearer_auth(token)
3737
.send()
3838
.await?
3939
.json::<SimpleMediaObject>()

src/mentions.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ pub async fn get_mentions(
66
fields: Option<&str>,
77
token: &str,
88
) -> Result<MetaMediaResponse<MetaMedia>, reqwest::Error> {
9-
let the_fields = if let Some(f) = fields {
10-
f
11-
} else {
12-
"id,username,text,media_url,root_post,replied_to"
13-
};
9+
let the_fields = fields.unwrap_or_else(|| "id,username,text,media_url,root_post,replied_to");
1410

1511
let url = format!(
1612
"https://graph.threads.net/{user_id}/mentions\
@@ -33,6 +29,11 @@ mod tests {
3329
use super::*;
3430
use crate::utils::read_dot_env;
3531
use log::debug;
32+
use std::any::{Any, TypeId};
33+
34+
fn is_meta_media_vec<T: Any>(_val: &T) -> bool {
35+
TypeId::of::<T>() == TypeId::of::<Vec<MetaMedia>>()
36+
}
3637

3738
#[tokio::test]
3839
async fn test_get_mentions() {
@@ -49,7 +50,7 @@ mod tests {
4950
Ok(val) => match val.data {
5051
Some(dat) => {
5152
debug!("mentions fetched: {:?}", dat);
52-
assert_eq!(dat[0].id, "foo")
53+
assert_eq!(is_meta_media_vec(&dat), true);
5354
}
5455
None => panic!("unexpected result"),
5556
},

src/oembed.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ pub async fn get_oembed_html(
1616
token: &str,
1717
) -> Result<OembedResponse, reqwest::Error> {
1818
let the_post_url = encode(post_url);
19-
let url = format!(
20-
"https://graph.threads.net/v1.0/oembed?url={the_post_url}\
21-
&access_token={token}"
22-
);
19+
let url = format!("https://graph.threads.net/v1.0/oembed?url={the_post_url}");
2320

2421
debug!("requesting oembed for: {:?}", &url);
2522

2623
let res = reqwest::Client::new()
2724
.get(&url)
25+
.bearer_auth(token)
2826
.send()
2927
.await?
3028
.json::<OembedResponse>()
@@ -49,12 +47,11 @@ mod tests {
4947
let env = read_dot_env();
5048
let token = env.get("ACCESS_TOKEN").unwrap();
5149

52-
let res =
53-
get_oembed_html("https://www.threads.net/@dkode___/post/DHwBylVNThs", token).await;
50+
let res = get_oembed_html("https://www.threads.net/@threads/post/DHvtwr8g63f", token).await;
5451

5552
debug!("oembed response fetched: {:?}", res);
5653

5754
assert_eq!(true, res.is_ok());
58-
assert_eq!(res.unwrap().html, "");
55+
assert_eq!(res.unwrap().provider_url, "https://www.threads.net/");
5956
}
6057
}

src/posts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pub async fn publish_media_container(
66
) -> Result<SimpleMediaObject, reqwest::Error> {
77
let url = format!(
88
"https://graph.threads.net/v1.0/me/threads_publish\
9-
?creation_id={media_container_id}\
10-
&access_token={token}"
9+
?creation_id={media_container_id}"
1110
);
1211

1312
let res = reqwest::Client::new()
1413
.post(&url)
14+
.bearer_auth(token)
1515
.send()
1616
.await?
1717
.json::<SimpleMediaObject>()

src/profiles.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ pub struct ThreadsUserProfile {
1212
pub error: Option<ThreadsApiRespErrorPayload>,
1313
}
1414

15-
// @TODO have fields as fn arguments instead of hardcoding
16-
pub async fn get_profile_info(bearer_token: &str) -> Result<ThreadsUserProfile, reqwest::Error> {
17-
let url = "https://graph.threads.net/me\
18-
?fields=id%2Cusername%2Cname%2C\
19-
threads_profile_picture_url%2Cthreads_biography";
15+
pub async fn get_profile_info(
16+
fields: Option<&str>,
17+
bearer_token: &str,
18+
) -> Result<ThreadsUserProfile, reqwest::Error> {
19+
let the_fields =
20+
fields.unwrap_or_else(|| "id,username,name,threads_profile_picture_url,threads_biography");
21+
let url = format!(
22+
"https://graph.threads.net/me\
23+
?fields={the_fields}"
24+
);
2025

2126
let res = reqwest::Client::new()
2227
.get(url)
@@ -57,7 +62,7 @@ mod tests {
5762
let env = read_dot_env();
5863
let token = env.get("ACCESS_TOKEN").unwrap();
5964

60-
let res = get_profile_info(token).await;
65+
let res = get_profile_info(None, token).await;
6166

6267
debug!("profile fetched {:?}", res);
6368

src/reply_management.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ use crate::shared::MetaMediaResponse;
33

44
pub async fn get_conversations(
55
media_id: &str,
6+
fields: Option<&str>,
7+
reverse: Option<bool>,
68
token: &str,
79
) -> Result<MetaMediaResponse<MetaMedia>, reqwest::Error> {
8-
// @TODO get fields from method arguments
9-
let reverse = false;
10+
let the_fields = fields.unwrap_or_else(|| {
11+
"id,is_reply_owned_by_me,username,text,timestamp,\
12+
media_product_type,media_type,media_url,shortcode,thumbnail_url,\
13+
children,has_replies,root_post,replied_to,is_reply,hide_status"
14+
});
15+
let the_reverse = reverse.unwrap_or(false);
1016
let url = format!(
1117
"https://graph.threads.net/v1.0/{media_id}/conversation\
12-
?fields=id,is_reply_owned_by_me,username,text,timestamp,\
13-
media_product_type,media_type,media_url,shortcode,thumbnail_url,\
14-
children,has_replies,root_post,replied_to,is_reply,hide_status\
15-
&reverse={reverse}\
16-
&access_token={token}"
18+
?fields={the_fields}\
19+
&reverse={the_reverse}"
1720
);
1821

1922
let res = reqwest::Client::new()
2023
.get(&url)
24+
.bearer_auth(token)
2125
.send()
2226
.await?
2327
.json::<MetaMediaResponse<MetaMedia>>()

src/retrieve_media.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,13 @@ pub async fn get_thread(
6969
fields: Option<&str>,
7070
token: &str,
7171
) -> Result<MetaMedia, reqwest::Error> {
72-
let the_fields = if let Some(f) = fields {
73-
f
74-
} else {
75-
"id,root_post,replied_to,media_product_type,media_type,media_url,permalink,owner,username,text,timestamp,shortcode,thumbnail_url,children,is_quote_post"
76-
};
72+
let the_fields = fields.unwrap_or_else(|| "id,root_post,replied_to,media_product_type,media_type,media_url,permalink,owner,username,text,timestamp,shortcode,thumbnail_url,children,is_quote_post");
7773

78-
let url = format!(
79-
"https://graph.threads.net/v1.0/{thread_id}?fields={the_fields}&access_token={token}"
80-
);
74+
let url = format!("https://graph.threads.net/v1.0/{thread_id}?fields={the_fields}");
8175

8276
let res = reqwest::Client::new()
8377
.get(&url)
78+
.bearer_auth(token)
8479
.send()
8580
.await?
8681
.json::<MetaMedia>()

0 commit comments

Comments
 (0)