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 af057b8

Browse files
committed
feat: Add validate lang
1 parent a82d414 commit af057b8

File tree

4 files changed

+64
-9
lines changed

4 files changed

+64
-9
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 = "1.0.1"
3+
version = "1.0.2"
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
@@ -19,7 +19,7 @@ To use the LeetCode API, you need to obtain an authentication token. Follow the
1919

2020
### Example: Action with problems
2121
```rust
22-
use leetcoderustapi::{problem_build::{Tags, Category, Difficulty, Status}, UserApi};
22+
use leetcoderustapi::{problem_build::{Tags, Category, Difficulty, Status}, UserApi, ProgrammingLanguage,};
2323

2424
#[tokio::main]
2525
async fn main() {
@@ -89,11 +89,11 @@ async fn main() {
8989
// We also can send submissions and tests
9090
// Need to specify a lang and provided code
9191
let subm_response = problem_info
92-
.send_subm("rust", "impl Solution { fn two_sum() {}}")
92+
.send_subm(ProgrammingLanguage::Rust, "impl Solution { fn two_sum() {}}")
9393
.await
9494
.unwrap();
9595
let test_response = problem_info
96-
.send_test("rust", "impl Solution { fn two_sum() {}}")
96+
.send_test(ProgrammingLanguage::Rust, "impl Solution { fn two_sum() {}}")
9797
.await
9898
.unwrap();
9999
}

‎src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,29 @@ impl UserApi {
300300
Ok(serde_json::from_str::<FavoriteList>(&list_data)?)
301301
}
302302
}
303+
304+
#[derive(Debug)]
305+
pub enum ProgrammingLanguage {
306+
CPP,
307+
Java,
308+
Python,
309+
Python3,
310+
C,
311+
CSharp,
312+
JavaScript,
313+
TypeScript,
314+
Ruby,
315+
Swift,
316+
Go,
317+
Bash,
318+
Scala,
319+
Kotlin,
320+
Rust,
321+
PHP,
322+
Racket,
323+
Erlang,
324+
Elixir,
325+
Dart,
326+
Pandas,
327+
React,
328+
}

‎src/problem_actions.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
subm_show::SubmList,
1313
test_send::{TestCase, TestCaseResp, TestExecutionResult},
1414
Descryption, Rate,
15-
},
15+
},ProgrammingLanguage,
1616
};
1717

1818
#[derive(Debug)]
@@ -26,13 +26,14 @@ pub struct Problem {
2626
impl Problem {
2727
pub async fn send_test(
2828
&self,
29-
lang: &str,
29+
lang: ProgrammingLanguage,
3030
typed_code: &str,
3131
) -> Result<TestExecutionResult, Errors> {
32+
let lang = Self::lang_converter(lang);
3233
let json_data = serde_json::to_string(&TestCase {
3334
question_id: self.full_data.data.question.questionId.clone(),
3435
data_input: self.full_data.data.question.sampleTestCase.clone(),
35-
lang: lang.to_lowercase(),
36+
lang: lang.to_owned(),
3637
judge_type: String::from("large"),
3738
typed_code: String::from(typed_code),
3839
})?;
@@ -67,10 +68,11 @@ impl Problem {
6768
}
6869
}
6970

70-
pub async fn send_subm(&self, lang: &str, code: &str) -> Result<SubmExecutionResult, Errors> {
71+
pub async fn send_subm(&self, lang: ProgrammingLanguage, code: &str) -> Result<SubmExecutionResult, Errors> {
72+
let lang = Self::lang_converter(lang);
7173
let json_data = serde_json::to_string(&SubmissionCase {
7274
question_id: self.full_data.data.question.questionId.clone(),
73-
lang: lang.to_lowercase(),
75+
lang: lang.to_owned(),
7476
typed_code: String::from(code),
7577
})?;
7678

@@ -103,6 +105,33 @@ impl Problem {
103105
tokio::time::sleep(Duration::from_secs(1)).await;
104106
}
105107
}
108+
109+
fn lang_converter(lang: ProgrammingLanguage) -> &'static str {
110+
match lang {
111+
ProgrammingLanguage::CPP => "cpp",
112+
ProgrammingLanguage::Java => "java",
113+
ProgrammingLanguage::Python => "python",
114+
ProgrammingLanguage::Python3 => "python3",
115+
ProgrammingLanguage::C => "c",
116+
ProgrammingLanguage::CSharp => "csharp",
117+
ProgrammingLanguage::JavaScript => "javascript",
118+
ProgrammingLanguage::TypeScript => "typescript",
119+
ProgrammingLanguage::Ruby => "ruby",
120+
ProgrammingLanguage::Swift => "swift",
121+
ProgrammingLanguage::Go => "go",
122+
ProgrammingLanguage::Bash => "bash",
123+
ProgrammingLanguage::Scala => "scala",
124+
ProgrammingLanguage::Kotlin => "kotlin",
125+
ProgrammingLanguage::Rust => "rust",
126+
ProgrammingLanguage::PHP => "php",
127+
ProgrammingLanguage::Racket => "racket",
128+
ProgrammingLanguage::Erlang => "erlang",
129+
ProgrammingLanguage::Elixir => "elixir",
130+
ProgrammingLanguage::Dart => "dart",
131+
ProgrammingLanguage::Pandas => "pandas",
132+
ProgrammingLanguage::React => "react",
133+
}
134+
}
106135
pub fn code_snippets(&self) -> Option<Vec<CodeSnippetNode>> {
107136
self.full_data.data.question.codeSnippets.clone()
108137
}

0 commit comments

Comments
(0)

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