Sha256: acc84e3c5767e6d1c744b5595cb591308647cf5d63bc7798e3eb4ac136439d0a

Contents?: true

Size: 877 Bytes

Versions: 2

Compression:

Stored size: 877 Bytes

Contents

module ItunesApi
  module Music
    module Requests
      # Allows querying the API via lookup for album songs.
      class Songs
        include Request
        attr_reader_init :collection_id, :store
        selfie :find_by_collection_id

        def find_by_collection_id
          unwrapped_results.map do |result|
            Results::Song.new(result)
          end
        end

        private

        def action
          'lookup'
        end

        def query
          {
            entity: 'song',
            id: collection_id,
            country: store.to_s.upcase,
            limit: LIMIT,
            sort: 'trackNumber'
          }
        end

        def unwrapped_results
          return [] unless results.any?

          results.find_all do |wrappers|
            wrappers['wrapperType'] == 'track'
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itunes_api-2.1.0 lib/itunes_api/music/requests/songs.rb
itunes_api-2.0.0 lib/itunes_api/music/requests/songs.rb