An API Wrapper for Ripledd API's services💫
Note: This is the Rust version of the original Ripledd API wrapper from Foxy
To use the Ripledd Rust library in your project, add it as a dependency in your Cargo.toml
file:
[dependencies]
ripledd_api_wrapper = { git = "https://github.com/Kazooki123/ripledd-api-rust" }
Then, run cargo build
to download and compile the library.
Here's an example of how to use the Ripledd Rust library to create a post:
use ripledd_api_wrapper::RipleddClient;
fn main() -> Result<(), reqwest::Error> {
// Replace with your Ripledd email and password (consider using environment variables for security)
let email = "your_email@example.com";
let password = "your_password";
// Create a Ripledd client
let mut ripledd = RipleddClient::new(email.to_string(), password.to_string(), None);
// Create a post
let post_body = "The post from the API";
let response = ripledd.create_post(post_body).await?;
// Check for successful response
if response.status().is_success() {
println!("Post created successfully!");
} else {
println!("Error creating post: {}", response.status());
}
Ok(())
}
- We import the RipleddClient struct from your ripledd_api_wrapper library. In the main function, we define placeholder values for email and password (consider using environment variables for security).
- We create a new RipleddClient instance.
- We define the post content (post_body).
- We call create_post on the client with the post body and await the asynchronous response.
- We check the response status code. If successful, we print a success message. Otherwise, we print an error message with the status code.
- Save the code snippet above as a Rust file (e.g., demo.rs).
- Make sure you have Rust and Cargo installed.
- In your terminal, navigate to the directory where you saved
demo.rs
. - Run the following command to compile and run the example:
cargo run
This will build the library and execute the example code, printing the response from the Ripledd API.