[−][src]Crate misskey
Asynchronous client for Misskey.
We provide three components in this crate:
- Clients that handles the connection between Misskey. As Misskey provides HTTP and WebSocket
interfaces to interact with, we have
HttpClient
andWebSocketClient
implementations correspondingly. - API data types, including requests/responses of endpoints and messages on channels.
- Abstraction that connects API datatypes and client implementations:
Request
,ConnectChannelRequest
, etc.
Examples
Create a note:
use misskey::{Client, HttpClient}; let client = HttpClient::builder("https://your.misskey.instance/api/".parse()?) .token("API_TOKEN".to_string()) .build()?; client .request( // Each endpoint implementation has a corresponding `Request` type. // We can dispatch an API call by passing `Request` to `Client::request` method. misskey::endpoint::notes::create::Request::builder() .text("Hello, Misskey") .build(), ) .await? .into_result()?;
Automatically follow-back:
use futures::stream::StreamExt; use misskey::streaming::channel::main::{self, MainStreamEvent}; use misskey::{Client, WebSocketClient}; let client = WebSocketClient::builder("wss://your.misskey.instance/streaming".parse()?) .token("YOUR_API_TOKEN") .connect() .await?; // Connect to the main stream. // The main stream is a channel that streams events about the connected account. let mut stream = client.channel(main::Request::default()).await?; loop { // Wait for the next event using `next` method from `StreamExt`. let event = stream.next().await.unwrap()?; match event { MainStreamEvent::Followed(user) if !user.is_bot => { println!("followed from @{}", user.username); client .request(misskey::endpoint::following::create::Request { user_id: user.id }) .await? .into_result()?; } _ => {} } }
See the example directory for more examples and detailed explanations.
Feature flags
http-client
: Enables the HTTP client which is capable for uploading files. Enabled by default.websocket-client
: Enables the WebSocket client which is capable for streaming. Enabled by default.tokio-runtime
: Use the tokio runtime in the WebSocket client. Enabled by default.async-std-runtime
: Use the async-std runtime in the WebSocket client.- and version flags, as described in version flags section.
Specifying Misskey version
We have a set of feature flags to specify the targeted Misskey version.
The latest one (12-47-0
) is enabled as a default. You can opt-in to compile for prior
Misskey version by using default-features = false
and the corresponding feature flag.
For example, to compile for Misskey v12.33.0 with WebSocket client on async-std runtime, add
the following to your Cargo.toml
file:
[dependencies.misskey]
version = "0.1"
default-features = false
features = ["12-31-0", "websocket-client", "async-std-runtime"]
Feature | Supported Misskey versions (inclusive) | Tested Misskey version |
---|---|---|
head | HEAD | not tested |
12-47-0 | v12.47.0 ~ v12.47.1 | v12.47.1 |
12-39-0 | v12.39.0 ~ v12.46.0 | v12.39.0 |
12-37-0 | v12.37.0 ~ v12.38.1 | v12.37.0 |
12-31-0 | v12.31.0 ~ v12.36.1 | v12.31.0 |
12-29-0 | v12.29.0 ~ v12.30.0 | v12.29.0 |
12-28-0 | v12.28.0 | v12.28.0 |
12-27-0 | v12.27.0 ~ v12.27.1 | v12.27.0 |
12-19-0 | v12.19.0 ~ v12.26.0 | v12.20.0 |
12-13-0 | v12.13.0 ~ v12.18.1 | v12.13.0 |
12-10-0 | v12.10.0 ~ v12.12.0 | v12.10.0 |
12-9-0 | v12.9.0 | v12.9.0 |
12-8-0 | v12.8.0 | v12.8.0 |
12-5-0 | v12.5.0 ~ v12.7.1 | v12.5.0 |
(no version flag enabled) | v12.0.0 ~ v12.4.1 | v12.0.0 |
Modules
endpoint | API endpoints. |
http | http-client Asynchronous HTTP-based client. |
model | Object types used in API. |
streaming | Streaming API. |
websocket | websocket-client Asynchronous WebSocket-based client. |
Structs
HttpClient | http-client Asynchronous HTTP-based client for Misskey. |
WebSocketClient | websocket-client Asynchronous WebSocket-based client for Misskey. |
Traits
Client | Abstraction over API clients. |