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
impl LinkDingClient
Sourcepub fn new(url: &str, token: &str) -> Self
pub fn new(url: &str, token: &str) -> Self
Examples found in repository?
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
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}
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}
Sourcepub fn list_bookmarks(
&self,
args: ListBookmarksArgs,
) -> Result<ListBookmarksResponse, LinkDingError>
pub fn list_bookmarks( &self, args: ListBookmarksArgs, ) -> Result<ListBookmarksResponse, LinkDingError>
List unarchived bookmarks
Examples found in repository?
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}
Sourcepub fn list_archived_bookmarks(
&self,
args: ListBookmarksArgs,
) -> Result<ListBookmarksResponse, LinkDingError>
pub fn list_archived_bookmarks( &self, args: ListBookmarksArgs, ) -> Result<ListBookmarksResponse, LinkDingError>
List archived bookmarks
Sourcepub fn get_bookmark(&self, id: i32) -> Result<Bookmark, LinkDingError>
pub fn get_bookmark(&self, id: i32) -> Result<Bookmark, LinkDingError>
Get a bookmark by ID
Sourcepub fn check_url(&self, url: &str) -> Result<CheckUrlResponse, LinkDingError>
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.
Sourcepub fn create_bookmark(
&self,
body: CreateBookmarkBody,
) -> Result<Bookmark, LinkDingError>
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.
Sourcepub fn update_bookmark(
&self,
id: i32,
body: UpdateBookmarkBody,
) -> Result<Bookmark, LinkDingError>
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.
Sourcepub fn archive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
pub fn archive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
Archive a bookmark
Sourcepub fn unarchive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
pub fn unarchive_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
Take a bookmark out of the archive
Sourcepub fn delete_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
pub fn delete_bookmark(&self, id: i32) -> Result<bool, LinkDingError>
Delete a bookmark
List tags
Sourcepub fn create_tag(&self, name: &str) -> Result<TagData, LinkDingError>
pub fn create_tag(&self, name: &str) -> Result<TagData, LinkDingError>
Create a tag
Sourcepub fn get_user_profile(&self) -> Result<UserProfile, LinkDingError>
pub fn get_user_profile(&self) -> Result<UserProfile, LinkDingError>
Get the user’s profile
Sourcepub fn list_bookmark_assets(
&self,
id: i32,
) -> Result<ListBookmarkAssetsResponse, LinkDingError>
pub fn list_bookmark_assets( &self, id: i32, ) -> Result<ListBookmarkAssetsResponse, LinkDingError>
Lists a bookmarks’ assets
Sourcepub fn retrieve_bookmark_asset(
&self,
bookmark_id: i32,
asset_id: i32,
) -> Result<BookmarkAsset, LinkDingError>
pub fn retrieve_bookmark_asset( &self, bookmark_id: i32, asset_id: i32, ) -> Result<BookmarkAsset, LinkDingError>
Retrieve info for a single asset of a bookmark
Sourcepub fn download_bookmark_asset(
&self,
bookmark_id: i32,
asset_id: i32,
) -> Result<Vec<u8>, LinkDingError>
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?
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}
Sourcepub fn upload_bookmark_asset(
&self,
bookmark_id: i32,
bytes: &[u8],
) -> Result<BookmarkAsset, LinkDingError>
pub fn upload_bookmark_asset( &self, bookmark_id: i32, bytes: &[u8], ) -> Result<BookmarkAsset, LinkDingError>
Upload an asset for a bookmark
Examples found in repository?
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}
Sourcepub fn delete_bookmark_asset(
&self,
bookmark_id: i32,
asset_id: i32,
) -> Result<bool, LinkDingError>
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
impl Clone for LinkDingClient
Source§fn clone(&self) -> LinkDingClient
fn clone(&self) -> LinkDingClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more