deviantart/
lib.rs

1/// The client
2mod client;
3/// API types
4pub mod types;
5
6pub use self::client::Client;
7pub use self::types::Deviation;
8pub use self::types::DeviationExtended;
9pub use self::types::ListFolderContentsResponse;
10pub use self::types::OEmbed;
11pub use self::types::ScrapedStashInfo;
12pub use self::types::ScrapedWebPageInfo;
13pub use url::Url;
14
15/// Library Error
16#[derive(Debug, thiserror::Error)]
17pub enum Error {
18    /// Reqwest HTTP Error
19    #[error(transparent)]
20    Reqwest(#[from] reqwest::Error),
21
22    /// Invalid Url
23    #[error(transparent)]
24    Url(#[from] url::ParseError),
25
26    /// A tokio task failed to join
27    #[error(transparent)]
28    TokioJoin(#[from] tokio::task::JoinError),
29
30    /// Json failed to parse
31    #[error(transparent)]
32    Json(#[from] serde_json::Error),
33
34    /// A scraped web page was invalid
35    #[error("invalid scraped webpage")]
36    InvalidScrapedWebPage(#[from] self::types::scraped_webpage_info::FromHtmlStrError),
37
38    /// Scraped Stash info was invalid
39    #[error("invalid scraped stash info")]
40    InvalidScrapedStashInfo(#[from] self::types::scraped_stash_info::FromHtmlStrError),
41
42    /// Signing in failed for an unspecified reason
43    #[error("sign in failed")]
44    SignInFailed,
45
46    /// Missing a field
47    #[error("missing field \"{name}\"")]
48    MissingField {
49        /// The missing field name
50        name: &'static str,
51    },
52
53    /// Missing the streams field
54    #[error("missing streams")]
55    MissingStreams,
56
57    /// Missing the browse page stream
58    #[error("missing browse page stream")]
59    MissingBrowsePageStream,
60
61    /// Missing the Deviation of the given id
62    #[error("missing deviation {0}")]
63    MissingDeviation(u64),
64
65    /// A cookie store error occured
66    #[error("cookie store error")]
67    CookieStore(WrapBoxError),
68}
69
70/// A wrapper over a `Box<dyn std::error::Error + Send + Sync + 'static>`.
71#[derive(Debug)]
72pub struct WrapBoxError(pub Box<dyn std::error::Error + Send + Sync + 'static>);
73
74impl std::fmt::Display for WrapBoxError {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        self.0.fmt(f)
77    }
78}
79
80impl std::error::Error for WrapBoxError {}
81
82// TODO:
83// investigate deviantart.com/view/<id>
84// ex: deviantart.com/view/852625718