Skip to content

Commit

Permalink
✨ Implement 'Get Settings' for episode
Browse files Browse the repository at this point in the history
  • Loading branch information
FeuRenard committed Jun 1, 2020
1 parent 7dde038 commit b429cda
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Rust client library for [gpodder.net](https://gpodder.net/)
- [x] [Subscriptions](https://gpoddernet.readthedocs.io/en/latest/api/reference/subscriptions.html)
- [x] [Episode Actions](https://gpoddernet.readthedocs.io/en/latest/api/reference/events.html)
- [ ] [Podcast Lists](https://gpoddernet.readthedocs.io/en/latest/api/reference/podcastlists.html)
- [ ] [Settings](https://gpoddernet.readthedocs.io/en/latest/api/reference/settings.html)
- [x] [Settings](https://gpoddernet.readthedocs.io/en/latest/api/reference/settings.html)
- [ ] [Favorites](https://gpoddernet.readthedocs.io/en/latest/api/reference/favorites.html)
- [ ] [Device Synchronization](https://gpoddernet.readthedocs.io/en/latest/api/reference/sync.html)
- [ ] [Client Parametrization](https://gpoddernet.readthedocs.io/en/latest/api/reference/clientconfig.html)
Expand Down
63 changes: 63 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,37 @@ pub trait GetPodcastSettings {
fn get_podcast_settings(&self, podcast: Url) -> Result<HashMap<String, String>, Error>;
}

/// see [`get_episode_settings`](./trait.GetEpisodeSettings.html#tymethod.get_episode_settings)
pub trait GetEpisodeSettings {
/// Get Episode Settings
///
/// # Examples
///
/// ```
/// use mygpoclient::client::AuthenticatedClient;
/// use mygpoclient::settings::GetEpisodeSettings;
/// use url::Url;
///
/// # let username = std::env::var("GPODDER_NET_USERNAME").unwrap();
/// # let password = std::env::var("GPODDER_NET_PASSWORD").unwrap();
/// #
/// let client = AuthenticatedClient::new(&username, &password);
///
/// let settings = client.get_episode_settings(Url::parse("http://example.com/feed1.rss").unwrap(), Url::parse("http://example.com/files/s01e20.mp3").unwrap())?;
/// #
/// # Ok::<(), mygpoclient::error::Error>(())
/// ```
///
/// # See also
///
/// - [gpodder.net API Documentation](https://gpoddernet.readthedocs.io/en/latest/api/reference/settings.html#get-settings)
fn get_episode_settings(
&self,
podcast: Url,
episode: Url,
) -> Result<HashMap<String, String>, Error>;
}

impl SaveAccountSettings for AuthenticatedClient {
fn save_account_settings(
&self,
Expand Down Expand Up @@ -413,3 +444,35 @@ impl GetPodcastSettings for DeviceClient {
self.authenticated_client.get_podcast_settings(podcast)
}
}

impl GetEpisodeSettings for AuthenticatedClient {
fn get_episode_settings(
&self,
podcast: Url,
episode: Url,
) -> Result<HashMap<String, String>, Error> {
Ok(self
.get_with_query(
&format!(
"https://gpodder.net/api/2/settings/{}/episode.json",
self.username
),
&[
&("podcast", podcast.as_str()),
&("episode", episode.as_str()),
],
)?
.json()?)
}
}

impl GetEpisodeSettings for DeviceClient {
fn get_episode_settings(
&self,
podcast: Url,
episode: Url,
) -> Result<HashMap<String, String>, Error> {
self.authenticated_client
.get_episode_settings(podcast, episode)
}
}
12 changes: 11 additions & 1 deletion tests/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use url::Url;
use mygpoclient::client::DeviceClient;
use mygpoclient::error::Error;
use mygpoclient::settings::GetAccountSettings;
use mygpoclient::settings::GetEpisodeSettings;
use mygpoclient::settings::GetPodcastSettings;
use mygpoclient::settings::SaveAccountSettings;
use mygpoclient::settings::SaveEpisodeSettings;
Expand Down Expand Up @@ -79,11 +80,20 @@ fn test_get_account_settings_device_client() -> Result<(), Error> {
#[test]
fn test_get_podcast_settings_device_client() -> Result<(), Error> {
let client = get_device_client();

client.get_podcast_settings(Url::parse("http://goinglinux.com/mp3podcast.xml").unwrap())?;
Ok(())
}

#[test]
fn test_get_episode_settings_device_client() -> Result<(), Error> {
let client = get_device_client();
client.get_episode_settings(
Url::parse("http://example.com/feed1.rss").unwrap(),
Url::parse("http://example.com/files/s01e20.mp3").unwrap(),
)?;
Ok(())
}

fn get_device_client() -> DeviceClient {
let username = env::var("GPODDER_NET_USERNAME").unwrap();
let password = env::var("GPODDER_NET_PASSWORD").unwrap();
Expand Down

0 comments on commit b429cda

Please sign in to comment.