Class: AppleMusic::Song
- Defined in:
- lib/apple_music/song.rb,
lib/apple_music/song/attributes.rb,
lib/apple_music/song/relationships.rb
Overview
Defined Under Namespace
Classes: Attributes, Relationships
Constant Summary
Constants inherited from Resource
Instance Attribute Summary
Attributes inherited from Resource
#attributes, #href, #id, #relationships, #type
Class Method Summary collapse
-
.find(id, **options) ⇒ Object
e.g.
-
.get_collection_by_ids(ids, **options) ⇒ Object
e.g.
-
.get_collection_by_isrc(isrc, **options) ⇒ Object
e.g.
-
.get_relationship(id, relationship_type, **options) ⇒ Object
e.g.
-
.list(**options) ⇒ Object
e.g.
-
.related_albums(id, **options) ⇒ Object
e.g.
-
.related_artists(id, **options) ⇒ Object
e.g.
-
.related_genres(id, **options) ⇒ Object
e.g.
-
.related_station(id, **options) ⇒ Object
e.g.
- .search(term, **options) ⇒ Object
Methods inherited from Resource
Constructor Details
This class inherits a constructor from AppleMusic::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class AppleMusic::Resource
Class Method Details
.find(id, **options) ⇒ Object
e.g. AppleMusic::Song.find(900032829) developer.apple.com/documentation/applemusicapi/get_a_catalog_song
9 10 11 12 13 |
# File 'lib/apple_music/song.rb', line 9 def find(id, **) storefront = Storefront.lookup(.delete(:storefront)) response = AppleMusic.get("catalog/#{storefront}/songs/#{id}", ) Response.new(response.body).data.first end |
.get_collection_by_ids(ids, **options) ⇒ Object
e.g. AppleMusic::Song.get_collection_by_ids([203709340, 201281527]) developer.apple.com/documentation/applemusicapi/get_multiple_catalog_songs_by_id
29 30 31 32 33 34 |
# File 'lib/apple_music/song.rb', line 29 def get_collection_by_ids(ids, **) ids = ids.is_a?(Array) ? ids.join(',') : ids storefront = Storefront.lookup(.delete(:storefront)) response = AppleMusic.get("catalog/#{storefront}/songs", .merge(ids: ids)) Response.new(response.body).data end |
.get_collection_by_isrc(isrc, **options) ⇒ Object
e.g. AppleMusic::Song.get_collection_by_isrc(‘NLH851300057’) developer.apple.com/documentation/applemusicapi/get_multiple_catalog_songs_by_isrc
38 39 40 41 42 43 |
# File 'lib/apple_music/song.rb', line 38 def get_collection_by_isrc(isrc, **) isrc = isrc.is_a?(Array) ? isrc.join(',') : isrc storefront = Storefront.lookup(.delete(:storefront)) response = AppleMusic.get("catalog/#{storefront}/songs", .merge('filter[isrc]': isrc)) Response.new(response.body).data end |
.get_relationship(id, relationship_type, **options) ⇒ Object
e.g. AppleMusic::Song.get_relationship(900032829, :albums) developer.apple.com/documentation/applemusicapi/get_a_catalog_song_s_relationship_directly_by_name
47 48 49 50 51 |
# File 'lib/apple_music/song.rb', line 47 def get_relationship(id, relationship_type, **) storefront = Storefront.lookup(.delete(:storefront)) response = AppleMusic.get("catalog/#{storefront}/songs/#{id}/#{relationship_type}", ) Response.new(response.body).data end |
.list(**options) ⇒ Object
e.g. AppleMusic::Song.list(ids: ‘203709340,201281527’) e.g. AppleMusic::Song.list(isrc: ‘NLH851300057’)
17 18 19 20 21 22 23 24 25 |
# File 'lib/apple_music/song.rb', line 17 def list(**) if [:ids] get_collection_by_ids(.delete(:ids), ) elsif [:isrc] get_collection_by_isrc(.delete(:isrc), ) else raise ParameterMissing, 'required parameter :ids or :isrc is missing' end end |
.related_albums(id, **options) ⇒ Object
e.g. AppleMusic::Song.related_albums(900032829)
54 55 56 |
# File 'lib/apple_music/song.rb', line 54 def (id, **) get_relationship(id, :albums, ) end |
.related_artists(id, **options) ⇒ Object
e.g. AppleMusic::Song.related_artists(900032829)
59 60 61 |
# File 'lib/apple_music/song.rb', line 59 def (id, **) get_relationship(id, :artists, ) end |
.related_genres(id, **options) ⇒ Object
e.g. AppleMusic::Song.related_genres(900032829)
64 65 66 |
# File 'lib/apple_music/song.rb', line 64 def (id, **) get_relationship(id, :genres, ) end |
.related_station(id, **options) ⇒ Object
e.g. AppleMusic::Song.related_station(900032829)
69 70 71 |
# File 'lib/apple_music/song.rb', line 69 def (id, **) get_relationship(id, :station, ).first end |
.search(term, **options) ⇒ Object
73 74 75 |
# File 'lib/apple_music/song.rb', line 73 def search(term, **) AppleMusic.search(**.merge(term: term, types: :songs)).songs end |