#game #gamedev

lunaria-api

A Rust API client for the video game Lunaria

6 releases

new 0.2.0 Jul 27, 2021
0.1.3 Jul 13, 2021
0.1.2 Jun 23, 2021
0.1.1 Oct 29, 2020
0.0.0 Sep 26, 2020

#67 in Game dev

Download history 80/week @ 2021-04-07 50/week @ 2021-04-14 47/week @ 2021-04-21 47/week @ 2021-04-28 43/week @ 2021-05-05 55/week @ 2021-05-12 39/week @ 2021-05-19 46/week @ 2021-05-26 44/week @ 2021-06-02 17/week @ 2021-06-09 6/week @ 2021-06-16 50/week @ 2021-06-23 9/week @ 2021-06-30 47/week @ 2021-07-07 26/week @ 2021-07-14 26/week @ 2021-07-21

149 downloads per month
Used in lunaria

MIT/Apache

8KB

🦀 lunaria-api

GitHub release (latest by date) GitHub Workflow Status License

A Rust API client for the video game Lunaria.

Lunaria is a video game for programmers, and is played by writing code that interacts with the game through a gRPC API. This crate contains a gRPC client that is auto-generated from the Protocol Buffers that declare Lunaria's API.

Getting Started

First, add lunaria-api as a dependency to your Cargo.toml.

Because lunaria-api wraps a client generated by tonic, it must be added as a dependency as well. And if you are building a binary, you also need an async runtime like tokio.

[dependencies]
lunaria-api = "0.2.0"
tokio = { version = "0.2.22", features = ["macros", "rt-threaded"] }
tonic = "0.3.1"

Next, import LunariaClient and connect to the game server. Check out Lunaria's API specification below to learn about all the requests you can send, and the data they require and return:

https://github.com/playlunaria/lunaria-api/tree/main/protobufs

Here is an example that fetches the version of the game:

use lunaria_api::lunaria::v1::lunaria_service_client::LunariaSerrviceClient;
use lunaria_api::lunaria::v1::{GetVersionRequest, GetVersionResponse, Version};
use tonic::Request;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Specify the address and port of Lunaria's API
    let address = "http://127.0.0.1:1904";

    // Initialize the client
    let mut lunaria = LunariaServiceClient::connect(address).await?;

    // Create a request to get the game's version and send it to the server
    let request = Request::new(GetVersionRequest {});
    let grpc_response = lunaria.get_version(request).await?;
    let version_response = grpc_response.into_inner();

    if let Some(version) = version_response.version {
        assert_eq!(0, version.major);
        assert_eq!(0, version.minor);
        assert_eq!(0, version.patch);
    }

    Ok(())
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~6MB
~109K SLoC