If you would like to help the project, pull requests and suggestions are always welcome :)
This crate is using cargo-features so your project compiles only code related to the endpoint you'll be using.
If you're querying only games
and characters
endpoint, Cargo.toml
should look like this:
toml
[dependencies]
rusty_igdb = { "0.3.0", default-features = false, features = ["game", "character"]}
Unless you want the entire codebase from the crate containing all endpoits methods and structs
add this to your Cargo.toml
:
toml
[dependencies]
rusty_igdb = "0.3.0"
You can read how to retrieve those credentials here. With Twitch Access Token and Twitch Client ID in hands, we can bring IGDB API wrapper into scope like this: ```rust // Along with the wrapper, bring the endpoint Structs to scope so your code knows the return type of the Vector use igdb::{APIWrapper, models::Game, models::Character}; use std::env;
fn main() { // Using stored environment variables to unwrap our credentials let accesstoken = env::var("TWITCHACCESSTOKEN").unwrap(); let clientid = env::var("TWITCHCLIENTID").unwrap();
// Authenticating with our API wrapper let apiwrapper = APIWrapper::new(&accesstoken, &client_id).unwrap();
// Using the API wrapper methods to query for Zelda games
// Here we are expecting a vector of Game struct, so we used the imported Struct.
let zeldagames: Vec
// Using the API wrapper methods to query for Characters named Mario
// Here we are expecting a vector of Character struct.
let charactersnamedmario: Vec
This example used **environment variables** to store the Twitch retrieved credentials, and then accessing with the rust standard feature
std::env`. In your personal project, you can manage these credentials as you please.
The crate offers a JSON public method, so you can customize the response content into your project.
Value
represents the serde_json::Value
struct in the below example.
See the serde_json crate for more information about.
```rust
let testcharacters: Vec
/*
response should look like this:
[{
"gender": 0,
"id": 4445,
"name": "Beast"
},
{
"gender": 0,
"id": 8988,
"name": "Mr. Wong"
}],
*/
```
The result should look and accessed like this:
json
[{
"gender": 0,
"id": 4445,
"name": "Beast"
},
{
"gender": 0,
"id": 8988,
"name": "Mr. Wong"
}]
rust
let first_character = &test_characters[0]["gender"];
Cargo is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.