Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 74acd1f

Browse files
committed
feat: Add profile integration
1 parent 2c70847 commit 74acd1f

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

‎Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "leetcoderustapi"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
authors = ["Kirill Melkozerov <k.melkozerov@gmail.com>"]
55
edition = "2021"
66
license = "MIT"

‎README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This Rust library provides a convenient way to interact with the LeetCode API, a
1111
Add the following line to your `Cargo.toml` file:
1212
```toml
1313
[dependencies]
14-
leetcoderustapi = "0.1.5"
14+
leetcoderustapi = "0.1.6"
1515
```
1616
## Usage
1717
### Authentication
@@ -78,8 +78,8 @@ async fn main() {
7878
// Retrieve difficulty
7979
let difficulty = problem_info.difficulty();
8080

81-
// Retrieve likes
82-
let likes = problem_info.likes();
81+
// Retrieve likes and dislikes
82+
let likes = problem_info.rating();
8383

8484
// Retrieve category
8585
let category = problem_info.category();

‎src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl UserApi {
5252
}
5353

5454
async fn valid_check(mut headers: HeaderMap, cookie: &str) -> Result<(bool, String), Errors> {
55-
let token = if let Some(cookie) = cookie
55+
let token = if let Some(token) = cookie
5656
.strip_prefix("csrftoken=")
5757
.and_then(|val| Some(&val[..64]))
5858
{
59-
cookie
59+
token
6060
} else {
6161
return Err(Errors::ApiError("Cannot take token from cookie".into()));
6262
};

‎src/problem_actions.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use std::{error::Error,time::Duration};
1+
use std::time::Duration;
22

33
use serde_json::json;
44

5-
use crate::resources::{
5+
use crate::{resources::{
66
problemfulldata::{
77
CodeSnippetNode, ProblemFullData, SimilarQuestions, Solution, Statistics, TopicTagNode,
88
},
99
subm_send::{SubmExecutionResult, SubmissionCase, SubmissionCaseResp},
1010
subm_show::SubmList,
1111
test_send::{TestCase, TestCaseResp, TestExecutionResult},
1212
Descryption, Rate,
13-
};
13+
}, error::Errors};
1414

1515
#[derive(Debug)]
1616
pub struct Problem {
@@ -25,17 +25,16 @@ impl Problem {
2525
&self,
2626
lang: &str,
2727
typed_code: &str,
28-
) -> Result<TestExecutionResult, Box<dynError>> {
28+
) -> Result<TestExecutionResult, Errors> {
2929
let json_data = serde_json::to_string(&TestCase {
3030
question_id: self.full_data.data.question.questionId.clone(),
3131
data_input: self.full_data.data.question.sampleTestCase.clone(),
3232
lang: lang.to_lowercase(),
3333
judge_type: String::from("large"),
3434
typed_code: String::from(typed_code),
35-
})
36-
.unwrap();
35+
})?;
3736

38-
let resp = matchself
37+
let resp = self
3938
.client
4039
.post(format!(
4140
"https://leetcode.com/problems/{}/interpret_solution/",
@@ -45,11 +44,7 @@ impl Problem {
4544
.send()
4645
.await?
4746
.json::<TestCaseResp>()
48-
.await
49-
{
50-
Ok(data) => data,
51-
Err(_err) => return Err("Your token is invalid or access to the Task is deny".into()),
52-
};
47+
.await?;
5348

5449
loop {
5550
let status = self
@@ -73,15 +68,15 @@ impl Problem {
7368
&self,
7469
lang: &str,
7570
code: &str,
76-
) -> Result<SubmExecutionResult, Box<dynError>> {
71+
) -> Result<SubmExecutionResult, Errors> {
7772
let json_data = serde_json::to_string(&SubmissionCase {
7873
question_id: self.full_data.data.question.questionId.clone(),
7974
lang: lang.to_lowercase(),
8075
typed_code: String::from(code),
8176
})
8277
.unwrap();
8378

84-
let resp = matchself
79+
let resp = self
8580
.client
8681
.post(format!(
8782
"https://leetcode.com/problems/{}/submit/",
@@ -91,11 +86,7 @@ impl Problem {
9186
.send()
9287
.await?
9388
.json::<SubmissionCaseResp>()
94-
.await
95-
{
96-
Ok(data) => data,
97-
Err(_err) => return Err("Your token is invalid or access to the task is deny".into()),
98-
};
89+
.await?;
9990

10091
loop {
10192
let status = self
@@ -152,7 +143,7 @@ impl Problem {
152143
self.full_data.data.question.difficulty.clone()
153144
}
154145

155-
pub fn likes(&self) -> Rate {
146+
pub fn rating(&self) -> Rate {
156147
let rate = json!({
157148
"likes": self.full_data.data.question.likes,
158149
"dislikes": self.full_data.data.question.dislikes
@@ -165,7 +156,7 @@ impl Problem {
165156
self.full_data.data.question.categoryTitle.clone()
166157
}
167158

168-
pub async fn my_submissions(&self) -> Result<SubmList, Box<dynError>> {
159+
pub async fn my_submissions(&self) -> Result<SubmList, Errors> {
169160
let query = json!({
170161
"operationName": "Submissions",
171162
"variables": {
@@ -179,17 +170,13 @@ impl Problem {
179170

180171
let query = serde_json::to_string(&query)?;
181172

182-
matchself
173+
Ok(self
183174
.client
184175
.post("https://leetcode.com/graphql/")
185176
.body(query)
186177
.send()
187178
.await?
188179
.json::<SubmList>()
189-
.await
190-
{
191-
Ok(data) => Ok(data),
192-
Err(_err) => Err("Can't take descryption from task".into()),
193-
}
180+
.await?)
194181
}
195182
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /