pub struct StackClient { /* private fields */ }
Implementations§
Source§impl StackClient
StackClient is a client for the Stack Exchange API
impl StackClient
StackClient is a client for the Stack Exchange API
Construct a default client for StackOverflow site, API version 2.3 (https://meta.stackexchange.com/questions/366977/api-2-3-release)
use stack_overflow_client::client::StackClient;
let client = StackClient::new();
Construct a e client for a specific site and API version
use stack_overflow_client::client::StackClientBuilder;
use stack_overflow_client::common::{ApiVersion, StackSite};
let client = StackClientBuilder::new()
.stack_site(StackSite::StackOverflow)
.version(ApiVersion::V2_3)
.build();
Sourcepub fn new() -> Self
pub fn new() -> Self
StackClient defaults to StackOverflow as the site and api version 2.3
Examples found in repository?
8async fn main() {
9 let question: QuestionRequest = QuestionRequest {
10 tag: Some("docker".to_string()),
11 site: StackSite::StackOverflow,
12 api_version: ApiVersion::V2_3,
13 };
14 println!("{:?}", question);
15
16 let client = StackClient::new();
17 let results = client
18 .get_featured_questions("docker")
19 .await
20 .expect("Unable to fetch featured docker questions");
21 dbg!(&results);
22 /*
23 QuestionRequest { tag: Some("rust"), site: StackOverflow, api_version: V2_3 }
24 "https://api.stackexchange.com/2.3/questions/featured?tagged=rust&site=stackoverflow"
25 {"items":[{"tags":["rust"],"owner":{"account_id":7063007,"reputation":13,"user_id":12276541,"user_type":"registered","profile_image":"https://www.gravatar.com/avatar/90649aebcc0cccc983abf5b461007176?s=256&d=identicon&r=
26 PG&f=1","display_name":"Rafaelo","link":"https://stackoverflow.com/users/12276541/rafaelo"},"is_answered":true,"view_count":109,"bounty_amount":150,"bounty_closes_date":1683583494,"answer_count":1,"score":0,"last_activ
27 ity_date":1682978694,"creation_date":1682714190,"question_id":76133120,"content_license":"CC BY-SA 4.0","link":"https://stackoverflow.com/questions/76133120/can-a-memory-pool-allocate-things-with-a-static-lifetime","ti
28 tle":"Can a memory pool allocate things with a `'static` lifetime?"}],"has_more":false,"quota_max":300,"quota_remaining":296}
29
30 "{\"items\":[{\"tags\":[\"docker\",\"docker-compose\",\"ngrok\",\"vapor\"],\"owner\":{\"account_id\":14409195,\"reputation\":2356,\"user_id\":10408494,\"user_type\":\"registered\",\"profile_image\":\"https://i.stack.imgur.com/6Clbj.jpg?s=256&g=1\",\"display_name\":\"Roland
31 Lariotte\",\"link\":\"https://stackoverflow.com/users/10408494/roland-lariotte\"},\"is_answered\":true,\"view_count\":52,\"bounty_amount\":50,\"bounty_closes_date\":1684225877,\"accepted_answer_id\":76224966,\"answer_count\":2,\"score\":2,\"last_activity_date\":1683789088,\"creation_date\":1682626252,\"last_edit_date\":1683635969,\"question_id\":76124274,\"content_license\":\"CC
32 BY-SA
33 4.0\",\"link\":\"https://stackoverflow.com/questions/76124274/how-can-i-set-ngrok-on-vapor-to-work-locally-with-an-owned-domain\",\"title\":\"How
34 can I set ngrok on Vapor to work locally with an owned
35 domain?\"},{\"tags\":[\"docker\",\"security\",\"github\",\"containers\",\"github-actions\"],\"owner\":{\"account_id\":2319125,\"reputation\":485,\"user_id\":2035417,\"user_type\":\"registered\",\"accept_rate\":75,\"profile_image\":\"https://www.gravatar.com/avatar/be22c7b705fa45820b740d9256e1593e?s=256&d=identicon&r=PG\",\"display_name\":\"ruckc\",\"link\":\"https://stackoverflow.com/users/2035417/ruckc\"},\"is_answered\":false,\"view_count\":159,\"bounty_amount\":50,\"bounty_closes_date\":1683835712,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683555302,\"creation_date\":1666965308,\"question_id\":74236426,\"content_license\":\"CC
36 BY-SA
37 4.0\",\"link\":\"https://stackoverflow.com/questions/74236426/github-actions-scheduled-container-rebuild-on-latest-release-tag-only\",\"title\":\"GitHub
38 Actions - Scheduled Container Rebuild On Latest Release Tag
39 only\"},{\"tags\":[\"docker\"],\"owner\":{\"account_id\":1312027,\"reputation\":4629,\"user_id\":1259842,\"user_type\":\"registered\",\"accept_rate\":49,\"profile_image\":\"https://www.gravatar.com/avatar/d23f0b2bb6cb82b239c03a31beb625a2?s=256&d=identicon&r=PG&f=y&so-version=2\",\"display_name\":\"miltone\",\"link\":\"https://stackoverflow.com/users/1259842/miltone\"},\"is_answered\":false,\"view_count\":40,\"bounty_amount\":50,\"bounty_closes_date\":1683972718,\"answer_count\":1,\"score\":1,\"last_activity_date\":1683368008,\"creation_date\":1683187049,\"last_edit_date\":1683368008,\"question_id\":76170819,\"content_license\":\"CC
40 BY-SA
41 4.0\",\"link\":\"https://stackoverflow.com/questions/76170819/docker-compose-build-generate-failed-to-fetch-oauth-token-post-https-auth-do\",\"title\":\"docker-compose
42 build generate failed to fetch oauth token: Post
43 "https://auth.docker.io/token": proxyconnect tcp: dial tcp
44 127.0.0.1:7080\"},{\"tags\":[\"docker\",\"heroku\",\"docker-compose\",\"fastapi\",\"streamlit\"],\"owner\":{\"account_id\":20813,\"reputation\":21665,\"user_id\":50065,\"user_type\":\"registered\",\"accept_rate\":93,\"profile_image\":\"https://i.stack.imgur.com/ZbEgH.jpg?s=256&g=1\",\"display_name\":\"BioGeek\",\"link\":\"https://stackoverflow.com/users/50065/biogeek\"},\"is_answered\":true,\"view_count\":106,\"bounty_amount\":200,\"bounty_closes_date\":1683883040,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683331610,\"creation_date\":1683031857,\"last_edit_date\":1683278209,\"question_id\":76155032,\"content_license\":\"CC
45 BY-SA
46 4.0\",\"link\":\"https://stackoverflow.com/questions/76155032/connectionerror-on-multi-docker-app-streamlit-fastapi-when-deployed-on-herok\",\"title\":\"ConnectionError
47 on multi-Docker app (Streamlit + FastAPI) when deployed on
48 Heroku\"}],\"has_more\":false,\"quota_max\":300,\"quota_remaining\":297}"
49 */
50
51 let user_id = 4676641;
52 let result = client
53 .get_answers_for_user(user_id, None)
54 .await
55 .expect("unable to fetch answers for user 4676641");
56 dbg!(&result);
57
58 let mut counter = 2;
59 loop {
60 if result.has_more {
61 let result =
62 client.get_answers_for_user(user_id, Some(counter)).await;
63 dbg!(&result);
64 counter += 1;
65 } else {
66 break;
67 }
68 }
69
70 /*
71 [src/main.rs:47] result = Response {
72 items: [
73 Question {
74 tagged: None,
75 owner: User {
76 reputation: 547,
77 account_id: 3863408,
78 user_id: 3200552,
79 user_type: "registered",
80 display_name: "merhoo",
81 },
82 is_answered: true,
83 view_count: 96,
84 favorite_count: None,
85 down_vote_count: None,
86 answer_count: 1,
87 score: 3,
88 last_activity_date: 1684111790,
89 creation_date: 1678979778,
90 question_id: 75758174,
91 title: "How to make profile default for docker-compose?",
92 },
93 ...
94 ],
95 has_more: true,
96 quota_max: 300,
97 quota_remaining: 281,
98 }
99 */
100}
Sourcepub async fn get_info(&self) -> Result<Response<Info>, Box<dyn Error>>
pub async fn get_info(&self) -> Result<Response<Info>, Box<dyn Error>>
Get info about the client’s Stack site. Returns a collection of statistics about the site. API Docs: https://api.stackexchange.com/docs/info
Sourcepub async fn get_featured_questions(
&self,
tag: &str,
) -> Result<Response<Question>, Box<dyn Error>>
pub async fn get_featured_questions( &self, tag: &str, ) -> Result<Response<Question>, Box<dyn Error>>
Get featured questions for a tag. Note that this only retrieves the first page of results. API Docs: https://api.stackexchange.com/docs/featured-questions
Examples found in repository?
8async fn main() {
9 let question: QuestionRequest = QuestionRequest {
10 tag: Some("docker".to_string()),
11 site: StackSite::StackOverflow,
12 api_version: ApiVersion::V2_3,
13 };
14 println!("{:?}", question);
15
16 let client = StackClient::new();
17 let results = client
18 .get_featured_questions("docker")
19 .await
20 .expect("Unable to fetch featured docker questions");
21 dbg!(&results);
22 /*
23 QuestionRequest { tag: Some("rust"), site: StackOverflow, api_version: V2_3 }
24 "https://api.stackexchange.com/2.3/questions/featured?tagged=rust&site=stackoverflow"
25 {"items":[{"tags":["rust"],"owner":{"account_id":7063007,"reputation":13,"user_id":12276541,"user_type":"registered","profile_image":"https://www.gravatar.com/avatar/90649aebcc0cccc983abf5b461007176?s=256&d=identicon&r=
26 PG&f=1","display_name":"Rafaelo","link":"https://stackoverflow.com/users/12276541/rafaelo"},"is_answered":true,"view_count":109,"bounty_amount":150,"bounty_closes_date":1683583494,"answer_count":1,"score":0,"last_activ
27 ity_date":1682978694,"creation_date":1682714190,"question_id":76133120,"content_license":"CC BY-SA 4.0","link":"https://stackoverflow.com/questions/76133120/can-a-memory-pool-allocate-things-with-a-static-lifetime","ti
28 tle":"Can a memory pool allocate things with a `'static` lifetime?"}],"has_more":false,"quota_max":300,"quota_remaining":296}
29
30 "{\"items\":[{\"tags\":[\"docker\",\"docker-compose\",\"ngrok\",\"vapor\"],\"owner\":{\"account_id\":14409195,\"reputation\":2356,\"user_id\":10408494,\"user_type\":\"registered\",\"profile_image\":\"https://i.stack.imgur.com/6Clbj.jpg?s=256&g=1\",\"display_name\":\"Roland
31 Lariotte\",\"link\":\"https://stackoverflow.com/users/10408494/roland-lariotte\"},\"is_answered\":true,\"view_count\":52,\"bounty_amount\":50,\"bounty_closes_date\":1684225877,\"accepted_answer_id\":76224966,\"answer_count\":2,\"score\":2,\"last_activity_date\":1683789088,\"creation_date\":1682626252,\"last_edit_date\":1683635969,\"question_id\":76124274,\"content_license\":\"CC
32 BY-SA
33 4.0\",\"link\":\"https://stackoverflow.com/questions/76124274/how-can-i-set-ngrok-on-vapor-to-work-locally-with-an-owned-domain\",\"title\":\"How
34 can I set ngrok on Vapor to work locally with an owned
35 domain?\"},{\"tags\":[\"docker\",\"security\",\"github\",\"containers\",\"github-actions\"],\"owner\":{\"account_id\":2319125,\"reputation\":485,\"user_id\":2035417,\"user_type\":\"registered\",\"accept_rate\":75,\"profile_image\":\"https://www.gravatar.com/avatar/be22c7b705fa45820b740d9256e1593e?s=256&d=identicon&r=PG\",\"display_name\":\"ruckc\",\"link\":\"https://stackoverflow.com/users/2035417/ruckc\"},\"is_answered\":false,\"view_count\":159,\"bounty_amount\":50,\"bounty_closes_date\":1683835712,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683555302,\"creation_date\":1666965308,\"question_id\":74236426,\"content_license\":\"CC
36 BY-SA
37 4.0\",\"link\":\"https://stackoverflow.com/questions/74236426/github-actions-scheduled-container-rebuild-on-latest-release-tag-only\",\"title\":\"GitHub
38 Actions - Scheduled Container Rebuild On Latest Release Tag
39 only\"},{\"tags\":[\"docker\"],\"owner\":{\"account_id\":1312027,\"reputation\":4629,\"user_id\":1259842,\"user_type\":\"registered\",\"accept_rate\":49,\"profile_image\":\"https://www.gravatar.com/avatar/d23f0b2bb6cb82b239c03a31beb625a2?s=256&d=identicon&r=PG&f=y&so-version=2\",\"display_name\":\"miltone\",\"link\":\"https://stackoverflow.com/users/1259842/miltone\"},\"is_answered\":false,\"view_count\":40,\"bounty_amount\":50,\"bounty_closes_date\":1683972718,\"answer_count\":1,\"score\":1,\"last_activity_date\":1683368008,\"creation_date\":1683187049,\"last_edit_date\":1683368008,\"question_id\":76170819,\"content_license\":\"CC
40 BY-SA
41 4.0\",\"link\":\"https://stackoverflow.com/questions/76170819/docker-compose-build-generate-failed-to-fetch-oauth-token-post-https-auth-do\",\"title\":\"docker-compose
42 build generate failed to fetch oauth token: Post
43 "https://auth.docker.io/token": proxyconnect tcp: dial tcp
44 127.0.0.1:7080\"},{\"tags\":[\"docker\",\"heroku\",\"docker-compose\",\"fastapi\",\"streamlit\"],\"owner\":{\"account_id\":20813,\"reputation\":21665,\"user_id\":50065,\"user_type\":\"registered\",\"accept_rate\":93,\"profile_image\":\"https://i.stack.imgur.com/ZbEgH.jpg?s=256&g=1\",\"display_name\":\"BioGeek\",\"link\":\"https://stackoverflow.com/users/50065/biogeek\"},\"is_answered\":true,\"view_count\":106,\"bounty_amount\":200,\"bounty_closes_date\":1683883040,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683331610,\"creation_date\":1683031857,\"last_edit_date\":1683278209,\"question_id\":76155032,\"content_license\":\"CC
45 BY-SA
46 4.0\",\"link\":\"https://stackoverflow.com/questions/76155032/connectionerror-on-multi-docker-app-streamlit-fastapi-when-deployed-on-herok\",\"title\":\"ConnectionError
47 on multi-Docker app (Streamlit + FastAPI) when deployed on
48 Heroku\"}],\"has_more\":false,\"quota_max\":300,\"quota_remaining\":297}"
49 */
50
51 let user_id = 4676641;
52 let result = client
53 .get_answers_for_user(user_id, None)
54 .await
55 .expect("unable to fetch answers for user 4676641");
56 dbg!(&result);
57
58 let mut counter = 2;
59 loop {
60 if result.has_more {
61 let result =
62 client.get_answers_for_user(user_id, Some(counter)).await;
63 dbg!(&result);
64 counter += 1;
65 } else {
66 break;
67 }
68 }
69
70 /*
71 [src/main.rs:47] result = Response {
72 items: [
73 Question {
74 tagged: None,
75 owner: User {
76 reputation: 547,
77 account_id: 3863408,
78 user_id: 3200552,
79 user_type: "registered",
80 display_name: "merhoo",
81 },
82 is_answered: true,
83 view_count: 96,
84 favorite_count: None,
85 down_vote_count: None,
86 answer_count: 1,
87 score: 3,
88 last_activity_date: 1684111790,
89 creation_date: 1678979778,
90 question_id: 75758174,
91 title: "How to make profile default for docker-compose?",
92 },
93 ...
94 ],
95 has_more: true,
96 quota_max: 300,
97 quota_remaining: 281,
98 }
99 */
100}
Sourcepub async fn get_featured_questions_paginated(
&self,
tag: &str,
page: u32,
) -> Result<Response<Question>, Box<dyn Error>>
pub async fn get_featured_questions_paginated( &self, tag: &str, page: u32, ) -> Result<Response<Question>, Box<dyn Error>>
Get featured questions for a tag and explicitly provide a page. Note that pagination is not supported beyond 25 pages because authentication is required. API Docs: https://api.stackexchange.com/docs/featured-questions
Sourcepub async fn get_answers_for_user(
&self,
user_id: u32,
page: Option<u32>,
) -> Result<Response<Answer>, Box<dyn Error>>
pub async fn get_answers_for_user( &self, user_id: u32, page: Option<u32>, ) -> Result<Response<Answer>, Box<dyn Error>>
Get answers provided by a user API Docs: https://api.stackexchange.com/docs/answers-on-users
Examples found in repository?
8async fn main() {
9 let question: QuestionRequest = QuestionRequest {
10 tag: Some("docker".to_string()),
11 site: StackSite::StackOverflow,
12 api_version: ApiVersion::V2_3,
13 };
14 println!("{:?}", question);
15
16 let client = StackClient::new();
17 let results = client
18 .get_featured_questions("docker")
19 .await
20 .expect("Unable to fetch featured docker questions");
21 dbg!(&results);
22 /*
23 QuestionRequest { tag: Some("rust"), site: StackOverflow, api_version: V2_3 }
24 "https://api.stackexchange.com/2.3/questions/featured?tagged=rust&site=stackoverflow"
25 {"items":[{"tags":["rust"],"owner":{"account_id":7063007,"reputation":13,"user_id":12276541,"user_type":"registered","profile_image":"https://www.gravatar.com/avatar/90649aebcc0cccc983abf5b461007176?s=256&d=identicon&r=
26 PG&f=1","display_name":"Rafaelo","link":"https://stackoverflow.com/users/12276541/rafaelo"},"is_answered":true,"view_count":109,"bounty_amount":150,"bounty_closes_date":1683583494,"answer_count":1,"score":0,"last_activ
27 ity_date":1682978694,"creation_date":1682714190,"question_id":76133120,"content_license":"CC BY-SA 4.0","link":"https://stackoverflow.com/questions/76133120/can-a-memory-pool-allocate-things-with-a-static-lifetime","ti
28 tle":"Can a memory pool allocate things with a `'static` lifetime?"}],"has_more":false,"quota_max":300,"quota_remaining":296}
29
30 "{\"items\":[{\"tags\":[\"docker\",\"docker-compose\",\"ngrok\",\"vapor\"],\"owner\":{\"account_id\":14409195,\"reputation\":2356,\"user_id\":10408494,\"user_type\":\"registered\",\"profile_image\":\"https://i.stack.imgur.com/6Clbj.jpg?s=256&g=1\",\"display_name\":\"Roland
31 Lariotte\",\"link\":\"https://stackoverflow.com/users/10408494/roland-lariotte\"},\"is_answered\":true,\"view_count\":52,\"bounty_amount\":50,\"bounty_closes_date\":1684225877,\"accepted_answer_id\":76224966,\"answer_count\":2,\"score\":2,\"last_activity_date\":1683789088,\"creation_date\":1682626252,\"last_edit_date\":1683635969,\"question_id\":76124274,\"content_license\":\"CC
32 BY-SA
33 4.0\",\"link\":\"https://stackoverflow.com/questions/76124274/how-can-i-set-ngrok-on-vapor-to-work-locally-with-an-owned-domain\",\"title\":\"How
34 can I set ngrok on Vapor to work locally with an owned
35 domain?\"},{\"tags\":[\"docker\",\"security\",\"github\",\"containers\",\"github-actions\"],\"owner\":{\"account_id\":2319125,\"reputation\":485,\"user_id\":2035417,\"user_type\":\"registered\",\"accept_rate\":75,\"profile_image\":\"https://www.gravatar.com/avatar/be22c7b705fa45820b740d9256e1593e?s=256&d=identicon&r=PG\",\"display_name\":\"ruckc\",\"link\":\"https://stackoverflow.com/users/2035417/ruckc\"},\"is_answered\":false,\"view_count\":159,\"bounty_amount\":50,\"bounty_closes_date\":1683835712,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683555302,\"creation_date\":1666965308,\"question_id\":74236426,\"content_license\":\"CC
36 BY-SA
37 4.0\",\"link\":\"https://stackoverflow.com/questions/74236426/github-actions-scheduled-container-rebuild-on-latest-release-tag-only\",\"title\":\"GitHub
38 Actions - Scheduled Container Rebuild On Latest Release Tag
39 only\"},{\"tags\":[\"docker\"],\"owner\":{\"account_id\":1312027,\"reputation\":4629,\"user_id\":1259842,\"user_type\":\"registered\",\"accept_rate\":49,\"profile_image\":\"https://www.gravatar.com/avatar/d23f0b2bb6cb82b239c03a31beb625a2?s=256&d=identicon&r=PG&f=y&so-version=2\",\"display_name\":\"miltone\",\"link\":\"https://stackoverflow.com/users/1259842/miltone\"},\"is_answered\":false,\"view_count\":40,\"bounty_amount\":50,\"bounty_closes_date\":1683972718,\"answer_count\":1,\"score\":1,\"last_activity_date\":1683368008,\"creation_date\":1683187049,\"last_edit_date\":1683368008,\"question_id\":76170819,\"content_license\":\"CC
40 BY-SA
41 4.0\",\"link\":\"https://stackoverflow.com/questions/76170819/docker-compose-build-generate-failed-to-fetch-oauth-token-post-https-auth-do\",\"title\":\"docker-compose
42 build generate failed to fetch oauth token: Post
43 "https://auth.docker.io/token": proxyconnect tcp: dial tcp
44 127.0.0.1:7080\"},{\"tags\":[\"docker\",\"heroku\",\"docker-compose\",\"fastapi\",\"streamlit\"],\"owner\":{\"account_id\":20813,\"reputation\":21665,\"user_id\":50065,\"user_type\":\"registered\",\"accept_rate\":93,\"profile_image\":\"https://i.stack.imgur.com/ZbEgH.jpg?s=256&g=1\",\"display_name\":\"BioGeek\",\"link\":\"https://stackoverflow.com/users/50065/biogeek\"},\"is_answered\":true,\"view_count\":106,\"bounty_amount\":200,\"bounty_closes_date\":1683883040,\"answer_count\":1,\"score\":2,\"last_activity_date\":1683331610,\"creation_date\":1683031857,\"last_edit_date\":1683278209,\"question_id\":76155032,\"content_license\":\"CC
45 BY-SA
46 4.0\",\"link\":\"https://stackoverflow.com/questions/76155032/connectionerror-on-multi-docker-app-streamlit-fastapi-when-deployed-on-herok\",\"title\":\"ConnectionError
47 on multi-Docker app (Streamlit + FastAPI) when deployed on
48 Heroku\"}],\"has_more\":false,\"quota_max\":300,\"quota_remaining\":297}"
49 */
50
51 let user_id = 4676641;
52 let result = client
53 .get_answers_for_user(user_id, None)
54 .await
55 .expect("unable to fetch answers for user 4676641");
56 dbg!(&result);
57
58 let mut counter = 2;
59 loop {
60 if result.has_more {
61 let result =
62 client.get_answers_for_user(user_id, Some(counter)).await;
63 dbg!(&result);
64 counter += 1;
65 } else {
66 break;
67 }
68 }
69
70 /*
71 [src/main.rs:47] result = Response {
72 items: [
73 Question {
74 tagged: None,
75 owner: User {
76 reputation: 547,
77 account_id: 3863408,
78 user_id: 3200552,
79 user_type: "registered",
80 display_name: "merhoo",
81 },
82 is_answered: true,
83 view_count: 96,
84 favorite_count: None,
85 down_vote_count: None,
86 answer_count: 1,
87 score: 3,
88 last_activity_date: 1684111790,
89 creation_date: 1678979778,
90 question_id: 75758174,
91 title: "How to make profile default for docker-compose?",
92 },
93 ...
94 ],
95 has_more: true,
96 quota_max: 300,
97 quota_remaining: 281,
98 }
99 */
100}