Crates.io | hypothesis |
lib.rs | hypothesis |
version | 0.12.0 |
source | src |
created_at | 2020-05-27 15:57:37.451717 |
updated_at | 2024-10-26 10:30:12.176688 |
description | a Rust wrapper and CLI for the Hypothesis API |
homepage | |
repository | https://github.com/out-of-cheese-error/rust-hypothesis |
max_upload_size | |
id | 246724 |
size | 147,251 |
A lightweight wrapper and CLI for the Hypothesis Web API v1.0.0. It includes all APIKey authorized endpoints related to
You'll need a Hypothesis account, and a personal API token obtained as described here.
Set the environment variables $HYPOTHESIS_NAME
and $HYPOTHESIS_KEY
to your username and the developer API key respectively.
cargo install hypothesis
Run hypothesis --help
to see subcommands and options.
NOTE: the CLI doesn't currently have all the capabilities of the Rust crate, specifically bulk actions and updating dates are not supported.
Generate shell completions:
hypothesis complete zsh > .oh-my-zsh/completions/_hypothesis
exec zsh
Add to your Cargo.toml:
[dependencies]
hypothesis = {version = "0.4.0", default-features = false}
tokio = { version = "0.2", features = ["macros"] }
use hypothesis::Hypothesis;
use hypothesis::annotations::{InputAnnotation, Target, Selector};
#[tokio::main]
async fn main() -> Result<(), hypothesis::errors::HypothesisError> {
let api = Hypothesis::from_env()?;
let new_annotation = InputAnnotation::builder()
.uri("https://www.example.com")
.text("this is a comment")
.target(Target::builder()
.source("https://www.example.com")
.selector(vec![Selector::new_quote("exact text in website to highlight",
"prefix of text",
"suffix of text")])
.build()?)
.tags(vec!["tag1".to_string(), "tag2".to_string()])
.build()?;
api.create_annotation(&new_annotation).await?;
Ok(())
}
See the documentation of the API struct (Hypothesis
) for a list of possible queries.
Use bulk functions to perform multiple actions - e.g. api.fetch_annotations
instead of a loop around api.fetch_annotation
.
Check the documentation for more usage examples.
See the CHANGELOG
Make sure you have a .env file (added to .gitignore) in the repo root with HYPOTHESIS_NAME, HYPOTHESIS_KEY, and TEST_GROUP_ID
Target.selector.RangeSelector
doesn't seem to follow W3C standards. It's just a hashmap for now.Annotation
hypermedia links are stored as a hashmap, b/c I don't know all the possible values.Document
works to properly document it (hah).UserProfile.preferences
and UserProfile.features
mean.