Struct hypothesis::Hypothesis

source ·
pub struct Hypothesis {
    pub username: String,
    pub user: UserAccountID,
    /* private fields */
}
Expand description

Hypothesis API client

Fields§

§username: String

Authenticated user

§user: UserAccountID

“acct:{username}@hypothes.is”

Implementations§

source§

impl Hypothesis

source

pub fn new(username: &str, developer_key: &str) -> Result<Self, HypothesisError>

Make a new Hypothesis client with your username and developer key (see here on how to get one)

Example
use hypothesis::Hypothesis;
let api = Hypothesis::new(&username, &developer_key)?;
source

pub fn from_env() -> Result<Self, HypothesisError>

Make a new Hypothesis client from environment variables. Username from $HYPOTHESIS_NAME, Developer key from $HYPOTHESIS_KEY (see here on how to get one)

Example
use hypothesis::Hypothesis;
let api = Hypothesis::from_env()?;
source

pub async fn create_annotation( &self, annotation: &InputAnnotation ) -> Result<Annotation, HypothesisError>

Create a new annotation

Posts a new annotation object to Hypothesis. Returns an Annotation as output. See InputAnnotation for examples on what you can add to an annotation.

Example
use hypothesis::Hypothesis;
use hypothesis::annotations::InputAnnotation;

let api = Hypothesis::new(&username, &developer_key)?;
let annotation = api.create_annotation(&InputAnnotation::builder()
                    .text("string")
                    .uri("http://example.com")
                    .group(&group_id)
                    .build()?).await?;
assert_eq!(&annotation.text, "string");
source

pub async fn create_annotations( &self, annotations: &[InputAnnotation] ) -> Result<Vec<Annotation>, HypothesisError>

Create many new annotations

Posts multiple new annotation objects asynchronously to Hypothesis. Returns Annotations as output. See InputAnnotation’s docs for examples on what you can add to an annotation.

Example
let api = Hypothesis::new(&username, &developer_key)?;
let input_annotations = vec![
    InputAnnotation::builder()
        .text("first")
        .uri("http://example.com")
        .group(&group_id)
        .build()?,
    InputAnnotation::builder()
        .text("second")
        .uri("http://example.com")
        .group(&group_id)   
        .build()?
];
let annotations = api.create_annotations(&input_annotations).await?;
assert_eq!(&annotations[0].text, "first");
assert_eq!(&annotations[1].text, "second");
source

pub async fn update_annotation( &self, annotation: &Annotation ) -> Result<Annotation, HypothesisError>

Update an existing annotation

Change any field in an existing annotation. Returns the modified Annotation

Example
use hypothesis::Hypothesis;
use hypothesis::annotations::InputAnnotation;
let api = Hypothesis::new(&username, &developer_key)?;
let mut annotation = api.create_annotation(&InputAnnotation::builder()
                  .text("string")
                  .uri("http://example.com")
                  .tags(vec!["tag1".to_string(), "tag2".to_string()])
                  .group(&group_id)
                  .build()?).await?;
annotation.text = String::from("New String");
let updated_annotation = api.update_annotation(&annotation).await?;
assert_eq!(updated_annotation.id, annotation.id);
assert_eq!(&updated_annotation.text, "New String");
source

pub async fn update_annotations( &self, annotations: &[Annotation] ) -> Result<Vec<Annotation>, HypothesisError>

Update many annotations at once

source

pub async fn search_annotations( &self, query: &SearchQuery ) -> Result<Vec<Annotation>, HypothesisError>

Search for annotations with optional filters

Returns a list of annotations matching the search query. See SearchQuery for more filtering options

This returns a max of 50 annotations at once, use search_annotations_return_all if you expect more

Example
use hypothesis::{Hypothesis, UserAccountID};
use hypothesis::annotations::SearchQuery;
let api = Hypothesis::new(&username, &developer_key)?;
/// Search for your own annotations:
let search_query = SearchQuery::builder().user(&api.user.0).build()?;
let search_results = api.search_annotations(&search_query).await?;
source

pub async fn search_annotations_return_all( &self, query: &mut SearchQuery ) -> Result<Vec<Annotation>, HypothesisError>

Retrieve all annotations matching query See SearchQuery for filtering options

source

pub async fn fetch_annotation( &self, id: &str ) -> Result<Annotation, HypothesisError>

Fetch annotation by ID

Example
use hypothesis::Hypothesis;
let api = Hypothesis::new(&username, &developer_key)?;
let annotation = api.fetch_annotation(&annotation_id).await?;
assert_eq!(annotation.id, annotation_id);
source

pub async fn fetch_annotations( &self, ids: &[String] ) -> Result<Vec<Annotation>, HypothesisError>

Fetch multiple annotations by ID

source

pub async fn delete_annotation(&self, id: &str) -> Result<bool, HypothesisError>

Delete annotation by ID

Example
use hypothesis::Hypothesis;
let api = Hypothesis::new(&username, &developer_key)?;
let deleted = api.delete_annotation(&annotation_id).await?;
assert!(deleted);
assert!(api.fetch_annotation(&annotation_id).await.is_err());
source

