Sha256: 271776bd244e8c32a0de38968d6f1bb250857e4869cfc26431b6e0372060ed56

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

module ItunesApi
  module Music
    module Requests
      # Allows querying the API via lookup for albums.
      class Albums
        include Request
        attr_reader_init :apple_id, :store
        selfie :find_by_apple_id

        def find_by_apple_id
          unwrapped_results.map do |result|
            Results::Album.new(result, store)
          end
        end

        private

        def action
          'lookup'
        end

        def query
          {
            id: apple_id,
            country: store.to_s.upcase,
            entity: :album,
            limit: LIMIT
          }
        end

        def unwrapped_results
          return [] unless results.any?

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itunes_api-2.0.0 lib/itunes_api/music/requests/albums.rb