Skip to content

Commit

Permalink
spacing fixes, simplify SeveralEpisodes
Browse files Browse the repository at this point in the history
  • Loading branch information
marioortizmanero committed Apr 17, 2021
1 parent 7398e83 commit 6eef453
Showing 10 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -2000,14 +2000,15 @@ impl Spotify {
&self,
ids: impl IntoIterator<Item = &'a EpisodeId>,
market: Option<Market>,
) -> ClientResult<SeveralEpisodes> {
) -> ClientResult<Vec<FullEpisode>> {
let mut params = Query::with_capacity(1);
params.insert("ids".to_owned(), join_ids(ids));
if let Some(market) = market {
params.insert("market".to_owned(), market.to_string());
}

let result = self.endpoint_get("episodes", &params).await?;
self.convert_result(&result)
self.convert_result::<EpisodesPayload>(&result).map(|x| x.episodes)
}

/// Check if one or more shows is already saved in the current Spotify user’s library.
1 change: 1 addition & 0 deletions src/model/audio.rs
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ pub struct AudioAnalysisMeta {
pub analysis_time: f32,
pub input_process: String,
}

/// Audio analysis segment object
///
///[Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-audio-analysis)
1 change: 1 addition & 0 deletions src/model/category.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
use super::image::Image;
use super::page::Page;
use serde::{Deserialize, Serialize};

/// Category object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-categories)
1 change: 1 addition & 0 deletions src/model/context.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;
use std::time::Duration;

/// Context object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-recently-played)
3 changes: 3 additions & 0 deletions src/model/idtypes.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ use thiserror::Error;
// This is a sealed trait pattern implementation, it stops external code from
// implementing the `IdType` trait. The `Sealed` trait must be in a private mod,
// so external code can not see and implement it.
//
// We use the `sealed_types` macro for an easier implementation here.
//
// See also: https://rust-lang.github.io/api-guidelines/future-proofing.html
mod private {
pub trait Sealed {}
13 changes: 12 additions & 1 deletion src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! All Spotify API endpoint response object
//! All Spotify API endpoint response objects.
//!
//! [Reference](https://developer.spotify.com/documentation/web-api/reference/#objects-index)
pub mod album;
pub mod artist;
pub mod audio;
@@ -17,6 +20,7 @@ pub mod search;
pub mod show;
pub mod track;
pub mod user;

use serde::{Deserialize, Serialize};

pub(in crate) mod duration_ms {
@@ -55,6 +59,7 @@ pub(in crate) mod duration_ms {
s.serialize_u64(x.as_millis() as u64)
}
}

pub(in crate) mod millisecond_timestamp {
use chrono::{DateTime, NaiveDateTime, Utc};
use serde::{de, Serializer};
@@ -66,12 +71,14 @@ pub(in crate) mod millisecond_timestamp {

impl<'de> de::Visitor<'de> for DateTimeVisitor {
type Value = DateTime<Utc>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"an unix millisecond timestamp represents DataTime<UTC>"
)
}

fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: de::Error,
@@ -104,6 +111,7 @@ pub(in crate) mod millisecond_timestamp {
s.serialize_i64(x.timestamp_millis())
}
}

pub(in crate) mod option_duration_ms {
use super::duration_ms;
use serde::{de, Serializer};
@@ -115,12 +123,14 @@ pub(in crate) mod option_duration_ms {

impl<'de> de::Visitor<'de> for OptionDurationVisitor {
type Value = Option<Duration>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"a optional milliseconds represents std::time::Duration"
)
}

fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
@@ -159,6 +169,7 @@ pub(in crate) mod option_duration_ms {
}
}
}

/// Deserialize/Serialize `Modality` to integer(0, 1, -1).
pub(in crate) mod modality {
use super::enums::Modality;
1 change: 1 addition & 0 deletions src/model/offset.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ impl<T: PlayableIdType> Offset<T> {
pub fn for_position(position: u32) -> Offset<T> {
Offset::Position(position)
}

pub fn for_uri(uri: &Id<T>) -> Offset<T> {
Offset::Uri(uri.to_owned())
}
2 changes: 2 additions & 0 deletions src/model/page.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ pub struct Page<T> {
pub previous: Option<String>,
pub total: u32,
}

/// Cursor-based paging object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-cursorpagingobject)
@@ -28,6 +29,7 @@ pub struct CursorBasedPage<T> {
/// Spotify document says
pub total: Option<u32>,
}

/// Cursor object
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#object-cursorobject)
1 change: 1 addition & 0 deletions src/model/search.rs
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ pub struct SearchAlbums {
pub struct SearchArtists {
pub artists: Page<FullArtist>,
}

///[Search item](https://developer.spotify.com/documentation/web-api/reference/#category-search)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct SearchTracks {
6 changes: 5 additions & 1 deletion src/model/show.rs
Original file line number Diff line number Diff line change
@@ -138,8 +138,12 @@ pub struct FullEpisode {
pub _type: String,
pub uri: String,
}

/// Episodes feature object wrapped by `Vec`
///
/// [Reference](https://developer.spotify.com/documentation/web-api/reference/#endpoint-get-multiple-episodes)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct SeveralEpisodes {
pub(in crate) struct EpisodesPayload {
pub episodes: Vec<FullEpisode>,
}

0 comments on commit 6eef453

Please sign in to comment.