Struct hypothesis::Hypothesis [−][src]
Hypothesis API client
Fields
username: String
Authenticated user
user: UserAccountID
“acct:{username}@hypothes.is”
Implementations
impl Hypothesis
[src]
pub fn new(username: &str, developer_key: &str) -> Result<Self, HypothesisError>
[src]
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)?;
pub fn from_env() -> Result<Self, HypothesisError>
[src]
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()?;
pub async fn create_annotation(
&self,
annotation: &InputAnnotation
) -> Result<Annotation, HypothesisError>
[src]
&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");
pub async fn create_annotations(
&self,
annotations: &[InputAnnotation]
) -> Result<Vec<Annotation>, HypothesisError>
[src]
&self,
annotations: &[InputAnnotation]
) -> Result<Vec<Annotation>, HypothesisError>
Create many new annotations
Posts multiple new annotation objects asynchronously to Hypothesis.
Returns Annotation
s 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");
pub async fn update_annotation(
&self,
annotation: &Annotation
) -> Result<Annotation, HypothesisError>
[src]
&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");
pub async fn update_annotations(
&self,
annotations: &[Annotation]
) -> Result<Vec<Annotation>, HypothesisError>
[src]
&self,
annotations: &[Annotation]
) -> Result<Vec<Annotation>, HypothesisError>
Update many annotations at once
pub async fn search_annotations(
&self,
query: &SearchQuery
) -> Result<Vec<Annotation>, HypothesisError>
[src]
&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?;
pub async fn search_annotations_return_all(
&self,
query: &mut SearchQuery
) -> Result<Vec<Annotation>, HypothesisError>
[src]
&self,
query: &mut SearchQuery
) -> Result<Vec<Annotation>, HypothesisError>
Retrieve all annotations matching query
See SearchQuery
for filtering options
pub async fn fetch_annotation(
&self,
id: &str
) -> Result<Annotation, HypothesisError>
[src]
&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);
pub async fn fetch_annotations(
&self,
ids: &[String]
) -> Result<Vec<Annotation>, HypothesisError>
[src]
&self,
ids: &[String]
) -> Result<Vec<Annotation>, HypothesisError>
Fetch multiple annotations by ID
pub async fn delete_annotation(&self, id: &str) -> Result<bool, HypothesisError>
[src]
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());
pub async fn delete_annotations(
&self,
ids: &[String]
) -> Result<Vec<bool>, HypothesisError>
[src]
&self,
ids: &[String]
) -> Result<Vec<bool>, HypothesisError>
Delete multiple annotations by ID
pub async fn flag_annotation(&self, id: &str) -> Result<(), HypothesisError>
[src]
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.
pub async fn hide_annotation(&self, id: &str) -> Result<(), HypothesisError>
[src]
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.
pub async fn show_annotation(&self, id: &str) -> Result<(), HypothesisError>
[src]
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.
pub async fn get_groups(
&self,
query: &GroupFilters
) -> Result<Vec<Group>, HypothesisError>
[src]
&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?;
pub async fn create_group(
&self,
name: &str,
description: Option<&str>
) -> Result<Group, HypothesisError>
[src]
&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?;
pub async fn create_groups(
&self,
names: &[String],
descriptions: &[Option<String>]
) -> Result<Vec<Group>, HypothesisError>
[src]
&self,
names: &[String],
descriptions: &[Option<String>]
) -> Result<Vec<Group>, HypothesisError>
Create multiple groups
pub async fn fetch_group(
&self,
id: &str,
expand: Vec<Expand>
) -> Result<Group, HypothesisError>
[src]
&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?;
pub async fn fetch_groups(
&self,
ids: &[String],
expands: Vec<Vec<Expand>>
) -> Result<Vec<Group>, HypothesisError>
[src]
&self,
ids: &[String],
expands: Vec<Vec<Expand>>
) -> Result<Vec<Group>, HypothesisError>
Fetch multiple groups by ID
pub async fn update_group(
&self,
id: &str,
name: Option<&str>,
description: Option<&str>
) -> Result<Group, HypothesisError>
[src]
&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);
pub async fn update_groups(
&self,
ids: &[String],
names: &[Option<String>],
descriptions: &[Option<String>]
) -> Result<Vec<Group>, HypothesisError>
[src]
&self,
ids: &[String],
names: &[Option<String>],
descriptions: &[Option<String>]
) -> Result<Vec<Group>, HypothesisError>
Update multiple groups
pub async fn get_group_members(
&self,
id: &str
) -> Result<Vec<Member>, HypothesisError>
[src]
&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?;
pub async fn leave_group(&self, id: &str) -> Result<(), HypothesisError>
[src]
Remove yourself from a group.
pub async fn fetch_user_profile(&self) -> Result<UserProfile, HypothesisError>
[src]
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);
pub async fn fetch_user_groups(&self) -> Result<Vec<Group>, HypothesisError>
[src]
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
impl !RefUnwindSafe for Hypothesis
impl Send for Hypothesis
impl Sync for Hypothesis
impl Unpin for Hypothesis
impl !UnwindSafe for Hypothesis
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<D> OwoColorize for D
pub fn fg<C>(&'a self) -> FgColorDisplay<'a, C, Self> where
C: Color,
C: Color,
pub fn bg<C>(&'a self) -> BgColorDisplay<'a, C, Self> where
C: Color,
C: Color,
pub fn black(&'a self) -> FgColorDisplay<'a, Black, Self>
pub fn on_black(&'a self) -> BgColorDisplay<'a, Black, Self>
pub fn red(&'a self) -> FgColorDisplay<'a, Red, Self>
pub fn on_red(&'a self) -> BgColorDisplay<'a, Red, Self>
pub fn green(&'a self) -> FgColorDisplay<'a, Green, Self>
pub fn on_green(&'a self) -> BgColorDisplay<'a, Green, Self>
pub fn yellow(&'a self) -> FgColorDisplay<'a, Yellow, Self>
pub fn on_yellow(&'a self) -> BgColorDisplay<'a, Yellow, Self>
pub fn blue(&'a self) -> FgColorDisplay<'a, Blue, Self>
pub fn on_blue(&'a self) -> BgColorDisplay<'a, Blue, Self>
pub fn magenta(&'a self) -> FgColorDisplay<'a, Magenta, Self>
pub fn on_magenta(&'a self) -> BgColorDisplay<'a, Magenta, Self>
pub fn purple(&'a self) -> FgColorDisplay<'a, Magenta, Self>
pub fn on_purple(&'a self) -> BgColorDisplay<'a, Magenta, Self>
pub fn cyan(&'a self) -> FgColorDisplay<'a, Cyan, Self>
pub fn on_cyan(&'a self) -> BgColorDisplay<'a, Cyan, Self>
pub fn white(&'a self) -> FgColorDisplay<'a, White, Self>
pub fn on_white(&'a self) -> BgColorDisplay<'a, White, Self>
pub fn bright_black(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
pub fn on_bright_black(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
pub fn bright_red(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
pub fn on_bright_red(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
pub fn bright_green(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
pub fn on_bright_green(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
pub fn bright_yellow(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
pub fn on_bright_yellow(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
pub fn bright_blue(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
pub fn on_bright_blue(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
pub fn bright_magenta(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
pub fn on_bright_magenta(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
pub fn bright_purple(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
pub fn on_bright_purple(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
pub fn bright_cyan(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
pub fn on_bright_cyan(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
pub fn bright_white(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
pub fn on_bright_white(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
pub fn bold(&'a self) -> BoldDisplay<'a, Self>
pub fn dimmed(&'a self) -> DimDisplay<'a, Self>
pub fn italic(&'a self) -> ItalicDisplay<'a, Self>
pub fn underline(&'a self) -> UnderlineDisplay<'a, Self>
pub fn blink(&'a self) -> BlinkDisplay<'a, Self>
pub fn blink_fast(&'a self) -> BlinkFastDisplay<'a, Self>
pub fn reversed(&'a self) -> ReversedDisplay<'a, Self>
pub fn hidden(&'a self) -> HiddenDisplay<'a, Self>
pub fn strikethrough(&'a self) -> StrikeThroughDisplay<'a, Self>
pub fn color<Color>(
&'a self,
color: Color
) -> FgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
&'a self,
color: Color
) -> FgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
pub fn on_color<Color>(
&'a self,
color: Color
) -> BgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
&'a self,
color: Color
) -> BgDynColorDisplay<'a, Color, Self> where
Color: DynColor,
pub fn truecolor(
&'a self,
r: u8,
g: u8,
b: u8
) -> FgDynColorDisplay<'a, Rgb, Self>
&'a self,
r: u8,
g: u8,
b: u8
) -> FgDynColorDisplay<'a, Rgb, Self>
pub fn on_truecolor(
&'a self,
r: u8,
g: u8,
b: u8
) -> BgDynColorDisplay<'a, Rgb, Self>
&'a self,
r: u8,
g: u8,
b: u8
) -> BgDynColorDisplay<'a, Rgb, Self>
pub fn style(&self, style: Style) -> Styled<&Self>
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,