pub async fn delete_annotations( &self, ids: &[String] ) -> Result<Vec<bool>, HypothesisError>

Delete multiple annotations by ID

source

pub async fn flag_annotation(&self, id: &str) -> Result<(), HypothesisError>

Flag an annotation

Flag an annotation for review (moderation). The moderator of the group containing the annotation will be notified of the flag and can decide whether or not to hide the annotation. Note that flags persist and cannot be removed once they are set.

source

pub async fn hide_annotation(&self, id: &str) -> Result<(), HypothesisError>

Hide an annotation

Hide an annotation. The authenticated user needs to have the moderate permission for the group that contains the annotation — this permission is granted to the user who created the group.

source

pub async fn show_annotation(&self, id: &str) -> Result<(), HypothesisError>

Show an annotation

Show/“un-hide” an annotation. The authenticated user needs to have the moderate permission for the group that contains the annotation—this permission is granted to the user who created the group.

source

pub async fn get_groups( &self, query: &GroupFilters ) -> Result<Vec<Group>, HypothesisError>

Retrieve a list of applicable Groups, filtered by authority and target document (document_uri). Also retrieve user’s private Groups.

Example
use hypothesis::Hypothesis;
use hypothesis::groups::GroupFilters;

let api = Hypothesis::new(&username, &developer_key)?;
/// Get all Groups belonging to user
let groups = api.get_groups(&GroupFilters::default()).await?;
source

pub async fn create_group( &self, name: &str, description: Option<&str> ) -> Result<Group, HypothesisError>

Create a new, private group for the currently-authenticated user.

Example
use hypothesis::Hypothesis;

let api = Hypothesis::new(&username, &developer_key)?;
let group = api.create_group("my_group", Some("a test group")).await?;
source

pub async fn create_groups( &self, names: &[String], descriptions: &[Option<String>] ) -> Result<Vec<Group>, HypothesisError>

Create multiple groups

source

pub async fn fetch_group( &self, id: &str, expand: Vec<Expand> ) -> Result<Group, HypothesisError>

Fetch a single Group resource.

Example
use hypothesis::Hypothesis;
use hypothesis::groups::Expand;

let api = Hypothesis::new(&username, &developer_key)?;
/// Expands organization into a struct
let group = api.fetch_group(&group_id, vec![Expand::Organization]).await?;
source

pub async fn fetch_groups( &self, ids: &[String], expands: Vec<Vec<Expand>> ) -> Result<Vec<Group>, HypothesisError>

Fetch multiple groups by ID

source

pub async fn update_group( &self, id: &str, name: Option<&str>, description: Option<&str> ) -> Result<Group, HypothesisError>

Update a Group resource.

Example
use hypothesis::Hypothesis;

let api = Hypothesis::new(&username, &developer_key)?;
let group = api.update_group(&group_id, Some("new_group_name"), None).await?;
assert_eq!(&group.name, "new_group_name");
assert_eq!(group.id, group_id);
source

pub async fn update_groups( &self, ids: &[String], names: &[Option<String>], descriptions: &[Option<String>] ) -> Result<Vec<Group>, HypothesisError>

Update multiple groups

source

pub async fn get_group_members( &self, id: &str ) -> Result<Vec<Member>, HypothesisError>

Fetch a list of all members (users) in a group. Returned user resource only contains public-facing user data. Authenticated user must have read access to the group. Does not require authentication for reading members of public groups. Returned members are unsorted.

Example
use hypothesis::Hypothesis;

let api = Hypothesis::new(&username, &developer_key)?;
let members = api.get_group_members(&group_id).await?;
source

pub async fn leave_group(&self, id: &str) -> Result<(), HypothesisError>

Remove yourself from a group.

source

pub async fn fetch_user_profile(&self) -> Result<UserProfile, HypothesisError>

Fetch profile information for the currently-authenticated user.

Example
use hypothesis::Hypothesis;
let api = Hypothesis::new(&username, &developer_key)?;
let profile = api.fetch_user_profile().await?;
assert!(profile.userid.is_some());
assert_eq!(profile.userid.unwrap(), api.user);
source

pub async fn fetch_user_groups(&self) -> Result<Vec<Group>, HypothesisError>

Fetch the groups for which the currently-authenticated user is a member.

Example
use hypothesis::Hypothesis;
let api = Hypothesis::new(&username, &developer_key)?;
let groups = api.fetch_user_groups().await?;

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<D> OwoColorize for D

§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the background color to black
§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the background color to red
§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the background color to green
§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the background color to yellow
§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the background color to blue
§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to magenta
§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to purple
§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the background color to cyan
§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the background color to white
§

fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>

Change the foreground color to the terminal default
§

fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>

Change the background color to the terminal default
§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the background color to bright black
§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the background color to bright red
§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the background color to bright green
§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the background color to bright yellow
§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the background color to bright blue
§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright magenta
§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright purple
§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the background color to bright cyan
§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the background color to bright white
§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more