Struct LinkDingClient

Source
pub struct LinkDingClient { /* private fields */ }
Expand description

A sync client for the LinkDing API.

This client is used to interact with the LinkDing API. It provides methods for managing bookmarks and tags, the full capability of the LinkDing API.

§Example

use linkding::{LinkDingClient, LinkDingError, CreateBookmarkBody};

fn main() -> Result<(), LinkDingError> {
    let client = LinkDingClient::new("https://linkding.local:9090", "YOUR_API_TOKEN");
    let new_bookmark = CreateBookmarkBody {
        url: "https://example.com".to_string(),
        ..Default::default()
    };
    let bookmark = client.create_bookmark(new_bookmark)?;
    println!("Bookmark created: {:?}", bookmark);
    client.delete_bookmark(bookmark.id)?;
    println!("Bookmark deleted");
    Ok(())
}

Implementations§

Source§

impl LinkDingClient

Source

pub fn new(url: &str, token: &str) -> Self

Examples found in repository?
examples/upload_asset.rs (line 10)
5fn main() {
6    let linkding_host =
7        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
8    let linkding_token =
9        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
10    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
11
12    let mut asset_file = std::fs::File::open("examples/asset.txt").unwrap();
13    let mut buffer: Vec<u8> = vec![];
14    asset_file.read_to_end(&mut buffer).unwrap();
15
16    linkding_client.upload_bookmark_asset(1, &buffer).unwrap();
17}
More examples
Hide additional examples
examples/download_asset.rs (line 10)
5fn main() {
6    let linkding_host =
7        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
8    let linkding_token =
9        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
10    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
11
12    let result = linkding_client
13        .download_bookmark_asset(1, 1)
14        .expect("Could not download asset");
15
16    let mut asset_file =
17        File::create("asset.html").expect("Could not create/overwrite the file asset.html");
18    asset_file
19        .write(&result)
20        .expect("Could not write to asset file");
21}
examples/count_bookmarks.rs (line 8)
3fn main() {
4    let linkding_host =
5        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
6    let linkding_token =
7        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
8    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
9
10    let mut total_bookmarks = 0;
11    let mut offset = 0;
12
13    loop {
14        let response = linkding_client
15            .list_bookmarks(ListBookmarksArgs {
16                query: None,
17                limit: None,
18                offset: Some(offset),
19            })
20            .expect("Couldn't fetch bookmarks");
21        total_bookmarks += response.results.len();
22        if response.next.is_none() {
23            break;
24        }
25        offset += 100;
26    }
27
28    println!("Total bookmarks: {}", total_bookmarks);
29}
Source

pub fn list_bookmarks( &self, args: ListBookmarksArgs, ) -> Result<ListBookmarksResponse, LinkDingError>

List unarchived bookmarks

Examples found in repository?
examples/count_bookmarks.rs (lines 15-19)
3fn main() {
4    let linkding_host =
5        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
6    let linkding_token =
7        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
8    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
9
10    let mut total_bookmarks = 0;
11    let mut offset = 0;
12
13    loop {
14        let response = linkding_client
15            .list_bookmarks(ListBookmarksArgs {
16                query: None,
17                limit: None,
18                offset: Some(offset),
19            })
20            .expect("Couldn't fetch bookmarks");
21        total_bookmarks += response.results.len();
22        if response.next.is_none() {
23            break;
24        }
25        offset += 100;
26    }
27
28    println!("Total bookmarks: {}", total_bookmarks);
29}
Source

pub fn list_archived_bookmarks( &self, args: ListBookmarksArgs, ) -> Result<ListBookmarksResponse, LinkDingError>

List archived bookmarks

Source

pub fn get_bookmark(&self, id: i32) -> Result<Bookmark, LinkDingError>

Get a bookmark by ID

Source

pub fn check_url(&self, url: &str) -> Result<CheckUrlResponse, LinkDingError>

Check if a URL has been bookmarked

If the URL has already been bookmarked this will return the bookmark data, otherwise the bookmark data will be None. The metadata of the webpage will always be returned.

Source

pub fn create_bookmark( &self, body: CreateBookmarkBody, ) -> Result<Bookmark, LinkDingError>

Create a bookmark

If the bookmark already exists, it will be updated with the new data passed in the body parameter.

Source

pub fn update_bookmark( &self, id: i32, body: UpdateBookmarkBody, ) -> Result<Bookmark, LinkDingError>

Update a bookmark

Pass only the fields you want to update in the body parameter.

Source

pub fn archive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>

Archive a bookmark

Source

pub fn unarchive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>

Take a bookmark out of the archive

Source

pub fn delete_bookmark(&self, id: i32) -> Result<bool, LinkDingError>

Delete a bookmark

Source

pub fn list_tags( &self, args: ListTagsArgs, ) -> Result<ListTagsResponse, LinkDingError>

List tags

Source

pub fn get_tag(&self, id: i32) -> Result<TagData, LinkDingError>

Get a tag by ID

Source

pub fn create_tag(&self, name: &str) -> Result<TagData, LinkDingError>

Create a tag

Source

pub fn get_user_profile(&self) -> Result<UserProfile, LinkDingError>

Get the user’s profile

Source

pub fn list_bookmark_assets( &self, id: i32, ) -> Result<ListBookmarkAssetsResponse, LinkDingError>

Lists a bookmarks’ assets

Source

pub fn retrieve_bookmark_asset( &self, bookmark_id: i32, asset_id: i32, ) -> Result<BookmarkAsset, LinkDingError>

Retrieve info for a single asset of a bookmark

Source

pub fn download_bookmark_asset( &self, bookmark_id: i32, asset_id: i32, ) -> Result<Vec<u8>, LinkDingError>

Download a bookmark’s asset

Examples found in repository?
examples/download_asset.rs (line 13)
5fn main() {
6    let linkding_host =
7        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
8    let linkding_token =
9        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
10    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
11
12    let result = linkding_client
13        .download_bookmark_asset(1, 1)
14        .expect("Could not download asset");
15
16    let mut asset_file =
17        File::create("asset.html").expect("Could not create/overwrite the file asset.html");
18    asset_file
19        .write(&result)
20        .expect("Could not write to asset file");
21}
Source

pub fn upload_bookmark_asset( &self, bookmark_id: i32, bytes: &[u8], ) -> Result<BookmarkAsset, LinkDingError>

Upload an asset for a bookmark

Examples found in repository?
examples/upload_asset.rs (line 16)
5fn main() {
6    let linkding_host =
7        std::env::var("LINKDING_HOST").unwrap_or("http://localhost:9090".to_string());
8    let linkding_token =
9        std::env::var("LINKDING_TOKEN").expect("LINKDING_TOKEN env variable is not set");
10    let linkding_client = LinkDingClient::new(&linkding_host, &linkding_token);
11
12    let mut asset_file = std::fs::File::open("examples/asset.txt").unwrap();
13    let mut buffer: Vec<u8> = vec![];
14    asset_file.read_to_end(&mut buffer).unwrap();
15
16    linkding_client.upload_bookmark_asset(1, &buffer).unwrap();
17}
Source

pub fn delete_bookmark_asset( &self, bookmark_id: i32, asset_id: i32, ) -> Result<bool, LinkDingError>

Delete a bookmark’s asset

Trait Implementations§

Source§

impl Clone for LinkDingClient

Source§

fn clone(&self) -> LinkDingClient

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkDingClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,