wallabag_api/
types.rs

1// Copyright 2018 Samuel Walladge <samuel@swalladge.net>
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! All types used by the client. Some are returned by the client and shouldn't
5//! need to be created manually, while others are designed to be created and
6//! passed to client methods (eg. creating new entries).
7use std::collections::HashMap;
8
9use serde::{Deserialize, Serialize};
10
11// TODO: decide how to implement PartialEq/Eq for types here. (eg on the whole
12// structs, or just by IDs?)
13
14mod annotations;
15mod common;
16mod entries_filter;
17mod entry;
18mod format;
19mod new_entry;
20mod patch_entry;
21mod query;
22mod tags;
23mod user;
24
25// re-export submodule types
26pub(crate) use self::annotations::AnnotationRows;
27pub use self::annotations::{Annotation, Annotations, NewAnnotation, Range};
28pub use self::common::ID;
29pub(crate) use self::entries_filter::RequestEntriesFilter;
30pub use self::entries_filter::{EntriesFilter, SortBy, SortOrder};
31pub(crate) use self::entry::{DeletedEntry, PaginatedEntries};
32pub use self::entry::{Entries, EntriesPage, Entry};
33pub use self::format::Format;
34pub use self::new_entry::NewEntry;
35pub use self::patch_entry::PatchEntry;
36pub(crate) use self::query::EntriesExistParams;
37pub use self::tags::{DeletedTag, Tag, TagString, Tags};
38pub use self::user::{NewlyRegisteredInfo, RegisterInfo, User};
39
40/// used internally to store information about the oauth token
41#[derive(Deserialize, Debug)]
42pub(crate) struct TokenInfo {
43    pub access_token: String,
44    pub expires_in: u32,
45    pub token_type: String,
46    pub scope: Option<String>,
47    pub refresh_token: String,
48}
49
50/// configuration to use to init a `Client`.
51#[derive(Debug, Clone)]
52pub struct Config {
53    /// An oauth client id.
54    pub client_id: String,
55
56    /// An oauth client secret.
57    pub client_secret: String,
58
59    /// Your username.
60    pub username: String,
61
62    /// Your password. Unfortunately Wallabag doesn't support full oauth yet, and still requires
63    /// applications to access your password.
64    pub password: String,
65
66    /// Should not include trailing slash. Eg. "https://framabag.org" is fine.
67    pub base_url: String,
68}
69
70/// The type returned from `check_exists`. The format is URL: ID. If ID is None,
71/// then that url doesn't exist in the db.
72pub type ExistsInfo = HashMap<String, Option<ID>>;
73
74/// Internal struct for deserializing a response upon checking the existance of
75/// a url.
76#[derive(Deserialize, Debug)]
77pub(crate) struct ExistsResponse {
78    pub exists: Option<ID>,
79}
80
81/// a little trick to get around having to provide type annotations for a unit or
82/// none value when passing to url serializer
83#[derive(Serialize, Debug)]
84pub(crate) struct Unit {}
85pub(crate) static UNIT: &Unit = &Unit {};