Skip to content

Commit

Permalink
Remove CustomObject class in favour of new PropertiesList behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenFrankel committed Apr 30, 2024
1 parent a78e968 commit 89e6529
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 172 deletions.
35 changes: 16 additions & 19 deletions tap_spotify/schemas/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
from tap_spotify.schemas.external import ExternalUrlObject
from tap_spotify.schemas.image import ImageObject
from tap_spotify.schemas.restriction import RestrictionObject as AlbumRestrictionObject
from tap_spotify.schemas.utils.custom_object import CustomObject


class AlbumObject(CustomObject):
properties = th.PropertiesList(
th.Property("album_type", th.StringType),
th.Property("artists", th.ArrayType(ArtistObject)),
th.Property("available_markets", th.ArrayType(th.StringType)),
th.Property("external_urls", ExternalUrlObject),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("images", th.ArrayType(ImageObject)),
th.Property("name", th.StringType),
th.Property("release_date", th.StringType),
th.Property("release_date_precision", th.StringType),
th.Property("restrictions", AlbumRestrictionObject),
th.Property("total_tracks", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
AlbumObject = th.PropertiesList(
th.Property("album_type", th.StringType),
th.Property("artists", th.ArrayType(ArtistObject)),
th.Property("available_markets", th.ArrayType(th.StringType)),
th.Property("external_urls", ExternalUrlObject),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("images", th.ArrayType(ImageObject)),
th.Property("name", th.StringType),
th.Property("release_date", th.StringType),
th.Property("release_date_precision", th.StringType),
th.Property("restrictions", AlbumRestrictionObject),
th.Property("total_tracks", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
27 changes: 12 additions & 15 deletions tap_spotify/schemas/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
from tap_spotify.schemas.external import ExternalUrlObject
from tap_spotify.schemas.followers import FollowersObject
from tap_spotify.schemas.image import ImageObject
from tap_spotify.schemas.utils.custom_object import CustomObject


class ArtistObject(CustomObject):
properties = th.PropertiesList(
th.Property("external_urls", ExternalUrlObject),
th.Property("followers", FollowersObject),
th.Property("genres", th.ArrayType(th.StringType)),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("images", th.ArrayType(ImageObject)),
th.Property("name", th.StringType),
th.Property("popularity", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
ArtistObject = th.PropertiesList(
th.Property("external_urls", ExternalUrlObject),
th.Property("followers", FollowersObject),
th.Property("genres", th.ArrayType(th.StringType)),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("images", th.ArrayType(ImageObject)),
th.Property("name", th.StringType),
th.Property("popularity", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
44 changes: 20 additions & 24 deletions tap_spotify/schemas/audio_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@
StringType,
)

from tap_spotify.schemas.utils.custom_object import CustomObject


class AudioFeaturesObject(CustomObject):
properties = PropertiesList(
Property("acousticness", NumberType),
Property("analysis_url", StringType),
Property("danceability", NumberType),
Property("duration_ms", IntegerType),
Property("energy", NumberType),
Property("id", StringType),
Property("instrumentalness", NumberType),
Property("key", IntegerType),
Property("liveness", NumberType),
Property("loudness", NumberType),
Property("mode", IntegerType),
Property("speechiness", NumberType),
Property("tempo", NumberType),
Property("time_signature", IntegerType),
Property("track_href", StringType),
Property("type", StringType),
Property("uri", StringType),
Property("valence", NumberType),
)
AudioFeaturesObject = PropertiesList(
Property("acousticness", NumberType),
Property("analysis_url", StringType),
Property("danceability", NumberType),
Property("duration_ms", IntegerType),
Property("energy", NumberType),
Property("id", StringType),
Property("instrumentalness", NumberType),
Property("key", IntegerType),
Property("liveness", NumberType),
Property("loudness", NumberType),
Property("mode", IntegerType),
Property("speechiness", NumberType),
Property("tempo", NumberType),
Property("time_signature", IntegerType),
Property("track_href", StringType),
Property("type", StringType),
Property("uri", StringType),
Property("valence", NumberType),
)
24 changes: 9 additions & 15 deletions tap_spotify/schemas/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class ExternalIdObject(CustomObject):
properties = th.PropertiesList(
th.Property("ean", th.StringType),
th.Property("isrc", th.StringType),
th.Property("upc", th.StringType),
)


class ExternalUrlObject(CustomObject):
properties = th.PropertiesList(
th.Property("spotify", th.StringType),
)
ExternalIdObject = th.PropertiesList(
th.Property("ean", th.StringType),
th.Property("isrc", th.StringType),
th.Property("upc", th.StringType),
)

ExternalUrlObject = th.PropertiesList(
th.Property("spotify", th.StringType),
)
12 changes: 4 additions & 8 deletions tap_spotify/schemas/followers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class FollowersObject(CustomObject):
properties = th.PropertiesList(
th.Property("href", th.StringType),
th.Property("total", th.IntegerType),
)
FollowersObject = th.PropertiesList(
th.Property("href", th.StringType),
th.Property("total", th.IntegerType),
)
14 changes: 5 additions & 9 deletions tap_spotify/schemas/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class ImageObject(CustomObject):
properties = th.PropertiesList(
th.Property("height", th.IntegerType),
th.Property("url", th.StringType),
th.Property("width", th.IntegerType),
)
ImageObject = th.PropertiesList(
th.Property("height", th.IntegerType),
th.Property("url", th.StringType),
th.Property("width", th.IntegerType),
)
10 changes: 3 additions & 7 deletions tap_spotify/schemas/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class RestrictionObject(CustomObject):
properties = th.PropertiesList(
th.Property("reason", th.StringType),
)
RestrictionObject = th.PropertiesList(
th.Property("reason", th.StringType),
)
47 changes: 22 additions & 25 deletions tap_spotify/schemas/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@
from tap_spotify.schemas.artist import ArtistObject
from tap_spotify.schemas.external import ExternalIdObject, ExternalUrlObject
from tap_spotify.schemas.restriction import RestrictionObject as TrackRestrictionObject
from tap_spotify.schemas.utils.custom_object import CustomObject


class TrackObject(CustomObject):
properties = th.PropertiesList(
th.Property("album", AlbumObject),
th.Property("artists", th.ArrayType(ArtistObject)),
th.Property("available_markets", th.ArrayType(th.StringType)),
th.Property("disc_number", th.IntegerType),
th.Property("duration_ms", th.IntegerType),
th.Property("explicit", th.BooleanType),
th.Property("external_ids", ExternalIdObject()),
th.Property("external_urls", ExternalUrlObject),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("is_local", th.BooleanType),
th.Property("is_playable", th.BooleanType),
# th.Property("linked_from", TrackObject), # noqa: ERA001
th.Property("name", th.StringType),
th.Property("popularity", th.IntegerType),
th.Property("preview_url", th.StringType),
th.Property("restrictions", TrackRestrictionObject),
th.Property("track_number", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
TrackObject = th.PropertiesList(
th.Property("album", AlbumObject),
th.Property("artists", th.ArrayType(ArtistObject)),
th.Property("available_markets", th.ArrayType(th.StringType)),
th.Property("disc_number", th.IntegerType),
th.Property("duration_ms", th.IntegerType),
th.Property("explicit", th.BooleanType),
th.Property("external_ids", ExternalIdObject),
th.Property("external_urls", ExternalUrlObject),
th.Property("href", th.StringType),
th.Property("id", th.StringType),
th.Property("is_local", th.BooleanType),
th.Property("is_playable", th.BooleanType),
# th.Property("linked_from", TrackObject), # noqa: ERA001
th.Property("name", th.StringType),
th.Property("popularity", th.IntegerType),
th.Property("preview_url", th.StringType),
th.Property("restrictions", TrackRestrictionObject),
th.Property("track_number", th.IntegerType),
th.Property("type", th.StringType),
th.Property("uri", th.StringType),
)
31 changes: 0 additions & 31 deletions tap_spotify/schemas/utils/custom_object.py

This file was deleted.

10 changes: 3 additions & 7 deletions tap_spotify/schemas/utils/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class Rank(CustomObject):
properties = th.PropertiesList(
th.Property("rank", th.IntegerType),
)
Rank = th.PropertiesList(
th.Property("rank", th.IntegerType),
)
10 changes: 3 additions & 7 deletions tap_spotify/schemas/utils/synced_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from singer_sdk import typing as th

from tap_spotify.schemas.utils.custom_object import CustomObject


class SyncedAt(CustomObject):
properties = th.PropertiesList(
th.Property("synced_at", th.DateTimeType),
)
SyncedAt = th.PropertiesList(
th.Property("synced_at", th.DateTimeType),
)
21 changes: 16 additions & 5 deletions tap_spotify/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime, timezone
from typing import Collection

from singer_sdk import typing as th
from singer_sdk.streams.rest import RESTStream
from typing_extensions import override

Expand Down Expand Up @@ -43,7 +44,7 @@ class _AudioFeaturesStream(SpotifyStream):
name = "_audio_features_stream"
path = "/audio-features"
records_jsonpath = "$.audio_features[*]"
schema = AudioFeaturesObject.schema
schema = AudioFeaturesObject.to_dict()
max_tracks = 100

def __init__(
Expand Down Expand Up @@ -122,14 +123,19 @@ class _UserTopTracksStream(_TracksStream, _UserTopItemsStream):
"""Define user top tracks stream."""

path = "/me/top/tracks"
schema = TrackObject.extend_with(Rank, SyncedAt, AudioFeaturesObject).schema
schema = th.PropertiesList(
*TrackObject,
*AudioFeaturesObject,
*Rank,
*SyncedAt,
).to_dict()


class _UserTopArtistsStream(_UserTopItemsStream):
"""Define user top artists stream."""

path = "/me/top/artists"
schema = ArtistObject.extend_with(Rank, SyncedAt).schema
schema = th.PropertiesList(*ArtistObject, *Rank, *SyncedAt).to_dict()


class UserTopTracksShortTermStream(
Expand Down Expand Up @@ -190,7 +196,12 @@ class _PlaylistTracksStream(_RankStream, _SyncedAtStream, _TracksStream):
"""Define playlist tracks stream."""

records_jsonpath = "$.tracks.items[*].track"
schema = TrackObject.extend_with(Rank, SyncedAt, AudioFeaturesObject).schema
schema = th.PropertiesList(
*TrackObject,
*AudioFeaturesObject,
*Rank,
*SyncedAt,
).to_dict()
primary_keys = ("rank", "synced_at")

def parse_response(self, response):
Expand Down Expand Up @@ -230,5 +241,5 @@ class UserSavedTracksStream(_SyncedAtStream, SpotifyStream):
path = "/me/tracks"
primary_keys = ("id", "synced_at")
limit = 50
schema = TrackObject.extend_with(SyncedAt).schema
schema = th.PropertiesList(*TrackObject, *SyncedAt).to_dict()
records_jsonpath = "$.items[*].track"

0 comments on commit 89e6529

Please sign in to comment.