Class: UnderFire::AlbumSearch

Inherits:
BaseQuery show all
Defined in:
lib/under_fire/album_search.rb

Overview

Builds XML for Gracenote’s ALBUM_SEARCH query.

Examples:

search = UnderFire::AlbumSearch.new(:artist => 'Radiohead')
search.query #=> XML for Gracenote ALBUM_SEARCH query for albums by Radiohead.

search = UnderFire::AlbumSearch.new(:track_title = > 'Paranoid Android',
                                    :artist => 'Radiohead',
                                    :mode => 'SINGLE_BEST_COVER')
search.query #=> XML for ALBUM_SEARCH

See Also:

Instance Attribute Summary collapse

Attributes inherited from BaseQuery

#config, #mode

Instance Method Summary collapse

Methods inherited from BaseQuery

#build_base_query

Constructor Details

#initialize(args = {}) ⇒ AlbumSearch

At least one of :artist, :track_title, :album_title is required (:mode is optional).

Parameters:

  • args (Hash) (defaults to: {})

    the arguments for an Album_Search.

Options Hash (args):

  • :artist (String)

    Name of the artist.

  • :track_title (String)

    Name of the song/track.

  • :album_title (String)

    Name of the album.

  • :mode (String)

    Either ‘SINGLE_BEST’ or ‘SINGLE_BEST_COVER’



42
43
44
45
46
47
# File 'lib/under_fire/album_search.rb', line 42

def initialize(args={})
  super args[:mode]
  @parameters = args.reject {|k,v| k == :mode}
  parameters.each do |k,v| send("#{k}=", v) end
  @query = build_query
end

Instance Attribute Details

#album_titleString

Returns:

  • (String)


33
34
35
# File 'lib/under_fire/album_search.rb', line 33

def album_title
  @album_title
end

#artistString

Returns:

  • (String)


27
28
29
# File 'lib/under_fire/album_search.rb', line 27

def artist
  @artist
end

#parametersHash (readonly)

Returns search parameters without :mode.

Returns:

  • (Hash)

    search parameters without :mode



24
25
26
# File 'lib/under_fire/album_search.rb', line 24

def parameters
  @parameters
end

#queryString (readonly)

Returns XML string for query.

Returns:

  • (String)

    XML string for query.



21
22
23
# File 'lib/under_fire/album_search.rb', line 21

def query
  @query
end

#track_titleString

Returns:

  • (String)


30
31
32
# File 'lib/under_fire/album_search.rb', line 30

def track_title
  @track_title
end

Instance Method Details

#build_queryString

Builds ALBUM_SEARCH-specific part of ALBUM_SEARCH query and adds it to the base query common to all query types. Called by constructor.

Returns:

  • (String)

    XML string for ALBUM_SEARCH query.



53
54
55
56
57
58
59
60
61
62
# File 'lib/under_fire/album_search.rb', line 53

def build_query
  build_base_query do |builder|
    builder.QUERY(CMD: "ALBUM_SEARCH"){
      builder.MODE "SINGLE_BEST_COVER"
      parameters.each do |k,v|
        builder.TEXT(v, TYPE: k.to_s.upcase)
      end
    }
  end
end