Skip to content

Commit

Permalink
Apply api updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Aug 13, 2023
1 parent efd0823 commit 09d45ff
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
12 changes: 9 additions & 3 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ pub struct Account {
#[serde(rename = "preferred_content_subtitle_language")]
pub preferred_subtitle_language: Locale,

pub opt_out_android_in_app_marketing: bool,
pub opt_out_free_trials: bool,
pub opt_out_new_media_queue_updates: bool,
pub opt_out_pm_updates: bool,
pub opt_out_queue_updates: bool,
#[serde(rename = "opt_out_store_deals")]
pub email_store_details: bool,
#[serde(rename = "opt_out_newsletters")]
Expand Down Expand Up @@ -236,6 +233,15 @@ impl Crunchyroll {
.await?,
);

let notification_endpoint =
"https://www.crunchyroll.com/accounts/v1/me/notification_settings";
result.extend(
self.executor
.get(notification_endpoint)
.request::<HashMap<String, Value>>()
.await?,
);

let mut account: Account = serde_json::from_value(Value::Object(result))?;
account.executor = self.executor.clone();

Expand Down
26 changes: 20 additions & 6 deletions src/media/anime/movie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ pub struct Movie {

#[serde(alias = "listing_id")]
pub movie_listing_id: String,

pub movie_listing_title: String,
#[serde(default)]
pub movie_listing_slug_title: String,

#[serde(alias = "duration_ms")]
#[serde(deserialize_with = "crate::internal::serde::deserialize_millis_to_duration")]
Expand Down Expand Up @@ -59,16 +60,29 @@ pub struct Movie {
pub availability_notes: String,

#[cfg(feature = "__test_strict")]
media_type: Option<crate::StrictValue>,
#[serde(rename = "type")]
#[serde(alias = "media_type")]
type_: crate::StrictValue,
#[cfg(feature = "__test_strict")]
audio_locale: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
external_id: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
linked_resource_key: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
promo_title: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
promo_description: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
extended_maturity_rating: crate::StrictValue,
#[cfg(feature = "__test_strict")]
available_date: crate::StrictValue,
#[cfg(feature = "__test_strict")]
premium_date: crate::StrictValue,
availability_starts: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
#[serde(default)]
movie_listing_slug_title: crate::StrictValue,
availability_ends: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
premium_date: crate::StrictValue,
}

impl Movie {
Expand All @@ -90,7 +104,7 @@ impl Media for Movie {
Ok(request_media(
crunchyroll.executor.clone(),
format!(
"https://www.crunchyroll.com/content/v2/cms/movies/{}",
"https://www.crunchyroll.com/content/v2/cms/objects/{}",
id.as_ref()
),
)
Expand Down
17 changes: 17 additions & 0 deletions src/media/music/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};
use std::sync::Arc;

#[derive(Clone, Debug, Default, Deserialize, Serialize, Request)]
#[request(executor(main_artist))]
#[serde(rename_all = "PascalCase")]
#[cfg_attr(feature = "__test_strict", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "__test_strict"), serde(default))]
pub struct ArtistsPreviewList {
pub main_artist: Vec<ArtistPreview>,
}

/// A preview / summary of an artist. Returned when requesting a [`MusicVideo`] or [`Concert`].
#[derive(Clone, Debug, Default, Deserialize, Serialize, Request)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "__test_strict", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "__test_strict"), serde(default))]
pub struct ArtistPreview {
Expand All @@ -20,6 +30,13 @@ pub struct ArtistPreview {

pub slug: String,
pub name: String,

#[cfg(feature = "__test_strict")]
connector: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
roles: Option<crate::StrictValue>,
#[cfg(feature = "__test_strict")]
sequence_number: Option<crate::StrictValue>,
}

impl ArtistPreview {
Expand Down
8 changes: 6 additions & 2 deletions src/media/music/concert.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::crunchyroll::Executor;
use crate::media::music::util::availability_object_to_keys;
use crate::media::util::request_media;
use crate::media::{ArtistPreview, Media, MusicGenre, ThumbnailImages};
use crate::media::{ArtistPreview, ArtistsPreviewList, Media, MusicGenre, ThumbnailImages};
use crate::{Crunchyroll, Request, Result};
use chrono::{DateTime, Duration, Utc};
use serde::de::{Error, IntoDeserializer};
Expand All @@ -10,7 +10,7 @@ use std::sync::Arc;

/// Metadata for a concert.
#[derive(Clone, Debug, Deserialize, Serialize, Request, smart_default::SmartDefault)]
#[request(executor(artist))]
#[request(executor(artist, artists))]
#[serde(rename_all = "camelCase")]
#[serde(remote = "Self")]
#[cfg_attr(feature = "__test_strict", serde(deny_unknown_fields))]
Expand All @@ -31,6 +31,10 @@ pub struct Concert {
pub sequence_number: f32,

pub artist: ArtistPreview,
pub artists: ArtistsPreviewList,
pub display_artist_name: String,
pub display_artist_name_required: bool,

pub licensor: String,
pub copyright: String,

Expand Down
8 changes: 6 additions & 2 deletions src/media/music/music_video.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::crunchyroll::Executor;
use crate::media::music::util::availability_object_to_keys;
use crate::media::util::request_media;
use crate::media::{ArtistPreview, Media, MusicGenre, ThumbnailImages};
use crate::media::{ArtistPreview, ArtistsPreviewList, Media, MusicGenre, ThumbnailImages};
use crate::{Crunchyroll, MediaCollection, Request, Result};
use chrono::{DateTime, Duration, Utc};
use serde::de::{Error, IntoDeserializer};
Expand All @@ -10,7 +10,7 @@ use std::sync::Arc;

/// Metadata for a music video.
#[derive(Clone, Debug, Deserialize, Serialize, Request, smart_default::SmartDefault)]
#[request(executor(artist))]
#[request(executor(artist, artists))]
#[serde(rename_all = "camelCase")]
#[serde(remote = "Self")]
#[cfg_attr(feature = "__test_strict", serde(deny_unknown_fields))]
Expand All @@ -33,6 +33,10 @@ pub struct MusicVideo {
pub sequence_number: f32,

pub artist: ArtistPreview,
pub artists: ArtistsPreviewList,
pub display_artist_name: String,
pub display_artist_name_required: bool,

pub licensor: String,
pub copyright: String,

Expand Down
4 changes: 2 additions & 2 deletions tests/test_concert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ mod utils;
static CONCERT: Store<Concert> = Store::new(|| {
Box::pin(async {
let crunchy = SESSION.get().await?;
let movie_listing = crunchy.media_from_id("MC27E95748").await?;
Ok(movie_listing)
let concert = crunchy.media_from_id("MC27E95748").await?;
Ok(concert)
})
});

Expand Down
6 changes: 5 additions & 1 deletion tests/test_music_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ async fn music_video_related_anime() {

#[tokio::test]
async fn music_video_artist() {
assert_result!(MUSIC_VIDEO.get().await.unwrap().artist.artist().await)
assert_result!(
MUSIC_VIDEO.get().await.unwrap().artists.main_artist[0]
.artist()
.await
)
}

0 comments on commit 09d45ff

Please sign in to comment.