class MetalArchives::Artist
Represents a single performer (but not a solo artist)
Attributes
Returns Array of String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns Array of Hash containing the following keys
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns raw HTML String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns ISO3166::Country
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns NilDate
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns NilDate
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns Symbol, either :male or :female
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns Integer
Returns Array of Hash containing the following keys
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
links-
:url:String -
:type:Symbol, either:official,:unofficialor:unlisted_bands -
:title:String
-
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns URI (rewritten if config option was enabled)
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Returns raw HTML String
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404)
Protected Class Methods
Get all artists
Returns Collection of Artist
- Raises
-
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 -
MetalArchives::Errors::ParserErrorwhen parsing failed. Please report this error.
# File lib/metal_archives/models/artist.rb, line 359 def all search "" end
Find by ID
Returns Artist, even when ID is invalid (because the data is lazily fetched)
id-
Integer
# File lib/metal_archives/models/artist.rb, line 222 def find(id) return cache[id] if cache.include? id Artist.new id: id end
Find by ID (no lazy loading)
Returns Artist
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 (except 404) -
MetalArchives::Errors::ParserErrorwhen parsing failed. Please report this error.
id-
Integer
# File lib/metal_archives/models/artist.rb, line 241 def find!(id) obj = find id obj.load! if obj && !obj.loaded? obj end
Find by attributes
Returns Artist or nil when no results
- Raises
-
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 -
MetalArchives::Errors::ParserErrorwhen parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentErrorwhen query contains no :name key
query-
Hash containing one or more of the following keys:
-
:name:String
-
# File lib/metal_archives/models/artist.rb, line 262 def find_by(query) raise MetalArchives::Errors::ArgumentError unless query.include? :name url = "#{MetalArchives.config.default_endpoint}search/ajax-artist-search/" params = Parsers::Artist.map_params query response = HTTPClient.get url, params json = JSON.parse response.body return nil if json["aaData"].empty? data = json["aaData"].first id = Nokogiri::HTML(data.first).xpath("//a/@href").first.value.delete('\\').split("/").last.gsub(/\D/, "").to_i find id end
Find by attributes (no lazy loading)
Returns Artist or nil when no results
- Raises
-
MetalArchives::Errors::InvalidIDErrorwhen no or invalid id -
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 -
MetalArchives::Errors::ParserErrorwhen parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentErrorwhen query contains no :name key
query-
Hash containing one or more of the following keys:
-
:name:String
-
# File lib/metal_archives/models/artist.rb, line 294 def find_by!(query) obj = find_by query obj.load! if obj && !obj.loaded? obj end
Search by name
Returns Collection of Artist
- Raises
-
MetalArchives::Errors::APIErrorwhen receiving a status code >= 400 -
MetalArchives::Errors::ParserErrorwhen parsing failed. Please report this error. -
MetalArchives::Errors::ArgumentErrorwhennameisn't aString
name-
String
# File lib/metal_archives/models/artist.rb, line 314 def search(name) raise MetalArchives::Errors::ArgumentError unless name.is_a? String url = "#{MetalArchives.config.default_endpoint}search/ajax-artist-search/" query = { name: name } params = Parsers::Artist.map_params query l = lambda do @start ||= 0 if @max_items && @start >= @max_items [] else response = HTTPClient.get url, params.merge(iDisplayStart: @start) json = JSON.parse response.body @max_items = json["iTotalRecords"] objects = [] json["aaData"].each do |data| # Create Artist object for every ID in the results list id = Nokogiri::HTML(data.first).xpath("//a/@href").first.value.delete('\\').split("/").last.gsub(/\D/, "").to_i objects << Artist.find(id) end @start += 200 objects end end MetalArchives::Collection.new l end